Author Topic: MicroSoft's version of Reversi  (Read 6454 times)

0 Members and 1 Guest are viewing this topic.

Offline qbguy

  • Newbie
  • Posts: 11
    • View Profile
MicroSoft's version of Reversi
« on: October 29, 2018, 08:50:58 am »
Code: QB64: [Select]
  1. REM This is a sample QBASIC program from MS-DOS 5 (June 1990)
  2. DEFINT A-Z
  3.  
  4. DECLARE FUNCTION CheckPath% (i, IBound, IStep, j, JBound, JStep, Opponent)
  5. DECLARE FUNCTION ValidMove% (Opponent)
  6. DECLARE SUB ComputerMove ()
  7. DECLARE SUB DisplayHelp ()
  8. DECLARE SUB DisplayMsg (a$)
  9. DECLARE SUB DrawCursor (row, col)
  10. DECLARE SUB DrawGamePiece (row, col, PieceColor)
  11. DECLARE SUB GameOver ()
  12. DECLARE SUB InitGame ()
  13. DECLARE SUB TakeBlocks (row, col, player)
  14. DECLARE SUB UpdateScore ()
  15. DECLARE SUB UserMove ()
  16. DECLARE SUB DrawGameBoard ()
  17.  
  18. CONST TRUE = -1
  19. CONST FALSE = 0
  20. CONST QUIT = 113
  21. CONST UP = 72
  22. CONST DOWN = 80
  23. CONST LEFT = 75
  24. CONST RIGHT = 77
  25. CONST BBLOCK = 1
  26. CONST EBLOCK = 8
  27. CONST ENTER = 13
  28. CONST ULEFT = 71
  29. CONST URIGHT = 73
  30. CONST DLEFT = 79
  31. CONST DRIGHT = 81
  32. CONST PASS = 112
  33. CONST DIFF = 100
  34. CONST START = 115
  35. CONST HELP = 104
  36. CONST FMOVE = 99
  37. CONST SPACE = 32
  38.  
  39. TYPE GameGrid
  40.     player AS INTEGER
  41.     nTake  AS INTEGER
  42.     cx     AS INTEGER
  43.     cy     AS INTEGER
  44.  
  45. TYPE GameStatus
  46.     curRow   AS INTEGER
  47.     curCol   AS INTEGER
  48.     stat     AS INTEGER
  49.     rScore   AS INTEGER
  50.     bScore   AS INTEGER
  51.     mDisplay AS INTEGER
  52.     dLevel   AS STRING * 6
  53.     GColor   AS INTEGER
  54.  
  55. DIM SHARED GS AS GameStatus, smode AS INTEGER
  56. DIM SHARED GG(8, 8) AS GameGrid, GBoard AS INTEGER
  57. DIM SHARED GP(8, 8, 8) AS INTEGER, GW(8, 8) AS INTEGER
  58.  
  59. ON ERROR GOTO BadMode
  60.  
  61.   READ smode
  62.   vmode = TRUE
  63.   SCREEN smode
  64. LOOP UNTIL vmode = TRUE
  65.  
  66. IF smode = 0 THEN
  67.   CLS
  68.   LOCATE 10, 15: PRINT "No graphics screen mode available; cannot run REVERSI.BAS"
  69.   GS.stat = START
  70.   GS.dLevel = "Novice"
  71.   WHILE GS.stat <> QUIT
  72.     IF GS.stat = START THEN
  73.       InitGame
  74.       DrawGameBoard
  75.     END IF
  76.     IF GS.stat <> COMP THEN
  77.       IF ValidMove(COMP) THEN
  78.         UserMove
  79.       ELSEIF ValidMove(HUMAN) THEN
  80.         DO
  81.           DisplayMsg "You have no valid moves.  Select pass."
  82.           DO
  83.             a$ = INKEY$
  84.           LOOP UNTIL a$ <> ""
  85.         LOOP UNTIL ASC(RIGHT$(a$, 1)) = PASS
  86.         LINE (0, 420)-(640, 447), 3, BF
  87.         GS.mDisplay = FALSE
  88.         GS.stat = COMP
  89.         ComputerMove
  90.       ELSE
  91.         GameOver
  92.       END IF
  93.     ELSE
  94.       IF ValidMove(HUMAN) THEN
  95.         ComputerMove
  96.       ELSEIF ValidMove(COMP) THEN
  97.         DisplayMsg "Computer has no valid moves.  Your Turn."
  98.         GS.stat = HUMAN
  99.         UserMove
  100.       ELSE
  101.         GameOver
  102.       END IF
  103.     END IF
  104.   WEND
  105.   DisplayMsg "Game Over"
  106.  
  107. DATA 9, 10, 2, 3, 0
  108.  
  109. BadMode:
  110.   vmode = FALSE
  111.  
  112.  
  113. FUNCTION CheckPath (i, IBound, IStep, j, JBound, JStep, Opponent)
  114.  
  115.   done = FALSE
  116.   WHILE (i <> IBound OR j <> JBound) AND NOT done
  117.     IF GG(i, j).player = GBoard THEN
  118.       count = 0
  119.       done = TRUE
  120.     ELSEIF GG(i, j).player = Opponent THEN
  121.       count = count + 1
  122.       i = i + IStep
  123.       j = j + JStep
  124.       IF (i < 1 OR i > 8) OR (j < 1 OR j > 8) THEN
  125.         count = 0
  126.         done = TRUE
  127.       END IF
  128.     ELSE
  129.       done = TRUE
  130.     END IF
  131.   WEND
  132.   CheckPath = count
  133.    
  134.  
  135. SUB ComputerMove
  136.   BestMove = -99
  137.   FOR row = 1 TO 8
  138.     FOR col = 1 TO 8
  139.       IF GG(row, col).nTake > 0 THEN
  140.         IF GS.dLevel = "Novice" THEN
  141.           value = GG(row, col).nTake + GW(row, col)
  142.         ELSE
  143.           value = GG(row, col).nTake + GW(row, col)
  144.           SELECT CASE row
  145.             CASE 1
  146.               IF col < 5 THEN value = value + ABS(10 * GG(1, 1).player = COMP)
  147.               IF col > 4 THEN value = value + ABS(10 * GG(1, 8).player = COMP)
  148.             CASE 2
  149.               IF GG(1, col).player <> COMP THEN value = value + 5 * (GG(1, col).player = HUMAN)
  150.               IF col > 1 AND GG(1, col - 1).player <> COMP THEN value = value + 5 * (GG(1, col - 1).player = HUMAN)
  151.               IF col < 8 AND GG(1, col + 1).player <> COMP THEN value = value + 5 * (GG(1, col + 1).player = HUMAN)
  152.             CASE 7
  153.               IF GG(8, col).player <> COMP THEN value = value + 5 * (GG(8, col).player = HUMAN)
  154.               IF col > 1 AND GG(8, col - 1).player <> COMP THEN value = value + 5 * (GG(8, col - 1).player = HUMAN)
  155.               IF col < 8 AND GG(8, col + 1).player <> COMP THEN value = value + 5 * (GG(8, col + 1).player = HUMAN)
  156.             CASE 8
  157.               IF col < 5 THEN value = value + ABS(10 * GG(8, 1).player = COMP)
  158.               IF col > 4 THEN value = value + ABS(10 * GG(8, 8).player = COMP)
  159.           END SELECT
  160.           SELECT CASE col
  161.             CASE 1
  162.               IF row < 5 THEN value = value + ABS(10 * GG(1, 1).player = COMP)
  163.               IF row > 4 THEN value = value + ABS(10 * GG(8, 1).player = COMP)
  164.             CASE 2
  165.               IF GG(row, 1).player <> COMP THEN value = value + 5 * (GG(row, 1).player = HUMAN)
  166.               IF row > 1 AND GG(row - 1, 1).player <> COMP THEN value = value + 5 * (GG(row - 1, 1).player = HUMAN)
  167.               IF row < 8 AND GG(row + 1, 1).player <> COMP THEN value = value + 5 * (GG(row + 1, 1).player = HUMAN)
  168.             CASE 7
  169.               IF GG(row, 8).player <> COMP THEN value = value + 5 * (GG(row, 8).player = HUMAN)
  170.               IF row > 1 AND GG(row - 1, 8).player <> COMP THEN value = value + 5 * (GG(row - 1, 8).player = HUMAN)
  171.               IF row < 8 AND GG(row + 1, 8).player <> COMP THEN value = value + 5 * (GG(row + 1, 8).player = HUMAN)
  172.             CASE 8
  173.               IF row < 5 THEN value = value + ABS(10 * GG(1, 8).player = COMP)
  174.               IF row > 4 THEN value = value + ABS(10 * GG(8, 8).player = COMP)
  175.           END SELECT
  176.         END IF
  177.         IF value > BestMove THEN
  178.           BestMove = value
  179.           bestrow = row
  180.           bestcol = col
  181.         END IF
  182.       END IF
  183.     NEXT col
  184.   NEXT row
  185.  
  186.   TakeBlocks bestrow, bestcol, COMP
  187.   GS.stat = HUMAN
  188.  
  189.  
  190. SUB DisplayHelp
  191.  
  192.   DIM a$(1 TO 18)
  193.  
  194.   a$(1) = "The object of Reversi is to finish the game with more of your red"
  195.   a$(2) = "circles on the board than the computer has of blue (Monochrome"
  196.   a$(3) = "monitors will show red as white and blue as black)."
  197.   a$(4) = ""
  198.   a$(5) = "1) You and the computer play by the same rules."
  199.   a$(6) = "2) To make a legal move, at least one of the computer's circles"
  200.   a$(7) = "   must lie in a horizontal, vertical, or diagonal line between"
  201.   a$(8) = "   one of your existing circles and the square where you want to"
  202.   a$(9) = "   move.  Use the arrow keys to position the cursor on the square"
  203.   a$(10) = "   and hit Enter or the Space Bar."
  204.   a$(11) = "3) You can choose Pass from the game controls menu on your first"
  205.   a$(12) = "   move to force the computer to play first."
  206.   a$(13) = "4) After your first move, you cannot pass if you can make a legal"
  207.   a$(14) = "   move."
  208.   a$(15) = "5) If you cannot make a legal move, you must choose Pass"
  209.   a$(16) = "6) When neither you nor the computer can make a legal move, the"
  210.   a$(17) = "   game is over."
  211.   a$(18) = "7) The one with the most circles wins."
  212.  
  213.   LINE (0, 0)-(640, 480), BG, BF
  214.   LINE (39, 15)-(590, 450), 0, B
  215.   IF GBoard = 85 THEN
  216.     PAINT (200, 200), CHR$(85), 0
  217.   ELSE
  218.     PAINT (200, 200), GBoard, 0
  219.   END IF
  220.   LINE (590, 25)-(600, 460), 0, BF
  221.   LINE (50, 450)-(600, 460), 0, BF
  222.  
  223.   LOCATE 2, 35: PRINT "REVERSI HELP"
  224.   FOR i = 1 TO 18
  225.     LOCATE 3 + i, 7
  226.     PRINT a$(i)
  227.   NEXT i
  228.   LOCATE 23, 25: PRINT "- Press any key to continue -"
  229.   SLEEP: a$ = INKEY$
  230.   DrawGameBoard
  231.   DrawCursor GS.curRow, GS.curCol
  232.  
  233.  
  234. SUB DisplayMsg (a$)
  235.  
  236.   slen = LEN(a$)
  237.   LX = (640 - 8 * (slen + 8)) / 2
  238.   LINE (LX - 1, 420)-(640 - LX, 447), 0, B
  239.   IF GBoard = 85 THEN
  240.     PAINT (LX + 10, 430), CHR$(85), 0
  241.   ELSE
  242.     PAINT (LX + 10, 430), GBoard, 0
  243.   END IF
  244.   LOCATE 23, (80 - slen) / 2
  245.   PRINT a$;
  246.   GS.mDisplay = TRUE
  247.  
  248.  
  249. SUB DrawCursor (row, col)
  250.   IF GG(row, col).nTake > 0 THEN
  251.     CIRCLE (GG(row, col).cx, GG(row, col).cy), 15, HUMAN
  252.     CIRCLE (GG(row, col).cx, GG(row, col).cy), 14, HUMAN
  253.   ELSE
  254.     lc = 0
  255.     IF GG(row, col).player = 0 THEN lc = 7
  256.     LINE (GG(row, col).cx, GG(row, col).cy - 15)-(GG(row, col).cx, GG(row, col).cy + 15), lc
  257.     LINE (GG(row, col).cx - 1, GG(row, col).cy - 15)-(GG(row, col).cx - 1, GG(row, col).cy + 15), lc
  258.     LINE (GG(row, col).cx + 15, GG(row, col).cy)-(GG(row, col).cx - 15, GG(row, col).cy), lc
  259.   END IF
  260.  
  261. SUB DrawGameBoard
  262.  
  263.   LINE (0, 0)-(640, 480), BG, BF
  264.   LINE (239, 15)-(400, 40), 0, B
  265.   LINE (39, 260)-(231, 390), 0, B
  266.   LINE (39, 70)-(231, 220), 0, B
  267.   LINE (269, 70)-(591, 390), 0, B
  268.  
  269.   IF GBoard = 85 THEN                  'If b&w
  270.     PAINT (300, 25), CHR$(85), 0
  271.     PAINT (150, 350), CHR$(85), 0
  272.     PAINT (150, 124), CHR$(85), 0
  273.     PAINT (450, 225), CHR$(85), 0
  274.   ELSE
  275.     PAINT (300, 25), GBoard, 0
  276.     PAINT (150, 350), GBoard, 0
  277.     PAINT (150, 124), GBoard, 0
  278.     PAINT (450, 225), GBoard, 0
  279.   END IF
  280.   LINE (400, 25)-(410, 50), 0, BF
  281.   LINE (250, 40)-(410, 50), 0, BF
  282.   LINE (231, 80)-(240, 230), 0, BF
  283.   LINE (50, 220)-(240, 230), 0, BF
  284.   LINE (590, 80)-(600, 400), 0, BF
  285.   LINE (280, 390)-(600, 400), 0, BF
  286.   LINE (231, 270)-(240, 400), 0, BF
  287.   LINE (50, 390)-(240, 400), 0, BF
  288.  
  289.   FOR i = 0 TO 8
  290.     LINE (270, 70 + i * 40)-(590, 70 + i * 40), 0
  291.     LINE (270 + i * 40, 70)-(270 + i * 40, 390), 0
  292.     LINE (269 + i * 40, 70)-(269 + i * 40, 390), 0
  293.   NEXT i
  294.  
  295.   LOCATE 2, 35: PRINT "R E V E R S I"
  296.  
  297.   LOCATE 5, 11: PRINT "Game Controls"
  298.   LOCATE 7, 7: PRINT "S = Start New Game"
  299.   LOCATE 8, 7: PRINT "P = Pass Turn"
  300.   LOCATE 9, 7: PRINT "D = Set Difficulty"
  301.   LOCATE 10, 7: PRINT "H = Display Help"
  302.   LOCATE 11, 7: PRINT "Q = Quit"
  303.   LOCATE 15, 12: PRINT "Game Status"
  304.   LOCATE 17, 7: PRINT "Your Score:      "; GS.rScore; ""
  305.   LOCATE 18, 7: PRINT "Computer Score:  "; GS.bScore
  306.   LOCATE 20, 7: PRINT "Difficulty:   "; GS.dLevel
  307.  
  308.   FOR row = 1 TO 8
  309.     FOR col = 1 TO 8
  310.       IF GG(row, col).player <> GBoard THEN
  311.         DrawGamePiece row, col, GG(row, col).player
  312.       END IF
  313.     NEXT col
  314.   NEXT row
  315.  
  316.  
  317. SUB DrawGamePiece (row, col, GpColor)
  318.  
  319.   IF GBoard = 85 THEN
  320.     LINE (232 + col * 40, 33 + row * 40)-(267 + col * 40, 67 + row * 40), 7, BF
  321.     IF GpColor <> GBoard THEN
  322.       CIRCLE (GG(row, col).cx, GG(row, col).cy), 15, 0
  323.       PAINT (GG(row, col).cx, GG(row, col).cy), GpColor, 0
  324.     END IF
  325.     PAINT (235 + col * 40, 35 + row * 40), CHR$(85), 0
  326.   ELSE
  327.     CIRCLE (GG(row, col).cx, GG(row, col).cy), 15, GpColor
  328.     CIRCLE (GG(row, col).cx, GG(row, col).cy), 14, GpColor
  329.     PAINT (GG(row, col).cx, GG(row, col).cy), GpColor, GpColor
  330.   END IF
  331.  
  332.  
  333. SUB GameOver
  334.   Scorediff = GS.rScore - GS.bScore
  335.   IF Scorediff = 0 THEN
  336.     DisplayMsg "Tie Game"
  337.   ELSEIF Scorediff < 0 THEN
  338.     DisplayMsg "You lost by"
  339.     PRINT ABS(Scorediff)
  340.   ELSE
  341.     DisplayMsg "You won by"
  342.     PRINT Scorediff
  343.   END IF
  344.   DO
  345.     GS.stat = ASC(RIGHT$(INKEY$, 1))
  346.   LOOP UNTIL GS.stat = QUIT OR GS.stat = START
  347.   LINE (0, 420)-(640, 447), BG, BF
  348.  
  349. SUB InitGame
  350.   SELECT CASE smode
  351.     CASE 9:
  352.       HUMAN = 4
  353.       COMP = 1
  354.       BG = 3
  355.       GBoard = 8
  356.     CASE ELSE:
  357.       HUMAN = 7
  358.       COMP = 0
  359.       BG = 7
  360.       IF smode = 10 THEN
  361.         GBoard = 1
  362.       ELSE
  363.         GBoard = 85
  364.       END IF
  365.  
  366.   WINDOW SCREEN (640, 480)-(0, 0)
  367.   GS.curCol = 5
  368.   GS.curRow = 3
  369.   GS.stat = FMOVE
  370.   GS.bScore = 2
  371.   GS.rScore = 2
  372.   GS.mDisplay = FALSE
  373.  
  374.   FOR row = 1 TO 8
  375.     FOR col = 1 TO 8
  376.       GG(row, col).player = GBoard
  377.       GG(row, col).nTake = 0
  378.       GG(row, col).cx = 270 + (col - .5) * 40
  379.       GG(row, col).cy = 70 + (row - .5) * 40
  380.       GW(row, col) = 2
  381.     NEXT col
  382.   NEXT row
  383.   GW(1, 1) = 99
  384.   GW(1, 8) = 99
  385.   GW(8, 1) = 99
  386.   GW(8, 8) = 99
  387.   FOR i = 3 TO 6
  388.     FOR j = 1 TO 8 STEP 7
  389.       GW(i, j) = 5
  390.       GW(j, i) = 5
  391.     NEXT j
  392.   NEXT i
  393.   GG(4, 4).player = HUMAN
  394.   GG(5, 4).player = COMP
  395.   GG(4, 5).player = COMP
  396.   GG(5, 5).player = HUMAN
  397.  
  398. SUB TakeBlocks (row, col, player)
  399.  
  400.   GG(row, col).player = player
  401.   DrawGamePiece row, col, player
  402.  
  403.   FOR i = 1 TO GP(row, col, 1)
  404.     GG(row, col - i).player = player
  405.     DrawGamePiece row, col - i, player
  406.   NEXT i
  407.   FOR i = 1 TO GP(row, col, 2)
  408.     GG(row, col + i).player = player
  409.     DrawGamePiece row, col + i, player
  410.   NEXT i
  411.   FOR i = 1 TO GP(row, col, 3)
  412.     GG(row - i, col).player = player
  413.     DrawGamePiece row - i, col, player
  414.   NEXT i
  415.   FOR i = 1 TO GP(row, col, 4)
  416.     GG(row + i, col).player = player
  417.     DrawGamePiece row + i, col, player
  418.   NEXT i
  419.   FOR i = 1 TO GP(row, col, 5)
  420.     GG(row - i, col - i).player = player
  421.     DrawGamePiece row - i, col - i, player
  422.   NEXT i
  423.   FOR i = 1 TO GP(row, col, 6)
  424.     GG(row + i, col + i).player = player
  425.     DrawGamePiece row + i, col + i, player
  426.   NEXT i
  427.   FOR i = 1 TO GP(row, col, 7)
  428.     GG(row - i, col + i).player = player
  429.     DrawGamePiece row - i, col + i, player
  430.   NEXT i
  431.   FOR i = 1 TO GP(row, col, 8)
  432.     GG(row + i, col - i).player = player
  433.     DrawGamePiece row + i, col - i, player
  434.   NEXT i
  435.  
  436.   IF player = HUMAN THEN
  437.     GS.rScore = GS.rScore + GG(row, col).nTake + 1
  438.     GS.bScore = GS.bScore - GG(row, col).nTake
  439.   ELSE
  440.     GS.bScore = GS.bScore + GG(row, col).nTake + 1
  441.     GS.rScore = GS.rScore - GG(row, col).nTake
  442.   END IF
  443.  
  444.   LOCATE 17, 7: PRINT "Your Score:      "; GS.rScore
  445.   LOCATE 18, 7: PRINT "Computer Score:  "; GS.bScore
  446.  
  447.  
  448. SUB UserMove
  449.  
  450.   DrawCursor GS.curRow, GS.curCol
  451.   DO
  452.     DO
  453.       a$ = INKEY$
  454.     LOOP UNTIL a$ <> ""
  455.     move = ASC(RIGHT$(a$, 1))
  456.     IF GS.mDisplay THEN
  457.       LINE (0, 420)-(640, 447), BG, BF
  458.       GS.mDisplay = FALSE
  459.     END IF
  460.     SELECT CASE move
  461.       CASE 71 TO 81:
  462.         DrawGamePiece GS.curRow, GS.curCol, GG(GS.curRow, GS.curCol).player
  463.         IF move < 74 THEN
  464.           IF GS.curRow = BBLOCK THEN
  465.             GS.curRow = EBLOCK
  466.           ELSE
  467.             GS.curRow = GS.curRow - 1
  468.           END IF
  469.         ELSEIF move > 78 THEN
  470.           IF GS.curRow = EBLOCK THEN
  471.             GS.curRow = BBLOCK
  472.           ELSE
  473.             GS.curRow = GS.curRow + 1
  474.           END IF
  475.         END IF
  476.         IF move = 71 OR move = 75 OR move = 79 THEN
  477.           IF GS.curCol = BBLOCK THEN
  478.             GS.curCol = EBLOCK
  479.           ELSE
  480.             GS.curCol = GS.curCol - 1
  481.           END IF
  482.         ELSEIF move = 73 OR move = 77 OR move = 81 THEN
  483.           IF GS.curCol = EBLOCK THEN
  484.             GS.curCol = BBLOCK
  485.           ELSE
  486.             GS.curCol = GS.curCol + 1
  487.           END IF
  488.         END IF
  489.         DrawCursor GS.curRow, GS.curCol
  490.       CASE START:
  491.         GS.stat = START
  492.       CASE PASS:
  493.         IF GS.stat = FMOVE THEN
  494.           DisplayMsg "You passed.  Computer will make first move."
  495.           GS.stat = COMP
  496.         ELSE
  497.           DisplayMsg "You can only pass on your first turn."
  498.         END IF
  499.       CASE HELP:
  500.         DisplayHelp
  501.       CASE DIFF:
  502.         IF GS.dLevel = "Novice" THEN
  503.           GS.dLevel = "Expert"
  504.         ELSE
  505.           GS.dLevel = "Novice"
  506.         END IF
  507.         LOCATE 20, 7
  508.         PRINT "Difficulty:   "; GS.dLevel;
  509.       CASE ENTER, SPACE:
  510.         IF GG(GS.curRow, GS.curCol).nTake > 0 THEN
  511.           TakeBlocks GS.curRow, GS.curCol, HUMAN
  512.           GS.stat = COMP
  513.         ELSE
  514.           DisplayMsg "Invalid move.  Move to a space where the cursor is a circle."
  515.         END IF
  516.       CASE QUIT:
  517.         GS.stat = QUIT
  518.     END SELECT
  519.   LOOP UNTIL GS.stat <> HUMAN AND GS.stat <> FMOVE
  520.  
  521.  
  522. FUNCTION ValidMove (Opponent)
  523.  
  524.   ValidMove = FALSE
  525.   ERASE GP
  526.   FOR row = 1 TO 8
  527.     FOR col = 1 TO 8
  528.       GG(row, col).nTake = 0
  529.  
  530.       IF GG(row, col).player = GBoard THEN
  531.         IF col > 2 THEN
  532.           GP(row, col, 1) = CheckPath(row, row, 0, col - 1, 0, -1, Opponent)
  533.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 1)
  534.         END IF
  535.         IF col < 7 THEN
  536.           GP(row, col, 2) = CheckPath(row, row, 0, col + 1, 9, 1, Opponent)
  537.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 2)
  538.         END IF
  539.         IF row > 2 THEN
  540.           GP(row, col, 3) = CheckPath(row - 1, 0, -1, col, col, 0, Opponent)
  541.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 3)
  542.         END IF
  543.         IF row < 7 THEN
  544.           GP(row, col, 4) = CheckPath(row + 1, 9, 1, col, col, 0, Opponent)
  545.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 4)
  546.         END IF
  547.         IF col > 2 AND row > 2 THEN
  548.           GP(row, col, 5) = CheckPath(row - 1, 0, -1, col - 1, 0, -1, Opponent)
  549.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 5)
  550.         END IF
  551.         IF col < 7 AND row < 7 THEN
  552.           GP(row, col, 6) = CheckPath(row + 1, 9, 1, col + 1, 9, 1, Opponent)
  553.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 6)
  554.         END IF
  555.         IF col < 7 AND row > 2 THEN
  556.           GP(row, col, 7) = CheckPath(row - 1, 0, -1, col + 1, 9, 1, Opponent)
  557.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 7)
  558.         END IF
  559.         IF col > 2 AND row < 7 THEN
  560.           GP(row, col, 8) = CheckPath(row + 1, 9, 1, col - 1, 0, -1, Opponent)
  561.           GG(row, col).nTake = GG(row, col).nTake + GP(row, col, 8)
  562.         END IF
  563.         IF GG(row, col).nTake > 0 THEN ValidMove = TRUE
  564.       END IF
  565.     NEXT col
  566.   NEXT row
  567.  
  568.  
  569.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MicroSoft's version of Reversi
