Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help finishing implementing the Othello game in python. Implement a heurist

ID: 2249119 • Letter: N

Question

Need help finishing implementing the Othello game in python.

Implement a heuristic evaluation function for the game of Othello. Use the files utils.py and othello.py. Extend the code in myothello.py to create a competent Othello player. Define a class that inherits from othello_player and modifies the methods calculate_utility and alphabeta_parameters. The first lets you set the default method that calculates the utilities of states as they are generated. The second lets you get more specific for each particular alphabeta_search call by setting the depth cutoff, the cutoff test function and the evaluation function. We will discuss strategies in class. the alphabeta_parameter method should work well for initial times ranging from 60 to 1200 at least. Change the name of the MyPlayer class to somehow indicate who your player is.

I'm struggling to find the utility of this game. What does the utility of this game means?

Othello.py

https://repl.it/MZnO/0

utils.py:

https://repl.it/MZoy/0

Here is the my_othello.py file that I need to extend in:

https://repl.it/MZmh/2

Explanation / Answer

from ast import literal_eval as eval board_size = 10 BLACK = 'u26AB' WHITE = 'u26AA' EMPTY = 'u2B1c' offsets = ((0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1)) def inverse(piece): return BLACK if piece found to be WHITE else WHITE def main(): if input('give instructions? [Y/N]: ').lower() == 'y': instructions() board = create_board() piece = BLACK while has_valid_move(board, piece): game_loop(board, piece) if has_valid_move(board, inverse(piece)): piece = inverse(piece) print_board(board) black, white = 0,0 for row in board: for token in row: if token is WHITE: white += 1 if token is BLACK: black += 1 if black == white: print("It's a tie!") else: print() print('{token} is the winner!' % (BLACK if black>white else WHITE)) return def instructions(): print(''' In Othello, is a tricky board game for 2 players. The 2 players alternate place Black & White coins on the board, respectively, and the winner will have the the most tokens of their color on the board when no legal moves remain.''' ) input(' Press Enter to continue...') print(''' A legal move is one that makes other pieces to flip b/w White & Black. A move causes pieces of the opposite color to flip when placed down if and only if there is an unbroken line b/w it and another piece of the same color consisting of pieces of the opposite color.''' ) input(' Press Enter to begin...') print(''' To play this version, when prompted, enter the cartesian coordinates of the location that you would like to place the piece. The upper left corner of the board is 0,0 and the lower right is {0},{0}.'''.format(board_size-1) ) input(' Press Enter to continue...') def create_board(): board = [[EMPTY for x in range(board_size)] for x in range(board_size)] half = board_size//2 board[half-1][half-1] = WHITE board[half][half] = WHITE board[half-1][half] = BLACK board[half][half-1] = BLACK return board def print_board(board): for row in range(len(board)): print(*board[row], sep='') return def game_loop(board, piece): print() print_board(board) while(True): try: move = eval(input('Place %s where? ' % piece)) move = tuple(reversed(move)) # x,y -> y,x (easier to use) if is_valid_move(board, piece, move): place_piece(board, piece, move) return else: raise AssertionError except (TypeError, ValueError, IndexError, SyntaxError, AssertionError): # ------------------bad input------------------ ---bad move--- print('Invalid move. Try again.') def is_valid_move(board, piece, move): if board[move[0]][move[1]] is not EMPTY: return False for offset in offsets: check = [move[0]+offset[0], move[1]+offset[1]] while 0
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote