Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
Red Blue NIMS Game
Date
October 2023
Location
Arlington Texas
This code implements a simple game called "Red Blue Nim." Nim is a mathematical game of strategy where players take turns removing objects from heaps or piles. The version implemented here involves two players, red and blue, taking turns removing red and blue balls from a pool. The winner is the player who removes the last ball.
Here's a breakdown of the code:
Class red_blue_nim:
Represents a state in the game.
Attributes:
prev_node: Reference to the previous state.
num_of_red: Number of red balls.
num_of_blue: Number of blue balls.
version: Game version (standard or misere).
points: Points earned by the player in this state.
misere_version_true: Flag indicating whether it's the misere version of the game.
Function select_action(node, score):
Selects the next possible actions for the current player.
Function pruned_minimax(node, depth, max_node, alpha, beta, max_depth):
Implements the minimax algorithm with alpha-beta pruning for decision-making.
Evaluates the utility of each state based on the game rules.
Function get_next_node(succ_mmn, init_node):
Traces back to the initial state to find the next node in the game.
Function take_turns(num_of_red, num_of_blue, version, first_player, depth):
Alternates turns between the human player and the computer until there are no balls left.
Utilizes the minimax algorithm to determine the computer's moves.
Function print_usage_and_exit():
Prints the correct format for running the script and exits.
Function main():
Parses command-line arguments.
Initiates the game and takes turns until the game is over.
Prints the winner and points earned.
Running the script:
The script is designed to be run from the command line, taking input parameters for the initial state of the game.




