REM Игра в крестики-нолики
DECLARE SUB STEP345 ()
DECLARE SUB RESULT (s$)
DECLARE SUB CURIND (cur%, porog%, dcur%, dind%)
DECLARE SUB SHOW (k%, c%)
DECLARE SUB USER ()
DECLARE FUNCTION XOD! (k%, k1%)
DEFINT A-Z
DIM SHARED POS1(1 TO 18) AS INTEGER, lines(0 TO 23) AS INTEGER
DIM SHARED A(1 TO 9) AS INTEGER, b(1 TO 9) AS INTEGER
DIM SHARED x0 AS INTEGER, y0 AS INTEGER
DIM SHARED Ind AS INTEGER, CurX AS INTEGER, CurY AS INTEGER
FOR k = 1 TO 9: A(k) = 0: NEXT k
DATA 3,1,1,1,5,3,1,7,3
FOR k = 1 TO 9: READ b(k): NEXT k
x0 = 1: y0 = 1
DATA 3,2,7,2,11,2,3,4,7,4,11,4,3,6,7,6,11,6
FOR k = 1 TO 18: READ POS1(k): NEXT k
DATA 1,2,3,4,5,6,7,8,9,1,4,7,2,5,8,3,6,9,1,5,9,3,5,7
FOR k = 0 TO 23: READ lines(k): NEXT k
CLS
SHOW 5, 2 ' Первый ход программы
USER ' Ввод 1-го хода игрока
FOR J = 1 TO 9 ' Второй ход программы
IF A(J) = -2 THEN SHOW b(J), 2: EXIT FOR
NEXT J
m2: USER ' Ввод последующих ходов игрока
STEP345 ' Последующие ходы программы
GOTO m2
END
SUB CURIND (cur%, porog%, dcur%, dind%)
IF cur <> porog THEN cur = cur + dcur: Ind = Ind + dind
END SUB
DEFSNG A-Z
SUB RESULT (s$)
LOCATE 1, 40: PRINT s$: END
END SUB
DEFINT A-Z
SUB SHOW (k%, c%)
DEFINT A-Z
CLS
LOCATE x0, y0: PRINT "----T---T---¬"
LOCATE x0 + 1, y0: PRINT "¦ ¦ ¦ ¦"
LOCATE x0 + 2, y0: PRINT "+---+---+---+"
LOCATE x0 + 3, y0: PRINT "¦ ¦ ¦ ¦"
LOCATE x0 + 4, y0: PRINT "+---+---+---+"
LOCATE x0 + 5, y0: PRINT "¦ ¦ ¦ ¦"
LOCATE x0 + 6, y0: PRINT "L---+---+----"
A(k%) = c%
FOR J = 1 TO 9
LOCATE y0 - 1 + POS1(J * 2), x0 - 1 + POS1(J * 2 - 1)
IF A(J) = 2 THEN PRINT "Х"
IF A(J) = -2 THEN PRINT "0"
NEXT J
CurX = x0 + 6: CurY = y0 + 3: Ind = 5
LOCATE CurY, CurX, 1
END SUB
SUB STEP345
DEFINT A-Z
IF XOD(2, 2) = 1 THEN RESULT "Победа компьютера": END
IF XOD(-2, 2) = 1 THEN EXIT SUB
FOR J = 1 TO 9
IF A(J) = 0 THEN SHOW J, 2: EXIT FOR
NEXT J
END SUB
DEFSNG A-Z
SUB USER
DEFINT A-Z
Left = 75: Right = 77: Up = 72: Down = 80: Enter = 13
k = 0: FOR J = 1 TO 9: k = k + ABS(A(J)): NEXT J
IF k = 18 THEN RESULT "Боевая ничья": END
m: ch$ = INKEY$: IF LEN(ch$) = 0 THEN GOTO m
SELECT CASE ASC(RIGHT$(ch$, 1))
CASE Left: CURIND CurX, 3, -4, -1
CASE Right: CURIND CurX, 11, 4, 1
CASE Up: CURIND CurY, 2, -2, -3
CASE Down: CURIND CurY, 6, 2, 3
CASE Enter: IF A(Ind) = 0 THEN SHOW Ind, -2: EXIT SUB
CASE ELSE: BEEP
END SELECT
LOCATE y0 - 1 + CurY, x0 - 1 + CurX, 1
USER
END SUB
DEFSNG A-Z
FUNCTION XOD (k%, k1%)
DIM J AS INTEGER, m AS INTEGER, p AS INTEGER
XOD = 0
FOR J = 0 TO 7
m = J * 3
IF A(lines(m)) + A(lines(m + 1)) + A(lines(m + 2)) = 2 * k% THEN
XOD = 1
FOR p = m TO m + 2
IF A(lines(p)) = 0 THEN
SHOW lines(p), k1%
EXIT FUNCTION
END IF
NEXT p
END IF
NEXT J
END FUNCTION