#GPT-4 Conversation #1094674131909353602

1 messages · Page 1 of 1 (latest)

grand sedgeBOT
tiny timber
#

I have the following for an assignment:

Your task is to build an agent to play a modified version of nim (called red-blue nim against a human player). The game consists of two piles of marbles (red and blue). On each players turn they pick a pile and remove one marble from it. If on their turn, either pile is empty then they win. The amount they win is dependent on the number of marbles left (2 for every red marble and 3 for every blue marble). So if on the computer player turn, it has 0 red marbles and 3 blue marbles, it wins 9 points.

Your program should be called red_blue_nim and the command line invocation should follow the following format:

red_blue_nim.py <num-red> <num-blue> <first-player> <depth>
<num-red> and <num-blue> are required. (Number of red and blue marbles respectively)
 <first-player> can be
computer - computer starts the game followed by human [default option if <first-player> is not given]
human - human starts the game followed by computer
<depth>  only used if depth limited search (Extra Credit) is implemented.
On Computer turn, the program should use MinMax with Alpha Beta Pruning to determine the best move to make and perform the move.
On Human turn, the program should use a prompt to get the move from the human user and perform the move.
The program should alternate between these turns till the game ends (when the players run out of either red or blue marbles). Once the game ends, calculate who won and their final score and display it to the user.

Extra Credit (20 Points):

If your program determines computer move by using depth limited MinMax search with alpha beta pruning then you will be given 20 points extra credit. You will need to come up with a eval function to use with the program also. Please submit a text file describing the reasoning behind your eval function for full credit.
grand sedgeBOT
# tiny timber I have the following for an assignment: ``` Your task is to build an agent to pl...

To complete this assignment, you'll need to create a Python program called red_blue_nim.py.

Below is an outline of the steps to follow:

  1. Begin by importing necessary libraries:
import sys
  1. Parse command-line arguments:
num_red = int(sys.argv[1])
num_blue = int(sys.argv[2])
first_player = sys.argv[3] if len(sys.argv) > 3 else 'computer'
depth = int(sys.argv[4]) if len(sys.argv) > 4 else None
  1. Implement MinMax function with Alpha-Beta Pruning:
def minmax_alpha_beta(node, depth, alpha, beta, maximizing_player):
    ...
  1. Implement depth-limited evaluation function (optional for extra credit):
def eval_function(state, depth, maximizing_player):
    ...
  1. Implement the main game loop:
  • Prompt the user for input (human turn) and make corresponding move
  • Use the MinMax function to determine the next move for the computer
while not game_over(num_red, num_blue):
    if current_player == "human":
        move = input("Enter your move (pile color):")
        num_red, num_blue = perform_move(num_red, num_blue, move)
    else:
        best_move = minmax_alpha_beta( ... )
        num_red, num_blue = perform_move(num_red, num_blue, best_move)
    current_player = toggle_player(current_player)
  1. After the game loop ends, calculate the scores and print the results:
winner, score = calculate_winner(num_red, num_blue)
print(f"{winner} won with a score of {score}")
  1. Put everything together in the red_blue_nim.py file.

Remember to submit a separate text file for extra credit, explaining the evaluation function you developed.