Hunt the Wumpus: Difference between revisions
m
syntax highlighting fixup automation
(fix force unwrapped room variable) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 40:
'''Wumpus package specification'''
<
procedure Start_Game;
end Wumpus;
</syntaxhighlight>
'''Wumpus package body'''
<
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Line 472:
end Wumpus;
</syntaxhighlight>
'''Main procedure'''
<syntaxhighlight lang="ada">
with Wumpus; use Wumpus;
Line 481:
Start_Game;
end Main;
</syntaxhighlight>
=={{header|BASIC}}==
<
20 FOR I=0 TO 19: READ R(I,0),R(I,1),R(I,2): NEXT
30 INPUT "Enter a number";X: X=RND(-ABS(X))
Line 535:
520 DATA 4,6,14, 5,7,16, 0,6,8, 7,9,17, 1,8,10
530 DATA 9,11,18, 2,10,12, 11,13,19, 3,12,14, 5,13,15
540 DATA 14,16,19, 6,15,17, 8,16,18, 10,17,19, 12,15,18</
=={{header|APL}}==
Line 547:
=={{header|C++}}==
<syntaxhighlight lang="cpp">
// constant value 2d array to represent the dodecahedron
// room structure
Line 1,035:
}
</syntaxhighlight>
=={{header|Common Lisp}}==
<syntaxhighlight lang="common lisp">
;;; File: HuntTheWumpus.lisp
Line 1,400:
)
(StartGame)
</syntaxhighlight>
=={{header|FORTRAN}}==
This code names rooms by alphabetic character, thereby making use of index function and simplifying the input to single characters. Compiled with gfortran, source compatible with FORTRAN 2008. You're welcome to move this content to a separate webpage.
Makefile
<
# gnu make
Line 1,422:
%.o: %.f08
gfortran -std=f2008 -c $(FFLAGS) $< -o $@
</syntaxhighlight>
The paint subroutine is a place-holder where is envisioned to place additional symbols representing possible hazards and determined hazards. With ANSI graphics or actual pictures. Source:
<
! compilation, linux. Filename htw.f90
! a=./htw && make $a && $a
Line 1,740:
end program htw
</syntaxhighlight>
short sample run
<pre>
Line 1,800:
=={{header|FreeBASIC}}==
<
data 4,9,13,2,10,15,1,5,11,4,6,20,5,7,12,3,6,8,3,7,10,2,4,5,1,3,9,2,8,14
data 1,2,3,1,3,2,2,1,3,2,3,1,3,1,2,3,2,1
Line 1,915:
print "You have slain the Wumpus!"
print "You have won!"
end</
=={{header|Go}}==
Line 1,927:
4. If the Wumpus wakes up and moves to an 'adjacent' room, it means a room adjacent to the Wumpus not necessarily the player.
<
import (
Line 2,089:
}
}
}</
=={{header|Haskell}}==
<
import System.IO
import Data.List
Line 2,257:
putStrLn "*** HUNT THE WUMPUS ***"
putStrLn ""
playGame</
=={{header|IS-BASIC}}==
<
110 RANDOMIZE
120 NUMERIC RO(1 TO 20,1 TO 3),LO(1 TO 20),WPOS
Line 2,333:
810 END DEF
820 DATA 2,6,5,3,8,1,4,10,2,5,2,3,1,14,4,15,1,7,17,6,8,7,2,9,18,8,10,9,3,11
830 DATA 19,10,12,11,4,13,20,12,14,5,11,13,6,16,14,20,15,17,16,7,18,17,9,19,18,11,20,19,13,16</
=={{header|Java}}==
Line 2,343:
=={{header|Julia}}==
A translation from the original Basic, using the original Basic code and text at https://github.com/kingsawyer/wumpus/blob/master/wumpus.basic as a guide.
<
ATTENTION ALL WUMPUS LOVERS!!!
Line 2,533:
end
end
</syntaxhighlight>
=={{header|M2000 Interpreter}}==
For Windows only (in Linux you hear nothing, using Wine 3.6): In Sense() you can change Print with Speech so you Hear your sense;
<syntaxhighlight lang="m2000 interpreter">
Module WumpusGame {
Print "Game: Hunt The Wumpus"
Line 2,641:
WumpusGame
</syntaxhighlight>
=={{header|MiniScript}}==
<
[4,6,14], [5,7,16], [0,6,8], [7,9,17], [1,8,10],
[9,11,18], [2,10,12], [11,13,19], [3,12,14], [5,13,15],
Line 2,724:
break
end while
end while</
=={{header|Nim}}==
{{trans|Go}}
<
type Adjacent = array[3, int]
Line 2,860:
randomize()
var game = initGame()
game.play()</
{{out}}
Line 2,892:
=={{header|Perl}}==
Besides running in a terminal, it also can run under xinetd.
<
use strict; # see https://rosettacode.org/wiki/Hunt_the_Wumpus
Line 2,934:
}
else { print "I don't understand :(\n"; }
}</
=={{header|Phix}}==
Line 2,945:
https://github.com/jburse/jekejeke-samples/raw/master/pack/games/wumpus-1.0.0.zip
<
/**
* Simple text based dungeon game in Prolog.
Line 3,320:
write(' BAT - ''BATS NEARBY'''), nl,
write(' PIT - ''I FEEL A DRAFT'''), nl, nl.
</syntaxhighlight>
=={{header|Python}}==
Line 3,326:
This implementation of "Hunt the Wumpus" follows is based on the rules of the original game (see discussion page for more information). It uses python 3 syntax and the standard library random.
<
import random
Line 3,603:
WG.gameloop()
</syntaxhighlight>
Example run (on a windows system):
<
D:\Workspace\rosettacode>python wumpus.py
HUNT THE WUMPUS
Line 3,622:
Game over!
</syntaxhighlight>
To create an example for a valid edge list, navigate to the folder where you saved wumpus.py, open up a python interactive shell and do:
<
>>> import wumpus
>>> WG = wumpus.WumpusGame()
Line 3,632:
>>> print edges
[[1,2], [1,3], [1,4], [2,1], [2,5], [2,6], [3,1], ...]
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket
Line 3,836:
(let ([current-game-state (new-game-state)])
(game-loop current-game-state)))
</syntaxhighlight>
<
Start the game with
Line 3,850:
S 2
</syntaxhighlight>
=={{header|Raku}}==
Line 3,857:
=={{header|Red}}==
<
Red [
Title: "Hunt the Wumpus"
Line 4,181:
start
</syntaxhighlight>
=={{header|Ruby}}==
Line 4,190:
=={{header|SenseTalk}}==
<
-- HUNT THE WUMPUS
-- BY GREGORY YOB
Line 4,455:
end if
end move
</syntaxhighlight>
=={{Header|Shale}}==
<
#!/usr/local/bin/shale
Line 4,914:
init()
toplevel()
</syntaxhighlight>
=={{header|Swift}}==
{{trans|Go}}
<
import Foundation
Line 5,133:
game()
</syntaxhighlight>
=={{header|Wren}}==
Line 5,140:
{{libheader|Wren-ioutil}}
{{libheader|Wren-str}}
<
import "/fmt" for Fmt
import "/ioutil" for Input
Line 5,251:
}
}
}</
|