]> git.donarmstrong.com Git - bin.git/commitdiff
more work on anamang
authorDon Armstrong <don@donarmstrong.com>
Thu, 22 Sep 2011 22:25:49 +0000 (22:25 +0000)
committerDon Armstrong <don@donarmstrong.com>
Thu, 22 Sep 2011 22:25:49 +0000 (22:25 +0000)
anamang

diff --git a/anamang b/anamang
index 81841ec89f123a71b63e5c17e6b0badd50d91bfd..42467a8a5dba0ed2e3608b269ed70b3fb4c5f9df 100755 (executable)
--- a/anamang
+++ b/anamang
@@ -74,6 +74,7 @@ $MLDBM::DumpMeth=q(portable);
 
 use File::stat;
 use List::Util qw(min max);
+use POSIX qw(floor);
 
 my %options = (debug           => 0,
               help            => 0,
@@ -133,6 +134,8 @@ my $database = update_and_load_database($options{database_dir},$options{wordlist
 
 # for now, concentrate on finding single word solutions
 if ($options{acrostic}) {
+}
+elsif ($options{acrostic}) {
     foreach my $word (@words) {
        my $length = length($word);
        my @let = split //, $word;
@@ -234,6 +237,73 @@ sub find_allowable_words {
     return grep {$words{$_} >= $must_match} keys %words;
 }
 
+sub solve_acrostic {
+    my ($acrostic) = @_;
+    # need to find unsolved words
+
+    # if there are multiple intersecting unsolved locations, try to
+    # solve the hard ones first, then the easy ones.
+
+    # given the current state of the board, find all possible words
+    # that fit the fixed positions
+
+    # find unsolved words
+
+    # find positions with _ or ?, * or | are unsolved bits
+    
+    # scan the puzzle from left to right, top to bottom (across
+    # answers), then top to bottom, left to right (down answers)
+    my $in_word=0;
+    my $current_answer=0;
+
+    sub __add_to_answers {
+       my ($acrostic,$current_answer,$in_word,$pos) = @_;
+       if ($acrostic->{grid}[$pos] !~ /^\*\|$/) {
+           if (not $$in_word) {
+               $$current_answer++;
+           }
+           $$in_word = 1;
+           $acrostic->{answers}[$$current_answer]{letters} .= $acrostic->{grid}[$pos];
+           $acrostic->{answers}[$$current_answer]{length}++;
+           $acrostic->{answers}[$$current_answer]{unsolved} = 0;
+           push @{$acrostic->{answers}[$current_answer]{positions}}, $pos;
+           push @{$acrostic->{answer_grid}[$pos]}, $current_answer;
+           if ($acrostic->{grid}[$pos] =~ /^\_\?$/) {
+               $acrostic->{answers}[$$current_answer]{unsolved} = 1;
+           }
+       }
+       else {
+           $$in_word = 0;
+       }
+    }
+
+    for my $width (0..($acrostic->{width}-1)) {
+       $in_word = 0;
+       for my $height (0..($acrostic->{height}-1)) {
+           my $pos = $height*$acrostic->{height} + $width;
+           __add_to_answers($acrostic,\$current_answer,\$in_word,$pos);
+       }
+    }
+    for my $height (0..($acrostic->{height}-1)) {
+       $in_word = 0;
+       for my $width (0..($acrostic->{width}-1)) {
+           my $pos = $height*$acrostic->{height} + $width;
+           __add_to_answers($acrostic,\$current_answer,\$in_word,$pos);
+       }
+    }
+
+    # for all possible answers which are unsolved, find allowable words
+    for my $answer (0..$#{$acrostic->{answers}}) {
+    }
+
+    # for all crossing positions, find allowed letters and eliminate
+    # words which do not share a letter in common with a word in the
+    # opposite direction
+
+    # for all crossing positions, eliminate words which do not share a
+    # letter in common with a word in the opposite direction
+}
+
 
 sub update_and_load_database {
     my ($dir,$wordlist) = @_;