Games::Wumpus is a Perl module that can be used to play a game of Hunt the Wumpus. It will keep state, perform action, and deduce whether a game is won or lost.
The following methods are available:
new
Class methods that returns an uninitialized object.
init
Initializes an object. Creates a Games::Wumpus::Cave object, fills the players quiver with arrows, and places the player at the start location. Returns the initialized object.
cave
Accessor returning the cave used in the current game.
item
Accessor returning the number of arrows.
lose_arrow
Accessor to reduce the number of arrows by one.
finished
Accessor returning the win/lose state of the game. If an undefined value is returned, the game isn't finished yet. A false but defined value means the player has lost the game (eaten by the Wumpus, fallen in a pit, shot by an arrow, ran out of arrows). A true value means the game was won (the Wumpus was shot).
win
Accessor setting a win for the player.
lose
Accessor setting the game lost for the player.
describe
Returns a string describing where the player is in the cave, the tunnels leading from the current location, any hints regarding nearby hazards, and the number of arrows left.
move
Takes a new location as argument. It assumes the argument is well formatted - that is, exactly one, defined, argument is parsed. Returns a status and a list of strings. If the player cannot move to the specified location 0 is returned as status, and the reason why as a string. Otherwise 1 is returned, and a (possibly empty) list of strings describing encounters with hazards. If the Wumpus or a pit is encountered, the game is declared a loss.
shoot
Takes a list (1 to 5) of locations as argument -- the path a shot arrow must follow. It assumes the argument is well formatted, 1 to 5 defined values. Returns a status and a list of strings. If the shot cannot be performed (no arrows, path goes through the same tunnel twice in succession, first location isn't connected to current location), 0 and the reason why the shot cannot be performed is returned as status and list of strings. Otherwise, 1 is returned, and list of strings describing interesting events. If the Wumpus is shot, the game is won. If the player is shot, the game is lost. Shooting an arrow may cause the Wumpus to move (and eat you).
SYNOPSIS
my $game = Games::Wumpus -> new -> init;
while (!defined $game -> finished) {
($status, @messages) = $game -> move ($someplace);
say for @messages;
($status, @messages) = $game -> shoot (@somewhere);
say for @messages;
}
if ($game -> finished) {say "Won!"}
else {say "Lost!"}
Requirements:
· Perl