-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathperft.py
More file actions
76 lines (62 loc) · 1.49 KB
/
perft.py
File metadata and controls
76 lines (62 loc) · 1.49 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
import manager
import time
import user
manager = manager.Manager()
tempUser = user.User(manager)
nodes = 0
captures = 0
ep = 0
castles = 0
promotions = 0
checks = 0
checkmates = 0
def perft(depth, manager):
global nodes
global captures
global ep
global castles
global promotions
global checks
global checkmates
if(depth == 0):
nodes += 1
return
moves = manager.getAllMoves(manager.getColorTurn(), False)
color = manager.getColorTurn()
for move in moves:
manager.movePieceTrusted(move)
if(manager.isInCheck(color)): #if the move puts the player in check, it is illegal
manager.undoMove()
continue
if(depth <= 1):
if(move.special == 'c'):
castles += 1
elif(move.special == 'en'):
ep += 1
elif(move.special is not None):
promotions += 1
if(manager.isInCheck(manager.getColorTurn())):
checks += 1
manager.checkMate()
if(manager.status == "checkmate"):
checkmates += 1
if(move.captured is not None):
captures += 1
nodes += 1
else:
perft(depth-1, manager)
manager.undoMove()
if(__name__ == "__main__"):
DEPTH = 4
start = time.time()
perft(DEPTH, manager)
end = time.time()
print("Time elapsed: " + str(end - start) + " seconds")
print(f"""
Nodes: {nodes}
Captures: {captures}
En Passant: {ep}
Castles: {castles}
Promotions: {promotions}
Checks: {checks}
Checkmates: {checkmates}""")