Question: Objective You will write a program to simulate a game called Stack Battle Royale, where two players compete for control of three shared stacks. The

Objective You will write a program to simulate a game called Stack Battle Royale, where two players compete for control of three shared stacks. The game will challenge you to use the stack data structure while focusing on alternating player actions and incorporating stack pop events at staggered intervals. Game Rules The game is played with two players. There are three Stacks in the game, labeled Stack A, Stack B, and Stack C. The game is played for a set number of rounds (n), where each round consists of a turn for both players. There must be at least 30 rounds in the game (n 30). Each player takes turns pushing a disk onto one of the three Stacks. Players alternate turns, with Player 1 going first. Each disk will be marked to denote which player it belongs to. Popping Mechanism: If a player pushes a disk onto a Stack where the top disk belongs to the opponent, the opponent's top disk is popped, and the player's disk is placed. This creates strategic opportunities to remove the opponent's disks. At the end of every 6 th,9th, and 12th round, a disk is automatically popped from one of the stacks, based on the following schedule: o In rounds divisible by 6, pop from Stack A. o In rounds divisible by 9, pop from Stack B. o In rounds divisible by 12, pop from Stack C. After the specified number of rounds (n), the player with the most disks remaining on the three Stacks combined is declared the winner. Program Requirements 1. Input: o Your program should ask the user to enter how many rounds will be played (n 30).2. Simulation: o Each turn, a random number (0,1, or 2) will be generated to determine which Stack (A, B, or C) the player will push their disk onto. o Players alternate turns pushing disks. Player 1 always goes first. o If a player pushes a disk onto a Stack where the opponent's disk is on top, the opponent's disk is popped, and the player's disk is placed on the Stack. o At the end of every round, pop timers will be checked to automatically pop a disk from one of the three stacks, based on the staggered pop intervals: Stack A pops every 6th round. Stack B pops every 9th round. Stack C pops every 12th round. o The simulation should include print statements indicating which round it is, which player is taking their turn, where they push their disk, and whether a disk is popped due to the popping mechanism or pop schedule. 3. End of Game: o After all rounds are complete, pop all remaining disks from each Stack and count the disks belonging to each player. o The player with the most disks remaining on the three Stacks combined is declared the winner. 4. Exception Handling: o Your program should handle attempts to pop from an empty Stack gracefully. Use appropriate exception handling (e.g., EmptyStackException) to catch and handle these cases without terminating the game. 5. Object-Oriented Design: o You must define appropriate classes to represent the different components of the game: A class to represent the game itself, keeping track of the current round, managing turns, and handling disk pushes and pops. A class to represent players, with each player having a name. A class to represent disks, which should store the player to whom they belong. o Functional decomposition should be used, with helper methods for actions such as pushing, popping, and printing the status of the game. 6. Stack ADT: o Your program should be written to work with any valid implementation of the Stack ADT. It should support the standard Stack operations: push, pop, peek, isEmpty, and clear. o Note: You are not allowed to modify the Stack implementation itself. You must write your game logic using these provided operations. 7. Generalization: o Your program should be flexible enough that it can be easily adjusted. For example, the pop intervals (currently set to 6,9, and 12 rounds) should be changeable without affecting other parts of the game logic. 8. Output: o Your program should output descriptive text at each step, including: The current round number. Which player pushes a disk onto which Stack. Any disks that are popped from the Stacks, either due to a player action or due to the automatic pop event. o At the end of the game, the program should display the final score for each player and announce the winner. Sample Output Enter number of rounds to play (n 30): 36 Round 1: Player 1 pushes a disk onto Stack A. Player 2 pushes a disk onto Stack C. Round 2: Player 1 pushes a disk onto Stack B. Player 2 pushes a disk onto Stack A, popping Player 1's disk. Round 3: Player 1 pushes a disk onto Stack C. Player 2 pushes a disk onto Stack A.... Round 6: Player 1 pushes a disk onto Stack C. Player 2 pushes a disk onto Stack B. A disk for Player 1 was popped from Stack A due to pop schedule. ... Game over! Player 1 has 10 disks remaining. Player 2 has 12 disks remaining. Player 2 wins!

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!