Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Hangmonks

by phydeauxarff (Priest)
on Aug 05, 2003 at 00:10 UTC ( #280842=CUFP: print w/ replies, xml ) Need Help??

Recently, Jeffa and I were discussing a flame by anonymous monk and I mentioned that I thought I knew the identity of the person posting....
Jeff said he thought he knew as well and asked if my guess began with an "a".
My reply was that it began with a "d" but there wasn't any point in playing hangmonk over something so trivial and thus the idea of Hangmonk came about.
The following grabs a list of the monks lurking in the Monastery and implements a game of hangman based on the name of one of the monks online at the time.
So, the next time you get flamed by anonymous monk you can play a quick game of Hangmonk to see if you can guess who it is ;-)
Special thanks go out to DrManhattan for his patient assistance and the recommendation to use map as well as to Jeffa for helping conceive the idea in the first place and also recommending I use map...you don't want to know how I was doing it before...also, to ybiC for reminding me to use -w.
Enjoy
#!/usr/bin/perl -w use strict; use XML::Simple; use LWP::UserAgent; use Games::GuessWord; my $ua = LWP::UserAgent->new(); my $response = $ua->get("http://www.perlmonks.org/index.pl?node_id=158 +51"); die $response->code() if $response->code() != 200; my $content = $response->content(); my $cblist = XMLin($content); my @user = map $_->{username}, @{$cblist->{user}}; my $monk = $user[rand @user]; my $g = Games::GuessWord->new(words => [$monk]); # Uncomment out the following for testing # print "Secret: " . $g->secret . "\n"; my @guesses = $g->guesses; do{ print "Guesses Remaining:" . $g->chances . "\n"; print "The Monk is: " . $g->answer . "\n"; print "What is your Guess?: "; my $response = <>; $g->guess($response); if ($g->won) { print "Yep, it was " . $g->secret . "...Great +Guess!\n"; exit; } }until($g->chances<=0); print "Sorry, the monk was: " . $g->secret . "\n";

Comment on Hangmonks
Download Code
Re: Hangmonks
by Coruscate (Sexton) on Aug 05, 2003 at 02:19 UTC

    Neat. Though of course all I have to do is the following. If it doesn't give me the answer on the first shot, then all I have to do is throw in numbers and/or other characters to finish it off :)

    [coruscate@localhost] ./hangmonks.pl Guesses Remaining:6 The Monk is: ******** What is your Guess?: abcdefghijklmnopqrstuvwxyz Yep, it was demerphq...Great Guess! [coruscate@localhost]


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

      heh...wasn't thinking of ways to cheat the game, but that is a pretty good one....I also found that if you send it a ], it produces an unexpected result.
      Guesses Remaining:6 The Monk is: ********* What is your Guess?: ] Yep, it was podmaster...Great Guess!
      But what the hey...I can't imagine it being for mass consumption.
Re: Hangmonks
by krisahoch (Deacon) on Aug 05, 2003 at 15:00 UTC

    This was a fun game. How about extending Games::Guessword to disallow the a..z guess cheat...

    use strict; use XML::Simple; use LWP::UserAgent; use Games::GuessWord; package GamesGuesswordExtended; { use Games::GuessWord; use base 'Games::GuessWord'; sub new { my $class = shift(); my $monk = shift(); my $self = Games::GuessWord->new(words => [$monk]); bless($self,$class); return $self; } # 8-6-2003. sub guess can be completely replaced with # the 'sub guess' found in the following node
      #Re: Re: Hangmonks
    sub guess { my $self = shift; my $word = shift; chop($word); if ($self->chances == 0) { return undef; } #orginally, '$letter' was made from the shift(). I #changed it to $word, and got '$letter' from the 1st #character in $word. my $letter = substr($word,0,1); #Don't want to type $self->secret() twice. my $secret = $self->secret(); push (@{$self->{guesses}}, $letter); #If you correctly guess the name, then push the #entire thing to guesses. push (@{$self->{guesses}}, $word) if ($secret eq $word); if ($secret =~ /$letter/){ $self->{score} += $self->chances + 1; } else { $self->{chances}--; } } } package main; my $ua = LWP::UserAgent->new(); my $response = $ua->get("http://www.perlmonks.org/index.pl?node_id=158 +51"); die $response->code() if $response->code() != 200; my $content = $response->content(); my $cblist = XMLin($content); my @user = map $_->{username}, @{$cblist->{user}}; my $monk = $user[rand @user]; #my $g = Games::GuessWord->new(words => [$monk]); my $g = new GamesGuesswordExtended($monk); # Uncomment out the following for testing print "Secret: " . $g->secret . "\n"; my @guesses = $g->guesses; do{ print "Guesses Remaining:" . $g->chances . "\n"; print "The Monk is: " . $g->answer . "\n"; print "What is your Guess?: "; my $response = <>; $g->guess($response); if ($g->won) { print "Yep, it was " . $g->secret . "...Great Guess!\n"; exit; } }until($g->chances<=0); print "Sorry, the monk was: " . $g->secret . "\n"
    Updated: See comment dated 8-6-2003 in code near 'sub guess'

    Kristofer Hoch

    Si vos can lego is, vos es super erudio

      Additionally, I could use the super way of doing things...

      #This function replaces GamesGuesswordExtend's #guess method. sub guess { my $self = shift(); my $word = shift(); chop($word); push (@{$self->{guesses}}, $word) if ($self->secret eq $word); $self->SUPER::guess(substr($word,0,1)); }
      Update: Condensed the code, just for fun

      Kristofer Hoch

      Si vos can lego is, vos es super erudio

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://280842]
Approved by ybiC
Front-paged by PodMaster
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-26 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls