NORTH
^Y=10
|
|
WEST | EAST (just to recap geometry of Hurkle's world)
|
|0,0 X=10
+--------------->
SOUTH
In this problem you are to implement the "opposite" of what was done in the Hurkle task - i.e. to implement the searching algorithm.
It is again to be done in Lua
so here are useful links: Quick Introduction on Lua
and online Lua sandbox.
So you are to implement "Computer AI" for Hurkle game. Algorithm is too obvious, perhaps, so let us only provide technical details.
Your code should define hunter
function, which takes single text argument - either
command to initialize (ready
) or response to previous guess (go north/southwest
) - i.e. it should match
I/O format of the previous problem.
The function should return a pair of integer values, X, Y
- the next guess.
In other words, we should be able to plug your function into the code like this:
function hunter(command)
-- such function won't work of course, unless Hurkle is at X=1, Y=1 :)
return 1, 1
end
print('Please think of X and Y both in range 1..10 - coordinates where Hurkle hides')
print('Type "ready" when you are...')
while true do
userResponse = io.read('*l')
if userResponse == 'win' then
print('Hooray')
break
end
if userResponse == 'lost' then
print('You are probably cheating :(')
break
end
x, y = hunter(userResponse)
print('My guess is X=' .. x .. ', Y=' .. y)
print('Type "go north/southwest/etc" or "win/lost"...')
end
However the code you submit should not contain such "helper" code - nothing except function(s) and probably, global variables definition because the "checker" code is added to your submission and most probably won't work well if something is executed before it.