'============
'GRIDWARS.BAS - v0.3
'============
'Coded by Dav OCT/2021
'v0.3
'* Added AI play. Now play against the computer!
'=== define board info
rows
= 9: cols
= 9: size
= _WIDTH / cols
DIM SHARED box.x
(rows
* cols
), box.y
(rows
* cols
) 'x/y's
'=======
restart:
'=======
bc = 1 'counter
x = (r * size)
y = 50 + (c * size)
box.x(bc) = x - size
box.y(bc) = y - size
box.v(bc) = 0 'zero means nothing, empty square
bc = bc + 1
'set user's piece
box.v(1) = 1: box.v(9) = 2
box.v(73) = 2: box.v(81) = 1
player = 1 'user goes first
'====
main:
'====
'do a computer move here
UpdateBoard
mv$ = ComputerMove$
_DELAY .5 'a little pause to make it seem human
'show all valid moves
v$ = ValidMoves$(old)
x2 = box.x(bv) + (size / 2) 'find middle of box
y2 = box.y(bv) + (size / 2)
'highlight piece to move
LINE (box.x
(old
) + 2, box.y
(old
) + 2)-(box.x
(old
) + size
- 2, box.y
(old
) + size
- 2), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(old
) + 3, box.y
(old
) + 3)-(box.x
(old
) + size
- 3, box.y
(old
) + size
- 3), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(old
) + 4, box.y
(old
) + 4)-(box.x
(old
) + size
- 4, box.y
(old
) + size
- 4), _RGB(RND * 255, RND * 255, RND * 255), B
'if making one space move, clone
IF HowManyPlaces
(old
, new
) = 1 THEN box.v(new) = player
UpdateBoard: convertneighbors player, new, 1
'if jumping...erase old place
IF HowManyPlaces
(old
, new
) = 2 THEN box.v(new) = player
box.v(old) = 0
UpdateBoard: convertneighbors player, new, 1
UpdateBoard
'check pieces here.....
'See how many empty places left
howmany = 0: reds = 0: blues = 0
'empty ones
IF box.v
(h
) = 0 THEN howmany
= howmany
+ 1 IF box.v
(h
) = 1 THEN reds
= reds
+ 1 IF box.v
(h
) = 2 THEN blues
= blues
+ 1
'If no places left, game over
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _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
'==== CHECK IF new PLAYER HAS any MOVE LEFT
movesleft = 0
IF ValidMoves$
(g
) <> "" THEN movesleft
= 1
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _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
'highlight box when a box is selected
LINE (box.x
(t
) + 2, box.y
(t
) + 2)-(box.x
(t
) + size
- 2, box.y
(t
) + size
- 2), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(t
) + 3, box.y
(t
) + 3)-(box.x
(t
) + size
- 3, box.y
(t
) + size
- 3), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(t
) + 4, box.y
(t
) + 4)-(box.x
(t
) + size
- 4, box.y
(t
) + size
- 4), _RGB(RND * 255, RND * 255, RND * 255), B
'====================================
'show valid moves, for testing...
v$ = ValidMoves$(t)
x2 = box.x(bv) + (size / 2) 'find middle of box
y2 = box.y(bv) + (size / 2)
'====================================
'If user clicked mouse
'see where they clicked
'cycle through all Check blocks...
FOR t
= 1 TO (rows
* cols
)
'Block loction...
tx = box.x(t): tx2 = box.x(t) + size
ty = box.y(t): ty2 = box.y(t) + size
'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 = box.v(t) 'save picked box number color
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
box.v(t) = oldtv
UpdateBoard
convertneighbors player, t, 1
'if jumping...
IF HowManyPlaces
(oldt
, t
) = 2 THEN
'jump...erase 1st box data
box.v(t) = oldtv
box.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
'empty ones
IF box.v
(h
) = 0 THEN howmany
= howmany
+ 1 IF box.v
(h
) = 1 THEN reds
= reds
+ 1 IF box.v
(h
) = 2 THEN blues
= blues
+ 1
'If no places left, game over
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _RGB(255, 255, 255), 0, "TIE GAME!"
'If no reds left, blue wins
bluewins:
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _RGB(255, 255, 255), 0, "BLUE WINS"
'If no blues left, red wins
redwins:
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _RGB(255, 255, 255), 0, "RED WINS!"
'players move done - switch turn, players
'computers turn here....
'CHANGE TO AI MOVE HERE '<<<<<<<<<<<<<<
player = 2
player = 1
'==== CHECK IF PLAYER HAS VALID MOVE LEFT
movesleft = 0
IF ValidMoves$
(g
) <> "" THEN movesleft
= 1
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _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 = box.v(t) 'save picked box number color
'clicked on enemy instead, redo
selected = 0
UpdateBoard
'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
205, 10, 20, _RGB(255, 255, 255), 0, "-=GridWar=-"
red = 0: blue = 0
'=== draw board based on box values
bc = 1 'counter
'=== count colors
IF box.v
(bc
) = 1 THEN red
= red
+ 1 IF box.v
(bc
) = 2 THEN blue
= blue
+ 1
'=== if empty box
LINE (box.x
(bc
) + 2, box.y
(bc
) + 2)-(box.x
(bc
) + size
- 2, box.y
(bc
) + size
- 2), _RGB(64, 64, 64), BF
LINE (box.x
(bc
) + 2, box.y
(bc
) + 2)-(box.x
(bc
) + size
- 2, box.y
(bc
) + size
- 2), _RGB(64, 64, 64), BF
'=== draw color ball
x2 = box.x(bc) + (size / 2) 'find middle of box
y2 = box.y(bc) + (size / 2)
sz = size / 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
30, 15, 14, _RGB(255, 128, 128), 0, "Red =" + STR$(red
) PPRINT
465, 15, 14, _RGB(128, 128, 255), 0, "Blue =" + STR$(blue
)
LINE (10, 10)-(150, 40), _RGBA(255, 100, 100, 50), BF
LINE (440, 10)-(590, 40), _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 box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF box.v
(num
+ 10) <> 0 AND box.v
(num
+ 10) <> player
THEN box.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 CASE 2 TO 8:
IF box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
+ 8) <> 0 AND box.v
(num
+ 8) <> player
THEN box.v
(num
+ 8) = player::
IF show
= 1 THEN change num
+ 8 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF box.v
(num
+ 10) <> 0 AND box.v
(num
+ 10) <> player
THEN box.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 CASE 9:
IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
+ 8) <> 0 AND box.v
(num
+ 8) <> player
THEN box.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 'down left side
CASE 10, 19, 28, 37, 46, 55, 64 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 8) <> 0 AND box.v
(num
- 8) <> player
THEN box.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF box.v
(num
+ 10) <> 0 AND box.v
(num
+ 10) <> player
THEN box.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 'down right side
CASE 18, 27, 36, 45, 54, 63, 72 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 10) <> 0 AND box.v
(num
- 10) <> player
THEN box.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
+ 8) <> 0 AND box.v
(num
+ 8) <> player
THEN box.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 'middle of board
IF box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
+ 8) <> 0 AND box.v
(num
+ 8) <> player
THEN box.v
(num
+ 8) = player:
IF show
= 1 THEN change num
+ 8 IF box.v
(num
+ 9) <> 0 AND box.v
(num
+ 9) <> player
THEN box.v
(num
+ 9) = player:
IF show
= 1 THEN change num
+ 9 IF box.v
(num
+ 10) <> 0 AND box.v
(num
+ 10) <> player
THEN box.v
(num
+ 10) = player:
IF show
= 1 THEN change num
+ 10 IF box.v
(num
- 8) <> 0 AND box.v
(num
- 8) <> player
THEN box.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 10) <> 0 AND box.v
(num
- 10) <> player
THEN box.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 'bottom row
CASE 73:
IF box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 8) <> 0 AND box.v
(num
- 8) <> player
THEN box.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 CASE 74 TO 80:
IF box.v
(num
+ 1) <> 0 AND box.v
(num
+ 1) <> player
THEN box.v
(num
+ 1) = player:
IF show
= 1 THEN change num
+ 1 IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
- 8) <> 0 AND box.v
(num
- 8) <> player
THEN box.v
(num
- 8) = player:
IF show
= 1 THEN change num
- 8 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 10) <> 0 AND box.v
(num
- 10) <> player
THEN box.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10 CASE 81:
IF box.v
(num
- 1) <> 0 AND box.v
(num
- 1) <> player
THEN box.v
(num
- 1) = player:
IF show
= 1 THEN change num
- 1 IF box.v
(num
- 9) <> 0 AND box.v
(num
- 9) <> player
THEN box.v
(num
- 9) = player:
IF show
= 1 THEN change num
- 9 IF box.v
(num
- 10) <> 0 AND box.v
(num
- 10) <> player
THEN box.v
(num
- 10) = player:
IF show
= 1 THEN change num
- 10
'=== find center x/y of place
x2 = box.x(num) + (size / 2): y2 = box.y(num) + (size / 2)
'do shrinking circle first
'wipe clean
LINE (box.x
(num
) + 2, box.y
(num
) + 2)-(box.x
(num
) + size
- 2, box.y
(num
) + size
- 2), _RGB(64, 64, 64), BF
t = t + 100
'Expand in the new circle
'do shrinking circle first
'wipe clean
LINE (box.x
(num
) + 2, box.y
(num
) + 2)-(box.x
(num
) + size
- 2, box.y
(num
) + size
- 2), _RGB(64, 64, 64), BF
SUB PPRINT
(x
, y
, size
, clr&
, trans&
, text$
) x1 = x + (t * size): x2 = x1 + size
y1 = y: y2 = y + size
_PUTIMAGE (x1
- (size
/ 2), y1
)-(x2
, y2
+ (size
/ 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 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
'backup original board values, for restoring later
'and count total blue pieces on board while were at it....
REDIM box.v2
(rows
* cols
): totalblues
= 0 box.v2(o) = box.v(o)
IF box.v
(0) = 2 THEN totalblues
= totalblues
+ 1
bestgain = 0: bestplace = 0
'step through pieces again, this time trying all moves on blues
FOR piece
= 1 TO rows
* cols
'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 box.v(new) = 2
convertneighbors player, new, 0
'if jumping...erase old place
IF HowManyPlaces
(piece
, new
) = 2 THEN box.v(new) = player
box.v(piece) = 0: convertneighbors player, new, 0
'now recount totalblues of board
newtotal = 0
FOR ss
= 1 TO rows
* cols
IF box.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
* cols
box.v(res) = box.v2(res)
ComputerMove$ = nums$(origplace) + nums$(bestplace)
'restore original board values again, just to be safe...
FOR res
= 1 TO rows
* cols
box.v(res) = box.v2(res)