#!/usr/add-on/perl5/bin/perl
# POTM ENTRY:  Oyster Knight
# Me:          Gary Gressel
# Email:       gressel@onac02.attmail.com
# Execution:   Change first line (/usr/bin/perl) to point to your local 
#              perl compiler.  Since I don't have a "winning" entry, I'm not
#              concerned about trying to compile this code ahead of execution.
#              $ oyster 
 print "0 0\n"; $MaxToCheck = 200; $CX = 0; $CY = 0; $moves = 0;
 &initDistanceChart; &get_points; &main_loop;
sub get_points { open(INP,"@ARGV[0]"); $counter = 0;
 while () { $counter++; chop($_); $Point{$_} = $MaxToCheck;
 } close(INP); } sub main_loop { while (1) {
  $moves++; &GetShortDistance($CX,$CY);
  print "$NX $NY\n"; $CX = $NX; $CY = $NY;
  if (($CX == 0) && ($CY == 0)) { exit; } } }
sub GetShortDistance { undef($NextPointHit); $NextDistance = $MaxToCheck;
 if (%Point eq 0) { $Point{"0 0"} = $MaxToCheck; }
 while (($key,$value) = each(%Point)) {
  if ($value <= $MaxToCheck) { ($kx,$ky) = split(" ",$key);
   $Point{$key} = &DetermineDistance($CX,$CY,$kx,$ky);
   if ($Point{$key} < $NextDistance) {
    $NextDistance = $Point{$key}; ($NX,$NY) = split(" ",$key); }
  } else { $Point{$key} = $value - 3; } }
 if ($NextDistance <2) { $NextPointHit = " "; $tmp = join(" ",$NX,$NY);
  $Visited{$tmp}++; delete($Point{$tmp}); return; } 
 ($NX,$NY) = &MoveTowards(); }
sub DetermineDistance { 
 $t1 = $_[0]-$_[2]; $t2 = $_[1]-$_[3]; $ax = &ReadDistanceChart($t1,$t2);
 return $ax; }
sub MoveTowards{
  $tx = $CX + 1; $ty = $CY + 2; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX + 1; $ty = $CY - 2; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX + 2; $ty = $CY + 1; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX + 2; $ty = $CY - 1; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX - 1; $ty = $CY + 2; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX - 1; $ty = $CY - 2; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX - 2; $ty = $CY + 1; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX - 2; $ty = $CY - 1; if (&TryMoveAxis() == 0) { return($tx,$ty); }
  $tx = $CX + 1; $ty = $CY + 2; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX + 1; $ty = $CY - 2; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX + 2; $ty = $CY + 1; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX + 2; $ty = $CY - 1; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX - 1; $ty = $CY + 2; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX - 1; $ty = $CY - 2; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX - 2; $ty = $CY + 1; if (&TryMoveAny() == 0) { return($tx,$ty); }
  $tx = $CX - 2; $ty = $CY - 1; if (&TryMoveAny() == 0) { return($tx,$ty); } }
sub initDistanceChart { $DistanceChart{"1 0"} = 3; $DistanceChart{"1 1"} = 2;
$DistanceChart{"2 0"} = 2; $DistanceChart{"2 1"} = 1; 
$DistanceChart{"2 2"} = 4; $DistanceChart{"3 0"} = 3;
$DistanceChart{"3 1"} = 2; $DistanceChart{"3 2"} = 3;
$DistanceChart{"3 3"} = 2; $DistanceChart{"4 0"} = 2;
$DistanceChart{"4 1"} = 3; $DistanceChart{"4 2"} = 2;
$DistanceChart{"4 3"} = 3; $DistanceChart{"5 0"} = 3;
$DistanceChart{"5 1"} = 4; $DistanceChart{"5 2"} = 3;
$DistanceChart{"5 3"} = 4; $DistanceChart{"5 4"} = 3;
$DistanceChart{"5 5"} = 4; $DistanceChart{"6 0"} = 4;
$DistanceChart{"6 1"} = 3; $DistanceChart{"6 2"} = 4;
$DistanceChart{"6 3"} = 3; $DistanceChart{"6 4"} = 4;
$DistanceChart{"6 5"} = 5; $DistanceChart{"6 6"} = 4;
$DistanceChart{"7 1"} = 4; $DistanceChart{"7 2"} = 5;
$DistanceChart{"7 3"} = 4; $DistanceChart{"7 4"} = 5;
$DistanceChart{"7 5"} = 4; $DistanceChart{"7 6"} = 5;
$DistanceChart{"7 7"} = 6; $DistanceChart{"8 1"} = 5;
$DistanceChart{"8 2"} = 4; $DistanceChart{"8 3"} = 5;
$DistanceChart{"8 4"} = 4; $DistanceChart{"8 5"} = 5;
$DistanceChart{"8 6"} = 6; $DistanceChart{"8 7"} = 5;
$DistanceChart{"8 8"} = 6; $DistanceChart{"0 0"} = 0;
}
sub ReadDistanceChart {
local($val_x,$val_y,$tmp); $val_x = $_[0]; $val_y = $_[1];
 if ($val_x < 0) { $val_x = - $val_x } if ($val_y < 0) { $val_y = - $val_y }
 if ($val_x < $val_y) {
  $tmp = join (" ",$val_y,$val_x); } else { $tmp = join (" ",$val_x,$val_y); }
 if ($DistanceChart{$tmp} > 0) { return($DistanceChart{$tmp});
 } else { return (sqrt(($val_x * $val_x) + ($val_y * $val_y))); } }
sub TryMoveAxis {
if (($tx >= 0) && ($ty >= 0)) { $tmp = join(" ",$tx,$ty);
  if (!defined($Visited{$tmp})) { $tdist = &DetermineDistance($NX,$NY,$tx,$ty);
   if ($tdist < $NextDistance) { $Visited{$tmp}++; return(0); }
  } } return (1); }
sub TryMoveAny { if (($tx >= 0) && ($ty >= 0)) { $tmp = join(" ",$tx,$ty);
  $Visited{$tmp}++; return(0); } return(1); }












Make your own free website on Tripod.com