def testNonWins(self): for non_win in self.non_wins: for playerId in range(2): b = GameBoard() for move in non_win: # move player b.makeMove(move, playerId) # move opponent for cell in b.getEmptyCells(): if cell not in non_win: b.makeMove(cell, range(2)[playerId-1]) break self.assertEqual(False, b.checkForWin(playerId)) # test opponent non-wins for non_win in self.non_wins: for playerId in range(2): b = GameBoard() for move in non_win: # move player for cell in b.getEmptyCells(): if cell not in non_win: b.makeMove(cell, playerId) break # move opponent b.makeMove(move, range(2)[playerId-1]) self.assertEqual(False, b.checkForWin(range(2)[playerId-1]))
def testDefaultWins(self): for win in self.wins: for playerId in range(2): b = GameBoard() for move in win: # move player b.makeMove(move, playerId) # move opponent for cell in b.getEmptyCells(): if cell not in win: b.makeMove(cell, range(2)[playerId-1]) break self.assertEqual(True, b.checkForWin(playerId)) # test opponent wins for win in self.wins: for playerId in range(2): b = GameBoard() for move in win: # move player for cell in b.getEmptyCells(): if cell not in win: b.makeMove(cell, playerId) break # move opponenet b.makeMove(move, range(2)[playerId-1]) self.assertEqual(True, b.checkForWin(range(2)[playerId-1]))
def testComputerNeverLoses(self): board = GameBoard() self.count = 0 for cell in board.getEmptyCells(): self._makeMove(board, cell) # computer makes first move for cell in board.getEmptyCells(): board.makeMove(cell, game.ID_COMPUTER) for cell in board.getEmptyCells(): self._makeMove(board, cell)
def testEmptyCellCount(self): for playerId in range(2): b = GameBoard() for cellCountShouldBe in (9,8,7,6,5,4,3,2,1,0): self.assertEquals(len(b.getEmptyCells()), cellCountShouldBe) if cellCountShouldBe > 0: b.makeMove(b.getEmptyCells()[0], playerId)
def testInitialEmptyCellCount(self): b = GameBoard() self.assertEqual(len(b.getEmptyCells()), 9)
def testMoveEmptyCellsByCell(self): for playerId in range(2): b = GameBoard() for cell in b.getEmptyCells(): b.makeMove(cell, playerId)