This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard.py
executable file
·54 lines (44 loc) · 1.62 KB
/
keyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#! /usr/bin/python3
"""Simulate keyboard inputs for the moves by one side."""
# LiBoard
# Copyright (C) 2021 Philipp Leclercq
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import argparse
import chess
import chess.pgn
import liboard
import pyautogui
from liboard import LiBoard
def main(_args: argparse.Namespace):
board = LiBoard(_args.port, _args.baud_rate, _args.move_delay)
@board.start_handler
def print_start(_board: LiBoard) -> bool:
print("New game.")
return False
@board.move_handler
def print_move(_board: LiBoard, _move: chess.Move) -> bool:
print(_move)
if bool(_board.chessboard.ply() % 2) != args.side:
pyautogui.write(str(_move))
return False
while True:
board.update()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__, parents=[liboard.ARGUMENT_PARSER])
parser.add_argument('-B', '--black', action='store_const', dest='side', default=0, const=1, help='Play as black')
args = parser.parse_args()
try:
main(args)
except KeyboardInterrupt:
pass