Need help writing the game of nim in python. Instruction: Write a program in whi
ID: 3682376 • Letter: N
Question
Need help writing the game of nim in python.
Instruction:
Write a program in which the computer plays against a human opponent. Generate a random integer between 10 and 100 to denote the initial size of the pile. Generate a random integer between 0 and 1 to decide wheter the computer or the human takes the first turn. Generate a random integer between 0 and 1 to decide whether the computer plays smart or stupid. In stupid mide the computer simply takes a random legal value (between 1 and n/2) from the pile whenever it has a turn. In smart mode the computer takes off enough marbles to make the size of the pile a power of twer minus 1 - that is, 3,7,15,31, or 63. That is always a legal move, except when the zise of the pile is currently one less than a power of two. In that casem the computer makes a random legal move. Obviously the computer cannot be beaten in smart mode when it has the first move unless the pile size happeneds to be 15,31, or 63. And if the human has the first turn and knows the winning strategy they can win agains tthe computer.
Explanation / Answer
class Chess_Board: def __init__(self): self.board = self.create_board() def create_board(self): board_x=[] for x in range(8): board_y =[] for y in range(8): board_y.append('.') board_x.append(board_y) board_x[7][4] = 'K' board_x[7][3] = 'Q' board_x[7][2] = 'B' board_x[7][1] = 'N' board_x[7][0] = 'R' return board_x class WHITE_KING(Chess_Board): def __init__(self): Chess_Board.__init__(self) self.position_x_WK = 7 self.position_y_WK = 4 self.symbol_WK = 'K' def move(self): while True: try: print ('give a x and y coordinate for WHITE KING') destination_x_WK = int(input()) destination_y_WK = int(input()) if self.board[destination_x_WK][destination_y_WK] == '.' : if ( abs(self.position_x_WK-destination_x_WK)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.