Beispiel #1
0
    def test_should_pick_random_if_no_win_option_for_player_opponent(self):
        board = TicTacBoard(3)
        game = Game(board, Difficult_level.HARD)
        board.place_position((1, 1), "X")
        board.place_position((2, 2), "O")
        bot_medium_playable = BotHardPlayable()

        with mock.patch('random.choice', self.choice1000):
            self.assertEqual(
                bot_medium_playable.make_next_move(game, "X", "O"), (0, 1))
    def test_should_move_to_random_position_without_blocking_win(self):
        board = TicTacBoard(3)
        game = Game(board, Difficult_level.EASY)
        bot_easy_playable = BotEasyPlayable()

        with mock.patch('random.choice', self.choice1000):
            self.assertEqual(bot_easy_playable.make_next_move(game, "X", "O"),
                             (2, 2))
Beispiel #3
0
    def test_should_identify_winning_position_if_there_is_a_win(self):
        board = TicTacBoard(3)
        game = Game(board, Difficult_level.MEDIUM)
        board.place_position((1,1), "X")
        board.place_position((2,2), "O")
        board.place_position((1,0), "X")
        board.place_position((1,2), "O")
        board.place_position((2,1), "X")
        bot_medium_playable = BotMediumPlayable()

        self.assertEqual(bot_medium_playable.make_next_move(game, "X", "O"), (0,2))
Beispiel #4
0
    def test_should_block_opponents_win_if_opponent_has_chance_to_win(self):
        board = TicTacBoard(3)
        game = Game(board, Difficult_level.HARD)
        board.place_position((1, 1), "O")
        board.place_position((2, 2), "X")
        board.place_position((1, 0), "O")
        board.place_position((1, 2), "X")
        board.place_position((2, 1), "O")
        bot_medium_playable = BotHardPlayable()

        self.assertEqual(bot_medium_playable.make_next_move(game, "O", "X"),
                         (0, 2))
Beispiel #5
0
    def test_should_pick_random_if(self):
        board = TicTacBoard(3)
        game = Game(board, Difficult_level.MEDIUM)
        board.place_position((1,1), "X")
        board.place_position((2,2), "O")
        board.place_position((1,0), "X")
        board.place_position((0,0), "O")
        board.place_position((2,1), "X")
        bot_medium_playable = BotMediumPlayable()

        with mock.patch('random.choice', self.choice1000):
           self.assertEqual(bot_medium_playable.make_next_move(game, "X", "O"), (0,1))
Beispiel #6
0
 def test_game_failure_if_straight_continous_blocks(self):
     board = TicTacBoard(3)
     game = Game(board, Difficult_level.MEDIUM)
     board.place_position((0, 0), "O")
     board.place_position((0, 1), "X")
     board.place_position((0, 2), "O")
     self.assertEqual(game.is_completed_with_win(board.grid), DRAW)
Beispiel #7
0
 def test_game_over_if_reverse_diagnol_continous_block(self):
     board = TicTacBoard(3)
     game = Game(board, Difficult_level.MEDIUM)
     board.place_position((1, 1), "X")
     board.place_position((0, 2), "X")
     board.place_position((2, 0), "X")
     self.assertEqual(game.is_completed_with_win(board.grid), X_WINS)
 def test_validate_move_position(self):
     #Todo move this to setup
     board = TicTacBoard(3)
     isValid = board.place_position((0, -1), "X")
     self.assertFalse(isValid)
 def test_create_an_empty_tictactoe_board(self):
     board = TicTacBoard(3)
     self.assertIsNotNone(board)
 def test_if_item_position_in_open_position(self):
     board = TicTacBoard(3)
     board.place_position((0, 0), "X")
     self.assertFalse(board.is_position_valid((0, 0)))
 def test_if_item_position_in_open_position(self):
     board = TicTacBoard(3)
     self.assertTrue(board.is_position_valid((0, 0)))
 def test_place_item_in_position_if_valid(self):
     board = TicTacBoard(3)
     isValid = board.place_position((1, 1), "X")
     self.assertTrue(isValid)
Beispiel #13
0
 def test_check_if_game_is_over(self):
     board = TicTacBoard(3)
     game = Game(board, Difficult_level.MEDIUM)
     self.assertFalse(game.is_over())