Hunt the Wumpus: Difference between revisions

m
syntax highlighting fixup automation
(fix force unwrapped room variable)
m (syntax highlighting fixup automation)
Line 40:
 
'''Wumpus package specification'''
<langsyntaxhighlight Adalang="ada">package Wumpus is
procedure Start_Game;
end Wumpus;
</syntaxhighlight>
</lang>
'''Wumpus package body'''
<langsyntaxhighlight Adalang="ada">with Ada.Numerics.Discrete_Random;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
Line 472:
 
end Wumpus;
</syntaxhighlight>
</lang>
'''Main procedure'''
<syntaxhighlight lang="ada">
<lang Ada>
with Wumpus; use Wumpus;
 
Line 481:
Start_Game;
end Main;
</syntaxhighlight>
</lang>
 
=={{header|BASIC}}==
<langsyntaxhighlight BASIClang="basic">10 DEFINT A-Z: DIM R(19,3),P(1),B(1)
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</langsyntaxhighlight>
 
=={{header|APL}}==
Line 547:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">
<lang CPP>
// constant value 2d array to represent the dodecahedron
// room structure
Line 1,035:
}
 
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
 
<syntaxhighlight lang="common lisp">
<lang Common Lisp>
;;; File: HuntTheWumpus.lisp
 
Line 1,400:
)
(StartGame)
</syntaxhighlight>
</lang>
 
=={{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
<langsyntaxhighlight lang="gnu make">
# gnu make
 
Line 1,422:
%.o: %.f08
gfortran -std=f2008 -c $(FFLAGS) $< -o $@
</syntaxhighlight>
</lang>
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:
<langsyntaxhighlight lang="f08">
! compilation, linux. Filename htw.f90
! a=./htw && make $a && $a
Line 1,740:
 
end program htw
</syntaxhighlight>
</lang>
short sample run
<pre>
Line 1,800:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">data 7,13,19,12,18,20,16,17,19,11,14,18,13,15,18,9,14,16,1,15,17,10,16,20,6,11,19,8,12,17
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</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,089:
}
}
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
 
<langsyntaxhighlight Haskelllang="haskell">import System.Random
import System.IO
import Data.List
Line 2,257:
putStrLn "*** HUNT THE WUMPUS ***"
putStrLn ""
playGame</langsyntaxhighlight>
 
=={{header|IS-BASIC}}==
<langsyntaxhighlight ISlang="is-BASICbasic">100 PROGRAM "Wumpus.bas"
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</langsyntaxhighlight>
 
=={{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.
<langsyntaxhighlight lang="julia">const starttxt = """
 
ATTENTION ALL WUMPUS LOVERS!!!
Line 2,533:
end
end
</syntaxhighlight>
</lang>
 
=={{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">
<lang M2000 Interpreter>
Module WumpusGame {
Print "Game: Hunt The Wumpus"
Line 2,641:
WumpusGame
 
</syntaxhighlight>
</lang>
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">exits = [[1,4,7], [0,2,9], [1,3,11], [2,4,13], [0,3,5],
[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</langsyntaxhighlight>
 
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight Nimlang="nim">import random, strformat, strutils
 
type Adjacent = array[3, int]
Line 2,860:
randomize()
var game = initGame()
game.play()</langsyntaxhighlight>
 
{{out}}
Line 2,892:
=={{header|Perl}}==
Besides running in a terminal, it also can run under xinetd.
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # see https://rosettacode.org/wiki/Hunt_the_Wumpus
Line 2,934:
}
else { print "I don't understand :(\n"; }
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 2,945:
https://github.com/jburse/jekejeke-samples/raw/master/pack/games/wumpus-1.0.0.zip
 
<langsyntaxhighlight lang="prolog">
/**
* Simple text based dungeon game in Prolog.
Line 3,320:
write(' BAT - ''BATS NEARBY'''), nl,
write(' PIT - ''I FEEL A DRAFT'''), nl, nl.
</syntaxhighlight>
</lang>
 
=={{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.
 
<langsyntaxhighlight lang="python">
import random
 
Line 3,603:
WG.gameloop()
 
</syntaxhighlight>
</lang>
 
Example run (on a windows system):
 
<langsyntaxhighlight lang="cmd">
D:\Workspace\rosettacode>python wumpus.py
HUNT THE WUMPUS
Line 3,622:
 
Game over!
</syntaxhighlight>
</lang>
 
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:
 
<langsyntaxhighlight lang="cmd">
>>> 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>
</lang>
 
=={{header|Racket}}==
 
<langsyntaxhighlight lang="racket">
#lang racket
 
Line 3,836:
(let ([current-game-state (new-game-state)])
(game-loop current-game-state)))
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="cmd">
Start the game with
 
Line 3,850:
 
S 2
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 3,857:
 
=={{header|Red}}==
<langsyntaxhighlight lang="red">
Red [
Title: "Hunt the Wumpus"
Line 4,181:
 
start
</syntaxhighlight>
</lang>
 
=={{header|Ruby}}==
Line 4,190:
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">
-- HUNT THE WUMPUS
-- BY GREGORY YOB
Line 4,455:
end if
end move
</syntaxhighlight>
</lang>
 
=={{Header|Shale}}==
<langsyntaxhighlight lang="shale">
#!/usr/local/bin/shale
 
Line 4,914:
init()
toplevel()
</syntaxhighlight>
</lang>
 
=={{header|Swift}}==
{{trans|Go}}
<langsyntaxhighlight lang="swift">
import Foundation
 
Line 5,133:
game()
 
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 5,140:
{{libheader|Wren-ioutil}}
{{libheader|Wren-str}}
<langsyntaxhighlight lang="ecmascript">import "random" for Random
import "/fmt" for Fmt
import "/ioutil" for Input
Line 5,251:
}
}
}</langsyntaxhighlight>
10,327

edits