QB64.org Forum

Active Forums => Programs => Topic started by: Dav on October 27, 2021, 10:46:56 pm

Title: GridWars game - going to add AI to it.
Post by: Dav 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.  
Title: Re: GridWars game - going to add AI to it.
Post by: Pete 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
Title: Re: GridWars game - going to add AI to it.
Post by: bplus 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!
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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

 

Title: Re: GridWars game - going to add AI to it.
Post by: Statsman1 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!
Title: Re: GridWars game - going to add AI to it.
Post by: bplus 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.
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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.  
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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.  

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: GridWars game - going to add AI to it.
Post by: bplus on October 28, 2021, 11:21:52 pm
Great @Dav you've created a monster!
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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
Title: Re: GridWars game - going to add AI to it.
Post by: Statsman1 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?
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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
Title: Re: GridWars game - going to add AI to it.
Post by: OldMoses on October 29, 2021, 07:28:58 pm
That's really cool, and the AI spanked me by two to one.
Title: Re: GridWars game - going to add AI to it.
Post by: Dav 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
Title: Re: GridWars game - going to add AI to it.
Post by: Statsman1 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!
Title: Re: GridWars game - going to add AI to it.
Post by: Dav on November 03, 2021, 09:17:56 pm
I haven't been able to work on this as much as I would like, but I have done something new with it and would like some testing on this version please. 

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

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

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

- Dav

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

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

PLUS for extra bonus, when showing legal moves show by color difference which are jumps that should leave hole and which are "clones" (good name, and maybe something I am not use to playing with/against).
Title: Re: GridWars game - going to add AI to it.
Post by: bplus on November 04, 2021, 02:48:59 pm
Quote
How does it display on yours?

Pretty much the same as before which was already fine.
Title: Re: GridWars game - going to add AI to it.
Post by: Statsman1 on November 04, 2021, 03:20:19 pm
@Dav ...

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

A couple of things I noticed...

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

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

But your game is coming along nicely!  Like the sound effects!
Title: Re: GridWars game - going to add AI to it.
Post by: Dav on November 05, 2021, 03:46:44 pm
@bplus:  Hmm, I haven't caught it cheating yet, but perhaps I made a mistake in the change sub, an it's flipping squares wrong somewhere.  I will double check that.  Maybe I can add a tracer to see what happened at last move.  Was thinking of adding a UNDO last move thing.  I may add difficulty levels, easy, medium, hard.  Where it is now would be the hard one.  Thanks for telling me how it displays on your system!

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

- Dav