Interactive Hexapawn Game Program

from Ron Mak
ron (at) apropos-logic (dot) com
Sept 20, 2009

OK, you guys asked for it. BASIC, indeed!

Here's the Autocoder source for a simple board game called Hexapawn that I wrote back in high school. I "revived" it a couple of years ago from my old listings but then decided it was too dangerous to unleash upon the unsuspecting world. I just did a quick run via ROPE and the program seems to work. It's mildly amusing.

There's no documentation other than the source code. But here's the idea: The game is played with chess pawns on an 8-by-8 board that's printed. The computer's pieces are labeled C and your pieces are labeled Y. A pawn can move forward one row into an empty square, or it can capture an opponent's pawn diagonally one row forward and one column over left or right (just like chess pawns). The winner is either the player who first gets a pawn into the opponent's home row (simple version) or the player who gets the most pawns into the opponent's home row (less simple version).

You get to move first. You specify each of your moves via the sense switches. First, identify the pawn you want to move by row and column. Set the row number in binary using switches BCD and the column number in binary using switches EFG. For example, row 5 column 1 is BDG. Press the "Continue program" button. Now indicate with the sense switches how you want your piece to move: B = capture left, C = move forward, D = capture right, BCD = game over. Press the "Continue program" button again. After your move, the computer will make its move.

Sorry, I didn't know anything about "artificial intelligence" back in high school, so the computer's play is not too smart. Nor is it very good about handling input errors.

-- Ron

============================================================

