#!/usr/bin/perl -wT

use strict;

my $http_cookie = $ENV{'HTTP_COOKIE'};
my $script_name = $ENV{'SCRIPT_NAME'};
my $misties;
my @comments;
my @paths;
my $i;
my $random;
my $buf;
my $file;

if($http_cookie =~ "mst3k=1")
{
  $file = "templates/mst3k.html";
  open(FH, $file);
  read(FH, $misties, 8192);
  close(FH);
  @paths = split(/\//,$script_name);
  $file = 'comments/' . pop(@paths) . '.txt';
  $buf = "";
  open(FH, $file);
  read(FH, $buf, 1024);
  close(FH);
  @comments = split(/\n/,$buf);
  for($i = 0;$i < 3;$i++)
  {
    $random = int(rand(@comments));    
    $random = splice(@comments,$random,1);
    $misties =~ s/TEXT/$random/;
  }
  $misties =~ s/FILENAME/$file/;
}

print "Content-type: text/html\n\n";

print <<END_OF_PAGE;
<html>
<head>
<title>M A A R</title>
</head>
<style type="text/css">
        body {
        background : #A0D0D0 ;
        color : #000000; }
        A:link, A:visited { text-decoration : none }
        A:visited { color : #2030E0 }
        A:link { color : #2030E0 }
        A:hover { color : #0020A0;
	background :  ;}

</style>
<body>
<a href = "http://www.yikes.com/~pengo">main</a>.<a href = "http://www.yikes.com/~pengo/projects.html">projects</a>.maar<br><br>
<table border = "0" cellpadding = "20" cellspacing ="10">
 <tr>
  <td align = "right" bgcolor = "202040">
   <img border="0" src="images/robot.jpg">
  </td>
  <td align = "left"valign = "bottom">
   <font face="Times" size=+2>
   <b>M.A.A.R.:</b>  <b>M</b>ap <b>A</b>cquiring <b>A</b>utonomous <b>R</b>over</b>
  </td>
 </tr>
 <tr>
  <td align = "right" valign = "top">
   <a href = "images/rover">Pictures</a><br><br>
   <a href = "123evail.html">Evaluation</a><br><br>
   <a href = "files/maar2.doc">Project Report</a>:<br>
   by Neil Otero
  </td>
  <td bgcolor = "#E0E0E0" valign = "top">
<p>The idea for this project came from the Mars Pathfinder mission.  The severe drawback in the human 
controlled rover is that signals take 5 minutes to travel to and from Mars.  The easy solution of course is 
to have automated rovers.</p>
<p>I was unlucky enough to have missed the first session of this class so all the groups had already 
formed.  I found one group (Neil Otero and Lei Deng) planning on building a "dumb rover" that would drive 
in a straight line until it's way was blocked, and another group (Linh Hoang and Lien Trinh) working on 
wireless communication.  I convinced them to all work with me and incoperate the projects together.  The 
teams stayed as they were, and I set out building and testing sensor systems, with the plan of combining 
them when we had all finished.</p>
<p>The division of labor worked rather well, we kept a team message board to keep track of changes that we 
made or would like to make that would affect other groups.  My sensors were finished early and I spent my 
time floating between groups to give help where I could and make sure everything would fit together in the 
end.</p>
<p>In the end, everything worked out quite nicely.  We had to settle for a slightly dumber AI as we ran out 
of program space, but it managed to miss the hazards and not fall off the table for the demo, so its all 
good.</p>
<p>It's a rather funny story about the program, I'd been writing the AI and simulating it in RAM instead of 
burning it to the EEPROM, never realizing that I'd gone way overbudget.  With about 4 days left I 
discovered my folly, there was no time to order a larger EEPROM and remap it so I'd have to hack and 
slash the AI.  I had a method that I had used to finish up my cs160 project: french bread, cheese, coke 
(cola!) and eyedrops.  Hunger grips you and you snack on the cheese and bread, the saltiness of the cheese 
brings you to drink more and more coke.  And for what used to be the bane of my all nighters, eyedrops 
would cure me of the burning need to close my eyes after a hard day spent infront of a CRT.  The old AI was 
written lavishly with no concern for diskspace, barely anything was salvagable.  I remained in lab 3 days 
programming a leaner (considerably stupider) AI.  It was the afternoon, I recognized the afternoon regulars 
coming in for the third time.  I burned my latest version onto the rover and started testing the tower 
routines.  Smoke started billowing out of the creases of the stepper motor.  I ripped the power cords off 
and started shutting down everything I could, expelling profanities and exclaimations all the while.  I 
blew the smoke away and reached out with my hand to touch it.  It was 
cold.  I froze at the realization, I had hallucinated the entire event.  I 
got up slowly, aware that everyone in the lab was staring at me, walked 
outside and fell immediately to sleep on the couch.  I slept through my 
"History of Jazz" final (though I didn't know it at the time) and awoke 
amidst a study group that had taken all the seats around me 
to prepare for some final.  Not knowing the time or day (or caring) I got up and walked back to lab to 
finish the program.</p>
  </td>
 </tr>
</table>
$misties
</body>
</html>
END_OF_PAGE
