Exemple #1
0
 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)
Exemple #2
0
 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))
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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)
Exemple #9
0
 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)
Exemple #10
0
 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))
Exemple #11
0
 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)
Exemple #12
0
 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)
Exemple #13
0
 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)