Commit e2b25a19 authored by lengfeld8's avatar lengfeld8
Browse files

Upload New File

parent e8a059af
from Board import Board
import numpy as np
class AlphaBeta:
def __init__(self, size):
actualBoard = np.zeros(size * size)
self.boardObject = Board(size, actualBoard)
self.test_list = []
self.the_very_best = []
def start_pruning(self, boardSize, color, moves):
if boardSize ==7:
horizon = 3
else:
horizon = 2
if color == "w":
is_max = True
else:
is_max = False
best_move = ()
best_score, best_move = self.alpha_beta_recursive(moves, horizon, -10000, 10000, is_max, None)
return best_move
def alpha_beta_recursive(self, moves, depth, alpha, beta, is_max, made_move):
if depth == 0 or len(moves) == 0:
evaluated = self.boardObject.eval_func(self.boardObject.board)
return evaluated, made_move
if is_max:
best_move = ()
value = alpha
for move in moves:
self.boardObject.add_taijitu(move)
new_moves = self.boardObject.generate_moves()
former_value, former_move = self.alpha_beta_recursive(new_moves, depth - 1, value, beta, False, move)
new_value = max(value, former_value)
if new_value != value:
best_move = move
value = new_value
self.boardObject.remove_taijitu(move)
if new_value >= beta:
break
return value, best_move
else:
best_move = ()
value = beta
for move in moves:
self.boardObject.add_taijitu(move)
new_moves = self.boardObject.generate_moves()
former_value, former_move = self.alpha_beta_recursive(new_moves, depth - 1, alpha, value, True, move)
self.the_very_best.append(former_move)
new_value = min(value, former_value)
if new_value != value:
best_move = move
value = new_value
self.boardObject.remove_taijitu(move)
if new_value <= alpha:
break
return value, best_move
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment