This simple game was found in the ancient book 101BCG - and
it seems to make ideal exercise to introduce us to Lua
programming language. It is similar to Python
and the
goal is to implement this game in Lua
according to directions below. The checker will make several runs agains
it to see if it "plays" well.
Quick Introduction on Lua was prepared to help you, and online Lua sandbox.
In brief, a Hurkle is a beast and favorite pet of Gwik (dominant race on Lirht, a planet with 3 moons)
and one is to find a Hurkle in a field of 10 by 10
rectangular cells in 5
attempts or less.
We agree that corner with X=1, Y=1
is at the lower-left corner, hence directions to north
mean increasing Y
and east
is increasing X
.
Hurkle doesn't move and on each attempt player tells a pair of coordinates (X, Y
) while the game answers with
approximate direction to go, until the cell with Hurkle is found (or attempts are exhausted).
You are to implement playable version of the game, however to match the checker's expectation please follow the guidelines:
print()
function to produce output and io.read('*n')
to read a number (or io.read('*n', '*n')
to
read a pair of numbers) - because the checker "clings" to these functions to capture the output and provide inputready
to inform player to make the first attempt2
numbers, in order X
, then Y
(they may be separated with space or newline, it should
work anyway, no worry).win
. Otherwise print directions, like go north
or go southeast
(only 8
general directions are recognized by checker, words like up
, northsouth
or eastnorth
will
result in error).5
attempts without finding Hurkle, print lost
.os.exit
etc (since checker is also
executed in Lua
.goto
to restart it after the end, so if you
feel some strange behavior, check that you properly (re-)initialize all your variables at start.That's all. Most probably you'll spend far less time on coding the game than I spent on coding the checker :))) Good luck and have fun!
We have the "opposite" game, where you are to write the searching algorithm - Hurkle Hunter.