Commits

Anonymous committed 73ef803

Import of worb sources, version 1.1 revision 2007.1123.

Comments (0)

Files changed (3)

doc/license.txt

-Copyright (c)2000, Cat's Eye Technologies.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-  Redistributions of source code must retain the above copyright
-  notice, this list of conditions and the following disclaimer.
-
-  Redistributions in binary form must reproduce the above copyright
-  notice, this list of conditions and the following disclaimer in
-  the documentation and/or other materials provided with the
-  distribution.
-
-  Neither the name of Cat's Eye Technologies nor the names of its
-  contributors may be used to endorse or promote products derived
-  from this software without specific prior written permission. 
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
-CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE. 
 <html><head>
     <meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
-    <meta name="Description" content="Cat's Eye Technologies: The "noit o' mnain worb" Language">
+    <meta name="Description" content="Cat's Eye Technologies: The 'noit o' mnain worb' Language">
     <title>Cat's Eye Technologies: The "noit o' mnain worb" Language</title>
 <meta name="Keywords" content=" Cat's Eye Technologies Language
  Programming computational computation non-deterministic
  nondeterminstic fungeoid funge befunge experimental ">
 </head>
 <body>
-<center>
 <h1>noit o' mnain worb</h1>
-</center><p><font size=-1>Version 1.1</font> <font size=-1>&nbsp;<img src="/images/icons/copyright.gif"
-   align=absmiddle width=12 height=12 alt="(c)" border=0>2000-2004 <a href="/">Cat's Eye Technologies</a>.  All rights reserved.<br>
-    This software is OSI Certified Open Source Software.<br>
-    OSI Certified is a certification mark of the <a href="http://www.opensource.org/"><img src="/images/icons/webicon.gif" alt="[WWW]" border=0 width=12 height=12>Open Source Initiative</a>.<br>
-    See the file <a href="license.txt">license.txt</a> for license information.</font>
-<hr>
 
-<h3>What is <u>noit o' mnain worb</u>?</h3>
+<p>Language version 1.1.  Distribution version 2007.1123.<br>
+Copyright &copy;2000-2007, Cat's Eye Technologies.  All rights reserved.</p>
+
+<h2>What is <u>noit o' mnain worb</u>?</h2>
 
 <p>The <u>noit o' mnain worb</u> language is a
 non-deterministic particle automaton based on brownian motion (or entropy).
 <li> <tt>!</tt> <i>loads</i> which represent something that the bobules can 'do'.
 </ul></p>
 
