[bit.listserv.games-l] Othello,

WONGR@MSVU.BITNET (E.T. RALPH) (02/03/90)

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.1-004  3-AUG-1989
$!   On  2-FEB-1990 21:37:32.57   By user WONGR
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 2 PARTS, TO KEEP EACH PART
$!  BELOW 30 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. REVERSI2.DOC;1
$!       2. REVERSI2.PAS;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ if f$getsyi("version") .ges. "V4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete/nolog 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete/nolog 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");
buff:=CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(buff))
;LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(buff));g:=0;LOOP EXITIF MARK(NONE)=END_OF(buff);x:=
ERASE_CHARACTER(1);IF g = 0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x=
"V" THEN APPEND_LINE;MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;
IF x="+" THEN g:=1;ERASE_LINE;ENDIF;ELSE IF x="-" THEN g:=0;ENDIF;ERASE_LINE;
ENDIF;ENDLOOP;p:="`";POSITION(BEGINNING_OF(buff));LOOP r:=SEARCH(p,FORWARD);
EXITIF r=0;POSITION(r);ERASE(r);COPY_TEXT(ASCII(INT(ERASE_CHARACTER(3))));
ENDLOOP;o:=GET_INFO(COMMAND_LINE,"output_file");WRITE_FILE(buff,o);
ENDPROCEDURE;Unpacker;EXIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create/nolog 'f'
X============================================================================
V====
X==
V                                                                        `032
V   ==
X==                            R  E  V  E  R  S  I
V                             ==
X==
V                                                                        `032
V   ==
X==                              by Nate Dorward
V                               ==
X==
V                                                                        `032
V   ==
X==
V                                                                        `032
V   ==
X==                                 Version 2
V                                  ==
X==
V                                                                        `032
V   ==
X==                           Written in VAX Pascal
V                            ==
X==                   This version completed Jan. 28, 1990.
V                    ==
X==
V                                                                        `032
V   ==
X==    You are totally free to make copies of this program for friends - or
V    ==
X==   enemies for that matter. But please give the documentation to them too.
V  ==
X==
V                                                                        `032
V   ==
X============================================================================
V====
X
X
X`009I will assume you know all the rules of Reversi (you DO, don't you?),
Xso without further ado....
X
X
X============================================================================
V====
X
X
X`009H O W   T O   U S E   T H E   P R O G R A M
X`009`009`009. . . . the bare bones of what you need to know.
X
X
X`009If you just want to play a normal game with someone, there's nothing
Xspecial you need to do. Simply RUN REVERSI, and start playing. White moves
Xfirst, and the score box to the side of the board will tell you whose turn i
Vt is
Xand what the scores are.
X`009Each board square is identified by a letter (representing the X co-ord-
Xinate) and a number (the Y co-ordinate). To make a move, just type in the co
V-
Xordinates of the square you want. It doesn't matter whether the X precedes t
Vhe
XY or not, since the computer can tell the numbers apart from the letters. Th
Ve
Xcomputer will flip over the pieces, or tell you if you haven't made a legal
Xmove.
X`009That is all you need to know if you are going to be playing simple games
Xwith a friend. But there is a little bit more to the program....
X
X
X============================================================================
V====
X
X
X `009S P E C I A L   C O M M A N D S
X`009`009`009. . . . to do a couple of neat things.
X
X
X`009You can type these when the computer asks for your move. Incidentally:
Xthe VAX has a few bugs with its READLN routine, so don't ever type (a) the
Xescape key, or (b) CTRL-Z. A bomb and debug-dump will be your reward. I will
Xtry to see if I can get around using this routine if I ever get a LOT of spa
Vre
Xtime.
X
X`009Now... there are four possible playing modes for the program:
X
X`009`009HUMAN (the default)
X`009`009COMPUTER BLACK or COMP BLACK
X`009`009COMPUTER WHITE or COMP WHITE
X`009`009AUTOPILOT
X
X`009Type in one of these four commands during a game to change the current
Xplaying mode. The meaning of these commands should be obvious. HUMAN lets tw
Vo
Xpeople play a normal game. COMPUTER BLACK or WHITE let you play against the
Xcomputer. AUTOPILOT makes the computer play both sides until the end of the
Xgame.
X
X`009The computer player can function on different depth levels. The depth
Xlevel is a factor that controls both the intelligence of its play and the ti
Vme
Xit takes to move. You may set the level by typing
X
X`009`009DEPTH x
X
Xwhere x is a number from 1 to 6. If you just type in the word DEPTH without
V a
Xnumber, the program will tell you what level it is current set at.
X`009The depth level simply measures how far ahead the computer will look
Xinto the game. You will find that levels 1 and 2 are far too simple for real
Xplay, although they may be useful for rank beginners. Level 3 is the default
Xsetting, which provides reasonable, average moves within a short time. Level
V 4
Xis a much more intelligent and challenging player, but takes much longer to
Xmove. Note that level 4 computer play requires a lot of CPU time (about 12 m
Vins
Xworth to finish a game!!)
X`009The computer player algorithm is very simple: it looks at how many
Xpieces it can flip, adds in positional considerations, then considers all th
Ve
Xpossible moves its opponect could make. It evaluates every possible move, th
Ven
Xrandomly picks one out of a list of good moves that it has created. This rou
Vtine
Xtakes a lot of CPU time -- try not to get the computer operators upset!
X
X
X`009There a few other commands available. For the convenience of the player,
Xthere is a TIME command:
X
X`009`009TIME
X
X`009This will display the time and date.
X
X`009And of course, there is a command to exit prematurely from a game:
X
X`009`009EXIT or
X`009`009QUIT
X
X
X`009When a game is finished, whether ordinarily or prematurely, the program
Xwill make all the pieces of the winning player blink, and display his final
Xscore in the score box.
X
X
X============================================================================
V====
X
X
X`009B U G S ,   P R O B L E M S ,   A N D   A N N O Y A N C E S
X`009`009`009. . . . plus some future revision possibilities.
X
X
X*`009The computer player could be a little better. It is, unfortunately, a
X`009trade-off between advanced analysis and reasonable speed. Since the
X`009algorithm I use is recursive, any increase in algorithm complexity will
X`009be accompanied by an EXPONENTIAL increase in thinking time.
X
X*`009The program has atrocious style, complete with misused FUNCTIONs and
X`009the infamous GOTO. Plus, absolutely no comments. So what?
X
X*`009In the future, REVERSI should include a PHONE utility, so you can phone
X`009a person at another place and challenge them to a game. Right now, both
X`009players must play at the same terminal.
X
X*`009On some terminals, BLACK pieces look whiter than WHITE! I either must
X`009change the characters used for pieces, or include a SWITCH command that
X`009will switch the colours of every single piece on the screen. Hmmm...
X
X*`009Better compatibility with certain terminals. A few very old terminals
X`009will not recognize the cursor commands the program sends them, thus
X`009garbling the screen.
X
X*`009Also, there should be a take-back-move command and a save-game command.
X
X*`009And anything else you can think of, tell me!!
X
X
X`009`009`009`009`009`009`009`009Enjoy!
X
X`009`009`009`009`009`009`009`009- NateD
$ CALL UNPACK REVERSI2.DOC;1 2054760481
$ create/nolog 'f'
XPROGRAM Reversi(INPUT,OUTPUT);
X
X`123Nate Dorward's REVERSI program.`125
X
XCONST
X  ESC = CHR(27);
X  BELL = CHR(7);
X
XLABEL
X  100;
X
XTYPE
X  PieceType = (BLANK,WHITE,BLACK);
X  BoardType = ARRAY`0911..8,1..8`093 OF PieceType;
X  WeightType = ARRAY`0911..8,1..8`093 OF INTEGER;
X  ScoreType = ARRAY`091WHITE..BLACK`093 OF INTEGER;
X  MindType = ARRAY`091WHITE..BLACK`093 OF (HUMAN,COMPUTER);
X  CoordType = RECORD
X                X,Y: INTEGER;
X              END;
X  DeltaType = ARRAY`0911..8`093 OF CoordType;
X  String = VARYING`09180`093 OF CHAR;
X  CountType = ARRAY`0911..8`093 OF INTEGER;
X
XVAR
X  Mind:`009`009MindType;
X  Weight:`009WeightType;
X  HypBoard:`009ARRAY`0911..9`093 OF BoardType;
X  Board:`009BoardType;
X  Score:`009ScoreType;
X  Player:`009PieceType;
X  Delta:`009DeltaType;
X  X,Y:`009`009INTEGER;
X  Count:`009CountType;
X  Stop:`009`009BOOLEAN;
X  Seed:`009`009INTEGER;
X  Depth:`009INTEGER;
X
X
XFUNCTION LIB$SET_CURSOR(R,C: INTEGER): INTEGER; EXTERN;
XFUNCTION LIB$ERASE_PAGE(R,C: INTEGER): INTEGER; EXTERN;
XFUNCTION LIB$PUT_SCREEN(%STDESCR D: CHAR; R,C,Flags: INTEGER): INTEGER; EXTE
VRN;
XFUNCTION MTH$RANDOM(VAR Seed: INTEGER): REAL; EXTERN;
XFUNCTION FOR$SECNDS(X: REAL): REAL; EXTERN;
X
XPROCEDURE Randomize;
X`123Seeds the generator. We assume that the global variable Seed has been cr
Veated.`125
XVAR I: INTEGER;
XBEGIN
X  Seed:=TRUNC(FOR$SECNDS(0));
X  FOR I:=1 TO 20 DO MTH$RANDOM(Seed);
XEND;
X
XFUNCTION Random(Range: INTEGER): INTEGER;
XBEGIN
X  Random:=TRUNC(MTH$RANDOM(Seed)*Range)+1;
XEND;
X
XPROCEDURE Position(X,Y: INTEGER);
XBEGIN
X  WRITE(ESC,'`091',Y:1,';',X:1,'H');
XEND;
X
XPROCEDURE ClearScreen;
XBEGIN
X  WRITELN(ESC,'`0912J');
XEND;
X
XPROCEDURE ClearBottom;
XBEGIN
X  WRITELN(ESC,'`09121;1H',ESC,'`091J');
XEND;
X
XPROCEDURE Message(STR: String);
XBEGIN
X  Position(1,24);
X  WRITE('* ',STR,' *');
XEND;
X
XPROCEDURE DisplaySquare(Piece: PieceType; X,Y: INTEGER);
XBEGIN
X  IF Piece=BLANK THEN LIB$PUT_SCREEN('.',Y*2+2,X*4+10,0)
X  ELSE IF Piece=BLACK THEN LIB$PUT_SCREEN('O',Y*2+2,X*4+10,1)
X  ELSE IF Piece=WHITE THEN LIB$PUT_SCREEN('0',Y*2+2,X*4+10,3);
XEND;
X
XPROCEDURE FlashPiece(Piece: PieceType; X,Y: INTEGER);
XBEGIN
X  IF Piece=BLANK THEN LIB$PUT_SCREEN('.',Y*2+2,X*4+10,0)
X  ELSE IF Piece=BLACK THEN LIB$PUT_SCREEN('O',Y*2+2,X*4+10,5)
X  ELSE IF Piece=WHITE THEN LIB$PUT_SCREEN('0',Y*2+2,X*4+10,7);
XEND;
X
XPROCEDURE DrawScreen;
XVAR X,Y: INTEGER;
XBEGIN
X  ClearScreen;
X  FOR X:=1 TO 8 DO
X    LIB$PUT_SCREEN(CHR(X+64),1,X*4+10,0);
X  FOR Y:=1 TO 8 DO
X    LIB$PUT_SCREEN(CHR(Y+48),Y*2+2,8,0);
X  FOR Y:=1 TO 8 DO
X    FOR X:=1 TO 8 DO
X      DisplaySquare(Board`091X,Y`093,X,Y);
X  LIB$PUT_SCREEN('0',9,60,3);
X  LIB$PUT_SCREEN('O',12,60,1);
X  LIB$PUT_SCREEN(':',9,62,0);
X  LIB$PUT_SCREEN(':',12,62,0);
XEND;
X
XPROCEDURE ShowTurn(Score: ScoreType; Player: PieceType);
XBEGIN
X  Position(64,9);
X  WRITE(Score`091WHITE`093:2);
X  Position(64,12);
X  WRITE(Score`091BLACK`093:2);
X  Position(58,9);
X  IF Player=WHITE THEN
X    WRITE('>')
X  ELSE
X    WRITE(' ');
X  Position(58,12);
X  IF Player=BLACK THEN
X    WRITELN('>')
X  ELSE
X    WRITELN(' ');
XEND;
X
XPROCEDURE ShowWinner(Score: ScoreType);
XVAR Winner: PieceType;
XBEGIN
X  Position(64,9);
X  WRITE(Score`091WHITE`093:2);
X  Position(64,12);
X  WRITE(Score`091BLACK`093:2);
X  IF Score`091WHITE`093>Score`091BLACK`093 THEN Winner:=WHITE
X  ELSE IF Score`091WHITE`093=Score`091BLACK`093 THEN Winner:=BLANK
X  ELSE Winner:=BLACK;
X  IF Winner=WHITE THEN
X  BEGIN
X    Position(52,9);
X    WRITE('Winner>');
X    Position(52,12);
X    WRITE('       ');
X  END
X  ELSE IF Winner=BLACK THEN
X  BEGIN
X    Position(52,9);
X    WRITE('       ');
X    Position(52,12);
X    WRITE('Winner>');
X  END
X  ELSE
X  BEGIN
X    Position(52,9);
X    WRITE('  Tied ');
X    Position(52,12);
X    WRITE('  game ');
X  END;
X  IF Winner<>BLANK THEN
X    FOR Y:=1 TO 8 DO
X      FOR X:=1 TO 8 DO
X        IF Board`091X,Y`093=Winner THEN
X          FlashPiece(Winner,X,Y);
X  Position(4,21);
X  WRITELN('*  *  *  G  A  M  E     O  V  E  R  *  *  *');
XEND;
X
XPROCEDURE SetUp(VAR Board: BoardType; VAR Score: ScoreType;
X`009`009VAR Player: PieceType);
XVAR X,Y: INTEGER;
XBEGIN
X  Randomize;
X  Depth:=3;
X  FOR X:=1 TO 8 DO
X    FOR Y:=1 TO 8 DO
X    BEGIN
X      Board`091X,Y`093:=BLANK;
X      Weight`091X,Y`093:=0;
X    END;
X  FOR X:=3 TO 6 DO
X    FOR Y:=3 TO 6 DO
X      Weight`091X,Y`093:=1;
X  Board`0915,5`093:=WHITE;
X  Board`0914,5`093:=BLACK;
X  Board`0914,4`093:=WHITE;
X  Board`0915,4`093:=BLACK;
X  Score`091WHITE`093:=2;
X  Score`091BLACK`093:=2;
X  Player:=WHITE;
X  Mind`091WHITE`093:=HUMAN;
X  Mind`091BLACK`093:=HUMAN;
X  DrawScreen;
X  ShowTurn(Score,Player);
X  FOR X:=1 TO 8 DO
X  BEGIN
X    Weight`091X,1`093:=4;
X    Weight`091X,8`093:=4;
X    Weight`0911,X`093:=4;
X    Weight`0918,X`093:=4;
X  END;
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-