def test_no_valid_moves(self): self.board[0, 0] = x self.board[0, 1] = o self.board[0, 2] = x self.board[1, 0] = x self.board[1, 1] = o self.board[1, 2] = o self.board[2, 0] = o self.board[2, 1] = x self.board[2, 2] = o with self.assertRaises(AssertionError): ttt.find_moves(self.board)
def test_wins_blocked(self): self.board[2, 0] = o self.board[2, 1] = o self.board[2, 2] = x (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(1, 1)) self.assertEqual(black_moves[0], ttt.Move(1, 1))
def test_x_place_to_win(self): self.board[0, 0] = x self.board[2, 2] = x (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(1, 1)) self.assertEqual(black_moves[0], ttt.Move(1, 1)) self.assertEqual(white_moves[0].power, 10) self.assertEqual(black_moves[0].power, 100)
def test_o_place_to_win(self): self.board[2, 0] = o self.board[2, 1] = o (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(2, 2)) self.assertEqual(black_moves[0], ttt.Move(2, 2)) self.assertEqual(white_moves[0].power, 100) self.assertEqual(black_moves[0].power, 10)
def test_another_off_one_win(self): self.board[0, 0] = o self.board[0, 1] = x self.board[1, 2] = x (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(1, 1)) self.assertEqual(black_moves[0], ttt.Move(1, 1)) self.assertEqual(white_moves[0].power, 5) self.assertEqual(black_moves[0].power, 6)
def test_one_from_win_move(self): self.board[0, 1] = o self.board[1, 2] = o self.board[1, 1] = x (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(0, 2)) self.assertEqual(black_moves[0], ttt.Move(0, 2)) self.assertEqual(white_moves[0].power, 6) self.assertEqual(black_moves[0].power, 5)
def test_same_win_square(self): self.board[0, 0] = x self.board[2, 2] = x self.board[1, 0] = o self.board[1, 2] = o (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(1, 1)) self.assertEqual(black_moves[0], ttt.Move(1, 1)) self.assertEqual(white_moves[0].power, 100) self.assertEqual(black_moves[0].power, 100)
def test_double_win_in_two(self): self.board[0, 1] = o self.board[1, 2] = o self.board[1, 0] = x self.board[2, 1] = x (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(0, 2)) self.assertEqual(black_moves[0], ttt.Move(2, 0)) self.assertEqual(white_moves[0].power, 6) self.assertEqual(black_moves[0].power, 6) self.assertEqual(white_moves[1], ttt.Move(2, 0)) self.assertEqual(black_moves[1], ttt.Move(0, 2)) self.assertEqual(white_moves[1].power, 5) self.assertEqual(black_moves[1].power, 5)
def test_already_won(self): self.board[1, 0] = x self.board[1, 1] = x self.board[1, 2] = x with self.assertRaises(ValueError): ttt.find_moves(self.board)
def test_no_wins(self): (white_moves, black_moves) = ttt.find_moves(self.board) self.assertEqual(white_moves[0], ttt.Move(1, 1)) self.assertEqual(black_moves[0], ttt.Move(1, 1))
def test_nominal(self): board = np.array([[x, n, n], [n, o, n], [n, o, n]], dtype=int) ttt.plot_board(self.ax, board) (o_moves, x_moves) = ttt.find_moves(board) ttt.plot_powers(self.ax, board, o_moves, x_moves)
def test_shared_wins(self): board = np.array([[x, n, o], [n, n, n], [o, n, x]], dtype=int) (o_moves, x_moves) = ttt.find_moves(board) ttt.plot_possible_win(self.ax, o_moves, x_moves)
def test_all_out_wins(self): board = np.array([[x, x, n], [n, n, n], [o, o, n]], dtype=int) (o_moves, x_moves) = ttt.find_moves(board) ttt.plot_possible_win(self.ax, o_moves, x_moves)