Author Topic: GridWars game - going to add AI to it.  (Read 8065 times)

0 Members and 1 Guest are viewing this topic.

Marked as best answer by Dav on November 03, 2021, 05:18:20 pm

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #15 on: November 03, 2021, 09:17:56 pm »
I haven't been able to work on this as much as I would like, but I have done something new with it and would like some testing on this version please. 

This new version auto-scales the puzzle board based on your current desktop size.  Hopefully the puzzle will now look and play the same regardless of your screen size.  (That means it won't look like an icon on Steves super duper laptop!) 

Instead or hard-coding the pixel size with everything, all the graphics are scaled based on _DESKTOPHEIGHT now, the font is too.  The only thing I have found is that on large screens (over 2000 desktopheight) the game plays sluggish. 

After doing all this changing, it then hit me that I really should have tried to add @SMcNeill autoscale thing first.  Anyway, I've tried this in 4 different screen sizes and the puzzle fills the screen pretty nicely.  How does it display on yours?

- Dav

Code: QB64: [Select]
  1.  
  2. '============
  3. 'GRIDWARS.BAS - v0.4
  4. '============
  5. 'Coded by Dav NOV/2021
  6.  
  7. 'NEW FOR v0.4:
  8. '  * Board auto sizes based on users desktop settings.
  9. '    Game should look and play same on any screen size now.
  10. '  * Randomized AI so game doesn't always start playing same way.
  11. '    (AI scans board from top OR bottom now - not always from top)
  12. '  * Random player starts - not always human goes first now.
  13.  
  14. 'TO DO: Make if player doesn't have a move, but other player does,
  15. '       auto-fill in rest of board with the movable players color.
  16.  
  17.  
  18. _DELAY .25
  19.  
  20. _TITLE "GridWars"
  21.  
  22. DIM SHARED Rows, Columns, SquareSize: Rows = 9: Columns = 9
  23.  
  24. SquareSize = _DESKTOPHEIGHT * .95 / Columns / 1.3
  25.  
  26. 'SquareSize = 800 * .95 / Columns / 1.3  '<< --- over-ride for testing
  27.  
  28. DIM SHARED Square.v(Rows * Columns) 'value of the square
  29. DIM SHARED Square.x(Rows * Columns), Square.y(Rows * Columns) 'square x/y
  30. DIM SHARED player
  31.  
  32.  
  33. SCREEN _NEWIMAGE(Rows * SquareSize, Columns * SquareSize + SquareSize, 32)
  34.  
  35. '=========================================================================
  36. restart:
  37. '=======
  38.  
  39. PLAY "MBL32O3CEGEC"
  40.  
  41.  
  42. bc = 1
  43. FOR c = 1 TO Columns
  44.     FOR r = 1 TO Rows
  45.         x = (r * SquareSize)
  46.         y = SquareSize + (c * SquareSize)
  47.         Square.x(bc) = x - SquareSize
  48.         Square.y(bc) = y - SquareSize
  49.         Square.v(bc) = 0
  50.         bc = bc + 1
  51.     NEXT
  52.  
  53. 'set players pieces on board
  54. Square.v(1) = 1: Square.v(9) = 2
  55. Square.v(73) = 2: Square.v(81) = 1
  56.  
  57. player = INT(RND * 2) + 1 'choose a random player to goes first
  58.  
  59.  
  60. '======================================================================
  61. main:
  62. '====
  63.  
  64. 'if it's the computers turn to move....
  65. IF player = 2 THEN
  66.     UpdateBoard 'draw board
  67.  
  68.     mv$ = ComputerMove$ 'get a computer move
  69.  
  70.     old = VAL(LEFT$(mv$, 2)) 'grab the move from place
  71.     new = VAL(RIGHT$(mv$, 2)) 'grab the move to place
  72.  
  73.     _DELAY .5 'a little pause to make it seem human
  74.  
  75.     'show all valid moves
  76.     v$ = ValidMoves$(old)
  77.     FOR f = 1 TO LEN(v$) STEP 2
  78.         bv = VAL(MID$(v$, f, 2))
  79.         x2 = Square.x(bv) + (SquareSize / 2) 'find middle of box
  80.         y2 = Square.y(bv) + (SquareSize / 2)
  81.         CIRCLE (x2, y2), SquareSize * .05, _RGBA(150, 150, 150, 150), b
  82.     NEXT
  83.  
  84.     'highlight piece to move
  85.     FOR k = 1 TO 30
  86.         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
  87.         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
  88.         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
  89.         _DISPLAY
  90.         _LIMIT 30
  91.     NEXT
  92.  
  93.     'if making one space move, clone
  94.     IF HowManyPlaces(old, new) = 1 THEN
  95.         SOUND 2000, .1
  96.         Square.v(new) = player
  97.         UpdateBoard: convertneighbors player, new, 1
  98.     END IF
  99.  
  100.     'if jumping...erase old place
  101.     IF HowManyPlaces(old, new) = 2 THEN
  102.         SOUND 2000, .1
  103.         Square.v(new) = player
  104.         Square.v(old) = 0
  105.         UpdateBoard: convertneighbors player, new, 1
  106.     END IF
  107.  
  108.     UpdateBoard
  109.  
  110.     'check pieces here.....
  111.  
  112.     'See how many empty places left
  113.     howmany = 0: reds = 0: blues = 0
  114.     FOR h = 1 TO Rows * Columns
  115.         'empty ones
  116.         IF Square.v(h) = 0 THEN howmany = howmany + 1
  117.         IF Square.v(h) = 1 THEN reds = reds + 1
  118.         IF Square.v(h) = 2 THEN blues = blues + 1
  119.     NEXT
  120.  
  121.     'If no places left, game over
  122.     IF howmany = 0 THEN
  123.         IF reds = blues THEN
  124.             LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  125.             LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  126.             PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "TIE GAME!"
  127.             PLAY "mbl16o2bagfedc"
  128.             _DISPLAY: SLEEP 5
  129.             GOTO restart
  130.         END IF
  131.         IF reds > blues THEN GOTO redwins ELSE GOTO bluewins
  132.     END IF
  133.  
  134.     'If no reds left, blue wins
  135.     IF reds = 0 THEN GOTO bluewins
  136.     'If no blues left, red wins
  137.     IF blues = 0 THEN GOTO redwins
  138.  
  139.     'switch player to human
  140.     player = 1
  141.  
  142.     '==== First check if the new PLAYER HAS any MOVE LEFT
  143.     movesleft = 0
  144.     FOR g = 1 TO Rows * Columns
  145.         IF Square.v(g) = player THEN
  146.             IF ValidMoves$(g) <> "" THEN movesleft = 1
  147.         END IF
  148.     NEXT
  149.  
  150.     IF movesleft = 0 THEN
  151.         LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  152.         LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  153.         PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "NO MOVES!"
  154.         PLAY "mbl16o2bagfedc"
  155.         _DISPLAY: SLEEP 3
  156.         IF reds > blues THEN GOTO redwins
  157.         IF blues > reds THEN GOTO bluewins
  158.         GOTO restart
  159.     END IF
  160.  
  161.     player = 1
  162.     GOTO main
  163.  
  164. selected = 0
  165.  
  166. UpdateBoard
  167.  
  168. second: 'Go back here when making second choice
  169.  
  170.  
  171.     'wait until mouse button up to continue
  172.     WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  173.  
  174.     trap = _MOUSEINPUT 'Poll mouse data
  175.  
  176.     'draw a highlight box when a box is selected
  177.     IF selected = 1 THEN
  178.         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
  179.         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
  180.         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
  181.         _DISPLAY
  182.     END IF
  183.  
  184.  
  185.     'If user clicked mouse in board area
  186.     IF _MOUSEBUTTON(1) AND _MOUSEY > SquareSize THEN
  187.  
  188.         'see where they clicked
  189.         mx = _MOUSEX: my = _MOUSEY
  190.  
  191.         'cycle through all Check blocks...
  192.         FOR t = 1 TO (Rows * Columns)
  193.  
  194.             'Block loction...
  195.             tx = Square.x(t): tx2 = Square.x(t) + SquareSize
  196.             ty = Square.y(t): ty2 = Square.y(t) + SquareSize
  197.  
  198.             'if clicked on a box clicked
  199.             IF mx >= tx AND mx <= tx2 THEN
  200.                 IF my >= ty AND my <= ty2 THEN
  201.  
  202.                     'if this is a first choice...
  203.                     IF selected = 0 THEN
  204.  
  205.                         'only select players color
  206.                         IF Square.v(t) = player THEN
  207.                             selected = 1
  208.                             SOUND 3000, .1 'made a select
  209.                             oldt = t
  210.                             oldtv = Square.v(t) 'save picked box number color
  211.  
  212.                             'show valid moves
  213.                             v$ = ValidMoves$(t)
  214.                             FOR f = 1 TO LEN(v$) STEP 2
  215.                                 bv = VAL(MID$(v$, f, 2))
  216.                                 x2 = Square.x(bv) + (SquareSize / 2) 'find middle of box
  217.                                 y2 = Square.y(bv) + (SquareSize / 2)
  218.                                 CIRCLE (x2, y2), SquareSize * .05, _RGBA(150, 150, 150, 150), b
  219.                             NEXT
  220.                             _DISPLAY
  221.  
  222.                             GOTO second 'now get second choice
  223.                         END IF
  224.  
  225.                     END IF
  226.  
  227.                     IF selected = 1 THEN 'making second choice
  228.  
  229.                         'if selected an empty box
  230.                         IF Square.v(t) = 0 THEN
  231.  
  232.                             'if making one space move
  233.                             IF HowManyPlaces(oldt, t) = 1 THEN
  234.  
  235.                                 'clone to 2nd box data
  236.                                 SOUND 2000, .1
  237.                                 Square.v(t) = oldtv
  238.                                 UpdateBoard
  239.  
  240.                                 convertneighbors player, t, 1
  241.  
  242.                             END IF
  243.  
  244.                             'if jumping...
  245.                             IF HowManyPlaces(oldt, t) = 2 THEN
  246.  
  247.                                 'jump...erase 1st box data
  248.                                 SOUND 2000, .1
  249.                                 Square.v(t) = oldtv
  250.                                 Square.v(oldt) = 0
  251.                                 UpdateBoard
  252.  
  253.                                 convertneighbors player, t, 1
  254.  
  255.                             END IF
  256.  
  257.  
  258.                             UpdateBoard
  259.  
  260.                             'must have clicked a out of bounds place, redo turn...
  261.                             IF HowManyPlaces(oldt, t) = 0 THEN
  262.                                 SOUND 500, .1
  263.                                 GOTO main
  264.                             END IF
  265.  
  266.                             '===============================
  267.                             'check pieces here.....
  268.  
  269.                             'See how many empty places left
  270.                             howmany = 0: reds = 0: blues = 0
  271.                             FOR h = 1 TO Rows * Columns
  272.                                 'empty ones
  273.                                 IF Square.v(h) = 0 THEN howmany = howmany + 1
  274.                                 IF Square.v(h) = 1 THEN reds = reds + 1
  275.                                 IF Square.v(h) = 2 THEN blues = blues + 1
  276.                             NEXT
  277.  
  278.                             'If no places left, game over
  279.                             IF howmany = 0 THEN
  280.  
  281.                                 IF reds = blues THEN
  282.                                     LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  283.                                     LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  284.                                     PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "TIE GAME!"
  285.                                     PLAY "mbl16o2bagfedc"
  286.                                     _DISPLAY: SLEEP 5
  287.                                     GOTO restart
  288.                                 END IF
  289.  
  290.                                 IF reds > blues THEN GOTO redwins ELSE GOTO bluewins
  291.  
  292.                             END IF
  293.  
  294.                             'If no reds left, blue wins
  295.                             IF reds = 0 THEN
  296.                                 bluewins:
  297.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  298.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  299.                                 PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "BLUE WINS"
  300.                                 PLAY "mbl16o2bagfedc"
  301.                                 _DISPLAY: SLEEP 5
  302.                                 GOTO restart
  303.                             END IF
  304.  
  305.                             'If no blues left, red wins
  306.                             IF blues = 0 THEN
  307.                                 redwins:
  308.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  309.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  310.                                 PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "RED WINS!"
  311.                                 PLAY "mbl16o2bagfedc"
  312.                                 _DISPLAY: SLEEP 5
  313.                                 GOTO restart
  314.                             END IF
  315.  
  316.  
  317.                             'players move done - switch turn, players
  318.                             IF player = 1 THEN
  319.                                 player = 2
  320.                             ELSE
  321.                                 player = 1
  322.                             END IF
  323.  
  324.                             '==== CHECK IF PLAYER HAS VALID MOVE LEFT
  325.                             movesleft = 0
  326.                             FOR g = 1 TO Rows * Columns
  327.                                 IF Square.v(g) = player THEN
  328.                                     IF ValidMoves$(g) <> "" THEN movesleft = 1
  329.                                 END IF
  330.                             NEXT
  331.  
  332.                             IF movesleft = 0 THEN
  333.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(0, 0, 0), BF
  334.                                 LINE (SquareSize * 3 - (SquareSize * .3), SquareSize * 4)-(SquareSize * 6 + (SquareSize * .3), SquareSize * 5.5), _RGB(255, 255, 255), B
  335.                                 PPRINT SquareSize * 3.3, SquareSize * 4.5, SquareSize / 3, _RGB(255, 255, 255), 0, "NO MOVES!"
  336.                                 PLAY "mbl16o2bagfedc"
  337.                                 _DISPLAY: SLEEP 3
  338.                                 IF reds > blues THEN GOTO redwins
  339.                                 IF blues > reds THEN GOTO bluewins
  340.                                 GOTO restart
  341.                             END IF
  342.  
  343.  
  344.                             GOTO main
  345.  
  346.                         ELSE
  347.  
  348.                             'if user clicked on another one of its color instead...
  349.                             IF Square.v(t) = player THEN
  350.                                 'clear previous highlighted selection
  351.                                 selected = 0
  352.                                 UpdateBoard
  353.                                 selected = 1
  354.                                 oldt = t
  355.                                 oldtv = Square.v(t) 'save picked box number color
  356.                                 SOUND 3000, .1
  357.                                 GOTO second
  358.                             END IF
  359.  
  360.                             'clicked on enemy instead, redo
  361.                             selected = 0
  362.                             UpdateBoard
  363.                             SOUND 500, .1
  364.                             GOTO main
  365.  
  366.                         END IF
  367.  
  368.                     END IF
  369.  
  370.                 END IF
  371.             END IF
  372.  
  373.         NEXT
  374.  
  375.     END IF
  376.  
  377.     _DISPLAY
  378.  
  379.     IF INKEY$ <> "" THEN GOTO restart
  380.  
  381.     '_LIMIT 600
  382.  
  383.  
  384. FUNCTION HowManyPlaces (old, new)
  385.     'computes how many places a user moved
  386.     '0 = out of bounds
  387.     '1 = one place
  388.     '2 = a jump
  389.  
  390.     p = 0 'default is out of bounds
  391.  
  392.     SELECT CASE old
  393.  
  394.         'row 1
  395.         CASE 1: IF new = old + 1 OR new = old + 9 OR new = old + 10 THEN p = 1
  396.             IF new = 3 OR new = 12 OR new = 19 OR new = 20 OR new = 21 THEN p = 2
  397.         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
  398.             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
  399.         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
  400.             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
  401.         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
  402.             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
  403.         CASE 9: IF new = old - 1 OR new = old + 8 OR new = old + 9 THEN p = 1
  404.             IF new = old - 2 OR new = old + 7 OR new = old + 16 OR new = old + 17 OR new = old + 18 THEN p = 2
  405.  
  406.             'row 2
  407.         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
  408.             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
  409.         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
  410.             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
  411.         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
  412.             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
  413.         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
  414.             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
  415.         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
  416.             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
  417.         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
  418.             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
  419.  
  420.             'row 3
  421.         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
  422.             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
  423.         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
  424.             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
  425.             'middle board, all ways,  (thru row 7)
  426.         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
  427.             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
  428.         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
  429.             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
  430.         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
  431.             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
  432.  
  433.             'row 8
  434.         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
  435.             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
  436.         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
  437.             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
  438.         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
  439.             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
  440.         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
  441.             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
  442.         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
  443.             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
  444.  
  445.             'bottom 9
  446.         CASE 73: IF new = old + 1 OR new = old - 8 OR new = old - 9 THEN p = 1
  447.             IF new = old + 2 OR new = old - 7 OR new = old - 16 OR new = old - 17 OR new = old - 18 THEN p = 2
  448.         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
  449.             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
  450.         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
  451.             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
  452.         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
  453.             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
  454.         CASE 81: IF new = old - 1 OR new = old - 9 OR new = old - 10 THEN p = 1
  455.             IF new = old - 2 OR new = old - 11 OR new = old - 18 OR new = old - 19 OR new = old - 20 THEN p = 2
  456.     END SELECT
  457.  
  458.     HowManyPlaces = p
  459.  
  460.  
  461. SUB UpdateBoard
  462.  
  463.     CLS , _RGB(32, 32, 32)
  464.  
  465.     PPRINT SquareSize * 3.4, SquareSize / 4, SquareSize / 3, _RGB(255, 255, 255), 0, "GridWars"
  466.  
  467.     red = 0: blue = 0
  468.  
  469.     '=== draw board based on box values
  470.     bc = 1 'counter
  471.     FOR cl = 1 TO Columns
  472.         FOR ro = 1 TO Rows
  473.  
  474.             '=== count colors
  475.             IF Square.v(bc) = 1 THEN red = red + 1
  476.             IF Square.v(bc) = 2 THEN blue = blue + 1
  477.  
  478.             '=== if empty box
  479.             IF Square.v(bc) = 0 THEN
  480.                 LINE (Square.x(bc) + 2, Square.y(bc) + 2)-(Square.x(bc) + SquareSize - 2, Square.y(bc) + SquareSize - 2), _RGB(64, 64, 64), BF
  481.             ELSE
  482.                 LINE (Square.x(bc) + 2, Square.y(bc) + 2)-(Square.x(bc) + SquareSize - 2, Square.y(bc) + SquareSize - 2), _RGB(64, 64, 64), BF
  483.                 '=== draw color ball
  484.                 x2 = Square.x(bc) + (SquareSize / 2) 'find middle of box
  485.                 y2 = Square.y(bc) + (SquareSize / 2)
  486.                 sz = SquareSize / 2
  487.                 SELECT CASE Square.v(bc)
  488.                     CASE IS = 1: r = 255: g = 64: b = 64 'red
  489.                     CASE IS = 2: r = 64: g = 64: b = 255 'blue
  490.                 END SELECT
  491.                 CIRCLE (x2, y2), sz - 4, _RGB(r, g, b)
  492.                 PAINT (x2, y2), _RGB(r, g, b)
  493.             END IF
  494.             bc = bc + 1
  495.         NEXT
  496.     NEXT
  497.  
  498.     PPRINT SquareSize / 2, SquareSize / 3.5, SquareSize / 4, _RGB(255, 128, 128), 0, "Red =" + STR$(red)
  499.     PPRINT SquareSize * 6 + (SquareSize / 1.6), SquareSize / 3.5, SquareSize / 4, _RGB(128, 128, 255), 0, "Blue =" + STR$(blue)
  500.  
  501.     'highlight current player
  502.     IF player = 1 THEN
  503.         LINE (SquareSize / 7, SquareSize / 8)-(SquareSize * 3 - (SquareSize / 2), SquareSize / 1.2), _RGBA(255, 100, 100, 50), BF
  504.     END IF
  505.  
  506.     IF player = 2 THEN
  507.         LINE (SquareSize * 6 + (SquareSize / 4), SquareSize / 8)-(SquareSize * 9 - (SquareSize / 7), SquareSize / 1.2), _RGBA(100, 100, 255, 50), BF
  508.     END IF
  509.  
  510.     _DISPLAY
  511.     _ICON _DISPLAY 'update app icon on taskbar
  512.  
  513. SUB convertneighbors (player, num, show)
  514.     'convert neighbors surrounding num to players value.
  515.     '(when a piece lands on num, it changes neighbors)
  516.     SELECT CASE num
  517.         'row 1
  518.         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
  519.             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
  520.             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
  521.         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
  522.             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
  523.             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
  524.             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
  525.             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
  526.         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
  527.             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
  528.             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
  529.             'down left side
  530.         CASE 10, 19, 28, 37, 46, 55, 64
  531.             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
  532.             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
  533.             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
  534.             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
  535.             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
  536.             'down right side
  537.         CASE 18, 27, 36, 45, 54, 63, 72
  538.             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
  539.             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
  540.             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
  541.             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
  542.             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
  543.             'middle of board
  544.         CASE 11 TO 17, 20 TO 26, 29 TO 35, 38 TO 44, 47 TO 53, 56 TO 62, 65 TO 71
  545.             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
  546.             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
  547.             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
  548.             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
  549.             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
  550.             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
  551.             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
  552.             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
  553.             'bottom row
  554.         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
  555.             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
  556.             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
  557.         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
  558.             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
  559.             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
  560.             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
  561.             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
  562.         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
  563.             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
  564.             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
  565.     END SELECT
  566.  
  567. SUB change (num)
  568.  
  569.     '=== find center x/y of place
  570.     x2 = Square.x(num) + (SquareSize / 2): y2 = Square.y(num) + (SquareSize / 2)
  571.  
  572.     'do shrinking circle first
  573.     IF player = 1 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  574.     FOR s = (SquareSize / 2.2) TO 1 STEP -(SquareSize * .025)
  575.         SOUND 100 + t, .05
  576.         'wipe clean
  577.         LINE (Square.x(num) + 2, Square.y(num) + 2)-(Square.x(num) + SquareSize - 2, Square.y(num) + SquareSize - 2), _RGB(64, 64, 64), BF
  578.         CIRCLE (x2, y2), s, clr&
  579.         PAINT (x2, y2), clr&
  580.         _DISPLAY
  581.         IF _DESKTOPHEIGHT < 2000 THEN _LIMIT 140
  582.         t = t + 100
  583.     NEXT
  584.  
  585.     'Expand in the new circle
  586.     'do shrinking circle first
  587.     IF player = 2 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  588.     FOR s = 1 TO (SquareSize / 2.2) STEP (SquareSize * .025)
  589.         'wipe clean
  590.         LINE (Square.x(num) + 2, Square.y(num) + 2)-(Square.x(num) + SquareSize - 2, Square.y(num) + SquareSize - 2), _RGB(64, 64, 64), BF
  591.         CIRCLE (x2, y2), s, clr&
  592.         PAINT (x2, y2), clr&
  593.         _DISPLAY
  594.         IF _DESKTOPHEIGHT < 2000 THEN _LIMIT 140
  595.     NEXT
  596.  
  597.  
  598. SUB PPRINT (x, y, SquareSize, clr&, trans&, text$)
  599.     orig& = _DEST
  600.     bit = 32: IF _PIXELSIZE(0) = 1 THEN bit = 256
  601.     FOR t = 0 TO LEN(text$) - 1
  602.         pprintimg& = _NEWIMAGE(16, 16, bit)
  603.         _DEST pprintimg&
  604.         CLS , trans&: COLOR clr&
  605.         PRINT MID$(text$, t + 1, 1);
  606.         _CLEARCOLOR _RGB(0, 0, 0), pprintimg&
  607.         _DEST orig&
  608.         x1 = x + (t * SquareSize): x2 = x1 + SquareSize
  609.         y1 = y: y2 = y + SquareSize
  610.         _PUTIMAGE (x1 - (SquareSize / 2), y1)-(x2, y2 + (SquareSize / 3)), pprintimg&
  611.         _FREEIMAGE pprintimg&
  612.     NEXT
  613.  
  614. FUNCTION ValidMoves$ (num)
  615.     'returns a string list of all valid moves for player that is sitting on the num
  616.     'The list contains 2 charater byte strings per num place.
  617.     'Each one is a num on the board that player could goto.
  618.  
  619.     list$ = ""
  620.     SELECT CASE num
  621.         CASE 1 'one steps
  622.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  623.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  624.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  625.             '2 steps
  626.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  627.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  628.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  629.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  630.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  631.         CASE 2
  632.             'one steps
  633.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  634.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  635.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  636.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  637.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  638.             'two steps
  639.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  640.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  641.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  642.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  643.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  644.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  645.  
  646.         CASE 3 TO 7
  647.             'one steps
  648.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  649.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  650.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  651.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  652.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  653.             'two steps
  654.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  655.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  656.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  657.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  658.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  659.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  660.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  661.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  662.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  663.         CASE 8
  664.             'one step
  665.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  666.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  667.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  668.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  669.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  670.             'two steps
  671.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  672.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  673.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  674.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  675.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  676.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  677.         CASE 9
  678.             'one step
  679.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  680.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  681.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  682.             'two steps
  683.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  684.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  685.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  686.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  687.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  688.  
  689.             '2nd row
  690.         CASE 10
  691.             'one step
  692.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  693.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  694.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  695.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  696.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  697.             'two steps
  698.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  699.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  700.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  701.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  702.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  703.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  704.         CASE 11
  705.             'one step
  706.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  707.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  708.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  709.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  710.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  711.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  712.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  713.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  714.             'two steps
  715.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  716.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  717.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  718.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  719.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  720.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  721.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  722.         CASE 12 TO 16
  723.             'one step
  724.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  725.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  726.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  727.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  728.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  729.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  730.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  731.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  732.             'two steps
  733.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  734.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  735.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  736.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  737.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  738.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  739.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  740.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  741.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  742.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  743.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  744.         CASE 17
  745.             'one step
  746.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  747.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  748.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  749.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  750.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  751.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  752.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  753.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  754.             'two steps
  755.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  756.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  757.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  758.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  759.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  760.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  761.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  762.         CASE 18
  763.             'one step
  764.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  765.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  766.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  767.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  768.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  769.             'two steps
  770.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  771.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  772.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  773.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  774.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  775.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  776.             'down left side, outer
  777.         CASE 19, 28, 37, 46, 55
  778.             'one step
  779.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  780.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  781.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  782.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  783.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  784.             'two steps
  785.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  786.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  787.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  788.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  789.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  790.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  791.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  792.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  793.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  794.             'down left side, inner
  795.         CASE 20, 29, 38, 47, 56
  796.             'one step
  797.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  798.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  799.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  800.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  801.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  802.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  803.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  804.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  805.             'two steps
  806.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  807.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  808.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  809.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  810.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  811.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  812.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  813.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  814.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  815.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  816.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  817.  
  818.             'middle of board (all directions)
  819.         CASE 21 TO 25, 30 TO 34, 39 TO 43, 48 TO 52, 57 TO 61
  820.             'one step
  821.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  822.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  823.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  824.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  825.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  826.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  827.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  828.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  829.             'two steps
  830.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  831.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  832.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  833.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  834.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  835.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  836.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  837.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  838.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  839.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  840.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  841.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  842.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  843.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  844.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  845.             IF Square.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  846.  
  847.             'right side, outer
  848.         CASE 27, 36, 45, 54, 63
  849.             'one step
  850.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  851.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  852.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  853.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  854.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  855.             'two steps
  856.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  857.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  858.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  859.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  860.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  861.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  862.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  863.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  864.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  865.  
  866.             'rigth side, inner
  867.         CASE 26, 35, 44, 53, 62
  868.             'one step
  869.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  870.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  871.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  872.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  873.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  874.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  875.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  876.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  877.             'two steps
  878.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  879.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  880.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  881.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  882.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  883.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  884.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  885.             IF Square.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  886.             IF Square.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  887.             IF Square.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  888.             IF Square.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  889.         CASE 64
  890.             'one step
  891.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  892.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  893.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  894.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  895.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  896.             'two steps
  897.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  898.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  899.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  900.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  901.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  902.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  903.         CASE 65
  904.             'one step
  905.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  906.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  907.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  908.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  909.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  910.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  911.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  912.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  913.             'two steps
  914.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  915.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  916.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  917.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  918.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  919.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  920.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  921.         CASE 66 TO 70
  922.             'one step
  923.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  924.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  925.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  926.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  927.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  928.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  929.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  930.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  931.             'two steps
  932.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  933.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  934.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  935.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  936.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  937.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  938.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  939.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  940.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  941.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  942.             IF Square.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  943.         CASE 71
  944.             'one step
  945.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  946.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  947.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  948.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  949.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  950.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  951.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  952.             IF Square.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  953.             'two steps
  954.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  955.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  956.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  957.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  958.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  959.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  960.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  961.         CASE 72
  962.             'one step
  963.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  964.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  965.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  966.             IF Square.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  967.             IF Square.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  968.             'two steps
  969.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  970.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  971.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  972.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  973.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  974.             IF Square.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  975.             'bottom row
  976.         CASE 73
  977.             'one step
  978.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  979.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  980.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  981.             'two steps
  982.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  983.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  984.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  985.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  986.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  987.         CASE 74
  988.             'one step
  989.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  990.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  991.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  992.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  993.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  994.             'two steps
  995.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  996.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  997.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  998.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  999.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  1000.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  1001.         CASE 75 TO 79
  1002.             'one step
  1003.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  1004.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  1005.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  1006.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  1007.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  1008.             'two steps
  1009.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  1010.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  1011.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  1012.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  1013.             IF Square.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  1014.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  1015.             IF Square.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  1016.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  1017.             IF Square.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  1018.         CASE 80
  1019.             'one step
  1020.             IF Square.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  1021.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  1022.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  1023.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  1024.             IF Square.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  1025.             'two steps
  1026.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  1027.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  1028.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  1029.             IF Square.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  1030.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  1031.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  1032.         CASE 81
  1033.             'one step
  1034.             IF Square.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  1035.             IF Square.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  1036.             IF Square.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  1037.             'two steps
  1038.             IF Square.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  1039.             IF Square.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  1040.             IF Square.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  1041.             IF Square.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  1042.             IF Square.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  1043.  
  1044.     END SELECT
  1045.  
  1046.     ValidMoves$ = list$
  1047.  
  1048.  
  1049. FUNCTION nums$ (num)
  1050.     'helper function returns num as a two byte string
  1051.     n$ = LTRIM$(RTRIM$(STR$(num)))
  1052.     IF LEN(n$) = 1 THEN n$ = "0" + n$
  1053.     nums$ = n$
  1054.  
  1055.  
  1056. FUNCTION ComputerMove$ ()
  1057.  
  1058.     'this function will find the best move and return a string of it.
  1059.     'the string will contain the from place and the new place numbers.
  1060.     '(like "0103" to move piece 1 to place 3
  1061.  
  1062.     'ideas: if bestgain is only 1 (no enemies) then use a random piece
  1063.     'instead of first one scanned.  This way game doesn't start same way
  1064.     'all the time.  Will have to keep track of pieces and make sure more than
  1065.     'one is found.
  1066.  
  1067.     'backup original board values, for restoring later
  1068.     'and count total blue pieces on board while were at it....
  1069.     REDIM box.v2(Rows * Columns): totalblues = 0
  1070.     FOR o = 1 TO Rows * Columns
  1071.         box.v2(o) = Square.v(o)
  1072.         IF Square.v(0) = 2 THEN totalblues = totalblues + 1
  1073.     NEXT
  1074.  
  1075.     bestgain = 0: bestplace = 0
  1076.  
  1077.     'added random below, so doesnt always start the same way.
  1078.     'now either scan from top, or from bottom.
  1079.  
  1080.     scandir = INT(RND * 2) 'returns a 0 or 1
  1081.  
  1082.     IF scandir = 0 THEN
  1083.         'step through pieces again, this time trying all moves on blues
  1084.         FOR piece = 1 TO Rows * Columns
  1085.             'if it's a blue piece
  1086.             IF Square.v(piece) = 2 THEN
  1087.                 'get valid moves of piece, if any
  1088.                 Valids$ = ValidMoves$(piece)
  1089.                 'If there is....
  1090.                 IF Valids$ <> "" THEN
  1091.                     'try each move on piece...recount board
  1092.                     FOR try = 1 TO LEN(Valids$) STEP 2
  1093.                         new = VAL(MID$(Valids$, try, 2))
  1094.                         'do the move, temporarily, just to see outcome
  1095.                         'if making one space move, clone player 2
  1096.                         IF HowManyPlaces(piece, new) = 1 THEN
  1097.                             Square.v(new) = 2
  1098.                             convertneighbors player, new, 0
  1099.                         END IF
  1100.                         'if jumping...erase old place
  1101.                         IF HowManyPlaces(piece, new) = 2 THEN
  1102.                             Square.v(new) = player
  1103.                             Square.v(piece) = 0: convertneighbors player, new, 0
  1104.                         END IF
  1105.                         'now recount totalblues of board
  1106.                         newtotal = 0
  1107.                         FOR ss = 1 TO Rows * Columns
  1108.                             IF Square.v(ss) = 2 THEN newtotal = newtotal + 1
  1109.                         NEXT
  1110.                         'see what new tally is
  1111.                         compute = newtotal - totalblues
  1112.                         'if better than others, save data
  1113.                         IF compute > bestgain THEN
  1114.                             'save this info
  1115.                             origplace = piece: bestplace = new
  1116.                             bestgain = compute
  1117.                         END IF
  1118.  
  1119.                         'restore original board values to try other valid moves
  1120.                         FOR res = 1 TO Rows * Columns
  1121.                             Square.v(res) = box.v2(res)
  1122.                         NEXT
  1123.                     NEXT
  1124.                 END IF
  1125.             END IF
  1126.         NEXT
  1127.  
  1128.     ELSE
  1129.  
  1130.         'step through pieces again, this time trying all moves on blues
  1131.         FOR piece = Rows * Columns TO 1 STEP -1
  1132.             'if it's a blue piece
  1133.             IF Square.v(piece) = 2 THEN
  1134.                 'get valid moves of piece, if any
  1135.                 Valids$ = ValidMoves$(piece)
  1136.                 'If there is....
  1137.                 IF Valids$ <> "" THEN
  1138.                     'try each move on piece...recount board
  1139.                     FOR try = 1 TO LEN(Valids$) STEP 2
  1140.                         new = VAL(MID$(Valids$, try, 2))
  1141.                         'do the move, temporarily, just to see outcome
  1142.                         'if making one space move, clone player 2
  1143.                         IF HowManyPlaces(piece, new) = 1 THEN
  1144.                             Square.v(new) = 2
  1145.                             convertneighbors player, new, 0
  1146.                         END IF
  1147.                         'if jumping...erase old place
  1148.                         IF HowManyPlaces(piece, new) = 2 THEN
  1149.                             Square.v(new) = player
  1150.                             Square.v(piece) = 0: convertneighbors player, new, 0
  1151.                         END IF
  1152.                         'now recount totalblues of board
  1153.                         newtotal = 0
  1154.                         FOR ss = 1 TO Rows * Columns
  1155.                             IF Square.v(ss) = 2 THEN newtotal = newtotal + 1
  1156.                         NEXT
  1157.                         'see what new tally is
  1158.                         compute = newtotal - totalblues
  1159.                         'if better than others, save data
  1160.                         IF compute > bestgain THEN
  1161.                             'save this info
  1162.                             origplace = piece: bestplace = new
  1163.                             bestgain = compute
  1164.                         END IF
  1165.                         'restore original board values to try other valid moves
  1166.                         FOR res = 1 TO Rows * Columns
  1167.                             Square.v(res) = box.v2(res)
  1168.                         NEXT
  1169.                     NEXT
  1170.                 END IF
  1171.             END IF
  1172.         NEXT
  1173.  
  1174.     END IF
  1175.  
  1176.     ComputerMove$ = nums$(origplace) + nums$(bestplace)
  1177.  
  1178.     'restore original board values again, just to be safe...
  1179.  
  1180.     FOR res = 1 TO Rows * Columns
  1181.         Square.v(res) = box.v2(res)
  1182.     NEXT
  1183.  
  1184.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #16 on: November 04, 2021, 01:14:48 pm »
Your AI plays "too good!", it makes a move and suddenly half my pieces are it's color. I go,"What?!" If it made a jump, I swear the place it jumps from is not leaving a hole that it occupied, maybe not?

Is it possible to highlight the last move AI made with it's piece, from and to? I don't want to accuse it of cheating simply because it doesn't care! (My tendency would be just to quit playing with it.)

PLUS for extra bonus, when showing legal moves show by color difference which are jumps that should leave hole and which are "clones" (good name, and maybe something I am not use to playing with/against).

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #17 on: November 04, 2021, 02:48:59 pm »
Quote
How does it display on yours?

Pretty much the same as before which was already fine.

Offline Statsman1

  • Newbie
  • Posts: 36
  • I'm just a jerk, but a hero is what I want to be.
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #18 on: November 04, 2021, 03:20:19 pm »
@Dav ...

Game looks great!  Played 2 games, won both, the second one by a large margin.  I am not going to dive into the AI at this time, you must have something going on - it appears that the AI looks for the move with the biggest piece turnover, and takes it, without considering position, especially along the sides.

A couple of things I noticed...

When the game ends and the winner is announced, the score is not updated, the game just moves on to the next game.

Also, sometimes there is a big delay between selecting a piece with the mouse, and the piece becoming "active" and ready to move.

But your game is coming along nicely!  Like the sound effects!
Good decisions come from experience.
Experience comes from bad decisions.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #19 on: November 05, 2021, 03:46:44 pm »
@bplus:  Hmm, I haven't caught it cheating yet, but perhaps I made a mistake in the change sub, an it's flipping squares wrong somewhere.  I will double check that.  Maybe I can add a tracer to see what happened at last move.  Was thinking of adding a UNDO last move thing.  I may add difficulty levels, easy, medium, hard.  Where it is now would be the hard one.  Thanks for telling me how it displays on your system!

@Statsman1.  Thanks!  You have a keen eye.  You are correct, the AI takes the move that gives it the most gain for that move.  I need to do a look ahead - see if the next best for the human would result in less pieces after all, or something. Thanks for catching the score not being updated at the end.  I hadn't noticed it.  About the delay, yeah it happens to me when the window is larger than 1400 pixels high, I'm not sure how to fix that but will investigate.  Thanks for trying it out!

- Dav
« Last Edit: November 05, 2021, 04:07:26 pm by Dav »