```

JOB  Interactive Hexapawn Game Program
CTL  6611
******************************************************************
*  Interactive Hexapawn Game Program
*      by Ronald Mak
*
*  Original: February 1969
*  Revived:  February 2005
******************************************************************
ORG  87
X1        DSA  0                  index register 1
ORG  92
X2        DSA  0                  index register 2
ORG  97
X3        DSA  0                  index register 3
*
ORG  201
DCW  @          The Hexapawn Game@
*
ORG  333
*
START     W                        print title
CS   299
W
W
B    PRINT               print initial board
******************************************************************
******************************************************************
MCW  @: YOU@,215
MCW  MCOUNT
MCW  @MOVE #@
MZ   @ @,209
W
CS   299
W
W
GETFRM    H
*
* Get from row from sense switches BCD.
*
ZA   &7,ROWFRM
BSS  *&8,B
S    &4,ROWFRM
BSS  *&8,C
S    &2,ROWFRM
BSS  *&8,D
S    &1,ROWFRM
*
* Get from column sense switches EFG.
*
ZA   &7,COLFRM
BSS  *&8,E
S    &4,COLFRM
BSS  *&8,F
S    &2,COLFRM
BSS  *&8,G
S    &1,COLFRM
*
* Check move from position.
*
MCW  ROWFRM,ROW          check board[row, col] for a C
MCW  COLFRM,COL
B    GET                 get the board piece
BCE  GETFRM,PIECE,.      don't want a .
BCE  GETFRM,PIECE,C      don't want a C
B    GETTYP
*
*
MCW  @,@
MCW  ROWFRM
MZ   @ @,224
MZ   @ @,222
W
CS   299
W
W
B    GETFRM
*
* Get move type sense switches BCD.
*
GETTYP    H
ZA   &7,TYPE
BSS  *&8,B
S    &4,TYPE
BSS  *&8,C
S    &2,TYPE
BSS  *&8,D
S    &1,TYPE
*
* Check move type.
*
C    TYPE,&7             if TYPE = 7
BE   OVER                    then game over
C    TYPE,&4             if TYPE = 4
BE   CAPTRL                  then go capture left
C    TYPE,&2             if TYPE = 2
BE   FORWRD                  then go forward
C    TYPE,&1             if TYPE = 1
BE   CAPTRR                  then go capture right
*
*
MCW  @***** BAD MOVE TYPE: @
MZ   @ @,223
W
CS   299
W
W
B    GETTYP
*
* Move forward.
*
FORWRD    MCW  ROWFRM,ROW          check board[row+1, col] for a .
A    &1,ROW              check next row
MCW  COLFRM,COL          check same column
B    GET                 get the board piece
BCE  BADFRM,PIECE,C      don't want a C
BCE  BADFRM,PIECE,Y      don't want a Y
*
MCW  ROWFRM,ROWTO        safe to move forward
MCW  COLFRM,COLTO        in the same column
B    MOVE
B    YCHECK              check for winners
*
* Capture left.
*
CAPTRL    BCE  BADFRM,COLFRM,?     if not column 0 then
MCW  ROWFRM,ROW
A    &1,ROW                  if board[row+1, col-1]
MCW  COLFRM,COL
S    &1,COL
B    GET
BCE  CAPTRC,PIECE,C              = C then capture it
*
* Capture right.
*
CAPTRR    BCE  BADFRM,COLFRM,G     if not column 7 then
MCW  ROWFRM,ROW
A    &1,ROW                  if board[row+1, col+1]
MCW  COLFRM,COL
A    &1,COL
B    GET
BCE  CAPTRC,PIECE,C              = C then capture it
*
CAPTRC    MCW  ROW,ROWTO           make the capture
MCW  COL,COLTO
B    MOVE
*
* Check for Y pieces in computer's home row.
*
YCHECK    C    &7,ROWTO            if row > 0
BL   COMPT1                  then your turn next
A    &1,YCOUNT               else add 1 to YCCOUNT
******************************************************************
*  Computer's move
******************************************************************
*
* Look for a capture from rows 1 through 7
*
COMPT1    S    ROWFRM
NXROW1    A    &1,ROWFRM           next from row
BCE  COMPT2,ROWFRM,H     if row = 8 then go to COMPT2
*
SBR  X3,SCAN
NXCOL1    MCW  0&X3,COLFRM         next from column
BWZ  NXROW1,COLFRM,K     if col < 0 then do next row
*
MCW  ROWFRM,ROW          check board[row, col] for a C
MCW  COLFRM,COL
B    GET                 get the board piece
BCE  SKIPR1,PIECE,.      don't want a .
BCE  SKIPR1,PIECE,Y      don't want a Y
*
BCE  SKIPL1,COLFRM,0     if not column 0 then
MCW  ROWFRM,ROW
S    &1,ROW                  if board[row-1, col-1]
MCW  COLFRM,COL
S    &1,COL
B    GET
BCE  CAPTUR,PIECE,Y              = Y then capture it
*
SKIPL1    BCE  SKIPR1,COLFRM,7     if not column 7 then
MCW  ROWFRM,ROW
S    &1,ROW                  if board[row-1, col+1]
MCW  COLFRM, COL
A    &1,COL
B    GET
BCE  CAPTUR,PIECE,Y              = Y then capture it
*
SKIPR1    SBR  X3,1&X3             point to next column number
B    NXCOL1              do next column
*
CAPTUR    MCW  ROW,ROWTO           make the capture
MCW  COL,COLTO
B    MOVE
B    CCHECK              check for winners
*
* Look for a safe move from rows 2 through 7
*
COMPT2    ZA   &1,ROWFRM
NXROW2    A    &1,ROWFRM           next from row
BCE  COMPT3,ROWFRM,H     if row = 8 then go to COMPT2
*
SBR  X3,SCAN
NXCOL2    MCW  0&X3,COLFRM         next from column
BWZ  NXROW2,COLFRM,K     if col < 0 then do next row
*
MCW  ROWFRM,ROW          check board[row, col] for a C
MCW  COLFRM,COL
B    GET                 get the board piece
BCE  SKIPR2,PIECE,.      don't want a .
BCE  SKIPR2,PIECE,Y      don't want a Y
*
MCW  ROWFRM,ROW          check board[row-1, col] for a .
S    &1,ROW              check next row
MCW  COLFRM,COL          check same column
B    GET                 get the board piece
BCE  SKIPR2,PIECE,C      don't want a C
BCE  SKIPR2,PIECE,Y      don't want a Y
*
BCE  SKIPL2,COLFRM,0     if not column 0 then
MCW  ROWFRM,ROW
S    &2,ROW                  if board[row-2, col-1]
MCW  COLFRM,COL
S    &1,COL
B    GET
BCE  SKIPR2,PIECE,Y              = Y then don't go there
*
SKIPL2    BCE  FORWD2,COLFRM,7     if not column 7 then
MCW  ROWFRM,ROW
S    &2,ROW                  if board[row-2, col+1]
MCW  COLFRM, COL
A    &1,COL
B    GET
BCE  SKIPR2,PIECE,Y              = Y then don't go there
*
FORWD2    MCW  ROWFRM,ROWTO        safe to move forward
MCW  COLFRM,COLTO        in the same column
B    MOVE
B    CCHECK              check for winners
*
SKIPR2    SBR  X3,1&X3             point to next column number
B    NXCOL2              do next column
*
* Look for any legal move from rows 1 through 7
*
COMPT3    S    ROWFRM
NXROW3    A    &1,ROWFRM           next from row
BCE  OVER,ROWFRM,H       if row = 8 then game over
*
SBR  X3,SCAN
NXCOL3    MCW  0&X3,COLFRM         next from column
BWZ  NXROW3,COLFRM,K     if col < 0 then do next row
*
MCW  ROWFRM,ROW          check board[row, col] for a C
MCW  COLFRM,COL
B    GET                 get the board piece
BCE  SKIPR3,PIECE,.      don't want a .
BCE  SKIPR3,PIECE,Y      don't want a Y
*
MCW  ROWFRM,ROW          check board[row-1, col] for a .
S    &1,ROW              check next row
MCW  COLFRM,COL          check same column
B    GET                 get the board piece
BCE  SKIPR3,PIECE,C      don't want a C
BCE  SKIPR3,PIECE,Y      don't want a Y
*
MCW  ROWFRM,ROWTO        make the legal move
MCW  COLFRM,COLTO        in the same column
B    MOVE
B    CCHECK              check for winners
*
SKIPR3    SBR  X3,1&X3             point to next column number
B    NXCOL3              do next column
*
* Check for C pieces in your home row.
*
CCHECK    A    &1,MCOUNT           print move header
MCW  @: COMPUTER@,220
MCW  MCOUNT
MCW  @MOVE #@
MZ   @ @,209
W
CS   299
W
W
*
B    PRINT               print board after move
C    &0,ROWTO            if row > 0
A    &1,CCOUNT               else add 1 to CCOUNT
*
* Game over
*
OVER      NOP
*
FINIS     H    FINIS
H
*
BOARD     DCW  0
DC   @CCCCCCCC@
DC   @........@
DC   @........@
DC   @........@
DC   @........@
DC   @........@
DC   @........@
DC   @YYYYYYYY@
*
ROW       DCW  0                   board row (0-7)
COL       DCW  0                   board column (0-7)
ROWFRM    DCW  0                   row to move from
COLFRM    DCW  0                   column to move from
ROWTO     DCW  0                   row to move to
COLTO     DCW  0                   column to move to
PIECE     DCW  0                   board piece (C, Y, or .)
TYPE      DCW  0                   type of your next move
*
MCOUNT    DCW  000                 move count
CCOUNT    DCW  0                   count of winning C's
YCOUNT    DCW  0                   count of winning Y's
*
SCAN      DCW  3                   computer's col scan sequence
DCW  4
DCW  2
DCW  5
DCW  1
DCW  6
DCW  0
DCW  7
DCW  -1
******************************************************************
*  Subroutine to move the board piece
*  from (row-from, col-from) to (row-to, col-to).
******************************************************************
MOVE      SBR  MOVEX&3
*
MCW  ROWFRM,ROW
MCW  COLFRM,COL
B    GET
MCW  PIECE,MOVEPC
MCW  @.@,PIECE
B    SET
*
MCW  ROWTO,ROW
MCW  COLTO,COL
MCW  MOVEPC,PIECE
B    SET
*
MOVEX     B    000
*
MOVEPC    DCW  0
******************************************************************
*  Subroutine to get the board piece at (row, col).
******************************************************************
GET       SBR  GETX&3              set return address
*
B    POSIT               (row, col) => board address
MN   0&X1,PIECE          get piece at board position
MZ   0&X1,PIECE
*
GETX      B    000                 return
******************************************************************
*  Subroutine to set the board piece at (row, col).
******************************************************************
SET       SBR  SETX&3              set return address
*
B    POSIT               (row, col) => board address
MN   PIECE,0&X1          set piece at board position
MZ   PIECE,0&X1
*
SETX      B    000                 return
******************************************************************
*  Subroutine to point X1 to the board position at (row, col).
******************************************************************
POSIT     SBR  POSITX&3            set return address
*
ZA   &7,X1               (7
S    ROW,X1                 - row)
A    X1
A    X1
A    X1                           *8
A    COL,X1                          + col
SBR  X1,BOARD&1&X1       offset into board
MZ   @ @,X1              X1 = address of board[row, col]
*
POSITX    B    000                 return
******************************************************************
*  Subroutine to print the game board.
******************************************************************
PRINT     SBR  PRINTX&3            set return address
*
SBR  X1,BOARD            point X1 to start of board
ZA   &8,PRTROW           row = 8
CS   299
*
* Loop once per row 7, 6, ... 0
*
PRTLPR    S    &1,PRTROW           row = row - 1
BWZ  PRTRDN,PRTROW,K     if row < 0 then rows done
*
MCW  PRTROW,210          print row number
MZ   @ @,210
MCW  @ - @,213
SBR  X2,212              point X2 into print area
ZA   &8,PRTCOL           col = 8
*
* Loop once per column 0, 1, ..., 7
*
PRTLPC    S    &1,PRTCOL           col = col - 1
BWZ  PRTCDN,PRTCOL,K     if col < 0 then columns done
*
SBR  X1,1&X1             bump X1 by 1 (board pointer)
SBR  X2,2&X2             bump X2 by 2 (print pointer)
MN   0&X1,0&X2           print board piece
MZ   0&X1,0&X2
MCW  @ @,1&X2
B    PRTLPC              go back to print next column
*
PRTCDN    W                        print row
B    PRTLPR              go back to print next row
*
* Print column numbers.
*
PRTRDN    MCW  @---------------@,228
W
CS   299
MCW  @0 1 2 3 4 5 6 7@,228
W
CS   299
W
W
*
PRINTX    B    000                 return
*
PRTROW    DCW  0
PRTCOL    DCW  0
*
END  START
```