mercredi 15 juin 2016

Objective C iOS puzzle game - Two random number generators with the same seed

TLDR;

Using Objective C I must randomly generate two puzzle boards at different time intervals using the same random seed. These numbers MUST be procedurally generated at the time either puzzle board needs them. This "time" could be different for either board. There is no pattern that tells when these time intervals may be for either puzzle board. Is there some way I could replicate the object that I know Java uses for this sort of problem? (Java has a "Random" object reference)

The full story;

I am working on a multiplayer iOS puzzle game. In my game the pieces on the puzzle board are randomly generated. You can play against another person online or against a computer and you can see both puzzle boards on the screen. In the situation where you play against the computer, the boards must be randomly generated on a single device. The trouble is that both boards must be absolutely balanced otherwise you could say "hey my opponent got a better board than me! no fair!". The boards in my puzzle game are super dynamic and modifiable and board pieces are generated very frequently, and at different time intervals for either puzzle board, because of it.

I did have the idea to allocate an array of bytes that would pre-roll all of the board pieces that could ever exist using srand(mySeed) and rand() (rand would be used repeatedly after seeding). Technically I could share this array with the opponent and then "procedurally generate" the board pieces using that array on both boards. This would make them balanced. The practical problem I have with this approach is how bad of a practice it is. It's absolutely horrible practice to assume the static length of an array regarding a dynamic quantity of data. This dynamic quantity is the amount of puzzle board pieces that will be generated on both puzzle boards for the life of the match. I do not want to use this method.

Most programmers have at-least "played around" with Java. Java actually has a Random object reference that allows you to seed the reference object and then call random number generating methods from it. In my head it sort of looks like if srand() and rand() were encapsulated into a single class. Is this something I could replicate in C?




Aucun commentaire:

Enregistrer un commentaire