« Reply #1 on: October 29, 2018, 09:14:29 am »
Nice game, I didn't catch onto diagonal moves until too late.

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: MicroSoft's version of Reversi
« Reply #2 on: October 29, 2018, 09:15:21 am »
? expert level ?

 
danrevexp.PNG


... expert is me ...

 
reversi.gif



Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MicroSoft's version of Reversi
« Reply #3 on: October 29, 2018, 09:20:37 am »
;-)) you've played this before!

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: MicroSoft's version of Reversi
« Reply #4 on: October 29, 2018, 09:28:57 am »
I do not specifically study theory of reversi
to be interesting to conquere
but this version does not contain expert moves
and best reversi: wzebra
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline qbguy

  • Newbie
  • Posts: 11
    • View Profile
Re: MicroSoft's version of Reversi
« Reply #5 on: October 29, 2018, 09:38:13 am »
My own version has a better AI than Microsoft's: https://www.qb64.org/forum/index.php?topic=677.0
The hereustics are still pretty basic though, just counting squares with some weights.
« Last Edit: October 29, 2018, 09:40:12 am by qbguy »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: MicroSoft's version of Reversi
« Reply #6 on: October 29, 2018, 09:44:14 am »
Ah that's where I saw this before, I remember reading Reversi is 2d version of NIM and then got distracted by something else...

