-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputer.py
49 lines (39 loc) · 1.33 KB
/
computer.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
45
46
47
48
49
import constants
import chess_constants as cc
#import time
from pieces import listPiecestoArr
import my_game as mg
import my_chess as mc
def getPlayInfo(listpieces, from_x, from_y, to_x, to_y, mgInit):
pieces = movedeep(listpieces ,1 ,constants.player2Color, from_x, from_y, to_x, to_y, mgInit)
if pieces == None:
return None
return [pieces[0].x, pieces[0].y, pieces[1], pieces[2]]
def movedeep(listpieces, deepstep, player, x1, y1, x2, y2, mgInit):
# temp.board.print_board()
s = mc.step(8 - x1, y1, 8 - x2, y2)
print(s)
mgInit.move_to(s)
# temp.evaluate(True)
mgInit.alpha_beta(cc.max_depth, cc.min_val, cc.max_val, True )
t = mgInit.best_move
mgInit.move_to(t)
print(mgInit.cnt)
print(t)
# return t
arr = listPiecestoArr(listpieces)
listMoveEnabel = []
for i in range(0, 9):
for j in range(0, 10):
for item in listpieces:
if item.x == 8 - t.from_x and item.y == t.from_y:
listMoveEnabel.append([item, 8 - t.to_x, t.to_y])
if not listMoveEnabel:
return None
piecesbest = listMoveEnabel[0]
return piecesbest
# print(piecesbest)
# print("test")
# print(piecesbest[0])
# print("test")
#return piecesbest