-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
154 lines (128 loc) · 3.43 KB
/
main.py
File metadata and controls
154 lines (128 loc) · 3.43 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
"""
OKAY! Grand plans here!
Here's what we need:
if my turn:
Parse input
first function in rust:
update FEN
Zobrist hash it
put current position in first index in TT
put opponent position in last index in TT
recursively call function in rust:
generate legal moves:
use magic bitboard to find legal moves
find best move:
look at captures first
then suggested moves
then previous best
then rest
Zobrist hash it
check if in TT.
if so, retrieve values.
if not
call eval calculator
store it if index is free
if index is filled and depth is greater, overwrite it
return best move
if not my turn:
do recursive rust function:
increase depth search for best values
white
None 10.0 10.0 FEN
<move>
A 9.6
<opp move> 9.6 9.1 FEN
<move>
A 8.9
black
<opp move> 10.0 9.1 FEN
<move>
A 9.4
<opp move> 9.4 7.2 FEN
<move>
A 8.9
"""
import sys
import chessbot
import threading
import time
#essential items
bestMove = None
currentFEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
# general status
previousMove = None
myTime: int = 0
oppTime: int = 0
boardFen = None
isMyTurn: bool = False
game_on: bool = True
myColor = None
def beginning():
global isMyTurn
global previousMove
global myTime
global oppTime
global boardFen
global myColor
who_starts: str = input()
myColor = who_starts
if who_starts == "white":
isMyTurn = True
elif who_starts == "black":
isMyTurn = False
if isMyTurn:
status_string: str = input()
parts = status_string.split()
previousMove = parts[0]
myTime = int(parts[1])
oppTime = int(parts[2])
boardFen = parts[3]
if len(parts) != 4:
print("Initial problem reading opening stats")
move_decision()
judge: str = input()
judge_parts = judge.split()
acceptance = judge_parts[0]
if acceptance == "D":
print("Judge denied move")
myTime = judge_parts[1]
def control_flow():
global currentFEN
global previousMove
global myTime
global oppTime
global boardFen
global isMyTurn
while game_on:
status_string = sys.stdin.readline().strip()
if status_string:
isMyTurn = True
parts = status_string.split(maxsplit=3)
if len(parts) != 4:
print("Problem with the status input", len(parts))
previousMove = parts[0]
myTime = int(parts[1])
oppTime = int(parts[2])
boardFen = parts[3]
currentFEN = chessbot.update_FEN(currentFEN, previousMove)
if currentFEN != boardFen:
print("BoardFEN and currentFEN do not match")
print(currentFEN)
move_decision()
judge: str = input()
judge_parts = judge.split()
acceptance = judge_parts[0]
if acceptance == "D":
print("Judge denied move")
myTime = judge_parts[1]
def move_decision():
global currentFEN
print(myColor)
best_move = chessbot.find_best_move(currentFEN, myTime, game_on, myColor)
currentFEN = chessbot.update_FEN(currentFEN, best_move);
print(best_move)
def main():
beginning()
control_flow()
if __name__ == "__main__":
main()