In a simple board game design, which of the following best describes the main responsibility of the Game class?
Think about which class controls the sequence of play and decides when the game ends.
The Game class is responsible for managing the game flow, such as alternating turns between players and checking if someone has won. The Board stores piece positions, and Player represents individual players.
Which design best supports a Player interacting with the Board in a turn-based game?
Consider which class should initiate changes to the board during a player's turn.
The Player should have a method to make a move that updates the Board state. This keeps responsibilities clear and interactions controlled.
For a game with a very large board (e.g., 1000x1000 cells), which approach best optimizes memory and performance?
Think about how to avoid wasting memory on empty cells.
Using a sparse data structure stores only occupied cells, saving memory and improving performance for large boards.
What is a key tradeoff when giving the Player class more decision-making logic versus centralizing logic in the Game class?
Consider how distributing logic affects modularity and coordination.
Giving Player more logic improves modularity but can make coordinating game flow harder. Centralizing logic simplifies coordination but reduces modularity.
A server runs multiple concurrent games, each with 2 players and a 10x10 board. Each game requires 1MB memory and 5ms CPU per turn. The server has 16GB RAM and 2GHz CPU with 8 cores. Estimate the maximum number of games it can handle simultaneously without performance degradation.
Calculate max games by dividing total resources by per-game usage, then find the bottleneck.
Memory allows 16,000 games (16GB / 1MB). CPU per core can handle 200 turns per second (1000ms/5ms). With 8 cores, total 1,600 turns per second. Assuming 1 turn per game per second, CPU limits to ~1,600 games.
