NØTscape Certified
Day Books: Thursday, 1997-03-06
12:35 EST - Freeman Lake
I had a job interview the other day, and it got me to digging through
folders I used to take on interviews. Since the position was
WebMaster, I took some examples of my Java code ... the AstroObj and
Planet classes. After the interview, I dug out some things I had been
porting to new platforms and languages since 1975 ... my CHESSBRD
(prints a chess board with pieces in a 64 line by 80 character
format)
and Ackermann's Function (a highly recursive function).
Then I stumbled across something I had completely forgotten ...
a game written in a language that I developed for in-house use
at Xerox in 1979. This single page of fading print-out from
a Texas Instruments thermal printer (5x7 dot matrix printer)
is dated 1980-01-25, and reading it made me think of a comment
that I had made over lunch at the interview:
"I've forgotten how to program in languages you've never even
heard of."
Here was an interactive game-playing program that I had written
in MOCC, a language that only
a dozen people in the world ever used ... a language that
I created based on another language (Digital's "shell" language
for the RSX/11M operating system, MCR), and I couldn't remember
how the program worked ... I'd forgotten the language!!
The program plays a PEBBLE game. The rules are very simple.
It is a trivial game, like TIC-TAC-TOE, and a good test
of the robustness of a programming language.
- We start with a pile of 19 pebbles.
- We take turns removing 1-3 at a time.
- The taker of the last pebble loses.
MOCC is an interpreted language, like BASIC. Anyone who knows
at least one programming language can figure out how the
program works, and will appreciate its simplicity and
efficiency.
I've been thinking of using it to teach basic programming
concepts by porting it to several languages, like PERL and
Java ... heck, I can teach myself BASH by porting this game!
The PEBBLE game is a Very Good assignment for an Intro to
Programming Languages course, and I can't imagine why I
haven't used it more often when learning a new language.
Click here
for the original MOCC version from 1980.
Because it is
interpreted from the ASCII text source file, comments have
been kept to a minimum ... the more lines of text between
a GOTO and the LABEL, the longer it takes to execute!
Here is the annotated version I made while transcribing it.
I hve changed a few labels for readbility, and changed the
logic for deciding that the game was over and who had won,
which I probably did 17 years ago, but I don't have
a later listing. :-)
.; PEBBLE GAME D. A. HARROD 25 JAN 80
.; DEMONSTRATES MOCC DIRECTIVES
.;
.; 1997-03-05 DAH - ADDED COMMENTS AND CHANGED "GAMEOVER" LOGIC
.;
.; DISPLAY RULES
.;
; we start with a pile of 23 (octal) pebbles
; we take turns removing 1-3 at a time
; the taker of the last pebble loses
;
.; ----------
.NEWGAME: .; INITIALIZATION
.SETN COUNT 23
.SETF MYMOVE
.; ----------
.LOOP: .; TOP OF GAME LOOP
; there are 'COUNT' pebbles left
.IFT MYMOVE .GOTO MAKEMOVE
.; ----------
.ASKMOVE: .; HUMAN MOVES
.ASKN TAKE how many will you take
.IF TAKE <=3 .IF TAKE >0 .GOTO GOODMOVE
; please take 1, 2, or 3
.GOTO ASKMOVE .; BAD INPUT - ASK AGAIN
.; ----------
.GOODMOVE: .; REMOVE PEBBLES FOR HUMAN
.IF TAKE >= COUNT .GOTO GAMEOVER
.SETN COUNT COUNT-TAKE
.SETT MYMOVE
.GOTO LOOP
.; ----------
.MAKEMOVE: .; MACHINE MOVES
.IF COUNT > 4 .SETN TAKE 4-TAKE
.IF COUNT !> 4 .SETN TAKE COUNT-1
.IF COUNT = 1 SETN TAKE 1
.IF TAKE = 1 ; i will take 'TAKE' pebble
.IF TAKE != 1 ; i will take 'TAKE' pebbles
.SETN COUNT COUNT-TAKE
.IF COUNT = O .GOTO GAMEOVER
.SETF MYMOVE
.GOTO LOOP
.; ----------
.GAMEOVER:
.IFT MYMOVE ; congratulations - you win!
.IFF MYMOVE ; sorry - you lose.
.ASK ANOTHER would you like to play again
.IFT ANOTHER .GOTO NEWGAME
.STOP
Last update: 1997-03-06 by dennette@wiz-worx.com
<Who is this "Dennette"
person?>