-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathai.py
40 lines (35 loc) · 1.46 KB
/
ai.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
''' Using a mini-max algorithm with alpha-beta pruning to find best moves'''
class AI:
''' AI to Play Chess Game '''
def __init__(self, color=5, move_time=5):
''' Creates the new AI object that will be stored in the game
'''
# One mode limits the amount of time the engine can spend on
# a single move, while the other limits the depth it can search
self.mode = 'move_time'
self.move_time = move_time
self.target_depth = 10
# Store a set of opening lines in a dictionary that the AI
# can use
# The keys are board data and the values are the best move
self.openings = {}
self.color = color
self.evaluation_type = 1
def get_next_move(self, board_data):
''' Given the data about the board, the AI will run a minimax
algorithm to find the best move in a given amount of time
'''
# First, check if the current board state is in the openings
# dictionary
if board_data in self.openings:
return self.openings[board_data]
return "1234"
def evaluate_board(self):
''' Gives a input board a score from 0-100
'''
# Simplest approach: if the board is winning for our opponent,
# we return 0. If the board is winning for us, we return 100
# More complex approach: take into account piece values
if self.evaluation_type == 1:
return 50
return 0