Had to simulate the Bowling alley game.
Problem Statement:
During the game, players and their scores will be maintained and shown by the system and winner will be declared at the end of the game. Likewise, multiple games can be played in parallel on multiple free lanes.
Some rules to follow:
- A game consists of ten sets.
- In each set, the player has two opportunities to knock down ten pins.
- The score for a set is the total number of pins knocked down, plus bonuses for strikes and spares.
- A spare is when the player knocks down all ten pins in two tries.If there is spare the player gets 5 bonus points.
- A strike is when the player knocks down all ten pins on his/her first try.If there is a strike the player gets 10 bonus points.
- In the final set, a player who rolls a spare or a strike is allowed to roll the extra balls to complete the set. However, only a maximum of three balls can be rolled in the final set.
I had to make the LLD extensible in a such a way, If admin wants to change the game strategy s/he should be able to do it.
Things admins should be able to move to config -
- Number of parallel games
- Number of rounds in single game
- Number of players in a game
- Player turn staretegy (who will get the next chance to play)
- Scoring Strategy
- Number of retries per user in a Round (once fixed at the beginning of the game, should be fixed)
I think I was able to come up with a fairly good OOPs design. Had to explain the interviewer the thought process in the initial phase and then had to code it out in the remaining time.
Entities in the system
- Round
- User
- Strategy (Interface)
- SpareStrategy
- StrikeStrategy
- SpareAndStrikeStrategy
- StrategyFactory
- DriverClass
- Retry
Entity relationship
- Game:Round (1:N)
- Game:User (1:N)
- Round:Retry(1:N)
- Game:Strategy (1:1)
- Driver:Game(1:N)