Name: Anonymous 2008-04-27 1:15
...with perl. I am so proud.
$dict = $ARGV[1] || 'words.list';
die "Dict file \"$dict\" does not exist." unless (-e $dict);
open DICT, $dict;
srand; rand $. < 1 and length $_ > 8 and chomp ($word = lc $_) while <DICT>;
close DICT;
$word =~ s/[^ \&\-a-z]//g;
$max_gs = $ARGV[0] || length $word;
($w_gs,$r_gs) = ('','');
print "Hangman!\n";
$_ = $word; s/[^ \&\-$r_gs]/_/g ; print "$_\n";
while (1) {
print "Guess: ";
chomp ($g = lc <STDIN>);
redo if $g !~ /^[a-z]$/ || "$r_gs$w_gs" =~ /$g/;
($word =~ /$g/ ? $r_gs : $w_gs) .= $g;
print (length $w_gs); print "/$max_gs\t";
$_ = $word; s/[^ \&\-$r_gs]/_/g ; print "$_\n";
if ($_ eq $word) {
print "\nLIFE!\n";
last;
}
if(length $w_gs >= $max_gs) {
print "\nDEATH!\n";
print "The word was $word\n";
last;
}
}
$_ = $word; s/[^ \&\-$r_gs]/_/g ; print "$_\n";print "$_\n"; = say;
$_ considered harmful.my $max_gs = shift;
push '/usr/share/dict/words' unless @ARGV;
die "Dict file \"$dict\" does not exist." unless (-e) for @ARGV;
my @words;
s/[^ &a-z-]//g and length > 8 and push @words, chomp lc while <>;
die 'No words in dict.' unless @words;
my $word = $words(rand @words);
$max_gs ||= length $word;
do {
print "Guess: ";
chomp ($g = lc <>);
redo if $g !~ /^[a-z]$/ || $r_gs . $w_gs =~ /$g/;
for ("$word\n") {
(/$g/ ? $r_gs : $w_gs) .= $g;
${($r_gs, $w_gs)[!/$g/]} .= $g;
s/[^ &$r_gs-]/_/g
print length $w_gs, "/$max_gs\t";
print;
print "\nLIFE!\n" and exit if /^$word$/;
}
} while (length $w_gw >= $max_gs);
print "\nDEATH!\n";
print "The word was $word\n";
do {
print "Guess: ";
chomp ($g = lc <>);
redo if $g !~ /^[a-z]$/ || $r_gs . $w_gs =~ /$g/;
for ("$word\n") {
(/$g/ ? $r_gs : $w_gs) .= $g;
s/[^ &$r_gs-]/_/g
print length $w_gs, "/$max_gs\t";
print;
print "\nLIFE!\n" and exit if /^$word$/;
}
} while (length $w_gw >= $max_gs);
#!/usr/bin/env perl
use strict;
use warnings;
use Carp;
use List::Util qw[first shuffle];
use File::Slurp;
use feature 'say';
my @files = ( $ARGV[1], 'words.list', '/usr/share/dict/words' );
my $dict = first { $_ && -e $_ } @files;
croak "Couldn't find a dict file" unless defined $dict;
my @words = map { lc } read_file $dict;
@words = shuffle @words;
say "Fucking hangman!";
thegame: foreach my $word (@words) {
chomp $word;
my $guesses = 8;
my $fails = 0;
my @underscores = (q[_]) x ( length $word );
while ($guesses) {
print join q[ ], @underscores;
say q[ ] . q[|] x $fails;
my $guess = lc <STDIN>;
if ( $guess eq $word ) {
say "Winnar!";
next thegame;
}
$guess = substr $guess, 0, 1;
say $guess;
redo if $guess !~ /[a-z]/;
my $found = 0;
for my $i ( 0 .. $#underscores ) {
if ( substr( $word, $i, 1 ) eq $guess ) {
$underscores[$i] = $guess;
$found = 1;
}
}
$fails++ unless $found;
if ( join( q[], @underscores ) eq $word ) {
say "Winrar!\n$word";
next thegame;
}
last if $fails == $guesses;
}
say "Fail\n$word";
}my @words = map { lc } read_file $dict;
@words = shuffle @words;my @words = shuffle map { lc } read_file $dict; be enough?
@perl $is %terrible
my $max_gs = shift;
push '/usr/share/dict/words' unless @ARGV;
die "Dict file \"$dict\" does not exist." unless (-e) for @ARGV;
my @words;
s/[^ &a-z-]//g and length > 8 and push @words, chomp lc while <>;
die 'No words in dict.' unless @words;
my $word = $words[rand @words];
$max_gs ||= length $word;
do {
print "Guess: ";
chomp ($g = lc <>);
redo if $g !~ /^[a-z]$/ || $r_gs . $w_gs =~ /$g/;
for ("$word\n") {
(/$g/ ? $r_gs : $w_gs) .= $g;
s/[^ &$r_gs-]/_/g
print length $w_gs, "/$max_gs\t";
print;
print "\nLIFE!\n" and exit if /^$word$/;
}
} while (length $w_gw >= $max_gs);
print "\nDEATH!\n";
print "The word was $word\n";