The user will hide, and the computer will try to find them.
First, the program will take an input, for the size of the grid. Like 5x5, 10x10, 15x15, etc. The grid won't always be a perfect square.
The grid is sort of like a chessboard:
_______________________________
| | | | | |
| A1 | | | | | A
|_____|_____|_____|_____|_____|
| | | | | |
| | B2 | | | | B
|_____|_____|_____|_____|_____|
| | | | | |
| | | C3 | | | C
|_____|_____|_____|_____|_____|
| | | | | |
| | | | D4 | | D
|_____|_____|_____|_____|_____|
| | | | | |
| | | | | E5 | E
|_____|_____|_____|_____|_____|
1 2 3 4 5
Now, the user will pick a square, such as B2
(without telling the computer)
The computer will start guessing squares. If it picks the correct square, the user will respond with y
. If not, they will input the direction their tile is from the one picked (N, NE, E, SE, S, SW, W).
So if the user picked B2
, and the computer guessed C3
, the user would input NW
.
Here is an example of the outputs and inputs:
Grid?
5x5
C3?
NW
C2?
N
B2?
y
Scoring:
This will be scored a little differently than a normal challenge.
The winner is the program that takes lowest number of guesses (on average) it takes to guess the correct square. The test cases to be averaged will be all of the possible squares in a 5x5 and then in a 10x10.
However, it must also work with every pattern of grid up to 26 rows (i.e. 5x8, 6x2, 20x5, etc.).
Please include a way for it to be tested, such as a JSFiddle.
And lastly, in case of a tie, the shortest program wins.
A1
and the computer guessesB9
, is the proper responseNW
orW
? \$\endgroup\$