Question: You are required to develop a Nim game where a human plays against a computer using the Minimax algorithm with a fixed depth of 3

You are required to develop a Nim game where a human plays against a computer using the
Minimax algorithm with a fixed depth of 3.
Requirements:
1. Game Representation: Represent the game using 3 piles of objects. The initial number of
objects in each pile is fixed at 5.
2. Human Player: Allow the human player to select a pile and specify the number of objects
to remove. The number of objects removed must be between 1 and 3(inclusive).
3. Computer Player: Implement the Minimax algorithm for the computer's moves with a
fixed depth of 3. The algorithm should evaluate possible moves to minimize the maximum
possible advantage of the opponent.
4. Game Logic: Alternate turns between the human and the computer. After each move,
update the piles and check for a win (if a player cannot make a valid move, they lose).
5. Output: Display the current state of the piles after each move and announce the winner or
declare the game over when a player cannot make a valid move.
Rules to Play Nim:
1. Objective: Avoid being the player who is forced to take the last object. The player who
cannot make a move loses.
2. Turns: Players take turns removing 1 to 3 objects from one pile. A player must choose a
pile with at least 1 object and remove 1 to 3 objects from it.
3. End Game: The game ends when all piles are empty and the current player cannot make a
valid move. That player loses.
Sample Moves:
Initial State: Piles are [5,5,5]
Move 1: Player 1 removes 2 objects from pile 1, resulting in piles [3,5,5].
Move 2: Player 2 removes 1 object from pile 2, resulting in piles [3,4,5].
Move 3: Player 1 removes 3 objects from pile 3, resulting in piles [3,4,2].
a. You are free to choose your own static evaluation function. Justify your choice of static
evaluation value design and explain with a sample game state. Do not use any machine learning
model for the evaluation function.
b. Similar to the virtual lab example, one of the players must be a human ie., it must get dynamic
inputs from us. The other two players must be simulated using the program.
c. Implement Python code for the design under part a, using Minimax Algorithm.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!