User:Brian/peal

{| border="1"
 * 1) !/usr/bin/perl


 * 1) prep.pl
 * 2) Autonumbers a textual grid.


 * 1) Copyright (c) Dysprosia, 2005, All rights reserved.
 * 2) Redistribution and use in source and binary forms, with or without
 * 3) modification, are permitted provided that the following conditions are met:
 * 4) * Redistributions of source code must retain the above copyright notice,
 * 5)   this list of conditions and the following disclaimer.
 * 6) * Redistributions in binary form must reproduce the above copyright notice,
 * 7)   this list of conditions and the following disclaimer in the documentation
 * 8)   and/or other materials provided with the distribution.
 * 9) * Neither the name of Dysprosia may be used to endorse or promote products
 * 10)   derived from this software without specific prior written permission.
 * 11) THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * 12) AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * 13) IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * 14) ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * 15) LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * 16) CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * 17) GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * 18) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * 19) LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * 20) OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$\="\n"; while(<>) {  chomp; last if /^--$/;

@line = split /,/; $j=0; foreach (@line) {     #print "'$_'"; $array[$i][$j] = $_; $j++; }  $i++; }

$number=1; for($y=0; $y < $i; $y++) {  for($x=0; $x < $j; $x++) {     my $sq = $array[$y][$x];

#Across cases if($sq =~ /[\.#]/ && $x == 0 && $x != $j-1 && $array[$y][$x+1] =~ /[\.#]/) {         $sq = $number; $acclues .= ";$number. ".$\; if($y != $i-1 && $array[$y+1][$x] =~ /[\.#]/ && $array[$y-1][$x] eq "*"){$dnclues .= ";$number. ".$\} if($y == 0 && $array[$y+1][$x] =~ /[\.#]/){$dnclues.=";$number. ".$\}; $number++; }

if($sq =~ /[\.#]/ && $x != $j-1 &&         $array[$y][$x-1] eq "*" && $array[$y][$x+1] =~ /[\.#]/) {         $sq = $number; $acclues .= ";$number. ".$\; if($y != $i-1 && $array[$y+1][$x] =~ /[\.#]/ && $array[$y-1][$x] eq "*"){$dnclues .= ";$number. ".$\} if($y == 0 && $array[$y+1][$x] =~ /[\.#]/){$dnclues.=";$number. ".$\}; $number++; }     #Down cases if($sq =~ /[\.#]/ && $y == 0 && $y != $i-1 && $array[$y+1][$x] =~ /[\.#]/) {         $sq = $number; $dnclues .= ";$number. ".$\; $number++; }     if($sq =~ /[\.#]/ && $y != $i-1 && $array[$y-1][$x] eq "*" && $array[$y+1][$x] =~ /^[\.#]/) {         $sq = $number; $dnclues .= ";$number. ".$\; $number++; }

$line .= $sq.","; }  print $line; $line = ""; } print "--"; print $acclues; print "--"; print $dnclues;