Question: 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
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 rounds in the game n
Each player takes turns pushing a disk onto one of the three Stacks. Players alternate
turns, with Player 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 thth and th round, a disk is automatically popped from one of
the stacks, based on the following schedule:
o In rounds divisible by pop from Stack A
o In rounds divisible by pop from Stack B
o In rounds divisible by 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
Input:
o Your program should ask the user to enter how many rounds will be played n
Simulation:
o Each turn, a random number or 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 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 th round.
Stack B pops every th round.
Stack C pops every th 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.
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.
Exception Handling:
o Your program should handle attempts to pop from an empty Stack gracefully. Use
appropriate exception handling eg EmptyStackException to catch and handle
these cases without terminating the game.
ObjectOriented 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.
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.
Generalization:
o Your program should be flexible enough that it can be easily adjusted. For
example, the pop intervals currently set to and rounds should be
changeable without affecting other parts of the game logic.
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.
Ground Rules:
ObjectOriented Principles: Use objectoriented principles to define your classes.
Avoid writing monolithic code, and ensure that the code is broken down into methods
that follow logical decomposition.
Testing: Ensure that your program works correctly by testing it with various inputs,
especially edge cases like popping from an empty stack.
Comments and Documentation: Your code should be wellorganized and fully
commented. Include clear comments explaining the purpose of each class, method, and
block of code.
code needed using java
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
