Files
ObsidianJournal/Work/Faithlife pair programming interview.md

54 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Minesweeper implementation
- Default to 8x8 board with 10 mines
- Variables
- numRows
- numCols
- numMines
- Structs
- Squarestate
- hasFlag
- hasMine
- hidden
- Numneighboringmines
- For grid
- Multidimensional array of squarestates
- Setup
- Ask for num rows (default 8)
- Ask for num cols (default 8)
- Ask for num mines (make sure it's not more than num of squares)
- Q to quit
- F1,2 format for flag setting
- 1,2 for "opening" square
- Init array with rows and cols
- Use random to get col idx and row idx for mine until we reach number of mines
- As we do, increment neighbor mine counts
Summary
Your task is to implement the logic (not necessarily the GUI) of the classic Windows “Minesweeper” game.
Game Description
The game board is a rectangular grid; placed randomly within the grid are “mines”. (The grid size and number of mines are user-configurable but default to an 8×8 with 10 mines.)
Initially, all grid squares are “hidden”.
The player chooses one square at a time to “reveal”. If the square contains a mine, the player loses and the game is over.
Otherwise, the square is changed to show the total number of immediate neighbor squares (diagonal and orthogonal) that contain mines (with a maximum of 8). If no neighboring squares contain mines (i.e., the count for this square is 0), then all neighboring squares are automatically revealed. (And if one of those squares has no neighbors that are mines, then all its neighbors are automatically revealed, and so on.)
The player can choose to “flag” a square that they think might contain a mine. This has no impact on gameplay; it is just to help the player record their guesses.
When the player has revealed every non-mine square, they win.
Detailed Objectives
• Create data structures to represent an 8×8 grid
• Lay 10 mines in random locations
• For each square, calculate the total number of immediate neighbors that contain mines
• Display the board to the user (with all squares “hidden”)
o Note: This can use console/text mode UI if thats quicker
• Accept user input to reveal or flag a square
o If the square is a mine, the game is over
o If the square has non-zero mine neighbors, display its count
o If the square has zero mine neighbors, reveal all adjacent squares
• Repeat until the player has revealed all non-mine squares