Version 2 code suggestions
by mtgrares
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Re: Version 2 code suggestions
by Incantus » 27 May 2009, 01:31
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.Rob Cashwalker wrote: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?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.
Re: Version 2 code suggestions
by mtgrares » 29 May 2009, 17:46
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.There are cryptographic solutions to the peeking problem (look up mental poker) but I don't understand them.
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
17 posts
• Page 2 of 2 • 1, 2
Who is online
Users browsing this forum: Bing [Bot] and 80 guests