-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathai.py
More file actions
47 lines (35 loc) · 999 Bytes
/
ai.py
File metadata and controls
47 lines (35 loc) · 999 Bytes
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
import copy
def pieceValue(type):
match(type):
case "p":
return 10
case "kn":
return 30
case "b":
return 35
case "r":
return 50
case "q":
return 90
case "k":
return 1000
def evaluateBoard(manager, color):
value = 0
pieces = set()
pieces.update(manager.board.getWhitePieces())
pieces.update(manager.board.getBlackPieces())
for pieceCoords in pieces:
piece = manager.board.getPiece(pieceCoords)
tempValue = pieceValue(piece.getType())
value += (tempValue if piece.color == color else (tempValue * -1))
return value
def generateMove(manager):
moves = manager.getAllMoves(manager.getColorTurn())
bestValue = [-10000]
for move in moves:
managerClone = copy.deepcopy(manager)
managerClone.movePiece(move)
value = evaluateBoard(managerClone, manager.getColorTurn())
if(value > bestValue[0]):
bestValue = [value, move]
return bestValue[1]