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

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
GridWars game - going to add AI to it.
« on: October 27, 2021, 10:46:56 pm »
@bplus's games has inspired me to try my hand at implementing AI to one of my puzzles.  I think this one is a good candidate. GridWars.  Currently it's a 2 player (2 humans) game, but I want to make it a human vs computer one.  Will have to re-write the code alot, add a valid move check.  Here is the BEFORE version. 

You click on a piece to move.  Move it one space to clone it, move two spaces to just jump.  Touching the other player will convert it to your color.  Object is to fill the grid with all your color.

(Sorry, @SMcNeill, this will be a tiny screen on your laptop...)

EDIT: I didnt come up with this puzzle, I use to play one like it years ago, pre Win95.

- Dav

Code: QB64: [Select]
  1.  
  2. '============
  3. 'GRIDWARS.BAS - v0.1
  4. '============
  5. 'Coded by Dav OCT/2021
  6. 'Work in progress - hoping to add AI play.
  7.  
  8.  
  9. SCREEN _NEWIMAGE(600, 650, 32)
  10. _TITLE "GridWar"
  11.  
  12. '=== define board info
  13. DIM SHARED rows, cols, size
  14. rows = 9: cols = 9: size = _WIDTH / cols
  15. DIM SHARED box.v(rows * cols) 'value of box
  16. DIM SHARED box.x(rows * cols), box.y(rows * cols) 'x/y's
  17. DIM SHARED player
  18.  
  19. '=======
  20. restart:
  21. '=======
  22.  
  23. PLAY "MBL32O3CEGEC"
  24.  
  25.  
  26. bc = 1 'counter
  27. FOR c = 1 TO cols
  28.     FOR r = 1 TO rows
  29.         x = (r * size)
  30.         y = 50 + (c * size)
  31.         box.x(bc) = x - size
  32.         box.y(bc) = y - size
  33.         box.v(bc) = 0 'zero means nothing, empty square
  34.         bc = bc + 1
  35.     NEXT
  36.  
  37. 'set user's piece
  38. box.v(1) = 1: box.v(9) = 2
  39. box.v(73) = 2: box.v(81) = 1
  40.  
  41. player = 1 'user goes first
  42.  
  43. '====
  44. main:
  45. '====
  46.  
  47. selected = 0
  48.  
  49. UpdateBoard
  50.  
  51. second: 'Go back here when making second choice
  52.  
  53.  
  54.     'wait until mouse button up to continue
  55.     WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  56.  
  57.     trap = _MOUSEINPUT 'Poll mouse data
  58.  
  59.     'highlight box when a box is selected
  60.     IF selected = 1 THEN
  61.         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
  62.         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
  63.         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
  64.         _DISPLAY
  65.     END IF
  66.  
  67.  
  68.     'If user clicked mouse
  69.  
  70.         'see where they clicked
  71.         mx = _MOUSEX: my = _MOUSEY
  72.  
  73.         'cycle through all Check blocks...
  74.         FOR t = 1 TO (rows * cols)
  75.  
  76.             'Block loction...
  77.             tx = box.x(t): tx2 = box.x(t) + size
  78.             ty = box.y(t): ty2 = box.y(t) + size
  79.  
  80.             'if clicked on a box clicked
  81.             IF mx >= tx AND mx <= tx2 THEN
  82.                 IF my >= ty AND my <= ty2 THEN
  83.  
  84.                     'if this is a first choice...
  85.                     IF selected = 0 THEN
  86.  
  87.                         'only select players color
  88.                         IF box.v(t) = player THEN
  89.                             selected = 1
  90.                             SOUND 3000, .1 'made a select
  91.                             oldt = t
  92.                             oldtv = box.v(t) 'save picked box number color
  93.                             GOTO second 'now get second choice
  94.                         END IF
  95.  
  96.                     END IF
  97.  
  98.                     IF selected = 1 THEN 'making second choice
  99.  
  100.                         'if selected an empty box
  101.                         IF box.v(t) = 0 THEN
  102.  
  103.                             'if making one space move
  104.                             IF HowManyPlaces(oldt, t) = 1 THEN
  105.  
  106.                                 'clone to 2nd box data
  107.                                 SOUND 2000, .1
  108.                                 box.v(t) = oldtv
  109.                                 UpdateBoard
  110.  
  111.                                 convertneighbors player, t
  112.  
  113.                             END IF
  114.  
  115.                             'if jumping...
  116.                             IF HowManyPlaces(oldt, t) = 2 THEN
  117.  
  118.                                 'jump...erase 1st box data
  119.                                 SOUND 2000, .1
  120.                                 box.v(t) = oldtv
  121.                                 box.v(oldt) = 0
  122.                                 UpdateBoard
  123.  
  124.                                 convertneighbors player, t
  125.  
  126.                             END IF
  127.  
  128.  
  129.                             UpdateBoard
  130.  
  131.                             'must have clicked a out of bounds place, redo turn...
  132.                             IF HowManyPlaces(oldt, t) = 0 THEN
  133.                                 SOUND 500, .1
  134.                                 GOTO main
  135.                             END IF
  136.  
  137.                             '===============================
  138.                             'check pieces here.....
  139.  
  140.                             'See how many empty places left
  141.                             howmany = 0: reds = 0: blues = 0
  142.                             FOR h = 1 TO rows * cols
  143.                                 'empty ones
  144.                                 IF box.v(h) = 0 THEN howmany = howmany + 1
  145.                                 IF box.v(h) = 1 THEN reds = reds + 1
  146.                                 IF box.v(h) = 2 THEN blues = blues + 1
  147.                             NEXT
  148.  
  149.                             'If no places left, game over
  150.                             IF howmany = 0 THEN
  151.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  152.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  153.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "GAME OVER"
  154.                                 PLAY "mbl16o2bagfedc"
  155.                                 _DISPLAY: SLEEP 5
  156.                                 GOTO restart
  157.                             END IF
  158.  
  159.                             'If no reds left, blue wins
  160.                             IF reds = 0 THEN
  161.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  162.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  163.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "BLUE WINS"
  164.                                 PLAY "mbl16o2bagfedc"
  165.                                 _DISPLAY: SLEEP 5
  166.                                 GOTO restart
  167.                             END IF
  168.  
  169.                             'If no blues left, red wins
  170.                             IF blues = 0 THEN
  171.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  172.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  173.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "RED WINS!"
  174.                                 PLAY "mbl16o2bagfedc"
  175.                                 _DISPLAY: SLEEP 5
  176.                                 GOTO restart
  177.                             END IF
  178.  
  179.  
  180.                             'players move done - switch turn, players
  181.                             IF player = 1 THEN
  182.  
  183.                                 'computers turn here....
  184.                                 'CHANGE TO AI MOVE HERE  '<<<<<<<<<<<<<<
  185.  
  186.                                 player = 2
  187.                             ELSE
  188.                                 player = 1
  189.                             END IF
  190.  
  191.                             'NEED TO CHECK IF PLAYER HAS VALID MOVE LEFT <<<<<<
  192.  
  193.                             GOTO main
  194.  
  195.                         ELSE
  196.  
  197.                             'if user clicked on another one of its color instead...
  198.                             IF box.v(t) = player THEN
  199.                                 'clear previous highlighted selection
  200.                                 selected = 0
  201.                                 UpdateBoard
  202.                                 selected = 1
  203.                                 oldt = t
  204.                                 oldtv = box.v(t) 'save picked box number color
  205.                                 SOUND 3000, .1
  206.                                 GOTO second
  207.                             END IF
  208.  
  209.                             'clicked on enemy instead, redo
  210.                             selected = 0
  211.                             UpdateBoard
  212.                             SOUND 500, .1
  213.                             GOTO main
  214.  
  215.                         END IF
  216.  
  217.                     END IF
  218.  
  219.                 END IF
  220.             END IF
  221.  
  222.         NEXT
  223.  
  224.     END IF
  225.  
  226.     _DISPLAY
  227.  
  228.     IF INKEY$ <> "" THEN GOTO restart
  229.  
  230.  
  231. FUNCTION HowManyPlaces (old, new)
  232.     'computes how many places a user moved
  233.     '0 = out of bounds
  234.     '1 = one place
  235.     '2 = a jump
  236.  
  237.     p = 0 'default is out of bounds
  238.  
  239.     SELECT CASE old
  240.  
  241.         'row 1
  242.         CASE 1: IF new = old + 1 OR new = old + 9 OR new = old + 10 THEN p = 1
  243.             IF new = 3 OR new = 12 OR new = 19 OR new = 20 OR new = 21 THEN p = 2
  244.         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
  245.             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
  246.         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
  247.             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
  248.         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
  249.             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
  250.         CASE 9: IF new = old - 1 OR new = old + 8 OR new = old + 9 THEN p = 1
  251.             IF new = old - 2 OR new = old + 7 OR new = old + 16 OR new = old + 17 OR new = old + 18 THEN p = 2
  252.  
  253.             'row 2
  254.         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
  255.             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
  256.         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
  257.             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
  258.         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
  259.             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
  260.         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
  261.             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
  262.         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
  263.             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
  264.         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
  265.             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
  266.  
  267.             'row 3
  268.         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
  269.             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
  270.         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
  271.             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
  272.             'middle board, all ways,  (thru row 7)
  273.         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
  274.             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
  275.         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
  276.             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
  277.         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
  278.             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
  279.  
  280.             'row 8
  281.         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
  282.             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
  283.         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
  284.             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
  285.         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
  286.             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
  287.         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
  288.             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
  289.         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
  290.             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
  291.  
  292.             'bottom 9
  293.         CASE 73: IF new = old + 1 OR new = old - 8 OR new = old - 9 THEN p = 1
  294.             IF new = old + 2 OR new = old - 7 OR new = old - 16 OR new = old - 17 OR new = old - 18 THEN p = 2
  295.         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
  296.             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
  297.         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
  298.             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
  299.         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
  300.             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
  301.         CASE 81: IF new = old - 1 OR new = old - 9 OR new = old - 10 THEN p = 1
  302.             IF new = old - 2 OR new = old - 11 OR new = old - 18 OR new = old - 19 OR new = old - 20 THEN p = 2
  303.     END SELECT
  304.  
  305.     HowManyPlaces = p
  306.  
  307.  
  308. SUB UpdateBoard
  309.  
  310.     CLS , _RGB(32, 32, 32)
  311.     PPRINT 205, 10, 20, _RGB(255, 255, 255), 0, "-=GridWar=-"
  312.  
  313.     red = 0: blue = 0
  314.  
  315.     '=== draw board based on box values
  316.     bc = 1 'counter
  317.     FOR cl = 1 TO cols
  318.         FOR ro = 1 TO rows
  319.  
  320.             '=== count colors
  321.             IF box.v(bc) = 1 THEN red = red + 1
  322.             IF box.v(bc) = 2 THEN blue = blue + 1
  323.  
  324.             '=== if empty box
  325.             IF box.v(bc) = 0 THEN
  326.                 LINE (box.x(bc) + 2, box.y(bc) + 2)-(box.x(bc) + size - 2, box.y(bc) + size - 2), _RGB(64, 64, 64), BF
  327.             ELSE
  328.                 LINE (box.x(bc) + 2, box.y(bc) + 2)-(box.x(bc) + size - 2, box.y(bc) + size - 2), _RGB(64, 64, 64), BF
  329.                 '=== draw color ball
  330.                 x2 = box.x(bc) + (size / 2) 'find middle of box
  331.                 y2 = box.y(bc) + (size / 2)
  332.                 sz = size / 2
  333.                 SELECT CASE box.v(bc)
  334.                     CASE IS = 1: r = 255: g = 64: b = 64 'red
  335.                     CASE IS = 2: r = 64: g = 64: b = 255 'blue
  336.                 END SELECT
  337.                 CIRCLE (x2, y2), sz - 4, _RGB(r, g, b)
  338.                 PAINT (x2, y2), _RGB(r, g, b)
  339.             END IF
  340.             bc = bc + 1
  341.         NEXT
  342.     NEXT
  343.  
  344.     PPRINT 30, 15, 14, _RGB(255, 128, 128), 0, "Red =" + STR$(red)
  345.     PPRINT 465, 15, 14, _RGB(128, 128, 255), 0, "Blue =" + STR$(blue)
  346.  
  347.     IF player = 1 THEN
  348.         LINE (10, 10)-(150, 40), _RGBA(255, 100, 100, 50), BF
  349.     END IF
  350.  
  351.     IF player = 2 THEN
  352.         LINE (440, 10)-(590, 40), _RGBA(100, 100, 255, 50), BF
  353.     END IF
  354.  
  355.     _DISPLAY
  356.     _ICON _DISPLAY 'update app icon on taskbar
  357.  
  358. SUB convertneighbors (player, num)
  359.     'convert neighbors surrounding num to players value.
  360.     '(when a piece lands on num, it changes neighbors)
  361.     SELECT CASE num
  362.         'row 1
  363.         CASE 1: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  364.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  365.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  366.         CASE 2 TO 8: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  367.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  368.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player:: change num + 8
  369.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  370.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  371.         CASE 9: IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  372.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  373.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  374.             'down left side
  375.         CASE 10, 19, 28, 37, 46, 55, 64
  376.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  377.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  378.             IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  379.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  380.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  381.             'down right side
  382.         CASE 18, 27, 36, 45, 54, 63, 72: IF box.v(num - 9) <> 0 THEN box.v(num - 9) = player: change num - 9
  383.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  384.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  385.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  386.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  387.             'middle of board
  388.         CASE 11 TO 17, 20 TO 26, 29 TO 35, 38 TO 44, 47 TO 53, 56 TO 62, 65 TO 71
  389.             IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  390.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  391.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  392.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  393.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  394.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  395.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  396.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  397.             'bottom row
  398.         CASE 73: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  399.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  400.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  401.         CASE 74 TO 80: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  402.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  403.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  404.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  405.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  406.         CASE 81: IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  407.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  408.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  409.     END SELECT
  410.  
  411. SUB change (num)
  412.  
  413.     '=== find center x/y of place
  414.     x2 = box.x(num) + (size / 2): y2 = box.y(num) + (size / 2)
  415.  
  416.     'do shrinking circle first
  417.     IF player = 1 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  418.     FOR s = 30 TO 1 STEP -2
  419.         SOUND 100 + t, .05
  420.         'wipe clean
  421.         LINE (box.x(num) + 2, box.y(num) + 2)-(box.x(num) + size - 2, box.y(num) + size - 2), _RGB(64, 64, 64), BF
  422.         CIRCLE (x2, y2), s, clr&
  423.         PAINT (x2, y2), clr&
  424.         _DISPLAY
  425.         _LIMIT 140
  426.         t = t + 100
  427.     NEXT
  428.  
  429.     'Expand in the new circle
  430.     'do shrinking circle first
  431.     IF player = 2 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  432.     FOR s = 1 TO 30 STEP 2
  433.         'wipe clean
  434.         LINE (box.x(num) + 2, box.y(num) + 2)-(box.x(num) + size - 2, box.y(num) + size - 2), _RGB(64, 64, 64), BF
  435.         CIRCLE (x2, y2), s, clr&
  436.         PAINT (x2, y2), clr&
  437.         _DISPLAY
  438.         _LIMIT 140
  439.     NEXT
  440.  
  441.  
  442. SUB PPRINT (x, y, size, clr&, trans&, text$)
  443.     orig& = _DEST
  444.     bit = 32: IF _PIXELSIZE(0) = 1 THEN bit = 256
  445.     FOR t = 0 TO LEN(text$) - 1
  446.         pprintimg& = _NEWIMAGE(16, 16, bit)
  447.         _DEST pprintimg&
  448.         CLS , trans&: COLOR clr&
  449.         PRINT MID$(text$, t + 1, 1);
  450.         _CLEARCOLOR _RGB(0, 0, 0), pprintimg&
  451.         _DEST orig&
  452.         x1 = x + (t * size): x2 = x1 + size
  453.         y1 = y: y2 = y + size
  454.         _PUTIMAGE (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  455.         _FREEIMAGE pprintimg&
  456.     NEXT
  457.  
  458.  
« Last Edit: October 27, 2021, 10:56:28 pm by Dav »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #1 on: October 27, 2021, 11:20:09 pm »
But whatever I do, I can't seem to get anything to blow up. How do you blow things up?

Yep, works as advertised. Hey, has anyone figured out a way to route (map) two mouse controllers with QB64?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #2 on: October 27, 2021, 11:31:21 pm »
What lovely sounds they make! Put I can't predict what is going to change when I move a piece next to the opponents, sometimes a couple sometimes maybe 7 or 4 or... ? Haven't picked up on the pattern yet but it's late at night.

Wow! AI for this, wow!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #3 on: October 28, 2021, 10:30:23 am »
What lovely sounds they make! Put I can't predict what is going to change when I move a piece next to the opponents, sometimes a couple sometimes maybe 7 or 4 or... ? Haven't picked up on the pattern yet but it's late at night.

Wow! AI for this, wow!

When you move a piece to a square, any other pieces on surrounding squares will be converted - like the attached picture shows.  If there's an odd one popping up, there may be a few errors on certain squares, I just caught one this morning. 

I made a Valid Moves function this morning to show valid moves when clicking on any piece.  That's a big hurdle to get to AI.  Also, I needed a way to see if any moves left for a player.

As for coming up with AI, I'm thinking of doing it simple like this first, then expand on it...

First count number of blue (computer) circles on the board.  Cycle through all valid moves for each blue piece, and count the number of blue pieces afterwards.  (A what if I move here and see the results..).  The move which makes the biggest blue gain will be played.  And If there a tie between doing a 1 move play and a jump move, do the 1 move instead as to not create a hole in a big group.  If there is no moves that will change a red piece to blue, then just do a random 1 move with a blue piece to add another blue piece on the board.

- Dav

 
gridwarhow.jpg

« Last Edit: October 28, 2021, 10:44:30 am by Dav »

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 #4 on: October 28, 2021, 10:45:14 am »
Love it!  This looks like Ataxx, one of my favorite arcade games. 

And wowee, did that game’s AI ever get hard when you played the top 2 characters.

Looking forward to seeing how this turns out - GridWars would be a must-play, in my book!
Good decisions come from experience.
Experience comes from bad decisions.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #5 on: October 28, 2021, 11:43:21 am »
AH, OK so every square touching square you click turns to your color if has piece on it. I think that clears it up nicely for me, that pretty easy to code too.

Yeah for AI testing all the squares is what I did for Connect 4, only had 8 at most. But you have to make up values for inner squares versus outer squares... for tie breakers. I imagine if you could establish a core center you could wall off opponent? This might be a little like Go where you wall off sections of board from opponent.

I did play to point where I couldn't move a red piece and blue still had many moves it could do and game just sat there. So determining if a player doesn't have a move is big step forward.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #6 on: October 28, 2021, 12:34:13 pm »
Here's the version with the ValidateMove function and game now shows available moves when clicking on a piece. Also it now checks if player has any moves left.  The code is MUCH more complicated than it needs to be, I will re-organize this mess.  I rushed coding it to get it functioning so I could get to an AI challenge.  Ashamed to post code this ugly, but here goes...

- Dav

Code: QB64: [Select]
  1. '============
  2. 'GRIDWARS.BAS - v0.2
  3. '============
  4. 'Coded by Dav OCT/2021
  5.  
  6. 'v0.2 changes
  7. '* Added validmoves function and show moves available.
  8. '* See if any moves left for players.  Game over if none.
  9.  
  10.  
  11.  
  12. SCREEN _NEWIMAGE(600, 650, 32)
  13. _TITLE "GridWar"
  14.  
  15. '=== define board info
  16. DIM SHARED rows, cols, size
  17. rows = 9: cols = 9: size = _WIDTH / cols
  18. DIM SHARED box.v(rows * cols) 'value of box
  19. DIM SHARED box.x(rows * cols), box.y(rows * cols) 'x/y's
  20. DIM SHARED player
  21.  
  22. '=======
  23. restart:
  24. '=======
  25.  
  26. PLAY "MBL32O3CEGEC"
  27.  
  28.  
  29. bc = 1 'counter
  30. FOR c = 1 TO cols
  31.     FOR r = 1 TO rows
  32.         x = (r * size)
  33.         y = 50 + (c * size)
  34.         box.x(bc) = x - size
  35.         box.y(bc) = y - size
  36.         box.v(bc) = 0 'zero means nothing, empty square
  37.         bc = bc + 1
  38.     NEXT
  39.  
  40. 'set user's piece
  41. box.v(1) = 1: box.v(9) = 2
  42. box.v(73) = 2: box.v(81) = 1
  43.  
  44. player = 1 'user goes first
  45.  
  46. '====
  47. main:
  48. '====
  49.  
  50. selected = 0
  51.  
  52. UpdateBoard
  53.  
  54. second: 'Go back here when making second choice
  55.  
  56.  
  57.     'wait until mouse button up to continue
  58.     WHILE _MOUSEBUTTON(1) <> 0: n = _MOUSEINPUT: WEND
  59.  
  60.     trap = _MOUSEINPUT 'Poll mouse data
  61.  
  62.     'highlight box when a box is selected
  63.     IF selected = 1 THEN
  64.         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
  65.         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
  66.         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
  67.  
  68.         '====================================
  69.         'show valid moves, for testing...
  70.         v$ = ValidMoves$(t)
  71.         FOR f = 1 TO LEN(v$) STEP 2
  72.             bv = VAL(MID$(v$, f, 2))
  73.             x2 = box.x(bv) + (size / 2) 'find middle of box
  74.             y2 = box.y(bv) + (size / 2)
  75.             CIRCLE (x2, y2), 3, _RGBA(150, 150, 150, 50), B
  76.         NEXT
  77.         '====================================
  78.  
  79.         _DISPLAY
  80.     END IF
  81.  
  82.  
  83.     'If user clicked mouse
  84.  
  85.         'see where they clicked
  86.         mx = _MOUSEX: my = _MOUSEY
  87.  
  88.         'cycle through all Check blocks...
  89.         FOR t = 1 TO (rows * cols)
  90.  
  91.             'Block loction...
  92.             tx = box.x(t): tx2 = box.x(t) + size
  93.             ty = box.y(t): ty2 = box.y(t) + size
  94.  
  95.             'if clicked on a box clicked
  96.             IF mx >= tx AND mx <= tx2 THEN
  97.                 IF my >= ty AND my <= ty2 THEN
  98.  
  99.                     'if this is a first choice...
  100.                     IF selected = 0 THEN
  101.  
  102.                         'only select players color
  103.                         IF box.v(t) = player THEN
  104.  
  105.                             selected = 1
  106.                             SOUND 3000, .1 'made a select
  107.                             oldt = t
  108.                             oldtv = box.v(t) 'save picked box number color
  109.                             GOTO second 'now get second choice
  110.                         END IF
  111.  
  112.                     END IF
  113.  
  114.                     IF selected = 1 THEN 'making second choice
  115.  
  116.                         'if selected an empty box
  117.                         IF box.v(t) = 0 THEN
  118.  
  119.                             'if making one space move
  120.                             IF HowManyPlaces(oldt, t) = 1 THEN
  121.  
  122.                                 'clone to 2nd box data
  123.                                 SOUND 2000, .1
  124.                                 box.v(t) = oldtv
  125.                                 UpdateBoard
  126.  
  127.                                 convertneighbors player, t
  128.  
  129.                             END IF
  130.  
  131.                             'if jumping...
  132.                             IF HowManyPlaces(oldt, t) = 2 THEN
  133.  
  134.                                 'jump...erase 1st box data
  135.                                 SOUND 2000, .1
  136.                                 box.v(t) = oldtv
  137.                                 box.v(oldt) = 0
  138.                                 UpdateBoard
  139.  
  140.                                 convertneighbors player, t
  141.  
  142.                             END IF
  143.  
  144.  
  145.                             UpdateBoard
  146.  
  147.                             'must have clicked a out of bounds place, redo turn...
  148.                             IF HowManyPlaces(oldt, t) = 0 THEN
  149.                                 SOUND 500, .1
  150.                                 GOTO main
  151.                             END IF
  152.  
  153.                             '===============================
  154.                             'check pieces here.....
  155.  
  156.                             'See how many empty places left
  157.                             howmany = 0: reds = 0: blues = 0
  158.                             FOR h = 1 TO rows * cols
  159.                                 'empty ones
  160.                                 IF box.v(h) = 0 THEN howmany = howmany + 1
  161.                                 IF box.v(h) = 1 THEN reds = reds + 1
  162.                                 IF box.v(h) = 2 THEN blues = blues + 1
  163.                             NEXT
  164.  
  165.                             'If no places left, game over
  166.                             IF howmany = 0 THEN
  167.  
  168.                                 IF reds = blues THEN
  169.                                     LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  170.                                     LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  171.                                     PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "TIE GAME!"
  172.                                     PLAY "mbl16o2bagfedc"
  173.                                     _DISPLAY: SLEEP 5
  174.                                     GOTO restart
  175.                                 END IF
  176.  
  177.                                 IF reds > blues THEN GOTO redwins ELSE GOTO bluewins
  178.  
  179.                             END IF
  180.  
  181.                             'If no reds left, blue wins
  182.                             IF reds = 0 THEN
  183.                                 bluewins:
  184.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  185.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  186.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "BLUE WINS"
  187.                                 PLAY "mbl16o2bagfedc"
  188.                                 _DISPLAY: SLEEP 5
  189.                                 GOTO restart
  190.                             END IF
  191.  
  192.                             'If no blues left, red wins
  193.                             IF blues = 0 THEN
  194.                                 redwins:
  195.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  196.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  197.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "RED WINS!"
  198.                                 PLAY "mbl16o2bagfedc"
  199.                                 _DISPLAY: SLEEP 5
  200.                                 GOTO restart
  201.                             END IF
  202.  
  203.  
  204.                             'players move done - switch turn, players
  205.                             IF player = 1 THEN
  206.                                 'computers turn here....
  207.                                 'CHANGE TO AI MOVE HERE  '<<<<<<<<<<<<<<
  208.                                 player = 2
  209.                             ELSE
  210.                                 player = 1
  211.                             END IF
  212.  
  213.                             '==== CHECK IF PLAYER HAS VALID MOVE LEFT
  214.                             movesleft = 0
  215.                             FOR g = 1 TO rows * cols
  216.                                 IF box.v(g) = player THEN
  217.                                     IF ValidMoves$(g) <> "" THEN movesleft = 1
  218.                                 END IF
  219.                             NEXT
  220.  
  221.                             IF movesleft = 0 THEN
  222.                                 LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
  223.                                 LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
  224.                                 PPRINT 233, 285, 18, _RGB(255, 255, 255), 0, "NO MOVES!"
  225.                                 PLAY "mbl16o2bagfedc"
  226.                                 _DISPLAY: SLEEP 3
  227.                                 IF reds > blues THEN GOTO redwins
  228.                                 IF blues > reds THEN GOTO bluewins
  229.                                 GOTO restart
  230.                             END IF
  231.  
  232.  
  233.                             GOTO main
  234.  
  235.                         ELSE
  236.  
  237.                             'if user clicked on another one of its color instead...
  238.                             IF box.v(t) = player THEN
  239.                                 'clear previous highlighted selection
  240.                                 selected = 0
  241.                                 UpdateBoard
  242.                                 selected = 1
  243.                                 oldt = t
  244.                                 oldtv = box.v(t) 'save picked box number color
  245.                                 SOUND 3000, .1
  246.                                 GOTO second
  247.                             END IF
  248.  
  249.                             'clicked on enemy instead, redo
  250.                             selected = 0
  251.                             UpdateBoard
  252.                             SOUND 500, .1
  253.                             GOTO main
  254.  
  255.                         END IF
  256.  
  257.                     END IF
  258.  
  259.                 END IF
  260.             END IF
  261.  
  262.         NEXT
  263.  
  264.     END IF
  265.  
  266.     _DISPLAY
  267.  
  268.     IF INKEY$ <> "" THEN GOTO restart
  269.  
  270.  
  271. FUNCTION HowManyPlaces (old, new)
  272.     'computes how many places a user moved
  273.     '0 = out of bounds
  274.     '1 = one place
  275.     '2 = a jump
  276.  
  277.     p = 0 'default is out of bounds
  278.  
  279.     SELECT CASE old
  280.  
  281.         'row 1
  282.         CASE 1: IF new = old + 1 OR new = old + 9 OR new = old + 10 THEN p = 1
  283.             IF new = 3 OR new = 12 OR new = 19 OR new = 20 OR new = 21 THEN p = 2
  284.         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
  285.             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
  286.         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
  287.             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
  288.         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
  289.             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
  290.         CASE 9: IF new = old - 1 OR new = old + 8 OR new = old + 9 THEN p = 1
  291.             IF new = old - 2 OR new = old + 7 OR new = old + 16 OR new = old + 17 OR new = old + 18 THEN p = 2
  292.  
  293.             'row 2
  294.         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
  295.             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
  296.         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
  297.             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
  298.         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
  299.             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
  300.         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
  301.             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
  302.         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
  303.             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
  304.         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
  305.             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
  306.  
  307.             'row 3
  308.         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
  309.             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
  310.         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
  311.             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
  312.             'middle board, all ways,  (thru row 7)
  313.         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
  314.             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
  315.         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
  316.             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
  317.         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
  318.             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
  319.  
  320.             'row 8
  321.         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
  322.             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
  323.         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
  324.             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
  325.         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
  326.             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
  327.         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
  328.             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
  329.         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
  330.             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
  331.  
  332.             'bottom 9
  333.         CASE 73: IF new = old + 1 OR new = old - 8 OR new = old - 9 THEN p = 1
  334.             IF new = old + 2 OR new = old - 7 OR new = old - 16 OR new = old - 17 OR new = old - 18 THEN p = 2
  335.         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
  336.             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
  337.         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
  338.             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
  339.         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
  340.             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
  341.         CASE 81: IF new = old - 1 OR new = old - 9 OR new = old - 10 THEN p = 1
  342.             IF new = old - 2 OR new = old - 11 OR new = old - 18 OR new = old - 19 OR new = old - 20 THEN p = 2
  343.     END SELECT
  344.  
  345.     HowManyPlaces = p
  346.  
  347.  
  348. SUB UpdateBoard
  349.  
  350.     CLS , _RGB(32, 32, 32)
  351.     PPRINT 205, 10, 20, _RGB(255, 255, 255), 0, "-=GridWar=-"
  352.  
  353.     red = 0: blue = 0
  354.  
  355.     '=== draw board based on box values
  356.     bc = 1 'counter
  357.     FOR cl = 1 TO cols
  358.         FOR ro = 1 TO rows
  359.  
  360.             '=== count colors
  361.             IF box.v(bc) = 1 THEN red = red + 1
  362.             IF box.v(bc) = 2 THEN blue = blue + 1
  363.  
  364.             '=== if empty box
  365.             IF box.v(bc) = 0 THEN
  366.                 LINE (box.x(bc) + 2, box.y(bc) + 2)-(box.x(bc) + size - 2, box.y(bc) + size - 2), _RGB(64, 64, 64), BF
  367.             ELSE
  368.                 LINE (box.x(bc) + 2, box.y(bc) + 2)-(box.x(bc) + size - 2, box.y(bc) + size - 2), _RGB(64, 64, 64), BF
  369.                 '=== draw color ball
  370.                 x2 = box.x(bc) + (size / 2) 'find middle of box
  371.                 y2 = box.y(bc) + (size / 2)
  372.                 sz = size / 2
  373.                 SELECT CASE box.v(bc)
  374.                     CASE IS = 1: r = 255: g = 64: b = 64 'red
  375.                     CASE IS = 2: r = 64: g = 64: b = 255 'blue
  376.                 END SELECT
  377.                 CIRCLE (x2, y2), sz - 4, _RGB(r, g, b)
  378.                 PAINT (x2, y2), _RGB(r, g, b)
  379.             END IF
  380.             bc = bc + 1
  381.         NEXT
  382.     NEXT
  383.  
  384.     PPRINT 30, 15, 14, _RGB(255, 128, 128), 0, "Red =" + STR$(red)
  385.     PPRINT 465, 15, 14, _RGB(128, 128, 255), 0, "Blue =" + STR$(blue)
  386.  
  387.     IF player = 1 THEN
  388.         LINE (10, 10)-(150, 40), _RGBA(255, 100, 100, 50), BF
  389.     END IF
  390.  
  391.     IF player = 2 THEN
  392.         LINE (440, 10)-(590, 40), _RGBA(100, 100, 255, 50), BF
  393.     END IF
  394.  
  395.     _DISPLAY
  396.     _ICON _DISPLAY 'update app icon on taskbar
  397.  
  398. SUB convertneighbors (player, num)
  399.     'convert neighbors surrounding num to players value.
  400.     '(when a piece lands on num, it changes neighbors)
  401.     SELECT CASE num
  402.         'row 1
  403.         CASE 1: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  404.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  405.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  406.         CASE 2 TO 8: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  407.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  408.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player:: change num + 8
  409.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  410.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  411.         CASE 9: IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  412.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  413.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  414.             'down left side
  415.         CASE 10, 19, 28, 37, 46, 55, 64
  416.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  417.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  418.             IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  419.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  420.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  421.             'down right side
  422.         CASE 18, 27, 36, 45, 54, 63, 72
  423.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  424.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  425.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  426.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  427.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  428.             'middle of board
  429.         CASE 11 TO 17, 20 TO 26, 29 TO 35, 38 TO 44, 47 TO 53, 56 TO 62, 65 TO 71
  430.             IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  431.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  432.             IF box.v(num + 8) <> 0 AND box.v(num + 8) <> player THEN box.v(num + 8) = player: change num + 8
  433.             IF box.v(num + 9) <> 0 AND box.v(num + 9) <> player THEN box.v(num + 9) = player: change num + 9
  434.             IF box.v(num + 10) <> 0 AND box.v(num + 10) <> player THEN box.v(num + 10) = player: change num + 10
  435.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  436.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  437.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  438.             'bottom row
  439.         CASE 73: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  440.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  441.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  442.         CASE 74 TO 80: IF box.v(num + 1) <> 0 AND box.v(num + 1) <> player THEN box.v(num + 1) = player: change num + 1
  443.             IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  444.             IF box.v(num - 8) <> 0 AND box.v(num - 8) <> player THEN box.v(num - 8) = player: change num - 8
  445.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  446.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  447.         CASE 81: IF box.v(num - 1) <> 0 AND box.v(num - 1) <> player THEN box.v(num - 1) = player: change num - 1
  448.             IF box.v(num - 9) <> 0 AND box.v(num - 9) <> player THEN box.v(num - 9) = player: change num - 9
  449.             IF box.v(num - 10) <> 0 AND box.v(num - 10) <> player THEN box.v(num - 10) = player: change num - 10
  450.     END SELECT
  451.  
  452. SUB change (num)
  453.  
  454.     '=== find center x/y of place
  455.     x2 = box.x(num) + (size / 2): y2 = box.y(num) + (size / 2)
  456.  
  457.     'do shrinking circle first
  458.     IF player = 1 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  459.     FOR s = 30 TO 1 STEP -2
  460.         SOUND 100 + t, .05
  461.         'wipe clean
  462.         LINE (box.x(num) + 2, box.y(num) + 2)-(box.x(num) + size - 2, box.y(num) + size - 2), _RGB(64, 64, 64), BF
  463.         CIRCLE (x2, y2), s, clr&
  464.         PAINT (x2, y2), clr&
  465.         _DISPLAY
  466.         _LIMIT 140
  467.         t = t + 100
  468.     NEXT
  469.  
  470.     'Expand in the new circle
  471.     'do shrinking circle first
  472.     IF player = 2 THEN clr& = _RGB(64, 64, 255) ELSE clr& = _RGB(255, 64, 64)
  473.     FOR s = 1 TO 30 STEP 2
  474.         'wipe clean
  475.         LINE (box.x(num) + 2, box.y(num) + 2)-(box.x(num) + size - 2, box.y(num) + size - 2), _RGB(64, 64, 64), BF
  476.         CIRCLE (x2, y2), s, clr&
  477.         PAINT (x2, y2), clr&
  478.         _DISPLAY
  479.         _LIMIT 140
  480.     NEXT
  481.  
  482.  
  483. SUB PPRINT (x, y, size, clr&, trans&, text$)
  484.     orig& = _DEST
  485.     bit = 32: IF _PIXELSIZE(0) = 1 THEN bit = 256
  486.     FOR t = 0 TO LEN(text$) - 1
  487.         pprintimg& = _NEWIMAGE(16, 16, bit)
  488.         _DEST pprintimg&
  489.         CLS , trans&: COLOR clr&
  490.         PRINT MID$(text$, t + 1, 1);
  491.         _CLEARCOLOR _RGB(0, 0, 0), pprintimg&
  492.         _DEST orig&
  493.         x1 = x + (t * size): x2 = x1 + size
  494.         y1 = y: y2 = y + size
  495.         _PUTIMAGE (x1 - (size / 2), y1)-(x2, y2 + (size / 3)), pprintimg&
  496.         _FREEIMAGE pprintimg&
  497.     NEXT
  498.  
  499. FUNCTION ValidMoves$ (num)
  500.     'returns a string list of all valid moves for player that is sitting on the num
  501.     'The list contains 2 charater byte strings per num place.
  502.     'Each one is a num on the board that player could goto.
  503.  
  504.     list$ = ""
  505.     SELECT CASE num
  506.         CASE 1 'one steps
  507.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  508.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  509.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  510.             '2 steps
  511.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  512.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  513.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  514.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  515.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  516.         CASE 2
  517.             'one steps
  518.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  519.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  520.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  521.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  522.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  523.             'two steps
  524.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  525.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  526.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  527.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  528.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  529.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  530.  
  531.         CASE 3 TO 7
  532.             'one steps
  533.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  534.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  535.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  536.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  537.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  538.             'two steps
  539.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  540.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  541.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  542.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  543.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  544.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  545.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  546.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  547.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  548.         CASE 8
  549.             'one step
  550.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  551.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  552.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  553.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  554.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  555.             'two steps
  556.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  557.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  558.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  559.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  560.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  561.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  562.         CASE 9
  563.             'one step
  564.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  565.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  566.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  567.             'two steps
  568.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  569.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  570.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  571.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  572.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  573.  
  574.             '2nd row
  575.         CASE 10
  576.             'one step
  577.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  578.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  579.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  580.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  581.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  582.             'two steps
  583.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  584.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  585.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  586.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  587.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  588.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  589.         CASE 11
  590.             'one step
  591.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  592.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  593.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  594.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  595.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  596.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  597.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  598.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  599.             'two steps
  600.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  601.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  602.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  603.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  604.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  605.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  606.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  607.         CASE 12 TO 16
  608.             'one step
  609.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  610.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  611.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  612.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  613.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  614.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  615.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  616.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  617.             'two steps
  618.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  619.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  620.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  621.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  622.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  623.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  624.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  625.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  626.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  627.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  628.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  629.         CASE 17
  630.             'one step
  631.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  632.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  633.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  634.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  635.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  636.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  637.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  638.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  639.             'two steps
  640.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  641.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  642.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  643.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  644.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  645.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  646.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  647.         CASE 18
  648.             'one step
  649.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  650.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  651.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  652.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  653.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  654.             'two steps
  655.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  656.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  657.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  658.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  659.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  660.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  661.             'down left side, outer
  662.         CASE 19, 28, 37, 46, 55
  663.             'one step
  664.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  665.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  666.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  667.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  668.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  669.             'two steps
  670.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  671.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  672.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  673.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  674.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  675.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  676.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  677.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  678.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  679.             'down left side, inner
  680.         CASE 20, 29, 38, 47, 56
  681.             'one step
  682.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  683.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  684.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  685.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  686.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  687.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  688.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  689.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  690.             'two steps
  691.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  692.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  693.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  694.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  695.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  696.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  697.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  698.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  699.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  700.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  701.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  702.  
  703.             'middle of board (all directions)
  704.         CASE 21 TO 25, 30 TO 34, 39 TO 43, 48 TO 52, 57 TO 61
  705.             'one step
  706.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  707.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  708.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  709.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  710.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  711.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  712.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  713.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  714.             'two steps
  715.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  716.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  717.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  718.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  719.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  720.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  721.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  722.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  723.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  724.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  725.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  726.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  727.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  728.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  729.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  730.             IF box.v(num + 20) = 0 THEN list$ = list$ + nums$(num + 20)
  731.  
  732.             'right side, outer
  733.         CASE 27, 36, 45, 54, 63
  734.             'one step
  735.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  736.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  737.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  738.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  739.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  740.             'two steps
  741.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  742.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  743.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  744.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  745.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  746.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  747.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  748.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  749.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  750.  
  751.             'rigth side, inner
  752.         CASE 26, 35, 44, 53, 62
  753.             'one step
  754.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  755.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  756.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  757.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  758.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  759.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  760.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  761.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  762.             'two steps
  763.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  764.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  765.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  766.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  767.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  768.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  769.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  770.             IF box.v(num + 16) = 0 THEN list$ = list$ + nums$(num + 16)
  771.             IF box.v(num + 17) = 0 THEN list$ = list$ + nums$(num + 17)
  772.             IF box.v(num + 18) = 0 THEN list$ = list$ + nums$(num + 18)
  773.             IF box.v(num + 19) = 0 THEN list$ = list$ + nums$(num + 19)
  774.         CASE 64
  775.             'one step
  776.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  777.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  778.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  779.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  780.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  781.             'two steps
  782.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  783.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  784.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  785.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  786.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  787.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  788.         CASE 65
  789.             'one step
  790.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  791.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  792.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  793.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  794.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  795.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  796.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  797.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  798.             'two steps
  799.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  800.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  801.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  802.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  803.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  804.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  805.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  806.         CASE 66 TO 70
  807.             'one step
  808.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  809.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  810.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  811.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  812.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  813.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  814.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  815.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  816.             'two steps
  817.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  818.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  819.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  820.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  821.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  822.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  823.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  824.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  825.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  826.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  827.             IF box.v(num + 11) = 0 THEN list$ = list$ + nums$(num + 11)
  828.         CASE 71
  829.             'one step
  830.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  831.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  832.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  833.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  834.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  835.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  836.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  837.             IF box.v(num + 10) = 0 THEN list$ = list$ + nums$(num + 10)
  838.             'two steps
  839.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  840.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  841.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  842.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  843.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  844.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  845.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  846.         CASE 72
  847.             'one step
  848.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  849.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  850.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  851.             IF box.v(num + 8) = 0 THEN list$ = list$ + nums$(num + 8)
  852.             IF box.v(num + 9) = 0 THEN list$ = list$ + nums$(num + 9)
  853.             'two steps
  854.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  855.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  856.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  857.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  858.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  859.             IF box.v(num + 7) = 0 THEN list$ = list$ + nums$(num + 7)
  860.             'bottom row
  861.         CASE 73
  862.             'one step
  863.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  864.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  865.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  866.             'two steps
  867.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  868.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  869.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  870.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  871.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  872.         CASE 74
  873.             'one step
  874.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  875.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  876.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  877.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  878.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  879.             'two steps
  880.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  881.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  882.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  883.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  884.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  885.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  886.         CASE 75 TO 79
  887.             'one step
  888.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  889.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  890.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  891.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  892.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  893.             'two steps
  894.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  895.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  896.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  897.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  898.             IF box.v(num - 16) = 0 THEN list$ = list$ + nums$(num - 16)
  899.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  900.             IF box.v(num - 7) = 0 THEN list$ = list$ + nums$(num - 7)
  901.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  902.             IF box.v(num + 2) = 0 THEN list$ = list$ + nums$(num + 2)
  903.         CASE 80
  904.             'one step
  905.             IF box.v(num - 8) = 0 THEN list$ = list$ + nums$(num - 8)
  906.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  907.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  908.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  909.             IF box.v(num + 1) = 0 THEN list$ = list$ + nums$(num + 1)
  910.             'two steps
  911.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  912.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  913.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  914.             IF box.v(num - 17) = 0 THEN list$ = list$ + nums$(num - 17)
  915.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  916.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  917.         CASE 81
  918.             'one step
  919.             IF box.v(num - 9) = 0 THEN list$ = list$ + nums$(num - 9)
  920.             IF box.v(num - 10) = 0 THEN list$ = list$ + nums$(num - 10)
  921.             IF box.v(num - 1) = 0 THEN list$ = list$ + nums$(num - 1)
  922.             'two steps
  923.             IF box.v(num - 20) = 0 THEN list$ = list$ + nums$(num - 20)
  924.             IF box.v(num - 19) = 0 THEN list$ = list$ + nums$(num - 19)
  925.             IF box.v(num - 18) = 0 THEN list$ = list$ + nums$(num - 18)
  926.             IF box.v(num - 11) = 0 THEN list$ = list$ + nums$(num - 11)
  927.             IF box.v(num - 2) = 0 THEN list$ = list$ + nums$(num - 2)
  928.  
  929.     END SELECT
  930.  
  931.     ValidMoves$ = list$
  932.  
  933.  
  934. FUNCTION nums$ (num)
  935.     'helper function returns num as a two byte string
  936.     n$ = LTRIM$(RTRIM$(STR$(num)))
  937.     IF LEN(n$) = 1 THEN n$ = "0" + n$
  938.     nums$ = n$
  939.  

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #7 on: October 28, 2021, 07:35:30 pm »
Got AI play working!  Now you can play against the computer.  It's not the strongest playing, but it's a beginning which can be expanded on, like choosing pieces closest to enemy, etc.. Now I can start cleaning up the code and reorganize it to make it look like a sane person wrote it.  Attached a screenshot of a game, which I'm losing.

Hope you enjoy playing it as much as I enjoying making it.

- Dav

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

 
gridwars.jpg

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #8 on: October 28, 2021, 11:21:52 pm »
Great @Dav you've created a monster!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #9 on: October 29, 2021, 12:40:05 pm »
@Pete, @Statsman1, @bplus, thanks for the comments. I may put in some barriers in the middle like ataxx game had.  Started cleaning the monster code up this morning.

Tweaked the AI to make computer moves more random so it doesn’t make the same moves at the beginning of every game. The computermove scanning now starts either at the bottom or top of board randomly, so different pieces are being used.  Doesn’t hurt the play, makes it seem more human.  Have some other ideas.  May update graphics.  Also, I’m working on a music player sub to add background looping music. Since PLAY won’t loop songs, I’m using _SNDRAW songs. Seems to work. I could use external files, but like the idea of have everything in code.

- Dav

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 #10 on: October 29, 2021, 12:51:46 pm »
I love the way it’s going, @Dav.  Great job!   I am looking forward to how you tune up the AI.

Do you plan to keep score / records / stats at all?  A way to show if a player is improving?
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 #11 on: October 29, 2021, 06:27:13 pm »
Do you plan to keep score / records / stats at all?  A way to show if a player is improving?

Hadn’t thought of it, but I can add that.  Thought to have different kinds of grids at one point.   I didn’t realize how much a following ataxx game has, there’s even a website dedicated to discussing the AI methods it uses. 

- Dav

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #12 on: October 29, 2021, 07:28:58 pm »
That's really cool, and the AI spanked me by two to one.

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: GridWars game - going to add AI to it.
« Reply #13 on: October 29, 2021, 09:30:19 pm »
That's really cool, and the AI spanked me by two to one.

Yeah, the board can change on me quick when making 1 wrong move.  I've been reading on ways to make AI play harder, but think I'll just code what I would look for on the board for a move instead, like locking in the edges with my color, not leaving a vulnerable hole exposing a bunch of my pieces when I jump somewhere. (Coding this little puzzle has been really a fun challenge)

- Dav

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 #14 on: October 29, 2021, 09:49:32 pm »
Hadn’t thought of it, but I can add that.  Thought to have different kinds of grids at one point.   I didn’t realize how much a following ataxx game has, there’s even a website dedicated to discussing the AI methods it uses. 

- Dav

Ataxx was a brain game that I loved, along with Klax, Tetris….those kinds of games were my jam!  But very popular, world-wide, as you have seen.

I hope to get some time to give your game a whirl this weekend.  Looks amazing, dude!
Good decisions come from experience.
Experience comes from bad decisions.