
  Programs for HP2000E
  ====================

These are programs for TSB E that were converted from non-HP systems,
created anew, and/or contain "fake" TSB-E screen codes.

OTHELL - My 1st attempt at writing a Reversi program
OTH    - A Reversi program with a side-by-side display and lookahead
FACTOR - Some old code I found that displays prime factors of numbers
LNAUTO - Displayes 4-state line automata from a 10-digit rule string
MANDPL - Plots the Mandelbrot Set and surrounding regions
OTHEL2 - terminal-enabled version of OTHEL.T000
BEASTE - terminal-enabled highly mod'd version of BEASTI.D600
OTHMOD - terminal-enabled ANSI-color version of OTH
MLIFE  - terminal-enabled Life display

The terminal-enabled programs require a modified simh hp2100 simulator
which converts "fake" terminal codes such as '27E etc to common ANSI codes.
To convert these to real TSB code (not E since E can't normally do this)
move the '27 etc codes outside the PRINT quotes, i.e. change PRINT "'27H"
etc to read PRINT '27"H". Of course that would require a real HP terminal
so for modern usage convert to ANSI codes instead.. PRINT '27"[H" for home,
PRINT '27"[2J"'27"[H" for clear screen, PRINT '27"[0J" for clear-to-end etc.
The modified hp2100 supports '-encoded lower case letters (i.e. '109 for m)
but not in the middle of HP-style terminal sequences, so attributes are
encoded as ANSI-style sequences instead. The intent is to make the programs
behave like old terminal-enabled games, not to actually be authentic code.
To achieve this effect under TSB-E I had to get creative with the sim..
pretend the code is running on a cleverly modified HP terminal.

Note... the original '27E codes were not compatible with HP264x terminals,
there <esc>E resets the terminal. This doesn't matter much since there is
no way to run them on a real HP mini unless a translator box is made that
does something similar to the modified simulator, essentially pick up on the
'27 etc codes and output the ascii equivalent but if running on a 2645 etc
terminal do something in the source to output something besides '27E, an
equivalent would be (assuming the translator box is in place) '27H'27J.


I wrote OTHELL to see what it takes to make a Reversi-playing program from
scratch. It wasn't exactly easy but came together once I broke it down to
smaller tasks like counting how many pieces will flip in a single direction,
doing that for all 8 directions, and reusing the same scan code to actually
flip the pieces once all the possibilities have been considered. OTHELL uses
a table of numbers to determine the relative importance (weight) of different
positions, an idea I got after reading "A genetic algorithm to improve an
Othello program" by Jean-Marc Alliot and Nicolas Durand, obtained from:
http://www.recherche.enac.fr/~alliot/chess.html
I made up my own numbers since my evaluation formula is likely very different
but the GA-generated values from the paper work when plugged into the DATA
statements provided the bias value B1 is increased to avoid negative scores.

FACTOR is based on an old Wang Basic listing I found in my folder of old
stuff I used to play with.

LNAUTO was written from scratch on the simulated TSB E system - after
figuring out how to make the backspace work. This implements the most
common line automata in which the line of cells could assume one of four
states, numbered 0-3. A 10-digit string specifies the state of the next
generation based on the sum of the cell and its immediate neighbors.
The first digit specifies the state if all three cells are 3, or a sum
of 9, and the last digit specifies the state if the sum is 0. Thus given
a line of cells: 013202210332001100  and the rule: 0023121300
the next gen is: 023122112301303300. These are assigned characters
to make pretty patterns on the screen. At the rule string prompt enter
anything invalid (like H) for a list of rules to try.

The OTHELL program went through many revisions, eventually ending
up as OTH. Some versions attempted to learn from the moves of the
player to optimize the move weights, keeping the results in a file,
but that didn't result in any apparent improvement over simply having
good weights to begin with. Along the way the display was changed
to show the previous and current configurations side-by-side.

The biggest improvement came from adding a single level of lookahead...
A copy of the main array was already in the "was" array, so the program saves
the current state, makes the move, then recursively calls the find-move sub
again with things set up to play the human side instead. After figuring out
a potential human move it restores the state and array, continuing on as if
nothing happened except for subtracting the simulated human player's score
from the score of the move so later it can better pick the "best" move once
all possible moves have been explored. A pitfall I had to work around was
the requirement that a GOSUB within a FOR loop cannot call a subroutine
(in this case itself) containing a FOR loop with the same variable name.
Fortunately the loops were compact enough to simply duplicate with
different FOR variable names when the program is looking ahead.

Rather than trying to learn from the player, OTH takes a simpler approach
to optimization.. if a corner position is chosen by either side the weights
of the 3 positions next to it are increased as it is no longer useful to
avoid those positions. DELETE-7120,7280 to disable this feature.

MANDPL is a Mandelbrot plotter based on a Wang Basic listing dated 10/28/86,
the original program did not have zooming functions. The original was set to
a 132x66 screen and did all calculations to an array before printing, having
the unfortunate effect of making other tasks think they locked up. I learned
not to play with it until all the night's processing was done. This version
for TSB E has a 72x22 screen and gets the idea of regional zooming from a
Mandelbrot plotter someone wrote for an Edsac simulation. At the time I wrote
the Wang version I'd been playing with a better-looking plotter on my C64 but
it took hours to make an image, the Wang could do a rough plot in a few
minutes so I used it to find interesting areas to leave plotting on my home
machine the next day while at work. Back then one or two decent pictures a
day was all I got... now fractal zoomers are so fast they can fly towards
the unreal imagery in real time. People are spoiled these days :)

Terminal-enabled programs... these require the '-code modified hp2100 sim...

OTHEL2 is an old OTHEL program found in the T000 account of an "Access"
system, first converted to TSB-E then added "fake" codes to restore the
original look and animation effects.

BEASTE is cool! Apparently this was a precursor to "PacMan" only without
walls. I haven't found a "real" version of it yet but found a BEASTI in the
D600 account of an "Access" system. The code was broken and didn't properly
eat the "organisms", traced to out-of-order and missing lines. At the end
of the game it didn't print the final configuration, added flow changes
to fix that. The original display used dots for empty spaces, replaced
with spaces and added a border.

OTHMOD is a ANSI-colorized version of OTH, the side-by-side display was
replaced with a single larger colorized board that updates in place after
both the human and computer moves. The color codes for the pieces are
in lines 153 and 154, the text and board are printed in default colors.
Only standard ANSI codes are used, so if converted to Access by moving
the 'codes outside of the print quotes it should display correctly on
most modern ANSI-capable telnets without requiring a special simulator.

MLIFE is a simple version of Conway's Game of Life that starts with
a random pattern, generates until the number of cells remains constant
for a few generations then restarts with another pattern until stopped.
HP-style "fake" codes were used, move the '27 before the quote for legal
"Access" syntax but still would need an HP terminal, change the clear's
"E" to "[2J" and the home's "H" to "[H" for ANSI-compatible output.

-------------------------------------------
Terry Newton (wtnewton@infionline.net)
http://www.infionline.net/~wtnewton/
