Hunt the Wumpus
InterviewTime limit1sMemory limit1024 MB
Given a seeded generator that places four wumpuses on a 10x10 grid, report each guess's hit status and the Manhattan distance to the nearest remaining wumpus.
- Level
Easy2 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Hunt the Wumpus is a game you play against the computer on a grid. At the start, four wumpuses are placed randomly on the grid, with no two sharing a square. You must find and capture all four. You guess a square by entering its coordinates as two decimal digits. If your guess is a wumpus, the game tells you so, and that wumpus is captured and removed from the grid. Whether or not you hit a wumpus, the game reports the Manhattan distance between your guess and the nearest remaining wumpus. You use this distance to narrow down where each wumpus is. The game ends when the last wumpus is captured.
You are writing the computer side of the game. A guess or a randomly generated wumpus location is a two-digit number, where the tens digit is and the ones digit is , giving the point .
To make the game deterministic, the program uses its own pseudo-random number generator with a given seed . Each random number is produced by first setting and then returning the two low digits of . The first four distinct numbers generated are the wumpus locations. For a seed of 132, the first number is the two low digits of , which is 57, corresponding to the point .
Input
The first line contains a single integer (), the seed for the random number generator. Each of the remaining lines contains a two-digit number (leading zeros allowed). Each number is one of the player's guesses, corresponding to one grid square.
The input is always well-formed and describes a complete game. The last guess always finds the last wumpus. There are at most 250 guesses.
Output
For each guess, output the computer's response. If the guess hits a wumpus, output You hit a wumpus! on its own line. Whether or not the guess hit, if any wumpuses remain uncaptured, output the Manhattan distance to the nearest remaining wumpus. The Manhattan distance between and is , always an integer.
When the game ends, output the total number of moves needed to locate all the wumpuses in the form Your score is $m$ moves. on its own line.