It is currently 24 Apr 2024, 06:55
   
Text Size

Version 2 code suggestions

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Re: Version 2 code suggestions

Postby Incantus » 27 May 2009, 01:31

Rob Cashwalker wrote:
mtgrares wrote:The idea is that only the Command objects have to be serialiazable, I think it is similar to your Tie Fighter game (if I have the right person). Only the actions are recorded and everything else works how it should.
This doesn't make sense. The game state would have to include primarily Card Objects and CardList Objects, and probably a few others. TIE Fighter and X-Wing save an initial set of data for each object in the game (Cards and CardLists) and then every action that occurs to each object (Commands). Unless you were to save a game while there were effects on the stack, which would mean that the Ability objects currently on the stack would need to be saved too. And what if you were to save the game in the middle of the computer analyzing the board position... now you have to save AI objects... or something. See where this is going?
Actually, mtgrares has the right idea. Magic is deterministic (well, once you've initialized the random number generator), so if you save the seed and starting decks, and the actions each player takes, you can replay any game (this is what Incantus does). Incidentally, this also makes network play fairly easy (since instead of saving the actions to disk, you just pass them to the other player). Basically each client runs the full state of the game, and gets one set of actions from the GUI and one set from the network (the other player). This does lead to possible peeking problems, but the nice thing is that the game doesn't require an extra server (games are p2p). There are cryptographic solutions to the peeking problem (look up mental poker) but I don't understand them.
Incantus
DEVELOPER
 
Posts: 267
Joined: 29 May 2008, 15:53
Has thanked: 0 time
Been thanked: 3 times

Re: Version 2 code suggestions

Postby mtgrares » 29 May 2009, 17:46

There are cryptographic solutions to the peeking problem (look up mental poker) but I don't understand them.
Don't worry about not understand mental poker, I don't get it either. Technically someone could hack your program and see some extra hidden information but practically it doesn't seem to be a big deal. It seems very unlikely to happen because no money is involved.

Rob, about Magic's randomness, everything would just have to use one Random object and you can "seed" it so it would always generate the same numbers. While I don't know all of the details, I think it makes sense somewhere in the back of my head. This is a sample of shuffling a player's library. This code isn't perfect but it gives you the right idea.

Code: Select all
UndoCommand
{
  int state;

  public void execute()
  {
    library = get players library;
    state = get the current state of random number generator
    library.shuffle(random number generator)
  }

  public void undo()
  {
    library = get players library;
    set random number generator using state
    list.unshuffle(random number generator)
  }
}
mtgrares
DEVELOPER
 
Posts: 1352
Joined: 08 Sep 2008, 22:10
Has thanked: 3 times
Been thanked: 12 times

Previous

Return to Forge

Who is online

Users browsing this forum: Bing [Bot] and 80 guests


Who is online

In total there are 81 users online :: 1 registered, 0 hidden and 80 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: Bing [Bot] and 80 guests

Login Form