From: Svjatoslav Agejenko Date: Tue, 15 Oct 2024 18:41:26 +0000 (+0300) Subject: Refactoring code for better readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=1967b9db96ab21e58b3026a0c90d72a31bbb0ebe;p=qbasicapps.git Refactoring code for better readability --- diff --git a/Games/Checkers 2/checkers2.bas b/Games/Checkers 2/checkers2.bas index b5274ba..6fa43c5 100755 --- a/Games/Checkers 2/checkers2.bas +++ b/Games/Checkers 2/checkers2.bas @@ -1,511 +1,493 @@ -' Checkers game (unfinished) -' by Svjatoslav Agejenko 2001 - - -DECLARE SUB compki (m%, h%, x1%, y1%) -DECLARE SUB compgo2 (h%) -DECLARE SUB compgo (h%) -DECLARE SUB humngo (h%) -DefInt A-Z - -DECLARE SUB thinkc () -DECLARE SUB thinkh () -DECLARE SUB cmd (a$) -DECLARE SUB freet () -DECLARE SUB prn (x%, y%, c%, a$) -DECLARE SUB msg (a$, c) -DECLARE SUB getfnt () -DECLARE SUB playg () -DECLARE SUB geth () -DECLARE SUB start () -DECLARE SUB mklau () -DECLARE SUB showr (x, y) -DECLARE SUB show () -Dim Shared font(0 To 7, 0 To 7, 0 To 255) -Dim Shared siz, fi, ri, rs -Dim Shared stri$ -Dim Shared humx1, humy1, humx2, humy2 -Dim Shared sug, smax -Dim Shared npos As Long -Dim Shared cx1, cy1, cx2, cy2 - -siz = 6 ' Board size -fi = 0 -ri = 2 -smax = 3 ' thinking depth - - -Dim Shared lau(-1 To siz + 2, -1 To siz + 2) - -start -mklau -show -playg - -Sub cmd (a$) - - mitus = 0 - Dim sona$(1 To 10) - For b = 1 To 10 - sona$(b) = "" - Next b - - d = 1 - e = 1 - For b = 1 To Len(a$) - c$ = Right$(Left$(a$, b), 1) - If c$ = " " Then - If e = 0 Then d = d + 1: e = 1 - GoTo 4 - End If - e = 0 - sona$(d) = sona$(d) + c$ - 4 - Next b - If e = 1 Then d = d - 1 - mitus = d - - - Select Case sona$(1) - Case "m" - If humx1 > 0 Then msg "move replaced", 14 - - humx1 = Asc(Left$(sona$(2), 1)) - 64 - If humx1 > 32 Then humx1 = humx1 - 32 - humy1 = Val(Right$(sona$(2), Len(sona$(2)) - 1)) - humx2 = Asc(Left$(sona$(3), 1)) - 64 - If humx2 > 32 Then humx2 = humx2 - 32 - humy2 = Val(Right$(sona$(3), Len(sona$(2)) - 1)) - - Case "h" - msg "h - display help screen", 14 - msg "q - to quit", 14 - msg "m - make move", 14 - msg "n - no. positions processed", 14 - - Case "q" - System - - Case "n" - b$ = "positions processed:" + Str$(npos) - msg b$, 14 - - End Select - -End Sub - -Sub compgo (h) - If sug > smax Then h = 0: GoTo 6 - sug = sug + 1 - npos = npos + 1 - freet - If sug = 1 Then h1 = -2000 Else h1 = -1000 - - 'cx1 = x: cy1 = y: cx2 = x - 1: cy2 = y + 1 - b = 0 - c = 0 - m = 0 - For y = 1 To siz ' check for eating - For x = 1 To siz - If lau(x, y) = 1 Then - 8 - If (lau(x - 1, y + 1) = 2) And (lau(x - 2, y + 2) = 0) Then - Swap lau(x, y), lau(x - 2, y + 2) - lau(x - 1, y + 1) = 0 - compki m1, h2, x - 2, y + 2 - lau(x - 1, y + 1) = 2 - Swap lau(x, y), lau(x - 2, y + 2) - m1 = m1 + 1 - If m1 > m Then m = m1: h1 = -1000 - If m1 = m Then - If h2 + 1 > h1 Then - h1 = h2 + 1 - If npos = 1 Then cx1 = x: cy1 = y: cx2 = x - 2: cy2 = y + 2 - End If - End If - b = 1 - End If - - - If (lau(x + 1, y + 1) = 2) And (lau(x + 2, y + 2) = 0) Then - Swap lau(x, y), lau(x + 2, y + 2) - lau(x + 1, y + 1) = 0 - compki m1, h2, x + 2, y + 2 - lau(x + 1, y + 1) = 2 - Swap lau(x, y), lau(x + 2, y + 2) - m1 = m1 + 1 - If m1 > m Then m = m1: h1 = -1000 - If m1 = m Then - If h2 + 1 > h1 Then - h1 = h2 + 1 - If npos = 1 Then cx1 = x: cy1 = y: cx2 = x + 2: cy2 = y + 2 - End If - End If - b = 1 - End If - - - If (lau(x - 1, y - 1) = 2) And (lau(x - 2, y - 2) = 0) Then - Swap lau(x, y), lau(x - 2, y - 2) - lau(x - 1, y - 1) = 0 - compki m1, h2, x - 2, y - 2 - lau(x - 1, y - 1) = 2 - Swap lau(x, y), lau(x - 2, y - 2) - m1 = m1 + 1 - If m1 > m Then m = m1: h1 = -1000 - If m1 = m Then - If h2 + 1 > h1 Then - h1 = h2 + 1 - If npos = 1 Then cx1 = x: cy1 = y: cx2 = x - 2: cy2 = y - 2 - End If - End If - b = 1 - End If - - - If (lau(x + 1, y - 1) = 2) And (lau(x + 2, y - 2) = 0) Then - Swap lau(x, y), lau(x + 2, y - 2) - lau(x + 1, y - 1) = 0 - compki m1, h2, x + 2, y - 2 - lau(x + 1, y - 1) = 2 - Swap lau(x, y), lau(x + 2, y - 2) - m1 = m1 + 1 - If m1 > m Then m = m1: h1 = -1000 - If m1 = m Then - If h2 + 1 > h1 Then - h1 = h2 + 1 - If npos = 1 Then cx1 = x: cy1 = y: cx2 = x + 2: cy2 = y - 2 - End If - End If - b = 1 - End If - - - - - - If c = 1 Then GoTo 9 - End If - Next x - Next y - - 9 - If (b = 1) And (npos = 1) Then - cx3 = (cx1 + cx2) / 2 - cy3 = (cy1 + cy2) / 2 - lau(cx3, cy3) = 0 - showr cx3, cy3 - - Swap lau(cx1, cy1), lau(cx2, cy2) - showr cx1, cy1 - showr cx2, cy2 - msg "NJAM!", 10 - x = cx2 - y = cy2 - c = 1 - b = 0 - GoTo 8 - End If - If c = 1 Then - cx1 = 1: cy1 = 1: cx2 = 1: cy2 = 1 - GoTo 10 - End If - - If sug = 1 Then - msg "l��a ei saa", 4 - msg Str$(h1), 4 - End If - - For y = 1 To siz ' unuseful move - For x = 1 To siz - If lau(x, y) = 1 Then - If lau(x - 1, y + 1) = 0 Then - Swap lau(x, y), lau(x - 1, y + 1) - humngo h2 - Swap lau(x, y), lau(x - 1, y + 1) - If h2 > h1 Then - h1 = h2 - If sug = 1 Then cx1 = x: cy1 = y: cx2 = x - 1: cy2 = y + 1 - End If - End If - - If lau(x + 1, y + 1) = 0 Then - Swap lau(x, y), lau(x + 1, y + 1) - humngo h2 - Swap lau(x, y), lau(x + 1, y + 1) - If h2 > h1 Then - h1 = h2 - If sug = 1 Then cx1 = x: cy1 = y: cx2 = x + 1: cy2 = y + 1 - End If - End If - - End If - Next x - Next y - h = h1 - 10 - sug = sug - 1 - 6 -End Sub - -Sub compki (m, h, x1, y1) - h1 = 0 - - For y = 1 To siz - For x = 1 To siz - Next x - Next y - h = h1 - -End Sub - -Sub freet - a$ = InKey$ - If a$ = "" Then - Else - If a$ = Chr$(8) Then - If Len(stri$) > 0 Then - stri$ = Left$(stri$, Len(stri$) - 1): GoTo 3 - End If - End If - If a$ = Chr$(13) Then - If Len(stri$) > 0 Then - msg stri$, 7 - cmd stri$ - stri$ = "" - End If - GoTo 3 - End If - stri$ = stri$ + a$ - 3 - Line (400, 468)-(639, 479), 1, BF - prn 405, 469, 14, stri$ - End If -End Sub - -Sub getfnt - Screen 13 - For a = 0 To 255 - If (a > 5) And (a < 17) Then GoTo 2 - Locate 1, 1 - Print Chr$(a) - 2 - For y = 0 To 7 - For x = 0 To 7 - font(x, y, a) = Point(x, y) - Next x - Next y - Next a - -End Sub - -Sub humngo (h) - npos = npos + 1 - h1 = 1000 - - For y = siz To 1 Step -1 - For x = siz To 1 Step -1 - If lau(x, y) = 2 Then - If lau(x - 1, y - 1) = 0 Then - Swap lau(x, y), lau(x - 1, y - 1) - compgo h2 - Swap lau(x, y), lau(x - 1, y - 1) - If h2 < h1 Then h1 = h2 - End If - - If lau(x + 1, y - 1) = 0 Then - Swap lau(x, y), lau(x + 1, y - 1) - compgo h2 - Swap lau(x, y), lau(x + 1, y - 1) - If h2 < h1 Then h1 = h2 - End If - - - If (lau(x - 1, y - 1) = 1) And (lau(x - 2, y - 2) = 0) Then - Swap lau(x, y), lau(x - 2, y - 2) - lau(x - 1, y - 1) = 0 - humngo h2 - lau(x - 1, y - 1) = 1 - Swap lau(x, y), lau(x - 2, y - 2) - If h2 - 1 < h1 Then h1 = h2 - 1 - End If - - If (lau(x + 1, y - 1) = 1) And (lau(x + 2, y - 2) = 0) Then - Swap lau(x, y), lau(x + 2, y - 2) - lau(x + 1, y - 1) = 0 - humngo h2 - lau(x + 1, y - 1) = 1 - Swap lau(x, y), lau(x + 2, y - 2) - If h2 - 1 < h1 Then h1 = h2 - 1 - End If - - - - - End If - Next x - Next y - h = h1 -End Sub - -Sub mklau - For y = -1 To siz + 2 - For x = -1 To siz + 2 - lau(x, y) = -1 - Next x - Next y - - For y = 1 To siz - For x = 1 To siz - lau(x, y) = 0 - Next x - Next y - - For y = 1 To ri - For x = 1 To siz - If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then - lau(x, y) = 1 - End If - Next x - Next y - - For y = siz - ri + 1 To siz - For x = 1 To siz - If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then - lau(x, y) = 2 - End If - Next x - Next y - -End Sub - -Sub msg (a$, c) - Dim buf(1 To 10000) - For x = 400 To 630 Step 40 - Get (x, 8)-(x + 39, 467), buf(1) - Put (x, 0), buf(1), PSet - Next x - Line (400, 460)-(639, 467), 0, BF - prn 405, 460, c, a$ -End Sub - -Sub playg - 'GOTO 7 - 1 - thinkc - show - 7 - thinkh - show - GoTo 1 - - -End Sub - -Sub prn (x, y, c, a$) - x1 = x - y1 = y - For a = 1 To Len(a$) - b = Asc(Right$(Left$(a$, a), 1)) - For y2 = 0 To 7 - For x2 = 0 To 7 - If font(x2, y2, b) > 0 Then PSet (x2 + x1, y2 + y1), c - Next x2 - Next y2 - x1 = x1 + 8 - Next a -End Sub - -Sub show - For y = 1 To siz - For x = 1 To siz - showr x, y - Next x - Next y - - sp = rs / 2 - For x = 1 To siz - prn ((x - 1) * rs + 12 + sp), 2, 10, Chr$(64 + x) - prn ((x - 1) * rs + 12 + sp), siz * rs + 11, 10, Chr$(64 + x) - Next x - - For y = 1 To siz - a$ = Str$(y) - a$ = Right$(a$, Len(a$) - 1) - prn 15 - (Len(a$) * 8), (y - 1) * rs + sp + 7, 10, a$ - prn (siz * rs + 16), (y - 1) * rs + sp + 7, 10, a$ - Next y - - -End Sub - -Sub showr (x, y) - If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then c = 8 Else c = 7 - x1 = (x - 1) * rs + 15 - y1 = (y - 1) * rs + 10 - Line (x1, y1)-(x1 + rs - 1, y1 + rs - 1), c, BF - If lau(x, y) > 0 Then - sp = rs / 2 - If lau(x, y) = 1 Then c1 = 15 Else c1 = 14 - Circle (x1 + sp, y1 + sp), sp - 1, c1 - Paint (x1 + sp, y1 + sp), c1 - End If -End Sub - -Sub start - getfnt - Screen 12 - Line (399, 0)-(399, 479), 13 - msg "type 'h' for help", 14 - - rs = Int(370 / siz) - - -End Sub - -Sub thinkc - msg "computer turn", 14 - sug = 0 - npos = 0 - cx1 = -1 - - compgo h - cmd "n" - If cx1 = -1 Then msg "you won!", 10: msg "--------", 10: System - - If h <= -2 Then msg "oh no...", 10 - If h = -1 Then msg "oops!", 10 - If h = 1 Then msg "yess! I will eat soon!", 10 - If h >= 2 Then msg "HA HA HA YOU ARE IN TROUBLE!", 10 - - - If Abs(cx1 - cx2) = 2 Then - cx3 = (cx1 + cx2) / 2 - cy3 = (cy1 + cy2) / 2 - lau(cx3, cy3) = 0 - showr cx3, cy3 - End If - - Swap lau(cx1, cy1), lau(cx2, cy2) - showr cx1, cy1 - showr cx2, cy2 - -End Sub - -Sub thinkh - msg "your turn", 14 - 5 - freet - If humx1 = 0 Then GoTo 5 - Swap lau(humx2, humy2), lau(humx1, humy1) - showr humx1, humy1 - showr humx2, humy2 - If Abs(humx1 - humx2) = 2 Then - cx3 = (humx1 + humx2) / 2 - cy3 = (humy1 + humy2) / 2 - lau(cx3, cy3) = 0 - showr cx3, cy3 - End If - - humx1 = 0 -End Sub +' Checkers game (unfinished) +' by Svjatoslav Agejenko 2001 + +DECLARE SUB compki (m%, h%, x1%, y1%) +DECLARE SUB compgo2 (h%) +DECLARE SUB compgo (h%) +DECLARE SUB humngo (h%) +DefInt A-Z + +DECLARE SUB thinkc () +DECLARE SUB thinkh () +DECLARE SUB cmd (a$) +DECLARE SUB freet () +DECLARE SUB prn (x%, y%, c%, a$) +DECLARE SUB msg (a$, c) +DECLARE SUB getfnt () +DECLARE SUB playg () +DECLARE SUB geth () +DECLARE SUB start () +DECLARE SUB mklau () +DECLARE SUB showr (x, y) +DECLARE SUB show () +Dim Shared font(0 To 7, 0 To 7, 0 To 255) +Dim Shared siz, fi, ri, rs +Dim Shared stri$ +Dim Shared humx1, humy1, humx2, humy2 +Dim Shared sug, smax +Dim Shared npos As Long +Dim Shared cx1, cy1, cx2, cy2 + +siz = 6 ' Board size +fi = 0 +ri = 2 +smax = 3 ' thinking depth + +Dim Shared lau(-1 To siz + 2, -1 To siz + 2) + +start +mklau +show +playg + +Sub cmd (a$) + mitus = 0 + Dim sona$(1 To 10) + For b = 1 To 10 + sona$(b) = "" + Next b + + d = 1 + e = 1 + For b = 1 To Len(a$) + c$ = Right$(Left$(a$, b), 1) + If c$ = " " Then + If e = 0 Then d = d + 1: e = 1 + GoTo 4 + End If + e = 0 + sona$(d) = sona$(d) + c$ + 4 + Next b + If e = 1 Then d = d - 1 + mitus = d + + Select Case sona$(1) + Case "m" + If humx1 > 0 Then msg "move replaced", 14 + + humx1 = Asc(Left$(sona$(2), 1)) - 64 + If humx1 > 32 Then humx1 = humx1 - 32 + humy1 = Val(Right$(sona$(2), Len(sona$(2)) - 1)) + humx2 = Asc(Left$(sona$(3), 1)) - 64 + If humx2 > 32 Then humx2 = humx2 - 32 + humy2 = Val(Right$(sona$(3), Len(sona$(2)) - 1)) + + Case "h" + msg "h - display help screen", 14 + msg "q - to quit", 14 + msg "m - make move", 14 + msg "n - no. positions processed", 14 + + Case "q" + System + + Case "n" + b$ = "positions processed:" + Str$(npos) + msg b$, 14 + + End Select + +End Sub + +Sub compgo (h) + If sug > smax Then h = 0: GoTo 6 + sug = sug + 1 + npos = npos + 1 + freet + If sug = 1 Then h1 = -2000 Else h1 = -1000 + + 'cx1 = x: cy1 = y: cx2 = x - 1: cy2 = y + 1 + b = 0 + c = 0 + m = 0 + For y = 1 To siz ' check for eating + For x = 1 To siz + If lau(x, y) = 1 Then + 8 + If (lau(x - 1, y + 1) = 2) And (lau(x - 2, y + 2) = 0) Then + Swap lau(x, y), lau(x - 2, y + 2) + lau(x - 1, y + 1) = 0 + compki m1, h2, x - 2, y + 2 + lau(x - 1, y + 1) = 2 + Swap lau(x, y), lau(x - 2, y + 2) + m1 = m1 + 1 + If m1 > m Then m = m1: h1 = -1000 + If m1 = m Then + If h2 + 1 > h1 Then + h1 = h2 + 1 + If npos = 1 Then cx1 = x: cy1 = y: cx2 = x - 2: cy2 = y + 2 + End If + End If + b = 1 + End If + + If (lau(x + 1, y + 1) = 2) And (lau(x + 2, y + 2) = 0) Then + Swap lau(x, y), lau(x + 2, y + 2) + lau(x + 1, y + 1) = 0 + compki m1, h2, x + 2, y + 2 + lau(x + 1, y + 1) = 2 + Swap lau(x, y), lau(x + 2, y + 2) + m1 = m1 + 1 + If m1 > m Then m = m1: h1 = -1000 + If m1 = m Then + If h2 + 1 > h1 Then + h1 = h2 + 1 + If npos = 1 Then cx1 = x: cy1 = y: cx2 = x + 2: cy2 = y + 2 + End If + End If + b = 1 + End If + + If (lau(x - 1, y - 1) = 2) And (lau(x - 2, y - 2) = 0) Then + Swap lau(x, y), lau(x - 2, y - 2) + lau(x - 1, y - 1) = 0 + compki m1, h2, x - 2, y - 2 + lau(x - 1, y - 1) = 2 + Swap lau(x, y), lau(x - 2, y - 2) + m1 = m1 + 1 + If m1 > m Then m = m1: h1 = -1000 + If m1 = m Then + If h2 + 1 > h1 Then + h1 = h2 + 1 + If npos = 1 Then cx1 = x: cy1 = y: cx2 = x - 2: cy2 = y - 2 + End If + End If + b = 1 + End If + + If (lau(x + 1, y - 1) = 2) And (lau(x + 2, y - 2) = 0) Then + Swap lau(x, y), lau(x + 2, y - 2) + lau(x + 1, y - 1) = 0 + compki m1, h2, x + 2, y - 2 + lau(x + 1, y - 1) = 2 + Swap lau(x, y), lau(x + 2, y - 2) + m1 = m1 + 1 + If m1 > m Then m = m1: h1 = -1000 + If m1 = m Then + If h2 + 1 > h1 Then + h1 = h2 + 1 + If npos = 1 Then cx1 = x: cy1 = y: cx2 = x + 2: cy2 = y - 2 + End If + End If + b = 1 + End If + + If c = 1 Then GoTo 9 + End If + Next x + Next y + + 9 + If (b = 1) And (npos = 1) Then + cx3 = (cx1 + cx2) / 2 + cy3 = (cy1 + cy2) / 2 + lau(cx3, cy3) = 0 + showr cx3, cy3 + + Swap lau(cx1, cy1), lau(cx2, cy2) + showr cx1, cy1 + showr cx2, cy2 + msg "NJAM!", 10 + x = cx2 + y = cy2 + c = 1 + b = 0 + GoTo 8 + End If + If c = 1 Then + cx1 = 1: cy1 = 1: cx2 = 1: cy2 = 1 + GoTo 10 + End If + + If sug = 1 Then + msg "l��a ei saa", 4 + msg Str$(h1), 4 + End If + + For y = 1 To siz ' unuseful move + For x = 1 To siz + If lau(x, y) = 1 Then + If lau(x - 1, y + 1) = 0 Then + Swap lau(x, y), lau(x - 1, y + 1) + humngo h2 + Swap lau(x, y), lau(x - 1, y + 1) + If h2 > h1 Then + h1 = h2 + If sug = 1 Then cx1 = x: cy1 = y: cx2 = x - 1: cy2 = y + 1 + End If + End If + + If lau(x + 1, y + 1) = 0 Then + Swap lau(x, y), lau(x + 1, y + 1) + humngo h2 + Swap lau(x, y), lau(x + 1, y + 1) + If h2 > h1 Then + h1 = h2 + If sug = 1 Then cx1 = x: cy1 = y: cx2 = x + 1: cy2 = y + 1 + End If + End If + + End If + Next x + Next y + h = h1 + 10 + sug = sug - 1 + 6 +End Sub + +Sub compki (m, h, x1, y1) + h1 = 0 + + For y = 1 To siz + For x = 1 To siz + Next x + Next y + h = h1 + +End Sub + +Sub freet + a$ = InKey$ + If a$ = "" Then + Else + If a$ = Chr$(8) Then + If Len(stri$) > 0 Then + stri$ = Left$(stri$, Len(stri$) - 1): GoTo 3 + End If + End If + If a$ = Chr$(13) Then + If Len(stri$) > 0 Then + msg stri$, 7 + cmd stri$ + stri$ = "" + End If + GoTo 3 + End If + stri$ = stri$ + a$ + 3 + Line (400, 468)-(639, 479), 1, BF + prn 405, 469, 14, stri$ + End If +End Sub + +Sub getfnt + Screen 13 + For a = 0 To 255 + If (a > 5) And (a < 17) Then GoTo 2 + Locate 1, 1 + Print Chr$(a) + 2 + For y = 0 To 7 + For x = 0 To 7 + font(x, y, a) = Point(x, y) + Next x + Next y + Next a + +End Sub + +Sub humngo (h) + npos = npos + 1 + h1 = 1000 + + For y = siz To 1 Step -1 + For x = siz To 1 Step -1 + If lau(x, y) = 2 Then + If lau(x - 1, y - 1) = 0 Then + Swap lau(x, y), lau(x - 1, y - 1) + compgo h2 + Swap lau(x, y), lau(x - 1, y - 1) + If h2 < h1 Then h1 = h2 + End If + + If lau(x + 1, y - 1) = 0 Then + Swap lau(x, y), lau(x + 1, y - 1) + compgo h2 + Swap lau(x, y), lau(x + 1, y - 1) + If h2 < h1 Then h1 = h2 + End If + + If (lau(x - 1, y - 1) = 1) And (lau(x - 2, y - 2) = 0) Then + Swap lau(x, y), lau(x - 2, y - 2) + lau(x - 1, y - 1) = 0 + humngo h2 + lau(x - 1, y - 1) = 1 + Swap lau(x, y), lau(x - 2, y - 2) + If h2 - 1 < h1 Then h1 = h2 - 1 + End If + + If (lau(x + 1, y - 1) = 1) And (lau(x + 2, y - 2) = 0) Then + Swap lau(x, y), lau(x + 2, y - 2) + lau(x + 1, y - 1) = 0 + humngo h2 + lau(x + 1, y - 1) = 1 + Swap lau(x, y), lau(x + 2, y - 2) + If h2 - 1 < h1 Then h1 = h2 - 1 + End If + + End If + Next x + Next y + h = h1 +End Sub + +Sub mklau + For y = -1 To siz + 2 + For x = -1 To siz + 2 + lau(x, y) = -1 + Next x + Next y + + For y = 1 To siz + For x = 1 To siz + lau(x, y) = 0 + Next x + Next y + + For y = 1 To ri + For x = 1 To siz + If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then + lau(x, y) = 1 + End If + Next x + Next y + + For y = siz - ri + 1 To siz + For x = 1 To siz + If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then + lau(x, y) = 2 + End If + Next x + Next y + +End Sub + +Sub msg (a$, c) + Dim buf(1 To 10000) + For x = 400 To 630 Step 40 + Get (x, 8)-(x + 39, 467), buf(1) + Put (x, 0), buf(1), PSet + Next x + Line (400, 460)-(639, 467), 0, BF + prn 405, 460, c, a$ +End Sub + +Sub playg + 'GOTO 7 + 1 + thinkc + show + 7 + thinkh + show + GoTo 1 + +End Sub + +Sub prn (x, y, c, a$) + x1 = x + y1 = y + For a = 1 To Len(a$) + b = Asc(Right$(Left$(a$, a), 1)) + For y2 = 0 To 7 + For x2 = 0 To 7 + If font(x2, y2, b) > 0 Then PSet (x2 + x1, y2 + y1), c + Next x2 + Next y2 + x1 = x1 + 8 + Next a +End Sub + +Sub show + For y = 1 To siz + For x = 1 To siz + showr x, y + Next x + Next y + + sp = rs / 2 + For x = 1 To siz + prn ((x - 1) * rs + 12 + sp), 2, 10, Chr$(64 + x) + prn ((x - 1) * rs + 12 + sp), siz * rs + 11, 10, Chr$(64 + x) + Next x + + For y = 1 To siz + a$ = Str$(y) + a$ = Right$(a$, Len(a$) - 1) + prn 15 - (Len(a$) * 8), (y - 1) * rs + sp + 7, 10, a$ + prn (siz * rs + 16), (y - 1) * rs + sp + 7, 10, a$ + Next y + +End Sub + +Sub showr (x, y) + If (x + y + fi) / 2 = Int((x + y + fi) / 2) Then c = 8 Else c = 7 + x1 = (x - 1) * rs + 15 + y1 = (y - 1) * rs + 10 + Line (x1, y1)-(x1 + rs - 1, y1 + rs - 1), c, BF + + If lau(x, y) > 0 Then + sp = rs / 2 + If lau(x, y) = 1 Then c1 = 15 Else c1 = 14 + Circle (x1 + sp, y1 + sp), sp - 1, c1 + Paint (x1 + sp, y1 + sp), c1 + End If +End Sub + +Sub start + getfnt + Screen 12 + Line (399, 0)-(399, 479), 13 + msg "type 'h' for help", 14 + + rs = Int(370 / siz) + +End Sub + +Sub thinkc + msg "computer turn", 14 + sug = 0 + npos = 0 + cx1 = -1 + + compgo h + cmd "n" + If cx1 = -1 Then msg "you won!", 10: msg "--------", 10: System + + If h <= -2 Then msg "oh no...", 10 + If h = -1 Then msg "oops!", 10 + If h = 1 Then msg "yess! I will eat soon!", 10 + If h >= 2 Then msg "HA HA HA YOU ARE IN TROUBLE!", 10 + + If Abs(cx1 - cx2) = 2 Then + cx3 = (cx1 + cx2) / 2 + cy3 = (cy1 + cy2) / 2 + lau(cx3, cy3) = 0 + showr cx3, cy3 + End If + + Swap lau(cx1, cy1), lau(cx2, cy2) + showr cx1, cy1 + showr cx2, cy2 + +End Sub + +Sub thinkh + msg "your turn", 14 + 5 + freet + If humx1 = 0 Then GoTo 5 + Swap lau(humx2, humy2), lau(humx1, humy1) + showr humx1, humy1 + showr humx2, humy2 + If Abs(humx1 - humx2) = 2 Then + cx3 = (humx1 + humx2) / 2 + cy3 = (humy1 + humy2) / 2 + lau(cx3, cy3) = 0 + showr cx3, cy3 + End If + + humx1 = 0 +End Sub