Dear all,

I've written a class State that subclasses tuple. The class has a method
move_state that takes a move and returns a new state object representing
the new state of the game.

I would expect S1 and S3 to be equal on the last line here, but they are
not.

>>> import game
>>> S = game.State()
>>> S1 = S.move_state(1).move_state("SWAP")
>>> S2 = S.move_state(1)
>>> S3 = S2.move_state("SWAP")
>>> S1 == S3
False

Printing the two states shows that they have very different internal states.

>>> print S1
 (8, 8, 8, 8, 8, 8, 0)
1                     0
 (7, 7, 7, 7, 7, 7, 7)
>>> print S3
 (7, 7, 7, 7, 7, 7, 7)
0                     1
 (0, 8, 8, 8, 8, 8, 8)

If anyone is interested, State represents the state of a 7 7 Kalah board.

The full code is on pastebin http://pastebin.com/tUh0W5Se

Are my expectations faulty? (I hope not)
Have I made some mistake in my code to get these results?

Thanks in advance,
Colin Caine
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to