Games::Wumpus - Play Hunt the Wumpus
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!"}
This class 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.
Games::Wumpus::Cave
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.
0
1
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).
None known.
Configuration of the game should be possible.
Games::Wumpus::Cave, Games::Wumpus::Room, Games::Wumpus::Constants
The current sources of this module are found on github, git://github.com/Abigail/Games--Wumpus.git.
Abigail, mailto:wumpus@abigail.be.
Copyright (C) 2009 by Abigail.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
To install this module, run, after unpacking the tar-ball, the following commands:
perl Makefile.PL make make test make install
To install Games::Wumpus, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::Wumpus
CPAN shell
perl -MCPAN -e shell install Games::Wumpus
For more information on module installation, please visit the detailed CPAN module installation guide.