Filename | /homes/dcw/src/perl/coloroids_solver/NewBoard.pm |
Statements | Executed 137237976 statements in 52.4s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
14145230 | 4 | 1 | 21.3s | 21.3s | cellstatus | NewBoard::
5584 | 3 | 2 | 12.7s | 27.5s | changeregioncolour | NewBoard::
5585 | 4 | 3 | 12.3s | 25.1s | extendregion | NewBoard::
2811488 | 1 | 1 | 4.51s | 4.51s | markcellcolour | NewBoard::
674063 | 7 | 2 | 1.09s | 1.09s | cell | NewBoard::
247875 | 6 | 1 | 397ms | 397ms | markcellstatus | NewBoard::
57 | 2 | 1 | 166ms | 166ms | as_string | NewBoard::
5579 | 2 | 2 | 8.74ms | 8.74ms | solved | NewBoard::
6757 | 5 | 2 | 8.26ms | 8.26ms | region | NewBoard::
1 | 1 | 1 | 2.34ms | 2.47ms | BEGIN@25 | NewBoard::
1 | 1 | 1 | 2.10ms | 2.29ms | BEGIN@24 | NewBoard::
1 | 1 | 1 | 1.91ms | 2.06ms | BEGIN@26 | NewBoard::
1 | 1 | 1 | 1.49ms | 1.49ms | CORE:open (opcode) | NewBoard::
1 | 1 | 1 | 1.01ms | 1.01ms | BEGIN@17 | NewBoard::
1 | 1 | 1 | 547µs | 5.29ms | mkboard | NewBoard::
1 | 1 | 1 | 539µs | 7.36ms | newfromfile | NewBoard::
1 | 1 | 1 | 407µs | 2.44ms | BEGIN@23 | NewBoard::
1 | 1 | 1 | 231µs | 231µs | BEGIN@43 | NewBoard::
1 | 1 | 1 | 225µs | 3.30ms | BEGIN@21 | NewBoard::
37 | 3 | 1 | 27µs | 27µs | CORE:readline (opcode) | NewBoard::
1 | 1 | 1 | 11µs | 35µs | BEGIN@28 | NewBoard::
1 | 1 | 1 | 9µs | 81µs | BEGIN@30 | NewBoard::
1 | 1 | 1 | 6µs | 6µs | CORE:close (opcode) | NewBoard::
1 | 1 | 1 | 6µs | 99µs | BEGIN@18 | NewBoard::
1 | 1 | 1 | 5µs | 33µs | BEGIN@17.3 | NewBoard::
1 | 1 | 1 | 5µs | 23µs | BEGIN@19 | NewBoard::
1 | 1 | 1 | 1µs | 1µs | boardsize | NewBoard::
0 | 0 | 0 | 0s | 0s | as_plain_string | NewBoard::
0 | 0 | 0 | 0s | 0s | new | NewBoard::
0 | 0 | 0 | 0s | 0s | newrandom | NewBoard::
0 | 0 | 0 | 0s | 0s | size | NewBoard::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package NewBoard; | ||||
2 | |||||
3 | # | ||||
4 | # new version of board object... represents much more information about | ||||
5 | # the state of the game so we can lookup more answers and spend less | ||||
6 | # time calculating. | ||||
7 | # a NewBoard stores the following: | ||||
8 | # GRID: ref to array of row | ||||
9 | # [row = ref to even-length pair array (colour,status)] | ||||
10 | # R: no of rows | ||||
11 | # C: no of columns | ||||
12 | # SIZE: R * C: no of cells in board | ||||
13 | # REGSIZE: Region size (no of cells in region) | ||||
14 | # ADJCOLBAG: bag of colours of cells immediately | ||||
15 | # adjacent to region. | ||||
16 | |||||
17 | 4 | 64µs | 3 | 1.07ms | use v5.12; # spent 1.01ms making 1 call to NewBoard::BEGIN@17
# spent 33µs making 1 call to NewBoard::BEGIN@17.3
# spent 27µs making 1 call to feature::import |
18 | 2 | 21µs | 2 | 192µs | # spent 99µs (6+93) within NewBoard::BEGIN@18 which was called:
# once (6µs+93µs) by main::BEGIN@12 at line 18 # spent 99µs making 1 call to NewBoard::BEGIN@18
# spent 93µs making 1 call to Function::Parameters::import |
19 | 2 | 19µs | 2 | 40µs | # spent 23µs (5+18) within NewBoard::BEGIN@19 which was called:
# once (5µs+18µs) by main::BEGIN@12 at line 19 # spent 23µs making 1 call to NewBoard::BEGIN@19
# spent 18µs making 1 call to Exporter::import |
20 | |||||
21 | 2 | 85µs | 2 | 6.32ms | # spent 3.30ms (225µs+3.07) within NewBoard::BEGIN@21 which was called:
# once (225µs+3.07ms) by main::BEGIN@12 at line 21 # spent 3.30ms making 1 call to NewBoard::BEGIN@21
# spent 3.03ms making 1 call to parent::import |
22 | |||||
23 | 2 | 86µs | 2 | 4.45ms | # spent 2.44ms (407µs+2.04) within NewBoard::BEGIN@23 which was called:
# once (407µs+2.04ms) by main::BEGIN@12 at line 23 # spent 2.44ms making 1 call to NewBoard::BEGIN@23
# spent 2.01ms making 1 call to lib::import |
24 | 2 | 1.73ms | 2 | 2.33ms | # spent 2.29ms (2.10+198µs) within NewBoard::BEGIN@24 which was called:
# once (2.10ms+198µs) by main::BEGIN@12 at line 24 # spent 2.29ms making 1 call to NewBoard::BEGIN@24
# spent 34µs making 1 call to Exporter::import |
25 | 2 | 1.65ms | 2 | 2.51ms | # spent 2.47ms (2.34+127µs) within NewBoard::BEGIN@25 which was called:
# once (2.34ms+127µs) by main::BEGIN@12 at line 25 # spent 2.47ms making 1 call to NewBoard::BEGIN@25
# spent 37µs making 1 call to Exporter::import |
26 | 2 | 1.62ms | 1 | 2.06ms | # spent 2.06ms (1.91+152µs) within NewBoard::BEGIN@26 which was called:
# once (1.91ms+152µs) by main::BEGIN@12 at line 26 # spent 2.06ms making 1 call to NewBoard::BEGIN@26 |
27 | |||||
28 | 2 | 41µs | 2 | 59µs | # spent 35µs (11+24) within NewBoard::BEGIN@28 which was called:
# once (11µs+24µs) by main::BEGIN@12 at line 28 # spent 35µs making 1 call to NewBoard::BEGIN@28
# spent 24µs making 1 call to overload::import |
29 | |||||
30 | # spent 81µs (9+72) within NewBoard::BEGIN@30 which was called:
# once (9µs+72µs) by main::BEGIN@12 at line 35 | ||||
31 | 1 | 7µs | 1 | 72µs | COLOUR => 0, # spent 72µs making 1 call to constant::import |
32 | STATUS => 1, | ||||
33 | INREGION => 1, | ||||
34 | ADJACENT => 2, | ||||
35 | 1 | 52µs | 1 | 81µs | }; # spent 81µs making 1 call to NewBoard::BEGIN@30 |
36 | |||||
37 | |||||
38 | # | ||||
39 | # my $board = Board->new( @boardarray ); | ||||
40 | # Build a new board object and return it. | ||||
41 | # @boardarray is an array of array refs of cells (colours) | ||||
42 | # | ||||
43 | 2 | 1.82ms | 3 | 6.60ms | # spent 231µs within NewBoard::BEGIN@43 which was called:
# once (231µs+0s) by main::BEGIN@12 at line 43 # spent 3.29ms making 1 call to utf8::AUTOLOAD
# spent 3.08ms making 1 call to utf8::SWASHNEW
# spent 231µs making 1 call to NewBoard::BEGIN@43 |
44 | { | ||||
45 | return mkboard( $class, @boardarray ); | ||||
46 | } | ||||
47 | |||||
48 | |||||
49 | # | ||||
50 | # my $board = Board->newfromfile( $filename ); | ||||
51 | # Build a new board object by opening and reading a file. | ||||
52 | # | ||||
53 | # spent 7.36ms (539µs+6.82) within NewBoard::newfromfile which was called:
# once (539µs+6.82ms) by main::RUNTIME at line 34 of testnewboardincnply | ||||
54 | 2 | 600ns | { | ||
55 | 1 | 1.50ms | 1 | 1.49ms | open( my $in, '<', $filename ) || die; # spent 1.49ms making 1 call to NewBoard::CORE:open |
56 | 1 | 14µs | 1 | 9µs | $_ = <$in>; # spent 9µs making 1 call to NewBoard::CORE:readline |
57 | 1 | 4µs | my( $w, $h ) = split( /\s+/, $_, 2 ); | ||
58 | 1 | 200ns | my @array; | ||
59 | 1 | 4µs | 1 | 700ns | while( <$in> ) # spent 700ns making 1 call to NewBoard::CORE:readline |
60 | { | ||||
61 | 35 | 6µs | chomp; | ||
62 | 35 | 478µs | 35 | 16µs | push @array, [ split( /\s+/, $_ ) ]; # spent 16µs making 35 calls to NewBoard::CORE:readline, avg 471ns/call |
63 | } | ||||
64 | 1 | 10µs | 1 | 6µs | close( $in ); # spent 6µs making 1 call to NewBoard::CORE:close |
65 | 1 | 46µs | 1 | 5.29ms | return mkboard( $class, @array ); # spent 5.29ms making 1 call to NewBoard::mkboard |
66 | 1 | 100ns | } | ||
67 | |||||
68 | |||||
69 | # | ||||
70 | # my $board = Board->newrandom( $w, $h, @colours ); | ||||
71 | # Build a new board object of width $w and height $h | ||||
72 | # with random colours from @colours. | ||||
73 | # | ||||
74 | method newrandom( $class: $w, $h, @colours ) | ||||
75 | { | ||||
76 | my @array; | ||||
77 | foreach my $i (1..$h) | ||||
78 | { | ||||
79 | my @row = map { $colours[int rand(@colours)] } 1..$w; | ||||
80 | push @array, \@row; | ||||
81 | } | ||||
82 | return mkboard( $class, @array ); | ||||
83 | } | ||||
84 | |||||
85 | |||||
86 | # | ||||
87 | # my $board = mkboard( $class, @array ); | ||||
88 | # Real constructor: turn @array (2-d array of colours) | ||||
89 | # into a NewBoard object | ||||
90 | # | ||||
91 | # spent 5.29ms (547µs+4.75) within NewBoard::mkboard which was called:
# once (547µs+4.75ms) by NewBoard::newfromfile at line 65 | ||||
92 | 2 | 3µs | { | ||
93 | 1 | 500ns | my $rows = @array; | ||
94 | 1 | 400ns | my $cols = @{$array[0]}; | ||
95 | 1 | 459µs | my @grid = map { [ map { $_, 0 } @$_ ] } @array; | ||
96 | #die Dumper \@grid; | ||||
97 | # make initial state: region is 0,0, adjacents are 0,1 and 1,0 | ||||
98 | 1 | 200ns | my $regionsize = 1; | ||
99 | 1 | 4µs | 1 | 26µs | my $adjcolbag = Sorthash->new; # spent 26µs making 1 call to Sorthash::new |
100 | 1 | 57µs | my $board = bless { | ||
101 | R => $rows, | ||||
102 | C => $cols, | ||||
103 | GRID => \@grid, | ||||
104 | SIZE => $rows * $cols, | ||||
105 | REGSIZE => $regionsize, | ||||
106 | ADJCOLBAG => $adjcolbag, | ||||
107 | }, $class; | ||||
108 | 1 | 2µs | 1 | 5µs | $board->markcellstatus( 0, 0, INREGION ); # mark 0,0 as inregion # spent 5µs making 1 call to NewBoard::markcellstatus |
109 | 1 | 1µs | 1 | 2µs | $board->markcellstatus( 0, 1, ADJACENT ); # mark 0,1 as adjacent # spent 2µs making 1 call to NewBoard::markcellstatus |
110 | 1 | 900ns | 1 | 2µs | $board->markcellstatus( 1, 0, ADJACENT ); # mark 1,0 as adjacent # spent 2µs making 1 call to NewBoard::markcellstatus |
111 | 1 | 2µs | 1 | 3µs | $adjcolbag->{ $board->cell( 0, 1 ) }++; # spent 3µs making 1 call to NewBoard::cell |
112 | 1 | 2µs | 1 | 2µs | $adjcolbag->{ $board->cell( 1, 0 ) }++; # spent 2µs making 1 call to NewBoard::cell |
113 | #die Dumper $board; | ||||
114 | 1 | 1µs | 1 | 4.70ms | $board->extendregion; # spent 4.70ms making 1 call to NewBoard::extendregion |
115 | #die Dumper $board; | ||||
116 | #die $board; | ||||
117 | 1 | 3µs | return $board; | ||
118 | 1 | 0s | } | ||
119 | |||||
120 | |||||
121 | # | ||||
122 | # my $newboard = $board->clone; | ||||
123 | # Clone a new board object and return it. | ||||
124 | # Provided by 'Clone' parent class. | ||||
125 | # | ||||
126 | #DCWmethod clone | ||||
127 | #DCW{ | ||||
128 | #DCW my $adjcolbag = Sorthash->new; | ||||
129 | #DCW %$adjcolbag = %{$self->{ADJCOLBAG}}; | ||||
130 | #DCW my @grid = map { | ||||
131 | #DCW [ map { Tuple->new(@$_) } @$_ ] | ||||
132 | #DCW } @{$self->{GRID}}; | ||||
133 | #DCW my $newboard = bless { | ||||
134 | #DCW R => $self->{R}, | ||||
135 | #DCW C => $self->{C}, | ||||
136 | #DCW GRID => \@grid, | ||||
137 | #DCW SIZE => $self->{SIZE}, | ||||
138 | #DCW REGSIZE => $self->{REGSIZE}, | ||||
139 | #DCW ADJCOLBAG => $adjcolbag, | ||||
140 | #DCW }, ref($self); | ||||
141 | #DCW} | ||||
142 | |||||
- - | |||||
145 | # | ||||
146 | # my $colour = $board->cell( $r, $c ); | ||||
147 | # Extract a specific cell colour ($r,$c) from the board | ||||
148 | # | ||||
149 | # spent 1.09s within NewBoard::cell which was called 674063 times, avg 2µs/call:
# 382848 times (617ms+0s) by NewBoard::extendregion at line 285, avg 2µs/call
# 180541 times (295ms+0s) by NewBoard::extendregion at line 329, avg 2µs/call
# 103908 times (168ms+0s) by NewBoard::extendregion at line 303, avg 2µs/call
# 5585 times (10.8ms+0s) by NewBoard::extendregion at line 272, avg 2µs/call
# 1179 times (3.06ms+0s) by main::fulllist_all_nply at line 65 of NewIncNPlyPicker.pm, avg 3µs/call
# once (3µs+0s) by NewBoard::mkboard at line 111
# once (2µs+0s) by NewBoard::mkboard at line 112 | ||||
150 | 1348126 | 231ms | { | ||
151 | 674063 | 98.5ms | my $pos = $c<<1; | ||
152 | 674063 | 177ms | my $row = $self->{GRID}[$r]; | ||
153 | 674063 | 98.1ms | my $colour = $row->[$pos]; | ||
154 | 674063 | 804ms | return $colour; | ||
155 | } | ||||
156 | |||||
157 | |||||
158 | # | ||||
159 | # my $status = $board->cellstatus( $r, $c ); | ||||
160 | # Extract the status (0, INREGION or ADJACENT) of cell ($r,$c) | ||||
161 | # | ||||
162 | # spent 21.3s within NewBoard::cellstatus which was called 14145230 times, avg 2µs/call:
# 6841625 times (10.3s+0s) by NewBoard::extendregion at line 282, avg 2µs/call
# 6840400 times (10.3s+0s) by NewBoard::changeregioncolour at line 364, avg 2µs/call
# 359297 times (562ms+0s) by NewBoard::extendregion at line 326, avg 2µs/call
# 103908 times (161ms+0s) by NewBoard::extendregion at line 304, avg 2µs/call | ||||
163 | 28290460 | 4.71s | { | ||
164 | 14145230 | 3.99s | my $row = $self->{GRID}[$r]; | ||
165 | 14145230 | 2.45s | my $pos = $c<<1|1; | ||
166 | 14145230 | 1.34s | my $status = $row->[$pos]; | ||
167 | 14145230 | 15.2s | return $status; | ||
168 | 1 | 0s | } | ||
169 | |||||
170 | |||||
171 | # | ||||
172 | # $board->markcellcolour( $r, $c, $col ); | ||||
173 | # Mark ($r,$c)' cell as INREGION and colour $col | ||||
174 | # | ||||
175 | # spent 4.51s within NewBoard::markcellcolour which was called 2811488 times, avg 2µs/call:
# 2811488 times (4.51s+0s) by NewBoard::changeregioncolour at line 365, avg 2µs/call | ||||
176 | 5622976 | 1.19s | { | ||
177 | 2811488 | 861ms | my $row = $self->{GRID}[$r]; | ||
178 | 2811488 | 381ms | my $pos = $c<<1; | ||
179 | 2811488 | 3.29s | $row->[$pos] = $col; | ||
180 | #print "debug: mcc($r,$c,$col): row $r [$pos] = $col\n"; | ||||
181 | } | ||||
182 | |||||
183 | |||||
184 | # | ||||
185 | # $board->markcellstatus( $r, $c, $status ); | ||||
186 | # Mark ($r,$c)' cellstatus as status | ||||
187 | # | ||||
188 | # spent 397ms within NewBoard::markcellstatus which was called 247875 times, avg 2µs/call:
# 92115 times (146ms+0s) by NewBoard::extendregion at line 313, avg 2µs/call
# 78893 times (134ms+0s) by NewBoard::extendregion at line 289, avg 2µs/call
# 76864 times (117ms+0s) by NewBoard::extendregion at line 342, avg 2µs/call
# once (5µs+0s) by NewBoard::mkboard at line 108
# once (2µs+0s) by NewBoard::mkboard at line 109
# once (2µs+0s) by NewBoard::mkboard at line 110 | ||||
189 | 495750 | 102ms | { | ||
190 | 247875 | 77.2ms | my $row = $self->{GRID}[$r]; | ||
191 | 247875 | 48.2ms | my $pos = $c<<1|1; | ||
192 | 247875 | 288ms | $row->[$pos] = $status; | ||
193 | #die "debug: markcellstatus($r, $c, $status): row[$pos] = $status\n"; | ||||
194 | 1 | 0s | } | ||
195 | |||||
196 | |||||
197 | # | ||||
198 | # my( $rows, $cols) = $board->size(); | ||||
199 | # Extract the size (rows x cols) of $board. | ||||
200 | # | ||||
201 | method size | ||||
202 | { | ||||
203 | return ( $self->{R}, $self->{C} ); | ||||
204 | } | ||||
205 | |||||
206 | |||||
207 | # | ||||
208 | # my $isover = $board->solved; | ||||
209 | # Is the game over? | ||||
210 | # | ||||
211 | method solved | ||||
212 | 5579 | 1.16ms | # spent 8.74ms within NewBoard::solved which was called 5579 times, avg 2µs/call:
# 5522 times (8.18ms+0s) by main::fulllist_all_nply at line 101 of NewIncNPlyPicker.pm, avg 1µs/call
# 57 times (557µs+0s) by main::solve_game at line 29 of NewSolveGame.pm, avg 10µs/call | ||
213 | 5579 | 10.3ms | return $self->{SIZE} == $self->{REGSIZE}; | ||
214 | 1 | 0s | } | ||
215 | |||||
216 | |||||
217 | # | ||||
218 | # my $size = $board->boardsize; | ||||
219 | # how many cells are in the board? | ||||
220 | method boardsize | ||||
221 | 1 | 200ns | # spent 1µs within NewBoard::boardsize which was called:
# once (1µs+0s) by main::incnply_pick_best at line 192 of NewIncNPlyPicker.pm | ||
222 | 1 | 3µs | return $self->{SIZE}; | ||
223 | } | ||||
224 | |||||
225 | |||||
226 | # | ||||
227 | # my( $ninregion, $adjcolbag ) = $board->region; | ||||
228 | # return information about the region: | ||||
229 | # the regionsize and the adjacent colour bag | ||||
230 | # | ||||
231 | method region | ||||
232 | 6757 | 1.15ms | # spent 8.26ms within NewBoard::region which was called 6757 times, avg 1µs/call:
# 5515 times (6.60ms+0s) by main::fulllist_all_nply at line 104 of NewIncNPlyPicker.pm, avg 1µs/call
# 1179 times (1.50ms+0s) by main::fulllist_all_nply at line 68 of NewIncNPlyPicker.pm, avg 1µs/call
# 56 times (153µs+0s) by main::solve_game at line 31 of NewSolveGame.pm, avg 3µs/call
# 6 times (8µs+0s) by main::fulllist_all_nply at line 79 of NewIncNPlyPicker.pm, avg 1µs/call
# once (1µs+0s) by main::solve_game at line 42 of NewSolveGame.pm | ||
233 | 6757 | 10.3ms | return ( $self->{REGSIZE}, $self->{ADJCOLBAG} ); | ||
234 | 1 | 0s | } | ||
235 | |||||
236 | |||||
237 | # | ||||
238 | # foreach_cell( $self, $property, $callback ); | ||||
239 | # For each cell in board that has $property (INREGION|ADJACENT) | ||||
240 | # invoke the coderef $callback with the row and the column and | ||||
241 | # the tuple. | ||||
242 | # | ||||
243 | #DCWmethod foreach_cell( $property, $callback ) | ||||
244 | #DCW{ | ||||
245 | #DCW my $rows = $self->{R}; | ||||
246 | #DCW my $cols = $self->{C}; | ||||
247 | #DCW my $g = $self->{GRID}; | ||||
248 | #DCW foreach my $r (0..$rows-1) | ||||
249 | #DCW { | ||||
250 | #DCW my $row = $self->{GRID}[$r]; | ||||
251 | #DCW foreach my $c (0..$cols-1) | ||||
252 | #DCW { | ||||
253 | #DCW my $colour = lc( substr($row, 2*$c, 1) ); | ||||
254 | #DCW my $tuple = $gr->[$c]; | ||||
255 | #DCW $callback->( $r, $c, $tuple ) if | ||||
256 | #DCW $tuple->[STATUS] == $property; | ||||
257 | #DCW } | ||||
258 | #DCW } | ||||
259 | #DCW} | ||||
260 | |||||
261 | 1 | 4µs | 4 | 43µs | my @delta = ( tuple(0,1), tuple(1,0), tuple(0,-1), tuple(-1,0) ); # spent 43µs making 4 calls to Tuple::tuple, avg 11µs/call |
262 | |||||
263 | # | ||||
264 | # $board->extendregion; | ||||
265 | # After changing the board, locate all cells that should join the | ||||
266 | # region, ie. which are now of the same colour as the region. | ||||
267 | # Start by locating the existing adjacent cells of the region colour, | ||||
268 | # then flood fill out from there. also updates the adjacent information. | ||||
269 | # | ||||
270 | method extendregion | ||||
271 | 5585 | 802µs | # spent 25.1s (12.3+12.8) within NewBoard::extendregion which was called 5585 times, avg 4.50ms/call:
# 5522 times (12.1s+12.7s) by main::fulllist_all_nply at line 98 of NewIncNPlyPicker.pm, avg 4.50ms/call
# 56 times (129ms+134ms) by main::solve_game at line 38 of NewSolveGame.pm, avg 4.71ms/call
# 6 times (10.3ms+11.1ms) by main::fulllist_all_nply at line 78 of NewIncNPlyPicker.pm, avg 3.57ms/call
# once (2.28ms+2.42ms) by NewBoard::mkboard at line 114 | ||
272 | 5585 | 4.91ms | 5585 | 10.8ms | my $regioncolour = $self->cell(0,0); # spent 10.8ms making 5585 calls to NewBoard::cell, avg 2µs/call |
273 | 5585 | 2.07ms | my $adjcolbag = $self->{ADJCOLBAG}; | ||
274 | 5585 | 1.08ms | my $rows = $self->{R}; | ||
275 | 5585 | 929µs | my $cols = $self->{C}; | ||
276 | 5585 | 698µs | my @todo; | ||
277 | # foreach adjacent cell of the regioncolour | ||||
278 | 5585 | 3.47ms | foreach my $r (0..$rows-1) | ||
279 | { | ||||
280 | 195475 | 153ms | foreach my $c (0..$cols-1) | ||
281 | { | ||||
282 | 6841625 | 4.58s | 6841625 | 10.3s | my $status = $self->cellstatus( $r, $c ); # spent 10.3s making 6841625 calls to NewBoard::cellstatus, avg 2µs/call |
283 | 6841625 | 1.87s | if( $status == ADJACENT ) | ||
284 | { | ||||
285 | 382848 | 279ms | 382848 | 617ms | my $colour = $self->cell( $r, $c ); # spent 617ms making 382848 calls to NewBoard::cell, avg 2µs/call |
286 | 382848 | 103ms | next unless $colour eq $regioncolour; | ||
287 | 78893 | 64.6ms | 78893 | 286ms | push @todo, tuple($r,$c); # spent 286ms making 78893 calls to Tuple::tuple, avg 4µs/call |
288 | # no longer adjacent | ||||
289 | 78893 | 67.1ms | 78893 | 134ms | $self->markcellstatus( $r, $c, 0 ); # spent 134ms making 78893 calls to NewBoard::markcellstatus, avg 2µs/call |
290 | } | ||||
291 | } | ||||
292 | } | ||||
293 | #print "debug: extendregion, extracted adjacent cells and neutered them\n"; | ||||
294 | #print "board is now:\n$self\ntodo is ", join(',', @todo), "\n"; | ||||
295 | # now @todo is all adjacent cells of regioncolour | ||||
296 | 5585 | 3.66ms | delete $adjcolbag->{$regioncolour}; # nothing adjacent | ||
297 | # adapted find linked colour code (aka flood fill) from here | ||||
298 | 5585 | 12.0ms | while( @todo ) | ||
299 | { | ||||
300 | 103908 | 17.9ms | my $pair = shift @todo; | ||
301 | #DCWmy( $r, $c ) = $pair->detuple; | ||||
302 | 103908 | 35.3ms | my( $r, $c ) = @$pair; | ||
303 | 103908 | 83.4ms | 103908 | 168ms | my $cellcolour = $self->cell( $r, $c ); # spent 168ms making 103908 calls to NewBoard::cell, avg 2µs/call |
304 | 103908 | 74.8ms | 103908 | 161ms | my $status = $self->cellstatus( $r, $c ); # spent 161ms making 103908 calls to NewBoard::cellstatus, avg 2µs/call |
305 | #print "debug: floodfill: cell $r,$c, colour $cellcolour, status $status\n"; | ||||
306 | 103908 | 14.9ms | die "extendregion: cell($r,$c), colour $cellcolour, ". | ||
307 | "should be $regioncolour\n" unless | ||||
308 | $cellcolour eq $regioncolour; | ||||
309 | # mark this cell as in the region - skipping cells already | ||||
310 | # in the region (eg. one cell reachable in the same move | ||||
311 | # via two different paths) | ||||
312 | 103908 | 15.3ms | next if $status == INREGION; | ||
313 | 92115 | 64.2ms | 92115 | 146ms | $self->markcellstatus( $r, $c, INREGION ); # spent 146ms making 92115 calls to NewBoard::markcellstatus, avg 2µs/call |
314 | 92115 | 18.0ms | $self->{REGSIZE}++; | ||
315 | # look at NSEW neighbours | ||||
316 | 92115 | 131ms | foreach my $dp (@delta) | ||
317 | { | ||||
318 | #DCWmy( $dr, $dc ) = $dp->detuple; | ||||
319 | 368460 | 101ms | my( $dr, $dc ) = @$dp; | ||
320 | 368460 | 67.2ms | my $tr = $r + $dr; | ||
321 | 368460 | 31.3ms | my $tc = $c + $dc; | ||
322 | # are we off the edge? | ||||
323 | 368460 | 84.5ms | next if $tr < 0 || $tr >= $rows | ||
324 | || $tc < 0 || $tc >= $cols; | ||||
325 | # have we already seen this cell? | ||||
326 | 359297 | 265ms | 359297 | 562ms | my $status = $self->cellstatus( $tr, $tc ); # spent 562ms making 359297 calls to NewBoard::cellstatus, avg 2µs/call |
327 | 359297 | 66.0ms | next if $status == INREGION; | ||
328 | # ok, new cell.. process | ||||
329 | 180541 | 145ms | 180541 | 295ms | my $neighbourcolour = $self->cell($tr,$tc); # spent 295ms making 180541 calls to NewBoard::cell, avg 2µs/call |
330 | #print "debug: process neighbour cell ($tr,$tc), colour=$neighbourcolour\n"; | ||||
331 | 180541 | 62.4ms | if( $neighbourcolour eq $regioncolour ) | ||
332 | { | ||||
333 | 25015 | 20.4ms | 25015 | 89.1ms | push @todo, tuple($tr,$tc); # spent 89.1ms making 25015 calls to Tuple::tuple, avg 4µs/call |
334 | 25015 | 9.33ms | next unless $status == ADJACENT; | ||
335 | # no longer ADJACENT | ||||
336 | $self->markcellstatus( $tr, $tc, 0 ); | ||||
337 | # nb: cells on todo list will end up INREGION | ||||
338 | $adjcolbag->{$regioncolour}--; | ||||
339 | } else | ||||
340 | { | ||||
341 | 155526 | 33.9ms | next if $status == ADJACENT; | ||
342 | 76864 | 49.9ms | 76864 | 117ms | $self->markcellstatus( $tr, $tc, ADJACENT ); # spent 117ms making 76864 calls to NewBoard::markcellstatus, avg 2µs/call |
343 | 76864 | 26.5ms | $adjcolbag->{$neighbourcolour}++; | ||
344 | } | ||||
345 | } | ||||
346 | } | ||||
347 | } | ||||
348 | |||||
349 | |||||
350 | # | ||||
351 | # $board->changeregioncolour( $newcolour ); | ||||
352 | # Change the colour of the whole region to $newcolour | ||||
353 | # NB: we do not extend the region at the end of this, | ||||
354 | # the caller should do that again. | ||||
355 | # | ||||
356 | # spent 27.5s (12.7+14.8) within NewBoard::changeregioncolour which was called 5584 times, avg 4.93ms/call:
# 5522 times (12.6s+14.6s) by main::fulllist_all_nply at line 97 of NewIncNPlyPicker.pm, avg 4.93ms/call
# 56 times (126ms+147ms) by main::solve_game at line 37 of NewSolveGame.pm, avg 4.88ms/call
# 6 times (18.0ms+22.8ms) by main::fulllist_all_nply at line 77 of NewIncNPlyPicker.pm, avg 6.80ms/call | ||||
357 | 11168 | 4.11ms | { | ||
358 | 5584 | 3.33ms | my $rows = $self->{R}; | ||
359 | 5584 | 1.12ms | my $cols = $self->{C}; | ||
360 | 5584 | 12.1ms | foreach my $r (0..$rows-1) | ||
361 | { | ||||
362 | 195440 | 125ms | foreach my $c (0..$cols-1) | ||
363 | { | ||||
364 | 6840400 | 4.53s | 6840400 | 10.3s | my $status = $self->cellstatus( $r, $c ); # spent 10.3s making 6840400 calls to NewBoard::cellstatus, avg 2µs/call |
365 | 6840400 | 3.67s | 2811488 | 4.51s | $self->markcellcolour( $r, $c, $newcolour ) # spent 4.51s making 2811488 calls to NewBoard::markcellcolour, avg 2µs/call |
366 | if $status == INREGION; | ||||
367 | } | ||||
368 | } | ||||
369 | #print "debug crc board now $self\n"; | ||||
370 | 1 | 100ns | } | ||
371 | |||||
372 | |||||
373 | # | ||||
374 | # my $str = $board->as_string; | ||||
375 | # Generate a printable string form of a complete board | ||||
376 | # Return the printable firm of a board | ||||
377 | # | ||||
378 | method as_string | ||||
379 | 57 | 26µs | # spent 166ms within NewBoard::as_string which was called 57 times, avg 2.91ms/call:
# 56 times (165ms+0s) by main::solve_game at line 32 of NewSolveGame.pm, avg 2.94ms/call
# once (906µs+0s) by main::solve_game at line 43 of NewSolveGame.pm | ||
380 | 57 | 50µs | my $rows = $self->{R}; | ||
381 | 57 | 40µs | my $cols = $self->{C}; | ||
382 | 57 | 22µs | my $str = "\t"; | ||
383 | 57 | 197µs | foreach my $col (0..$cols-1) | ||
384 | { | ||||
385 | 1995 | 648µs | $str .= sprintf( "%2d", $col ); | ||
386 | } | ||||
387 | 57 | 23µs | $str .= "\n"; | ||
388 | 57 | 45µs | foreach my $row (0..$rows-1) | ||
389 | { | ||||
390 | 1995 | 691µs | $str .= sprintf( " %2d ", $row ); | ||
391 | 1995 | 670µs | my $rowarr = $self->{GRID}[$row]; | ||
392 | 1995 | 167µs | my $pos = 0; | ||
393 | 1995 | 931µs | foreach my $col (0..$cols-1) | ||
394 | { | ||||
395 | 69825 | 9.11ms | my $colour = $rowarr->[$pos++]; | ||
396 | 69825 | 8.81ms | my $status = $rowarr->[$pos++]; | ||
397 | 69825 | 5.52ms | my $extra = " "; | ||
398 | 69825 | 6.33ms | $colour = uc($colour) if $status == INREGION; | ||
399 | 69825 | 3.80ms | $extra = '+' if $status == ADJACENT; | ||
400 | 69825 | 14.7ms | $str .= "$colour$extra"; | ||
401 | } | ||||
402 | 1995 | 464µs | $str .= "\n"; | ||
403 | } | ||||
404 | 57 | 114ms | return $str; | ||
405 | } | ||||
406 | |||||
407 | |||||
408 | # | ||||
409 | # my $str = $board->as_plain_string; | ||||
410 | # Build and return a printable plain string form of a board, | ||||
411 | # with no status information | ||||
412 | # | ||||
413 | method as_plain_string | ||||
414 | { | ||||
415 | my $rows = $self->{R}; | ||||
416 | my $cols = $self->{C}; | ||||
417 | my $str = "$rows $cols\n"; | ||||
418 | foreach my $row (0..$rows-1) | ||||
419 | { | ||||
420 | foreach my $col (0..$cols-1) | ||||
421 | { | ||||
422 | $str .= $self->cell($row,$col). " "; | ||||
423 | } | ||||
424 | $str .= "\n"; | ||||
425 | } | ||||
426 | return $str; | ||||
427 | 1 | 100ns | } | ||
428 | |||||
429 | |||||
430 | 1 | 5µs | 1; | ||
# spent 6µs within NewBoard::CORE:close which was called:
# once (6µs+0s) by NewBoard::newfromfile at line 64 | |||||
# spent 1.49ms within NewBoard::CORE:open which was called:
# once (1.49ms+0s) by NewBoard::newfromfile at line 55 | |||||
sub NewBoard::CORE:readline; # opcode |