def test_give_to_chess_library(self, fn):
        initial_pos = ChessPosition("b", 4)
        final_pos = ChessPosition("c", 1)
        chessMove = ChessMove(initial_pos, final_pos)
        self.game_loop.give_to_chess_library(initial_pos, final_pos)

        fn.assert_called_once_with(chessMove)
    def test_gather_user_input(self, input_checker):
        result = self.game_loop.gather_user_input()
        initial_pos = ChessPosition("b", 4)
        final_pos = ChessPosition("c", 5)
        chessMove = ChessMove(initial_pos, final_pos)

        self.assertEqual(result, chessMove)
    def test_get_move(self):
        command = FakeEngineCommand()
        self.chess_library.engine.go = MagicMock(return_value=command)

        bm = self.chess_library.get_move()

        x = ChessMove(ChessPosition("e", 2), ChessPosition("e", 4))

        self.assertEquals(x.__str__(), bm.__str__())
    def test_show_opponent_move(self, turn_on_led_checker,
                                start_blinking_led_checker):
        initial_pos = ChessPosition("b", 4)
        final_pos = ChessPosition("c", 1)
        chessMove = ChessMove(initial_pos, final_pos)

        self.game_loop.show_opponent_move(initial_pos, final_pos)

        turn_on_led_checker.assert_called_with(initial_pos)
        start_blinking_led_checker.assert_called_with(final_pos, 1)
    def test_get_opponent_move(self):
        initial_pos = ChessPosition("b", 4)
        final_pos = ChessPosition("c", 1)
        chessMove = ChessMove(initial_pos, final_pos)

        self.game_loop.chess_library.get_move = MagicMock(
            return_value=chessMove)

        opponentMove = self.game_loop.get_opponent_move_from_library()

        self.assertEqual(chessMove, opponentMove)
    def test_gather_user_input_initial_check(self, input_checker):
        self.game_loop.lcd_interface.display = MagicMock()
        result = self.game_loop.gather_user_input()

        self.game_loop.lcd_interface.display.assert_called_once_with(
            "Incorrect initial coordinate, try again.", "")

        initial_pos = ChessPosition("b", 4)
        final_pos = ChessPosition("c", 5)
        chessMove = ChessMove(initial_pos, final_pos)

        self.assertEqual(result, chessMove)
    def test_hand_off(self):
        initial = ChessPosition("e", 2)
        final = ChessPosition("e", 4)
        move = ChessMove(initial, final)

        self.chess_library.board.push_uci = MagicMock()
        self.chess_library.engine.position = MagicMock()

        self.chess_library.hand_off(move)

        self.chess_library.board.push_uci.assert_called_with(move.__str__())
        self.chess_library.engine.position.assert_called_with(
            self.chess_library.board)
Exemple #8
0
    def get_move(self):
        command = self.engine.go(movetime=2000, async_callback=True)
        best_move, ponder = command.result()
        bm = str(best_move)

        # Converts UCI protocol to ChessPosition via slicing
        init = ChessPosition(str(bm[:1]), int(bm[1:-2]))
        final = ChessPosition(str(bm[2:-1]), int(bm[3:]))

        move = ChessMove(init, final)

        self.board.push_uci(str(move))
        return move
Exemple #9
0
    def gather_user_input(self, prompt):
        while not self.new_game_on_exit:
            while True:
                self.lcd_interface.display(prompt, "position")
                user_input = self.lcd_input(prompt, "position")

                if user_input == "pause":
                    self.pause()
                    if self.new_game_on_exit:
                        return
                else:
                    break
            try:
                col = user_input[0]
                row = int(user_input[1])

                position = ChessPosition(col, row)
                return position
            except ValueError:
                self.lcd_interface.display("Bad move", "Try again")
                input()
            except IndexError:
                self.lcd_interface.display("Bad move", "Try again")
                input()
Exemple #10
0
    def test_turn_on_led(self):
        pos = ChessPosition("b", 4)
        self.led_interface.turn_on_led(pos)

        self.assert_equals(True, True)