-<h3>Notes</h3>
+<h2>Notes</h2>
 
 <p>[Historical note: In version 1.0 (Jul 5 2000) of the language, which was released only
 on the Cat's Eye Technologies Mailing List,
-#/usr/local/bin/perl -w
+#!/usr/bin/perl -w
 
 # noit o' mnain worb - fungeoid language based on brownian motion
-# v1.1 Jul 19 2000 Chris Pressey, Cat's Eye Technologies
+# v2007.1123 Chris Pressey, Cat's Eye Technologies
 
-# Copyright (c)2000, Cat's Eye Technologies.
+# Copyright (c)2000-2007, Chris Pressey, Cat's Eye Technologies.
 # All rights reserved.
-# 
+#
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
 # are met:
-# 
-#   Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# 
-#   Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in
-#   the documentation and/or other materials provided with the
-#   distribution.
-# 
-#   Neither the name of Cat's Eye Technologies nor the names of its
-#   contributors may be used to endorse or promote products derived
-#   from this software without specific prior written permission. 
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
-# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-# OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE. 
+#
+#  1. Redistributions of source code must retain the above copyright
+#     notices, this list of conditions and the following disclaimer.
+#  2. Redistributions in binary form must reproduce the above copyright
+#     notices, this list of conditions, and the following disclaimer in
+#     the documentation and/or other materials provided with the
+#     distribution.
+#  3. Neither the names of the copyright holders nor the names of their
+#     contributors may be used to endorse or promote products derived
+#     from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
 
-# usage: [perl] worb[.pl] worb-playfield-file
+# usage: [perl] worb[.pl] [-delay ms] worb-playfield-file
 # requirements: ANSI terminal emulation, for animation.
 
 # history: v1.0 Jul  5 2000 - original release.
 #                             optimized display routine for ANSI
 #                             optimized is_bobule_at (cached)
 #                             relicensed & released on web site
+#          v2007.1123       - adapted to use Console::Virtual
+#                           - added strict qw(vars refs subs)
+#                           - added delay in ms cmdline option
+#                           - fixed hashbang line
+#                           - updated BSD license (no "REGENTS")
+
+use strict qw(vars refs subs);
+
+# This allows us to keep Console::Virtual in same directory as script
+BEGIN { use File::Basename; push @INC, dirname($0); }
+
+# Uncomment these lines to use specific display/input/color drivers.
+# BEGIN { $Console::Virtual::setup{display} = 'ANSI'; }
+# BEGIN { $Console::Virtual::setup{input} = 'Teletype'; }
+# BEGIN { $Console::Virtual::setup{color} = 'ANSI16'; }
+
+use Console::Virtual 2007.1122
+     qw(getkey display gotoxy clrscr clreol
+        normal inverse bold update_display color);
+
+# This lets us do sub-second sleeps, if Time::HiRes is available.
+my $sleep = sub($) { sleep(shift); };
+my $found_time_hires = 0;
+foreach my $c (@INC)
+{
+  $found_time_hires = 1 if -r "$c/Time/HiRes.pm";
+}
+if ($found_time_hires) {
+  require Time::HiRes;
+  $sleep = sub($) { Time::HiRes::sleep(shift); };
+}
 
 ### GLOBALS ###
 
-@bobule = ();
-@source = ();
-@sink = ();
-@playfield = ();
+my @bobule = ();
+my @source = ();
+my @sink = ();
+my @playfield = ();
 
-@bobule_at_cache = ();
+my @bobule_at_cache = ();
 
-$x = 0; $y = 0;
+my $x = 0;
+my $y = 0;
+
+my $maxx = 1;
+my $maxy = 1;
+
+my $delay = 100;
 
 ### SUBS ###
 
 sub draw_playfield
 {
-  printf "%c[1;1H", 27;  # gotoxy 1,1
   my $i; my $j; my $p;
   for($j = 0; $j <= $maxy; $j++)
   {
+    gotoxy(1, $j+1);
     for($i = 0; $i <= $maxx; $i++)
     {
       if ($p = is_bobule_at($i,$j))
       {
-        if ($p == 1) { print '.'; }
-        elsif ($p >= 2 and $p <= 3) { print 'o'; }
-        elsif ($p >= 4 and $p <= 6) { print 'O'; }
-        elsif ($p >= 7 and $p <= 10) { print '0'; }
-        else { print '@'; }
+        if ($p == 1) { display '.'; }
+        elsif ($p >= 2 and $p <= 3) { display 'o'; }
+        elsif ($p >= 4 and $p <= 6) { display 'O'; }
+        elsif ($p >= 7 and $p <= 10) { display '0'; }
+        else { display '@'; }
       } else
       {
-        print $playfield[$i][$j];
+        display($playfield[$i][$j] or ' ');
       }
     }
-    print "\n";
   }
 }
 
 
 ### MAIN ###
 
+while ($ARGV[0] =~ /^\-\-?(.*?)$/)
+{
+  my $opt = $1;
+  shift @ARGV;
+  if ($opt eq 'delay')
+  {
+    $delay = 0+shift @ARGV;
+  }
+  else
+  {
+    die "Unknown command-line option --$opt";
+  }
+}
+
+my $line;
+
 open PLAYFIELD, $ARGV[0];
 while(defined($line = <PLAYFIELD>))
 {
 }
 close PLAYFIELD;
 
-printf "%c[2J", 27;  # clear screen
+clrscr();
+color('white', 'black');
+draw_playfield();
+update_display();
 
-draw_playfield();
+my $new_x;
+my $new_y;
 
-$start_time = time();
-$tick = 1;
-while(1)
+while (1)
 {
   my $bobule; my $pole;
   foreach $bobule (@bobule)
     if ($bobule->[2] == 2 or $bobule->[2] == 4 or $bobule->[2] == 7 or $bobule->[2] == 11)
     {
       my $p = $bobule->[2];
-      printf "%c[%d;%dH", 27, $bobule->[1]+1, $bobule->[0]+1;
-      if ($p == 2) { print 'o'; }
-      elsif ($p == 4) { print 'O'; }
-      elsif ($p == 7) { print '0'; }
-      elsif ($p == 11) { print '@'; }
+      gotoxy($bobule->[0]+1, $bobule->[1]+1);
+      if ($p == 2) { display 'o'; }
+      elsif ($p == 4) { display 'O'; }
+      elsif ($p == 7) { display '0'; }
+      elsif ($p == 11) { display '@'; }
     }
     $new_x = $bobule->[0] + int(rand(1) * 3)-1;
     $new_y = $bobule->[1] + int(rand(1) * 3)-1;
     next if $playfield[$new_x][$new_y] eq 'v' and $bobule->[1] > $new_y;
     next if $new_x == $bobule->[0] and $new_y == $bobule->[1];
     print chr(7) if $playfield[$new_x][$new_y] eq '!';
-      printf "%c[%d;%dH%s", 27, $bobule->[1]+1, $bobule->[0]+1,
-        $playfield[$bobule->[0]][$bobule->[1]];
+    gotoxy($bobule->[0]+1, $bobule->[1]+1);
+    display $playfield[$bobule->[0]][$bobule->[1]];
     $bobule_at_cache[$bobule->[0]][$bobule->[1]] = 0;
     $bobule->[0] = $new_x;
     $bobule->[1] = $new_y;
     $bobule_at_cache[$bobule->[0]][$bobule->[1]] = 1;
-    printf "%c[%d;%dH.", 27, $bobule->[1]+1, $bobule->[0]+1;
+    gotoxy($bobule->[0]+1, $bobule->[1]+1);
+    display '.';
     $bobule->[2] = 1;
   }
   foreach $pole (@source)
       $bobule[$q] = $bobule[$#bobule]; pop @bobule;
     }
   }
-  # track_time();
-}
-
-sub track_time
-{
-  $tick++;
-  if ($tick > 1000)
-  {
-    $total_time = time() - $start_time;
-    $fps = int(1000 / $total_time);
-    die "Total time: $total_time seconds, approx fps: $fps\n";
-  }
+  update_display();
+  &$sleep($delay / 1000);
 }
 
 ### END ###