tylerjw / badukpy

Baduk (aka Go) game in python
2 stars 2 forks source link

test_firstMove fails on asserting side #4

Closed sphaso closed 11 years ago

sphaso commented 11 years ago

test_firstMove plays a move on an empty board then asserts that side is WHITE. This test fails because (I guess) the side changes at the beginning of each move not at the end. Is this something we want? are other functions dependant on this behaviour?

tylerjw commented 11 years ago

The issue is not that they change sides, it is what your board reference points to.

Here is the code from the init method:

self.game = simple_go.Game(self.size)
self.board = simple_go.Board(self.size)

You have two different objects you are dealing with. When you make a move in Game object it does this:

  1. Checks to make sure the move is legal in current_board
  2. Makes a copy of current_board
  3. Appends the old current_board to the board history
  4. makes the move in the new current_board
  5. returns the current board.

I edited your code in test_firstMove to test the board returned by the Game.make_move operation:

def test_firstMove(self):
    pos = (3, 3)
    board = self.game.make_move(pos)
    self.assertEqual(self.game.current_board.goban[pos], simple_go.BLACK)
    # TOTHINK: side doesn't change until the next move? this fails'
    self.assertEqual(board.side, simple_go.WHITE)