Thursday, December 17, 2009


Imagine we are in such a good mood that we forget all our sorrows, make big business, and one day we notice that our earth isn't very well. We better had implemented undo so that the tropic rain forest is up and fossil oil is down again...

that's one of the hard parts with undo: the consequences of your action must be undoable. the second is not to forget anything.

What are the consequences of playing a card? you tap your lands, pay the costs, and put the spell on the stack. so to reverse that, is it enough to take the card back and untap your lands? in very certain cases, maybe, but not generally. a single triggered ability might crash your concept. there might even be abilities that triggered from untapping lands, because of the undo!

the second point is the other side of the same medal. if you view a triggered ability not as the consequence of playing a spell, but a different thing, the matter goes from "undoing all consequences" to "not overseeing other actions caused by playing the spell". while it effectively means the same - really going back to that same state - it's good to see the different aspects

in my opinion, the deeper you look into the game, the easier it is not to forget an action. if you have looked into the comprehensive rules a few times, you can notice how detailed everything is, timestamps, priority and so on. if we don't only look at huge things:
  • play a card, triggering an ability
but at the small ones:
  • tap the land for mana
  • an ability triggers
  • the ability is put on the stack
  • you receive priority again
all these are very small actions that are easily undone, and multiple actions are grouped into bigger ones, like playing a spell (and everything that happened in between), declaring attackers, a full phase, and turns. This way, you can quickly choose what you want to undo.


nantuko84 said...

yep, I'm starting to realize that I have to find all such small pieces that changes game state and make undo only for them.
it is more or less easy for game actions as all handled now by GameManager. but this is not true for permanent states, as they can be changed directly from card implementation. so I have
GameManager.dealDamage(target, 2, source) instead of card.addDamage(2) - that is good

but still have card.addAttack(3) or card.addKeyword(KEYWORD_HASTE)

now I think whether I should add methods to GameManager and restrict changing attributes directly

Bruno Cardoso said...

Is it really necessary to undo everything?

One of the skillful aspect of MTG is the fact that you don't do mistake. If you play at a tournament, your opponent won't let you undo anything you do and even while playtesting, undoing influenciates the flow of the game. I played MTGO for a while and I never missed an undo feature.

The only undo action I think it's acceptable is the mana tapping but even that, if the rules says you can't untapped, then you can't.

About replays, i would probably only record the actions that were peformed. In the same way you have the GUI, Player and Network that interacts with the rules engine API, you will also have a 4th actor called Replay that will do the same thing.

Well, it just my view on things...

So... in the end I think the "undo" feature is really questionable.

Silly Freak said...

implementing undo and enabling the user to undo are two different things ;)
for example, I use undo to rollback the state if a plaer fails to play a spell. say, he can't pay the mana cost. undo is also very helpful for AI searching.

Nonetheless, I think undo is a feature that could be enabled for the user, at least in single-player games, and depending on how good and fault-proof the UI is ;)

replaying is a feature that comes easily from undo, and only recording actions or also how they are reversed doesn't make that much of a difference

I have still problems figuring out networking. Edits depend on the object they edit, but there is a separate one on the remote side...