From: Svjatoslav Agejenko Date: Mon, 21 Oct 2024 21:00:26 +0000 (+0300) Subject: Using AI to improve code readability X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=fc4227512100c6b56dfa13b3124af71b878a48d1;p=qbasicapps.git Using AI to improve code readability --- diff --git a/Games/checkers.bas b/Games/checkers.bas index 6ded57d..de66e46 100755 --- a/Games/checkers.bas +++ b/Games/checkers.bas @@ -39,7 +39,9 @@ FOR a = 1 TO 200 nu(a) = 4 NEXT a -' Draw the initial checkerboard pattern +' Draw the initial checkerboard pattern. +' (alternating squares to create the checkerboard) + FOR a = 2 TO 10 STEP 2 FOR b = 1 TO 10 STEP 2 PAINT ((b * 40) + 5, (a * 18) + 5) @@ -90,6 +92,7 @@ kaik = 1 mang SUB asend + ' Draw the pieces on the board FOR b = 1 TO 10 FOR a = 1 TO 10 v = nu(((b - 1) * 20) + a) @@ -116,6 +119,7 @@ SUB asend END SUB SUB look + ' checks if there are any possible moves on the board looma = 0 FOR a = 1 TO 200 IF nu(a) = 0 AND nu(a - 21) = 1 AND nu(a - 42) = 3 THEN looma = 1 @@ -136,7 +140,7 @@ END SUB SUB motleb 3 -REM T O P E L T L O O K +' Check for possible jumps (double eating) FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 21) = 0 AND nu(a + 42) = 3 AND nu(a + 61) = 0 AND nu(a + 80) = 3 THEN nu(a) = 3: nu(a + 21) = 3: nu(a + 42) = 1: kaik = 1: asend: GOTO 3 IF nu(a) = 1 AND nu(a + 21) = 0 AND nu(a + 42) = 3 AND nu(a + 23) = 0 AND nu(a + 4) = 3 THEN nu(a) = 3: nu(a + 21) = 3: nu(a + 42) = 1: kaik = 1: asend: GOTO 3 @@ -153,14 +157,15 @@ FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a - 19) = 0 AND nu(a - 38) = 3 AND nu(a - 57) = 0 AND nu(a - 76) = 3 THEN nu(a) = 3: nu(a - 19) = 3: nu(a - 38) = 1: aiki = 1: asend: GOTO 3 NEXT a -REM L I H T S A L T L O O K +' Check for possible single moves (single eating) FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 21) = 0 AND nu(a + 42) = 3 THEN nu(a) = 3: nu(a + 21) = 3: nu(a + 42) = 1: GOTO 2 IF nu(a) = 1 AND nu(a + 19) = 0 AND nu(a + 38) = 3 THEN nu(a) = 3: nu(a + 19) = 3: nu(a + 38) = 1: GOTO 2 IF nu(a) = 1 AND nu(a - 21) = 0 AND nu(a - 42) = 3 THEN nu(a) = 3: nu(a - 21) = 3: nu(a - 42) = 1: GOTO 2 IF nu(a) = 1 AND nu(a - 19) = 0 AND nu(a - 38) = 3 THEN nu(a) = 3: nu(a - 19) = 3: nu(a - 38) = 1: GOTO 2 NEXT a -REM K A I T S E B + +' Check for possible captures (to protect your pieces) FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 19) = 3 AND nu(a + 21) = 3 AND nu(a + 40) = 1 AND nu(a + 38) = 3 AND nu(a + 61) = 0 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 IF nu(a) = 1 AND nu(a + 19) = 3 AND nu(a + 21) = 0 AND nu(a + 40) = 1 AND nu(a + 38) = 3 AND nu(a + 61) = 0 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 @@ -172,12 +177,14 @@ FOR a = 1 TO 200 IF nu(a - 2) = 1 AND nu(a + 19) = 3 AND nu(a) = 3 AND nu(a + 40) = 1 AND nu(a + 38) = 1 AND nu(a + 61) = 0 THEN nu(a - 2) = 3: nu(a + 19) = 1: GOTO 2 IF nu(a - 2) = 1 AND nu(a + 19) = 3 AND nu(a) = 1 AND nu(a + 40) = 1 AND nu(a + 38) = 1 AND nu(a + 61) = 0 THEN nu(a - 2) = 3: nu(a + 19) = 1: GOTO 2 NEXT a -REM L A H E B N U R K A + +' Check for possible moves to the edge FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 2) = 4 AND nu(a + 21) = 3 THEN nu(a) = 3: nu(a + 21) = 1: GOTO 2 IF nu(a) = 1 AND nu(a - 2) = 4 AND nu(a + 19) = 3 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 NEXT a -REM O H U T U K A I K + +' Check for possible moves to the corner (safe moves) FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 19) = 3 AND nu(a + 38) = 3 AND nu(a + 40) = 3 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 IF nu(a) = 1 AND nu(a + 21) = 3 AND nu(a + 42) = 3 AND nu(a + 40) = 3 THEN nu(a) = 3: nu(a + 21) = 1: GOTO 2 @@ -191,7 +198,8 @@ FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 19) = 3 AND nu(a + 38) = 1 AND nu(a + 40) = 1 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 IF nu(a) = 1 AND nu(a + 21) = 3 AND nu(a + 42) = 1 AND nu(a + 40) = 1 THEN nu(a) = 3: nu(a + 21) = 1: GOTO 2 NEXT a -REM M O T T E T U K A I K + +' Check for possible moves to the middle (useless moves) FOR a = 1 TO 200 IF nu(a) = 1 AND nu(a + 21) = 3 THEN nu(a) = 3: nu(a + 21) = 1: GOTO 2 IF nu(a) = 1 AND nu(a + 19) = 3 THEN nu(a) = 3: nu(a + 19) = 1: GOTO 2 @@ -280,7 +288,8 @@ SUB sisend PRINT a1; "-"; a2 10 - ' K O N T R O L L + + ' This section controls the movement of pieces on the board IF a1 = a2 + 19 AND nu(a1) = 0 AND nu(a2) = 3 THEN BEEP SWAP nu(a1), nu(a2)