I coded a test_strategy sub, that takes a guessing function (a strategy) and runs many games with it, on the easy dictionary. Here it is:
sub test_strategy { my $func_ref = $_[0]; my $dict_file = "easy.txt"; open(FH, $dict_file) or die "Can't open $dict_file: $!\n"; my @words = <FH>; chomp(@words); my $n_runs = 200; my $verbose = 0; my $total_count = 0; for (my $i = 0; $i < $n_runs; ++$i) { my @dup_words = @words; my $count = 1; # Pick the word that should be guessed my $the_word = random_arr_elem(\@dup_words); print "The word: $the_word\n" if ($verbose); # Here the guessing starts # my $guess = &$func_ref(\@dup_words); while (1) { my $score = score($the_word, $guess); print "$guess $score\n" if ($verbose); last if ($score == $words_equal); my $ref = refine_words_array(\@dup_words, $guess, $score); @dup_words = @$ref; die if (scalar(@words) == 0); $guess = &$func_ref(\@dup_words); ++$count; } print "Guessed after $count tries\n" if ($verbose); $total_count += $count; print "$i " if ($i % 10 == 1); } my $av_count = $total_count / $n_runs; print "\nRun $n_runs games. Average guess count: $av_count\n"; }
When run like this:
test_strategy(\&random_arr_elem);
On average, this strategy guesses a word after 7.8 tries.

This will serve as a framework for me to test more advanced heuristics, and see how they match against the simple random one.

In reply to Re: The Jotto word game by spurperl
in thread The Jotto word game by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.