iosgame-centergamekitgkscore

iOS Game Center GKScore context, how to encode information?


I'm doing my first implementation with Game Center. I'm trying to let players issue GKScore challenges to one another. My game consists of playing a certain number of levels in a random order. (Let's say, a game is 9 levels long, randomly chosen from 30 possible levels.)

When the challenge is issued, I need to be able to include which levels the challenging player played so that the receiving player can play those same levels hopefully in the same order.

I know that I can include a GKScore.context : UInt64 which will get passed back to me, but I'm having trouble figuring out how best to encode my level information to get passed along and was hoping for some pointers toward examples or other solutions/best practices.

I know that I could use bitwise flags to encode which levels should be included in the 9-level-game, but I'm not sure how I could also include the order if I did that.

I know that I could use the GKScore.context to generate a random id number, upload the game info to my server, and then fetch it back down with that same identifier, but I really do NOT want to add a server component to this game which should run entirely on device. I don't want the server load nor the server code maintenance.

What other options have you used for transmitting challenge information with the GKScore.context without relying on a server component?


Solution

  • Generate a random value that will fit in 64-bits. Use that to seed a random number generator and produce whatever level numbers in whatever order you need. Save the seed as the context. For the challenged player, get the seed from the context info and initialize your random number generator with the same seed. You'll get the same sequence of "random" values and hence the same level numbers in the same order. The only network stuff will be through Game Center when it has to deliver the challenge.