Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My program doesn't play chess automatically, how can I fix it. from othello.OthelloUtil import getValidMoves, makeMove, isEndGame import time class BOT(): def __init__(self, max_depth=3, max_time=180):

My program doesn't play chess automatically, how can I fix it.

from othello.OthelloUtil import getValidMoves, makeMove, isEndGame

import time

class BOT():

def __init__(self, max_depth=3, max_time=180):

self.max_depth = max_depth

self.max_time = max_time

def getBestMove(self, game_state, player):

start_time = time.time()

best_move = (-1, -1)

best_score = float('-inf') if player == BLACK else float('inf')

for move in getValidMoves(game_state, player):

new_game_state = game_state.clone()

executeMove(new_game_state, player, move)

score = self.min_max(new_game_state, self.max_depth-1, -player, start_time)

if player == BLACK:

if score > best_score:

best_move = move

best_score = score

else:

if score < best_score:

best_move = move

best_score = score

return best_move

def min_max(self, game_state, depth, player, start_time):

if depth == 0 or isEndGame(game_state) != None:

return self.evaluate(game_state, player)

if time.time()-start_time > self.max_time:

raise TimeoutError

best_score = float('-inf') if player == BLACK else float('inf')

for move in getValidMoves(game_state, player):

new_game_state = game_state.clone()

executeMove(new_game_state, player, move)

score = self.min_max(new_game_state, depth-1, -player, start_time)

if player == BLACK:

best_score = max(best_score, score)

else:

best_score = min(best_score, score)

return best_score

def evaluate(self, game_state, player):

# Implement a function to evaluate the current game state

# and return a score for the given player.

pass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 23rd International Conference Dexa 2012 Vienna Austria September 2012 Proceedings Part 1 Lncs 7446

Authors: Stephen W. Liddle ,Klaus-Dieter Schewe ,A Min Tjoa ,Xiaofang Zhou

2012th Edition

3642325998, 978-3642325991

More Books

Students also viewed these Databases questions

Question

What do you understand by MBO?

Answered: 1 week ago

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

Discuss five types of employee training.

Answered: 1 week ago

Question

Identify the four federally mandated employee benefits.

Answered: 1 week ago