Hurkle

Problem #352

Tags: special lua games

Who solved this?

No translations... yet
quote about hurkle from book 101 basic computer games
game description in the old book

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.

Problem Statement

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:

  1. Use 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 input
  2. Start the game by picking random coordinates for hurkle and printing ready to inform player to make the first attempt
  3. For user input read 2 numbers, in order X, then Y (they may be separated with space or newline, it should work anyway, no worry).
  4. Then if user hit the cell with Hurkle, print 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. If you detect user made 5 attempts without finding Hurkle, print lost.
  6. Let the program end by "falling through" the end of code, don't call for os.exit etc (since checker is also executed in Lua.
  7. As the "checker" will try your code several time, it will use 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.

You need to login to get test data and submit solution.