Hunt the Wumpus: Difference between revisions

m
No edit summary
m (→‎{{header|Wren}}: Minor tidy)
(2 intermediate revisions by 2 users not shown)
Line 1:
{{task|Games}}
{{Clarify_task}}
Create a simple implementation of the classic textual game [http[w://en.wikipedia.org/wiki/Hunt_the_WumpusHunt the Wumpus|Hunt Thethe Wumpus]].
 
The rules are:
Line 3,633:
[[1,2], [1,3], [1,4], [2,1], [2,5], [2,6], [3,1], ...]
</syntaxhighlight>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ table
[ 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 ] [ 14 16 19 ]
[ 6 15 17 ] [ 8 16 18 ] [ 10 17 19 ] [ 12 15 18 ] ] is adjacent ( n --> [ )
 
[ stack ] is player ( --> s )
[ stack ] is arrows ( --> s )
[ stack ] is wumpus ( --> s )
[ stack ] is bat1 ( --> s )
[ stack ] is bat2 ( --> s )
[ stack ] is pit1 ( --> s )
[ stack ] is pit2 ( --> s )
 
[ over find swap found ] is has ( [ n --> b )
 
[ dup dup size random peek join ] is addrand ( [ --> [ )
 
[ trim reverse trim reverse
$->n not if [ drop -1 ] ] is validate ( $ --> n )
 
[ say "A giant bat transports you to chamber "
20 random dup echo say "." cr
player replace
20 random swap replace ] is relocate ( s --> )
 
[ player share
dup bat1 share = iff
[ drop bat1 relocate ] again
dup bat2 share = iff
[ drop bat2 relocate ] again
dup pit1 share =
over pit2 share = or iff
[ say "You fell into a bottomless pit."
drop false ]
done
dup wumpus share = iff
[ say "The Wumpus eats you." drop false ]
done
say "You are in chamber " dup echo say "." cr
say "Adjacent chambers are: "
adjacent dup witheach
[ echo i 0 = iff [ say "." cr ]
else
[ say ", "
i 1 = if [ say "and " ] ] ]
say "You have " arrows share echo say " arrows." cr
dup wumpus share has if
[ say "You smell something terrible nearby." cr ]
dup bat1 share has
over bat2 share has or if
[ say "You hear a rustling." cr ]
dup pit1 share has
swap pit2 share has or if
[ say "You feel a cold wind "
say "blowing from a nearby chamber." cr ]
true ] is report ( --> b )
 
[ $ "Move to which chamber? " input validate
player share adjacent
dup addrand unrot find
peek player put true ] is move ( --> b )
 
[ true
$ "Shoot into which chambers? " input nest$
dup [] = if [ drop ' [ [ -1 ] ] ]
player share swap witheach
[ $->n not if [ drop -1 ]
swap adjacent
dup addrand unrot find peek
say "The arrow enters chamber "
dup echo say "." cr
dup player share = iff
[ say "You shot yourself." cr
dip not conclude ]
done
dup wumpus share = iff
[ say "You shot the Wumpus." cr
dip not conclude ]
done ]
drop dup while
say "You did not hit anything." cr
4 random 0 != if
[ wumpus take adjacent
3 random peek wumpus put ]
-1 arrows tally
arrows share 0 = if
[ say "You have run out of arrows." cr not ] ] is shoot ( --> b )
 
[ $ "Move or shoot? " input space join
0 peek upper dup char M = iff [ drop move ] done
char S = iff shoot done
again ] is action ( b --> b )
 
[ cr
say "Your mission is to anaesthetise an ailing "
say "Wumpus so that it can be healed." cr
say "It is in a dodecahedral labyrinth "
say "that is fraught with dangers." cr
say "The labyrinth has 20 chambers numbered 0 to "
say "19 which are connected by tunnels." cr cr
say "- The Wumpus will eat you if it sees you." cr
say "- Two of the chambers are bottomless pits." cr
say "- There are two giant bats that will "
say "transport you to a random chamber." cr cr
say "You can smell the Wumpus from an adjoining "
say "chamber. It smells terrible." cr
say "When you are in a chamber next to a bottomless "
say "pit you can feel a cold wind." cr
say "You can hear the giant bats rustle from a "
say "chamber away." cr cr
say "You are equipped with five progammable arrows." cr
say "They can be programmed with up to five "
say "adjoining chambers." cr
say "If a destination is invalid the arrow will move "
say "to a random adjoining chamber." cr cr
say "Be careful! Do not shoot yourself. Wumpus "
say "anasthetic is lethal to humans." cr
say "If you miss the Wumpus it will probably wake "
say "and move to an adjoining chamber." cr cr ] is rules ( --> )
 
[ say "Hunt the Wumpus, the Quackery cut." cr cr
randomise
5 arrows put
[] 20 times [ i join ] shuffle
' [ player wumpus bat1 bat2 pit1 pit2 ]
witheach [ dip behead put ]
drop
$ "Would you like to see the rules? " input
space join 0 peek upper char Y = if rules
[ report while
action while
cr again ]
' [ player arrows wumpus bat1 bat2 pit1 pit2 ]
witheach release ] is play ( --> )
 
play</syntaxhighlight>
 
{{out}}
 
Sample game.
 
<pre>Hunt the Wumpus, the Quackery cut.
 
Would you like to see the rules? y
 
Your mission is to anaesthetise an ailing Wumpus so that it can be healed.
It is in a dodecahedral labyrinth that is fraught with dangers.
The labyrinth has 20 chambers numbered 0 to 19 which are connected by tunnels.
 
- The Wumpus will eat you if it sees you.
- Two of the chambers are bottomless pits.
- There are two giant bats that will transport you to a random chamber.
 
You can smell the Wumpus from an adjoining chamber. It smells terrible.
When you are in a chamber next to a bottomless pit you can feel a cold wind.
You can hear the giant bats rustle from a chamber away.
 
You are equipped with five progammable arrows.
They can be programmed with up to five adjoining chambers.
If a destination is invalid the arrow will move to a random adjoining chamber.
 
Be careful! Do not shoot yourself. Wumpus anasthetic is lethal to humans.
If you miss the Wumpus it will probably wake and move to an adjoining chamber.
 
You are in chamber 13.
Adjacent chambers are: 3, 12, and 14.
You have 5 arrows.
You feel a cold wind blowing from a nearby chamber.
Move or shoot? m
Move to which chamber? 12
 
You are in chamber 12.
Adjacent chambers are: 11, 13, and 19.
You have 5 arrows.
You hear a rustling.
Move or shoot? m
Move to which chamber? 19
 
You are in chamber 19.
Adjacent chambers are: 12, 15, and 18.
You have 5 arrows.
Move or shoot? m
Move to which chamber? 12
 
You are in chamber 12.
Adjacent chambers are: 11, 13, and 19.
You have 5 arrows.
You hear a rustling.
Move or shoot? m
Move to which chamber? 11
 
A giant bat transports you to chamber 18.
You are in chamber 18.
Adjacent chambers are: 10, 17, and 19.
You have 5 arrows.
Move or shoot? s
Shoot into which chambers? 10 18 17 8 0
The arrow enters chamber 10.
The arrow enters chamber 18.
You shot yourself.
</pre>
 
=={{header|Racket}}==
Line 5,531 ⟶ 5,737:
{{libheader|Wren-ioutil}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./fmt" for Fmt
import "./ioutil" for Input
import "./str" for Str
 
var cave = {
9,476

edits