LoginSignup
3
2

More than 3 years have passed since last update.

Translation of Hunt the Wumpus to Erlang Style Prolog

Last updated at Posted at 2019-05-13

Since we have complete the translation of Hunt the Wumpus to
Prolog, we might also report on how we did it. The game play
is basically a discovery of a tunnel system, whereby the discovery

only happens in the brain of the player. In larger editions of the
game the tunnel system is not fixed, but we went with a fixed version.
The only variable per game are the locations of the player, wumpus

wumpus_play.gif

holes and bats, and during the game the location of the player and the
wumpus. And there are also arrows. We found a BASIC source of the
game in an Atari archive about creative computing. We based our

translation to Prolog strictly on this 1972 source by Gregory Yob:

Original Hunt the Wumpus BASIC Program from 1972
https://www.atariarchives.org/bcc1/showpage.php?page=247

To realize the game we didn't use any assert and retract. We also didn't use
any repeat fail loops, except for asking the end user about some choice. This
was the prevalent pattern for user interaction. Here is an example from the

code wumpus.pl, asking whether the end-user wants to move or shoot:

wumpus.pl
choose(O) :- repeat,
   write('SHOOT OR MOVE (S-M)? '), flush_output,
   read_line(I),
   (  'S' = I
   -> O = 1
   ;  'M' = I
   -> O = 2; fail), !.

On the otherhand the game play itself was coded Erlang Style.
The intial state was generate into a list. And the game state is just
passed along and modified along tail-recursive and mutally-recursive

predicate calls. This is already seen in the main loop:

wumpus.pl
% 0400  REM-MOVE OR SHOOT
% play(+List, +List, +Integer)
play(M, L, A) :-
   location(L),
   choose(O),
   (  O = 2
   -> move(L, H),
      check(H, R, F),
      B = A
   ;  rooms(N),
      path(N, [], P),
      shoot(P, L, A, R, B, F)),
   result(F, M, R, B).

% result(+Integer, +List, +List, +Integer)
result(0, M, L, A) :- !,
   play(M, L, A).

In the above play/3 calls result/4, and result/4 calls play/3. But the game
also contains many sub loops. Like bats might carry away the player
multiple times, or an arrow can be shot along a path with many steps.

Hunt the Wumpus as a Prolog Package at Jekejeke
https://github.com/jburse/jekejeke-samples/tree/master/pack/games

Hunt the Wumpus as a Prolog Package at SWI-Prolog
https://www.swi-prolog.org/pack/list?p=wumpus

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2