-
Notifications
You must be signed in to change notification settings - Fork 0
/
textchess.py
executable file
·44 lines (35 loc) · 1.13 KB
/
textchess.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
#!/opt/local/bin/python
import sys
chess = r'/Users/marc/devtools/bin/stockfish'.split()['linux' in sys.platform]
import subprocess as S
getprompt = 'isready'
done= 'readyok'
proc= S.Popen(chess, stdin=S.PIPE, stdout=S.PIPE, bufsize=1, universal_newlines=True)
print(proc.stdout.readline().strip())
proc.stdin.write('uci\n')
while True :
text = proc.stdout.readline().strip()
print(text)
if text == "uciok":
break
print('Choose skill level (0-20):')
skillLevel=str(raw_input())
proc.stdin.write('setoption name Skill Level value '+skillLevel+'\n')
proc.stdin.write('ucinewgame\n')
moveList='position startpos moves '
checkmate=False
while checkmate==False:
print('Enter move:')
move=str(raw_input())
moveList=moveList+move+' '
proc.stdin.write(moveList+'\n')
#proc.stdin.write('go movetime 1000\n')
proc.stdin.write('go nodes 100000\n')
print('Computer moves:')
while True :
text = proc.stdout.readline().strip()
if text[0:8] == 'bestmove':
cpuMove=text[9:13]
print(cpuMove)
moveList=moveList+cpuMove+' '
break