Offline DANILIN

  • Forum Regular
  • Posts: 128
    • View Profile
    • Danilin youtube
Re: MicroSoft's version of Reversi
« Reply #7 on: October 29, 2018, 10:26:43 am »
nothing interferes and nobody interferes

hold competitions between both reversi
when a human enters moves as a mediator

chess between programs 1 minute
Russia looks world from future. big data is peace data.
https://youtube.com/playlist?list=PLBBTP9oVY7IagpH0g9FNUQ8JqmHwxDDDB
i never recommend anything to anyone and always write only about myself

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: MicroSoft's version of Reversi
« Reply #8 on: October 29, 2018, 05:13:06 pm »
Hi Qbguy
I like it very much also if I prefer the other version that support also mouse input.
However it is smart for me!

As I am able to understand Keyboard input uses LowerCase ASCII code for letters so I can restart pressing s key (115 ASCII) and not S key (83 ASCII) so if you pardon me I can suggest to optimize the code at input time like for example at 361 linecode forcing to get lowercase version of input switching from
Quote
    GS.stat = ASC(RIGHT$(INKEY$, 1))   
to
Code: QB64: [Select]
  1.    GS.stat = ASC(LCASE$(RIGHT$(INKEY$, 1)))    
Thanks to share

thanks to read
Programming isn't difficult, only it's  consuming time and coffee

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: MicroSoft's version of Reversi
« Reply #9 on: October 29, 2018, 05:29:36 pm »
Hi Qbguy
I like it very much also if I prefer the other version that support also mouse input.
However it is smart for me!

As I am able to understand Keyboard input uses LowerCase ASCII code for letters so I can restart pressing s key (115 ASCII) and not S key (83 ASCII) so if you pardon me I can suggest to optimize the code at input time like for example at 361 linecode forcing to get lowercase version of input switching from
Quote
    GS.stat = ASC(RIGHT$(INKEY$, 1))   
to
Code: QB64: [Select]
  1.    GS.stat = ASC(LCASE$(RIGHT$(INKEY$, 1)))    
Thanks to share

thanks to read

Another easy way to do this is the remember that the ONLY difference in lowercase and uppercase letters is whether or not bit 6 is set in our byte.
 
DO
    var$ = INKEY$
    IF var$ <> "" THEN
         LC = ASC(var$) OR 32
         UC = ASC(var$) AND NOT 32
         PRINT var$
         PRINT "lower case"; CHR$(LC)
         PRINT "UPPER CASE"; CHR$(UC)
   END IF
LOOP UNTIL var$ = CHR$(27)

** Code wrote on iPad, from memory, and hasn't been tested yet, but it highlights the general concept, if there's an unintended glitch in there somewhere.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!