-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.py
31 lines (29 loc) · 890 Bytes
/
board.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
import chess
import chess.engine
from blessed import Terminal
term = Terminal()
board = chess.Board("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
engine = chess.engine.SimpleEngine.popen_uci(
"./Stockfish-master/src/stockfish")
engine.close()
with term.cbreak(), term.hidden_cursor(), term.fullscreen():
move = ""
while True:
print(term.home + term.clear)
print(board)
print("enter move: " + move)
inp = term.inkey()
if inp.isdigit() or inp.isalpha():
move = move + inp
if inp.code == 263:
move = move[:-1]
if inp == 'q':
break
if inp.code == 343:
try:
x = chess.Move.from_uci(move)
if x in board.legal_moves:
board.push(x)
except ValueError:
pass
move = ""