forked from JasonVBN/ChessBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_console.py
More file actions
55 lines (46 loc) · 1.33 KB
/
main_console.py
File metadata and controls
55 lines (46 loc) · 1.33 KB
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
55
import time
import numpy as np
from Board3 import Board
from Engine import Engine
from Move import Move
DEPTH = 3
COLOR = input("Computer color (w or b): ")
assert COLOR in ['w','b']
board = Board()
print(board)
eng = Engine(board)
def coord2tup(coord: str):
assert len(coord)==2
c,r = coord
return (8-int(r), ord(c)-ord('a'))
lastmove = Move()
lastcap = None
while True:
print(f"\ncalculating for depth {DEPTH}...")
print("current eval:",board.evaluation())
startTime = time.time()
bestEval,move,line = eng.bestMoveInX(COLOR,DEPTH)
print(f"engine move: {move} | eval with depth {DEPTH}: {bestEval}")
elapsedTime = time.time()-startTime
print(f"computing time: {elapsedTime}")
board.move(move)
print(board)
ipt = input("Enter START square: ")
if ipt == 'undo':
board.undo(lastmove, lastcap)
print(board)
print(board.kingPos)
continue
start = coord2tup(ipt)
legal = board.squaresSeenFrom(start)
print("legal moves:", legal)
ipt = input("Enter DEST square: ")
dest = coord2tup(ipt)
while dest not in legal:
print("not a legal move!")
ipt = input("Enter DEST square: ")
dest = coord2tup(ipt)
lastcap = board.move(Move(start, dest))
lastmove.start, lastmove.dest = start, dest
print(board)
print(board.kingPos)