Anonymous avatar Anonymous committed 62a94c8

Added the input from the board.

Comments (0)

Files changed (3)

nurikabe-solver/Games-Nurikabe-Solver/MANIFEST

 Build.PL
 Changes
 examples/gui.pl
+examples/logic-games-online-2008-10-01.txt
 inc/Test/Run/Builder.pm
 lib/Games/Nurikabe/Solver/Base.pm
 lib/Games/Nurikabe/Solver/Board.pm

nurikabe-solver/Games-Nurikabe-Solver/examples/gui.pl

 use strict;
 use warnings;
 
+use blib;
+
 package NurikabeCanvas;
 
 use Wx ':everything';
 use Wx::Event qw(EVT_PAINT);
 use base 'Wx::Window';
 
+use Games::Nurikabe::Solver::Board;
+use Games::Nurikabe::Solver::Cell qw($NK_UNKNOWN $NK_WHITE $NK_BLACK);
+
 my $cell_width = 30;
 my $cell_height = 30;
 
+sub slurp
+{
+    my $filename = shift;
+    {
+        local $/;
+        open my $in, "<", $filename;
+        my $text = <$in>;
+        close($in);
+        return $text;
+    }
+}
+
+my $board = Games::Nurikabe::Solver::Board->load_from_string(
+    slurp(shift(@ARGV))
+);
+
+my %numbers = ();
+
+sub assign_board
+{
+    my $self = shift;
+
+    foreach my $island (@{$board->_islands()})
+    {
+        my $cell = $island->known_cells->[0];
+        $numbers{join(",", @$cell)} = $island->order();
+    }
+}
+
 sub new
 {
     my $class = shift;
         Wx::Size->new($cell_width*9, $cell_height*9)
     );
 
+    $self->assign_board();
+
     EVT_PAINT( $self, \&OnPaint );
 
     return $self;
 
     my $dc = Wx::PaintDC->new($self);
 
-    my $black_pen = Wx::Pen->new(Wx::Colour->new(0,0,0), 3, wxSOLID());
+    my $black_pen = Wx::Pen->new(Wx::Colour->new(0,0,0), 4, wxSOLID());
 
     $dc->SetPen( $black_pen );
 
     {
         for my $x (0 .. 8)
         {
-            $dc->SetBrush(wxGREY_BRUSH());
-            $dc->DrawRectangle($cell_width*$x, $cell_height*$y, $cell_width, $cell_height);
+            my $status = $board->get_cell([$y,$x])->status();
+
+            if ($status eq $NK_UNKNOWN)
+            {
+                $dc->SetBrush(wxGREY_BRUSH());
+            }
+            elsif ($status eq $NK_WHITE)
+            {
+                $dc->SetBrush(wxWHITE_BRUSH());
+            }
+            elsif ($status eq $NK_BLACK)
+            {
+                $dc->SetBrush(wxBLACK_BRUSH());
+            }
+
+            my $p_x = $cell_width*$x;
+            my $p_y = $cell_height*$y;
+            $dc->DrawRectangle(
+                $p_x, $p_y, $cell_width, $cell_height
+            );
+
+            if (exists($numbers{join(",",$y,$x)}))
+            {
+                my $s = $numbers{join(",",$y,$x)};
+
+                my $c_x = $p_x + $cell_width/2;
+                my $c_y = $p_y + $cell_height/2;
+
+                my ($w, $h) = $dc->GetTextExtent($s);
+                $dc->DrawText(
+                    $s,
+                    $c_x - $w/2,
+                    $c_y - $h/2,
+                );
+            }
         }
     }
 }

nurikabe-solver/Games-Nurikabe-Solver/examples/logic-games-online-2008-10-01.txt

+Width=9 Height=9
+[]  []  []  []  []  [3] []  []  []
+[]  [1] []  [5] []  []  []  []  []
+[]  []  []  []  []  []  []  []  []
+[]  []  []  []  [1] []  []  []  []
+[]  []  []  []  []  []  []  []  []
+[]  []  []  []  [6] []  []  []  []
+[]  []  []  []  []  []  []  []  []
+[]  []  []  []  []  [8] []  [7] []
+[]  []  []  [2] []  []  []  []  []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.