Esempio n. 1
0
 def test_victory_via_no_moves(self):
     # make a board full of the same tile
     pieces = [[tile(0, 0) for i in range(4)] for j in range(4)]
     # set the Previous Tile to something incompatible
     board = Position(pieces, black(), tile(1, 1))
     # black to move, so red wins
     self.assertEqual(board.check_victory(), red())
     # now reverse the roles and check again
     board = Position(pieces, red(), tile(1, 1))
     self.assertEqual(board.check_victory(), black())
Esempio n. 2
0
 def test_victory_via_no_moves(self):
     # make a board full of the same tile
     pieces = [[tile(0,0) for i in range(4)] for j in range(4)]
     # set the Previous Tile to something incompatible
     board = Position(pieces,black(),
                               tile(1,1))
     # black to move, so red wins
     self.assertEqual(board.check_victory(),red())
     # now reverse the roles and check again
     board = Position(pieces,red(),
                               tile(1,1))
     self.assertEqual(board.check_victory(),black())
Esempio n. 3
0
 def test_data_storage(self):
     pieces = self.pieces
     board = Position(pieces,red(),None)
     self.assertEqual(red(),board.whose_move())
     for i in range(4):
         for j in range(4):
             self.assertEqual(pieces[i][j],board.get_piece(i,j))
     p = pieces[2][3]
     for i in range(4):
         for j in range(4):
             pieces[i][j] = None
     self.assertEqual(p,board.get_piece(2,3))
Esempio n. 4
0
 def test_data_storage(self):
     pieces = self.pieces
     board = Position(pieces, red(), None)
     self.assertEqual(red(), board.whose_move())
     for i in range(4):
         for j in range(4):
             self.assertEqual(pieces[i][j], board.get_piece(i, j))
     p = pieces[2][3]
     for i in range(4):
         for j in range(4):
             pieces[i][j] = None
     self.assertEqual(p, board.get_piece(2, 3))
Esempio n. 5
0
 def test_configuration_victory(self):
     pieces = self.pieces
     # check a 2x2 block in the middle
     for i in range(1,3):
         for j in range(1,3):
             pieces[i][j] = player_piece(red())
     board = Position(pieces,black(),None)
     self.assertEqual(board.check_victory(),red())
     # now change the board so that black wins and red doesn't
     for i in range(4):
         pieces[i][i] = player_piece(black())
     # check that data is stored correctly
     self.assertEqual(board.check_victory(),red())
     # now check for real
     board = Position(pieces,black(),None)
     self.assertEqual(board.check_victory(),black())
Esempio n. 6
0
 def test_configuration_victory(self):
     pieces = self.pieces
     # check a 2x2 block in the middle
     for i in range(1, 3):
         for j in range(1, 3):
             pieces[i][j] = player_piece(red())
     board = Position(pieces, black(), None)
     self.assertEqual(board.check_victory(), red())
     # now change the board so that black wins and red doesn't
     for i in range(4):
         pieces[i][i] = player_piece(black())
     # check that data is stored correctly
     self.assertEqual(board.check_victory(), red())
     # now check for real
     board = Position(pieces, black(), None)
     self.assertEqual(board.check_victory(), black())
Esempio n. 7
0
 def test_doing_and_undoing(self):
     pieces = self.pieces
     board = Position(pieces, black(), None)
     move = Move(board, loc(0, 0))
     move.do()
     self.assertEqual(board.get_piece(0, 0), player_piece(black()))
     self.assertNotEqual(board.get_piece(0, 0), pieces[0][0])
     self.assertEqual(board.whose_move(), red())
     self.assertEqual(board.previous_piece, pieces[0][0])
     moves = board.get_moves()
     self.assertEqual(len(moves), 3 + 3)
     move.undo()
     self.assertEqual(board.get_piece(0, 0), pieces[0][0])
     self.assertEqual(board.previous_piece, None)
     self.assertEqual(board.whose_move(), black())
     moves = board.get_moves()
     self.assertEqual(len(moves), 4 * 4 - 2 * 2)
Esempio n. 8
0
 def test_doing_and_undoing(self):
     pieces = self.pieces
     board = Position(pieces,black(),None)
     move = Move(board,loc(0,0))
     move.do()
     self.assertEqual(board.get_piece(0,0),
                      player_piece(black()))
     self.assertNotEqual(board.get_piece(0,0),pieces[0][0])
     self.assertEqual(board.whose_move(),red())
     self.assertEqual(board.previous_piece,pieces[0][0])
     moves = board.get_moves()
     self.assertEqual(len(moves),3+3)
     move.undo()
     self.assertEqual(board.get_piece(0,0),pieces[0][0])
     self.assertEqual(board.previous_piece,None)
     self.assertEqual(board.whose_move(),black())
     moves = board.get_moves()
     self.assertEqual(len(moves),4*4-2*2)
Esempio n. 9
0
 def test_victory_values_distinct(self):
     self.assertNotEqual(red(),black())
     self.assertNotEqual(0,red())
     self.assertNotEqual(0,black())
Esempio n. 10
0
 def test_non_victory(self):
     pieces = self.pieces
     board = Position(pieces,red(),None)
     self.assertEqual(board.check_victory(),0)
Esempio n. 11
0
 def test_victory_values_distinct(self):
     self.assertNotEqual(red(), black())
     self.assertNotEqual(0, red())
     self.assertNotEqual(0, black())
Esempio n. 12
0
 def test_non_victory(self):
     pieces = self.pieces
     board = Position(pieces, red(), None)
     self.assertEqual(board.check_victory(), 0)