Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
zew15101 authored Dec 6, 2019
1 parent a5bec75 commit 3935ac4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions state.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
import math

max_depth = 0
def Minimax(state, depth, maximizingPlayer, alpha, beta):
if depth == max_depth:
return state.eval()
if maximizingPlayer:
best_move = -1 * math.inf
for successor_state in state.successors():
val = Minimax(successor_state, depth + 1, False, alpha, beta)
best_move = max(best_move, val)
alpha = max(alpha, best_move)
if beta <= alpha:
break
return best_move
else:
best_move = math.inf
for successor_state in state.successors():
val = Minimax(successor_state, depth + 1, True, alpha, beta)
best_move = min(best_move, val)
beta = min(beta, best_move)
if beta <= alpha:
break
return best_move

WHITE = "W"
BLACK = "B"

Expand Down Expand Up @@ -167,3 +192,13 @@ def generate_moves(self, board, color):
else:
break
return possible_moves

#Evaluation function
def eval(self, board, playerColor, opponentColor):
player_moves = self.generate_moves(playerColor)
opponent_moves = self.generate_moves(opponentColor)
if player_moves == 0:
return -1 * math.inf
if opponent_moves == 0:
return math.inf
return len(player_moves) - (len(opponent_moves)*3)

0 comments on commit 3935ac4

Please sign in to comment.