#!/usr/bin/perl -w

use Quantum::Entanglement;

my $num_letters = $ARGV[0];
my ($op, $t, $f);

if ($ARGV[1] =~ /play/) { # perfect player
  $op = '=~'; $t = ''; $f = ' not';
  $Quantum::Entanglement::conform = 1;
}
elsif ($ARGV[1] =~ /deal/) { # perfect dealer
  $op = '!~'; $t = ' not'; $f = '';
  $Quantum::Entanglement::conform = 1;
}
else { # Feynman style 20 questions
  $op = '=~'; $t = ''; $f = ' not';
  $Quantum::Entanglement::conform = 0;
}

print "Reading word list...";
open DICT, '</usr/share/dict/words' or die "dict: $!";
while (<DICT>) {
  chomp;
  push(@words,1,lc($_)) if length($_) == $num_letters;
}
close DICT; print "done\n";

my $word = entangle(@words);

while (<STDIN>) {
  chomp;
  print "So, you give up... $word\n" and last if /tell/;
  if (p_op($word, $op, qr/$_/)) {
    print " \$word does$t contain $_\n";
  }
  else {
    print " \$word does$f contain $_\n";
  }
}

__END__;

Usage:

./hangman.pl [num letters] [game type]

num letters => number of letters in word
game type   => /deal/ for a perfect dealer, so that the game is
                      weighted against the player.
               /play/ for a perfect player, so that every guess is
                      correct (if possible)
               other: for a Feynman style twenty questions type
                      game, where neither the player nor the dealer
                      know what the word will be, except that it must
                      remain consistant with the answers given by
                      the dealer

type in one letter at a time to guess, when you have had enough,
type in "tell" and you will be told one of the possible good words
which remain.
