'============
'GRIDWARS.BAS - v0.4
'============
'Coded by Dav NOV/2021
'NEW FOR v0.4:
' * Board auto sizes based on users desktop settings.
' Game should look and play same on any screen size now.
' * Randomized AI so game doesn't always start playing same way.
' (AI scans board from top OR bottom now - not always from top)
' * Random player starts - not always human goes first now.
'TO DO: Make if player doesn't have a move, but other player does,
' auto-fill in rest of board with the movable players color.
DIM SHARED Rows
, Columns
, SquareSize: Rows
= 9: Columns
= 9
'SquareSize = 800 * .95 / Columns / 1.3 '<< --- over-ride for testing
DIM SHARED Square.v
(Rows
* Columns
) 'value of the square DIM SHARED Square.x
(Rows
* Columns
), Square.y
(Rows
* Columns
) 'square x/y
'=========================================================================
restart:
'=======
bc = 1
x = (r * SquareSize)
y = SquareSize + (c * SquareSize)
Square.x(bc) = x - SquareSize
Square.y(bc) = y - SquareSize
Square.v(bc) = 0
bc = bc + 1
'set players pieces on board
Square.v(1) = 1: Square.v(9) = 2
Square.v(73) = 2: Square.v(81) = 1
player
= INT(RND * 2) + 1 'choose a random player to goes first
'======================================================================
main:
'====
'if it's the computers turn to move....
UpdateBoard 'draw board
mv$ = ComputerMove$ 'get a computer move
old
= VAL(LEFT$(mv$
, 2)) 'grab the move from place new
= VAL(RIGHT$(mv$
, 2)) 'grab the move to place
_DELAY .5 'a little pause to make it seem human
'show all valid moves
v$ = ValidMoves$(old)
x2 = Square.x(bv) + (SquareSize / 2) 'find middle of box
y2 = Square.y(bv) + (SquareSize / 2)
CIRCLE (x2
, y2
), SquareSize
* .05, _RGBA(150, 150, 150, 150), b
'highlight piece to move
LINE (Square.x
(old
) + 2, Square.y
(old
) + 2)-(Square.x
(old
) + SquareSize
- 2, Square.y
(old
) + SquareSize
- 2), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (Square.x
(old
) + 3, Square.y
(old
) + 3)-(Square.x
(old
) + SquareSize
- 3, Square.y
(old
) + SquareSize
- 3), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (Square.x
(old
) + 4, Square.y
(old
) + 4)-(Square.x
(old
) + SquareSize
- 4, Square.y
(old
) + SquareSize
- 4), _RGB(RND * 255, RND * 255, RND * 255), B
'if making one space move, clone
IF HowManyPlaces
(old
, new
) = 1 THEN Square.v(new) = player
UpdateBoard: convertneighbors player, new, 1
'if jumping...erase old place
IF HowManyPlaces
(old
, new
) = 2 THEN Square.v(new) = player
Square.v(old) = 0
UpdateBoard: convertneighbors player, new, 1
UpdateBoard
'check pieces here.....
'See how many empty places left
howmany = 0: reds = 0: blues = 0
FOR h
= 1 TO Rows
* Columns
'empty ones
IF Square.v
(h
) = 0 THEN howmany
= howmany
+ 1 IF Square.v
(h
) = 1 THEN reds
= reds
+ 1 IF Square.v
(h
) = 2 THEN blues
= blues
+ 1
'If no places left, game over
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "TIE GAME!"
'If no reds left, blue wins
'If no blues left, red wins
'switch player to human
player = 1
'==== First check if the new PLAYER HAS any MOVE LEFT
movesleft = 0
FOR g
= 1 TO Rows
* Columns
IF ValidMoves$
(g
) <> "" THEN movesleft
= 1
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "NO MOVES!"
player = 1
selected = 0
UpdateBoard
second: 'Go back here when making second choice
'wait until mouse button up to continue
'draw a highlight box when a box is selected
LINE (Square.x
(t
) + 2, Square.y
(t
) + 2)-(Square.x
(t
) + SquareSize
- 2, Square.y
(t
) + SquareSize
- 2), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (Square.x
(t
) + 3, Square.y
(t
) + 3)-(Square.x
(t
) + SquareSize
- 3, Square.y
(t
) + SquareSize
- 3), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (Square.x
(t
) + 4, Square.y
(t
) + 4)-(Square.x
(t
) + SquareSize
- 4, Square.y
(t
) + SquareSize
- 4), _RGB(RND * 255, RND * 255, RND * 255), B
'If user clicked mouse in board area
'see where they clicked
'cycle through all Check blocks...
FOR t
= 1 TO (Rows
* Columns
)
'Block loction...
tx = Square.x(t): tx2 = Square.x(t) + SquareSize
ty = Square.y(t): ty2 = Square.y(t) + SquareSize
'if clicked on a box clicked
'if this is a first choice...
'only select players color
selected = 1
SOUND 3000, .1 'made a select oldt = t
oldtv = Square.v(t) 'save picked box number color
'show valid moves
v$ = ValidMoves$(t)
x2 = Square.x(bv) + (SquareSize / 2) 'find middle of box
y2 = Square.y(bv) + (SquareSize / 2)
CIRCLE (x2
, y2
), SquareSize
* .05, _RGBA(150, 150, 150, 150), b
GOTO second
'now get second choice
IF selected
= 1 THEN 'making second choice
'if selected an empty box
'if making one space move
IF HowManyPlaces
(oldt
, t
) = 1 THEN
'clone to 2nd box data
Square.v(t) = oldtv
UpdateBoard
convertneighbors player, t, 1
'if jumping...
IF HowManyPlaces
(oldt
, t
) = 2 THEN
'jump...erase 1st box data
Square.v(t) = oldtv
Square.v(oldt) = 0
UpdateBoard
convertneighbors player, t, 1
UpdateBoard
'must have clicked a out of bounds place, redo turn...
IF HowManyPlaces
(oldt
, t
) = 0 THEN
'===============================
'check pieces here.....
'See how many empty places left
howmany = 0: reds = 0: blues = 0
FOR h
= 1 TO Rows
* Columns
'empty ones
IF Square.v
(h
) = 0 THEN howmany
= howmany
+ 1 IF Square.v
(h
) = 1 THEN reds
= reds
+ 1 IF Square.v
(h
) = 2 THEN blues
= blues
+ 1
'If no places left, game over
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "TIE GAME!"
'If no reds left, blue wins
bluewins:
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "BLUE WINS"
'If no blues left, red wins
redwins:
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "RED WINS!"
'players move done - switch turn, players
player = 2
player = 1
'==== CHECK IF PLAYER HAS VALID MOVE LEFT
movesleft = 0
FOR g
= 1 TO Rows
* Columns
IF ValidMoves$
(g
) <> "" THEN movesleft
= 1
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(0, 0, 0), BF
LINE (SquareSize
* 3 - (SquareSize
* .3), SquareSize
* 4)-(SquareSize
* 6 + (SquareSize
* .3), SquareSize
* 5.5), _RGB(255, 255, 255), B
PPRINT SquareSize
* 3.3, SquareSize
* 4.5, SquareSize
/ 3, _RGB(255, 255, 255), 0, "NO MOVES!"
'if user clicked on another one of its color instead...
'clear previous highlighted selection
selected = 0
UpdateBoard
selected = 1
oldt = t
oldtv = Square.v(t) 'save picked box number color
'clicked on enemy instead, redo
selected = 0
UpdateBoard
'_LIMIT 600
'computes how many places a user moved
'0 = out of bounds
'1 = one place
'2 = a jump
p = 0 'default is out of bounds
'row 1
CASE 1:
IF new
= old
+ 1 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 CASE 2:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
+ 2 OR new
= old
+ 11 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 3 TO 7:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
+ 2 OR new
= old
+ 7 OR new
= old
+ 11 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 8:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 THEN p
= 2 IF new
= old
- 2 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 THEN p
= 2
'row 2
CASE 10:
IF new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 1 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
+ 2 OR new
= old
+ 11 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 11:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
+ 2 OR new
= old
+ 11 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 12:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 7 OR new
= old
- 11 OR new
= old
+ 2 OR new
= old
+ 7 OR new
= old
+ 11 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 13 TO 16:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
+ 2 OR new
= old
- 11 OR new
= old
- 7 OR new
= old
+ 7 OR new
= old
+ 11 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 17:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 11 OR new
= old
- 2 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 THEN p
= 2 CASE 18:
IF new
= old
- 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
+ 8 OR new
= old
+ 9 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 THEN p
= 2
'row 3
CASE 19, 28, 37, 46, 55:
IF new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 1 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
+ 2 OR new
= old
+ 11 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 20, 29, 38, 47, 56:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
+ 2 OR new
= old
+ 11 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 'middle board, all ways, (thru row 7)
CASE 21 TO 25, 30 TO 34, 39 TO 43, 48 TO 52, 57 TO 61:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
+ 2 OR new
= old
- 7 OR new
= old
- 11 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 OR new
= old
+ 7 OR new
= old
+ 11 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 OR new
= old
+ 20 THEN p
= 2 CASE 26, 35, 44, 53, 62:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 OR new
= old
+ 19 THEN p
= 2 CASE 27, 36, 45, 54, 63:
IF new
= old
- 1 OR new
= old
- 9 OR new
= old
- 10 OR new
= old
+ 8 OR new
= old
+ 9 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 OR new
= old
+ 7 OR new
= old
+ 16 OR new
= old
+ 17 OR new
= old
+ 18 THEN p
= 2
'row 8
CASE 64:
IF new
= old
+ 1 OR new
= old
- 8 OR new
= old
- 9 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
+ 2 OR new
= old
+ 11 THEN p
= 2 CASE 65:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
+ 2 OR new
= old
+ 11 THEN p
= 2 CASE 66 TO 70:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
+ 2 OR new
= old
+ 7 OR new
= old
+ 11 OR new
= old
- 2 OR new
= old
- 7 OR new
= old
- 11 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 THEN p
= 2 CASE 71:
IF new
= old
- 1 OR new
= old
+ 1 OR new
= old
- 10 OR new
= old
- 9 OR new
= old
- 8 OR new
= old
+ 8 OR new
= old
+ 9 OR new
= old
+ 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 OR new
= old
+ 7 THEN p
= 2 CASE 72:
IF new
= old
- 1 OR new
= old
- 9 OR new
= old
- 10 OR new
= old
+ 8 OR new
= old
+ 9 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 OR new
= old
+ 7 THEN p
= 2
'bottom 9
CASE 73:
IF new
= old
+ 1 OR new
= old
- 8 OR new
= old
- 9 THEN p
= 1 IF new
= old
+ 2 OR new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 THEN p
= 2 CASE 74:
IF new
= old
+ 1 OR new
= old
- 1 OR new
= old
- 8 OR new
= old
- 9 OR new
= old
- 10 THEN p
= 1 IF new
= old
+ 2 OR new
= old
- 7 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 THEN p
= 2 CASE 75 TO 79:
IF new
= old
+ 1 OR new
= old
- 1 OR new
= old
- 8 OR new
= old
- 9 OR new
= old
- 10 THEN p
= 1 IF new
= old
+ 2 OR new
= old
- 2 OR new
= old
- 7 OR new
= old
- 11 OR new
= old
- 16 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 THEN p
= 2 CASE 80:
IF new
= old
+ 1 OR new
= old
- 1 OR new
= old
- 8 OR new
= old
- 9 OR new
= old
- 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 17 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 THEN p
= 2 CASE 81:
IF new
= old
- 1 OR new
= old
- 9 OR new
= old
- 10 THEN p
= 1 IF new
= old
- 2 OR new
= old
- 11 OR new
= old
- 18 OR new
= old
- 19 OR new
= old
- 20 THEN p
= 2
HowManyPlaces = p
PPRINT SquareSize
* 3.4, SquareSize
/ 4, SquareSize
/ 3, _RGB(255, 255, 255), 0, "GridWars"
red = 0: blue = 0
'=== draw board based on box values
bc = 1 'counter
'=== count colors
IF Square.v
(bc
) = 1 THEN red
= red
+ 1 IF Square.v
(bc
) = 2 THEN blue
= blue
+ 1
'=== if empty box
LINE (Square.x
(bc
) + 2, Square.y
(bc
) + 2)-(Square.x
(bc
) + SquareSize
- 2, Square.y
(bc
) + SquareSize
- 2), _RGB(64, 64, 64), BF
LINE (Square.x
(bc
) + 2, Square.y
(bc
) + 2)-(Square.x
(bc
) + SquareSize
- 2, Square.y
(bc
) + SquareSize
- 2), _RGB(64, 64, 64), BF
'=== draw color ball
x2 = Square.x(bc) + (SquareSize / 2) 'find middle of box
y2 = Square.y(bc) + (SquareSize / 2)
sz = SquareSize / 2
CASE IS = 1: r
= 255: g
= 64: b
= 64 'red CASE IS = 2: r
= 64: g
= 64: b
= 255 'blue bc = bc + 1
PPRINT SquareSize
/ 2, SquareSize
/ 3.5, SquareSize
/ 4, _RGB(255, 128, 128), 0, "Red =" + STR$(red
) PPRINT SquareSize
* 6 + (SquareSize
/ 1.6), SquareSize
/ 3.5, SquareSize
/ 4, _RGB(128, 128, 255), 0, "Blue =" + STR$(blue
)
'highlight current player
LINE (SquareSize
/ 7, SquareSize
/ 8)-(SquareSize
* 3 - (SquareSize
/ 2), SquareSize
/ 1.2), _RGBA(255, 100, 100, 50), BF
LINE (SquareSize
* 6 + (SquareSize
/ 4), SquareSize
/ 8)-(SquareSize
* 9 - (SquareSize
/ 7), SquareSize
/ 1.2), _RGBA(100, 100, 255, 50), BF
SUB convertneighbors
(player
, num
, show
) 'convert neighbors surrounding num to players value.
'(when a piece lands on num, it changes neighbors)
'row 1
CASE 1:
IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF Square.v
(num
+ 10) <> 0 AND Square.v
(num
+ 10) <> player
THEN Square.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 CASE 2 TO 8:
IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
+ 8) <> 0 AND Square.v
(num
+ 8) <> player
THEN Square.v
(num
+ 8) = player::
IF show
= 1 THEN change num
+ 8 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF Square.v
(num
+ 10) <> 0 AND Square.v
(num
+ 10) <> player
THEN Square.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 CASE 9:
IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
+ 8) <> 0 AND Square.v
(num
+ 8) <> player
THEN Square.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 'down left side
CASE 10, 19, 28, 37, 46, 55, 64 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 8) <> 0 AND Square.v
(num
- 8) <> player
THEN Square.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF Square.v
(num
+ 10) <> 0 AND Square.v
(num
+ 10) <> player
THEN Square.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 'down right side
CASE 18, 27, 36, 45, 54, 63, 72 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 10) <> 0 AND Square.v
(num
- 10) <> player
THEN Square.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
+ 8) <> 0 AND Square.v
(num
+ 8) <> player
THEN Square.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 'middle of board
IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
+ 8) <> 0 AND Square.v
(num
+ 8) <> player
THEN Square.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF Square.v
(num
+ 9) <> 0 AND Square.v
(num
+ 9) <> player
THEN Square.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF Square.v
(num
+ 10) <> 0 AND Square.v
(num
+ 10) <> player
THEN Square.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 IF Square.v
(num
- 8) <> 0 AND Square.v
(num
- 8) <> player
THEN Square.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 10) <> 0 AND Square.v
(num
- 10) <> player
THEN Square.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 'bottom row
CASE 73:
IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 8) <> 0 AND Square.v
(num
- 8) <> player
THEN Square.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 CASE 74 TO 80:
IF Square.v
(num
+ 1) <> 0 AND Square.v
(num
+ 1) <> player
THEN Square.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
- 8) <> 0 AND Square.v
(num
- 8) <> player
THEN Square.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 10) <> 0 AND Square.v
(num
- 10) <> player
THEN Square.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 CASE 81:
IF Square.v
(num
- 1) <> 0 AND Square.v
(num
- 1) <> player
THEN Square.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF Square.v
(num
- 9) <> 0 AND Square.v
(num
- 9) <> player
THEN Square.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF Square.v
(num
- 10) <> 0 AND Square.v
(num
- 10) <> player
THEN Square.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10
'=== find center x/y of place
x2 = Square.x(num) + (SquareSize / 2): y2 = Square.y(num) + (SquareSize / 2)
'do shrinking circle first
FOR s
= (SquareSize
/ 2.2) TO 1 STEP -(SquareSize
* .025) 'wipe clean
LINE (Square.x
(num
) + 2, Square.y
(num
) + 2)-(Square.x
(num
) + SquareSize
- 2, Square.y
(num
) + SquareSize
- 2), _RGB(64, 64, 64), BF
t = t + 100
'Expand in the new circle
'do shrinking circle first
FOR s
= 1 TO (SquareSize
/ 2.2) STEP (SquareSize
* .025) 'wipe clean
LINE (Square.x
(num
) + 2, Square.y
(num
) + 2)-(Square.x
(num
) + SquareSize
- 2, Square.y
(num
) + SquareSize
- 2), _RGB(64, 64, 64), BF
SUB PPRINT
(x
, y
, SquareSize
, clr&
, trans&
, text$
) x1 = x + (t * SquareSize): x2 = x1 + SquareSize
y1 = y: y2 = y + SquareSize
_PUTIMAGE (x1
- (SquareSize
/ 2), y1
)-(x2
, y2
+ (SquareSize
/ 3)), pprintimg&
'returns a string list of all valid moves for player that is sitting on the num
'The list contains 2 charater byte strings per num place.
'Each one is a num on the board that player could goto.
'2 steps
'one steps
'two steps
'one steps
'two steps
'one step
'two steps
'one step
'two steps
'2nd row
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'down left side, outer
'one step
'two steps
'down left side, inner
'one step
'two steps
'middle of board (all directions)
'one step
'two steps
'right side, outer
'one step
'two steps
'rigth side, inner
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'bottom row
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'one step
'two steps
'helper function returns num as a two byte string
nums$ = n$
'this function will find the best move and return a string of it.
'the string will contain the from place and the new place numbers.
'(like "0103" to move piece 1 to place 3
'ideas: if bestgain is only 1 (no enemies) then use a random piece
'instead of first one scanned. This way game doesn't start same way
'all the time. Will have to keep track of pieces and make sure more than
'one is found.
'backup original board values, for restoring later
'and count total blue pieces on board while were at it....
REDIM box.v2
(Rows
* Columns
): totalblues
= 0 FOR o
= 1 TO Rows
* Columns
box.v2(o) = Square.v(o)
IF Square.v
(0) = 2 THEN totalblues
= totalblues
+ 1
bestgain = 0: bestplace = 0
'added random below, so doesnt always start the same way.
'now either scan from top, or from bottom.
scandir
= INT(RND * 2) 'returns a 0 or 1
'step through pieces again, this time trying all moves on blues
FOR piece
= 1 TO Rows
* Columns
'if it's a blue piece
'get valid moves of piece, if any
Valids$ = ValidMoves$(piece)
'If there is....
'try each move on piece...recount board
'do the move, temporarily, just to see outcome
'if making one space move, clone player 2
IF HowManyPlaces
(piece
, new
) = 1 THEN Square.v(new) = 2
convertneighbors player, new, 0
'if jumping...erase old place
IF HowManyPlaces
(piece
, new
) = 2 THEN Square.v(new) = player
Square.v(piece) = 0: convertneighbors player, new, 0
'now recount totalblues of board
newtotal = 0
FOR ss
= 1 TO Rows
* Columns
IF Square.v
(ss
) = 2 THEN newtotal
= newtotal
+ 1 'see what new tally is
compute = newtotal - totalblues
'if better than others, save data
'save this info
origplace = piece: bestplace = new
bestgain = compute
'restore original board values to try other valid moves
FOR res
= 1 TO Rows
* Columns
Square.v(res) = box.v2(res)
'step through pieces again, this time trying all moves on blues
'if it's a blue piece
'get valid moves of piece, if any
Valids$ = ValidMoves$(piece)
'If there is....
'try each move on piece...recount board
'do the move, temporarily, just to see outcome
'if making one space move, clone player 2
IF HowManyPlaces
(piece
, new
) = 1 THEN Square.v(new) = 2
convertneighbors player, new, 0
'if jumping...erase old place
IF HowManyPlaces
(piece
, new
) = 2 THEN Square.v(new) = player
Square.v(piece) = 0: convertneighbors player, new, 0
'now recount totalblues of board
newtotal = 0
FOR ss
= 1 TO Rows
* Columns
IF Square.v
(ss
) = 2 THEN newtotal
= newtotal
+ 1 'see what new tally is
compute = newtotal - totalblues
'if better than others, save data
'save this info
origplace = piece: bestplace = new
bestgain = compute
'restore original board values to try other valid moves
FOR res
= 1 TO Rows
* Columns
Square.v(res) = box.v2(res)
ComputerMove$ = nums$(origplace) + nums$(bestplace)
'restore original board values again, just to be safe...
FOR res
= 1 TO Rows
* Columns
Square.v(res) = box.v2(res)