\r
' Changelog:\r
' 2002, Initial version\r
-' 2024.09, Improved program readability using AI\r
+' 2024, Improved program readability using AI\r
\r
DECLARE FUNCTION cnum$ (a%)\r
DECLARE SUB putworm (a%)\r
DECLARE SUB sc (x%, y%)\r
DEFINT A-Z\r
\r
+' Shared arrays for the game grid and worms\r
DIM SHARED buf(0 TO 36, 0 TO 36)\r
DIM SHARED buf2(0 TO 36, 0 TO 36)\r
DIM SHARED ussx(1 TO 2000, 1 TO 5)\r
DIM SHARED ussk(1 TO 2000, 1 TO 5)\r
DIM SHARED usskp(1 TO 5)\r
\r
+' Variables for worm positions and game state\r
DIM SHARED ux(1 TO 5), uy(1 TO 5), uxp(1 TO 5), uyp(1 TO 5)\r
DIM SHARED mtm\r
-DIM SHARED ussm\r
+DIM SHARED playerCount\r
DIM SHARED elud(1 TO 5)\r
DIM SHARED auto(1 TO 5)\r
-DIM SHARED ail, lvl, wai\r
+DIM SHARED ail\r
+DIM SHARED lvl\r
+DIM SHARED wai\r
DIM SHARED elum\r
DIM SHARED spd\r
\r
-ussm = 1\r
+playerCount = 1\r
ail = 10\r
lvl = 1\r
wai = 20\r
\r
+' Array defines if player is human (0) or computer (1).\r
auto(1) = 0\r
auto(2) = 0\r
auto(3) = 0\r
auto(4) = 0\r
auto(5) = 0\r
+\r
CLS\r
\r
-INPUT "How many players (1 - 5):", ussm\r
+INPUT "How many players (1 - 5):", playerCount\r
INPUT "How many of them are computers:", a\r
-FOR b = ussm TO ussm - a + 1 STEP -1\r
+FOR b = playerCount TO playerCount - a + 1 STEP -1\r
auto(b) = 1\r
NEXT b\r
\r
' Initialize the worms for each player.\r
show\r
\r
- FOR b = 1 TO ussm\r
+ FOR b = 1 TO playerCount\r
ussl(b) = 0\r
putworm b\r
NEXT b\r
\r
SUB prc (a%)\r
' This subroutine handles the main game loop for each worm.\r
- subt a\r
+ subt a%\r
\r
- ussp(a) = ussp(a) + 1\r
+ ussp(a%) = ussp(a%) + 1\r
\r
' If the worm has no lives left, end its turn.\r
- IF elud(a) = 0 THEN\r
+ IF elud(a%) = 0 THEN\r
GOTO 4\r
END IF\r
\r
' If the worm is controlled by AI, recalculate its path.\r
- IF auto(a) = 1 THEN\r
- autop a\r
+ IF auto(a%) = 1 THEN\r
+ autop a%\r
END IF\r
\r
' Move the worm based on user input or AI direction.\r
- ux(a) = ux(a) + uxp(a)\r
- uy(a) = uy(a) + uyp(a)\r
+ ux(a%) = ux(a%) + uxp(a%)\r
+ uy(a%) = uy(a%) + uyp(a%)\r
\r
' Wrap around the edges of the grid.\r
- IF ux(a) = 35 THEN\r
- ux(a) = 2\r
+ IF ux(a%) = 35 THEN\r
+ ux(a%) = 2\r
END IF\r
\r
- IF uy(a) = 35 THEN\r
- uy(a) = 2\r
+ IF uy(a%) = 35 THEN\r
+ uy(a%) = 2\r
END IF\r
\r
- IF ux(a) = 1 THEN\r
- ux(a) = 34\r
+ IF ux(a%) = 1 THEN\r
+ ux(a%) = 34\r
END IF\r
\r
- IF uy(a) = 1 THEN\r
- uy(a) = 34\r
+ IF uy(a%) = 1 THEN\r
+ uy(a%) = 34\r
END IF\r
\r
- x = ux(a)\r
- y = uy(a)\r
+ x = ux(a%)\r
+ y = uy(a%)\r
\r
3\r
IF buf(x, y) = 2 THEN\r
\r
stuff\r
\r
- ussl(a) = ussl(a) + mtm\r
+ ussl(a%) = ussl(a%) + mtm\r
\r
- usss(a) = usss(a) + mtm\r
+ usss(a%) = usss(a%) + mtm\r
\r
- FOR b = 1 TO ussm\r
+ FOR b = 1 TO playerCount\r
IF (elud(b) > 0) AND (auto(b) = 1) THEN\r
ai b\r
END IF\r
END IF\r
\r
IF buf(x, y) > 0 THEN\r
- dead a\r
+ dead a%\r
\r
GOTO 4\r
END IF\r
\r
- IF a = 1 THEN\r
+ IF a% = 1 THEN\r
buf(x, y) = 10\r
- ELSEIF a = 2 THEN\r
+ ELSEIF a% = 2 THEN\r
buf(x, y) = 11\r
- ELSEIF a = 3 THEN\r
+ ELSEIF a% = 3 THEN\r
buf(x, y) = 12\r
- ELSEIF a = 4 THEN\r
+ ELSEIF a% = 4 THEN\r
buf(x, y) = 13\r
- ELSEIF a = 5 THEN\r
+ ELSEIF a% = 5 THEN\r
buf(x, y) = 14\r
END IF\r
\r
sc x, y\r
\r
- IF ussp(a) > 2000 THEN\r
- ussp(a) = ussp(a) - 2000\r
+ IF ussp(a%) > 2000 THEN\r
+ ussp(a%) = ussp(a%) - 2000\r
END IF\r
\r
- ussx(ussp(a), a) = x\r
+ ussx(ussp(a%), a%) = x\r
\r
- ussy(ussp(a), a) = y\r
+ ussy(ussp(a%), a%) = y\r
\r
4\r
END SUB\r
\r
SUB putworm (a%)\r
' This subroutine initializes a new worm for a player.\r
- b = ussl(a)\r
+ b = ussl(a%)\r
\r
' Move the worm back to its starting position.\r
FOR c = b TO 1 STEP -1\r
- ussl(a) = c\r
+ ussl(a%) = c\r
\r
- subt a\r
+ subt a%\r
NEXT c\r
\r
9\r
- uy(a) = INT(RND * 30 + 2)\r
+ uy(a%) = INT(RND * 30 + 2)\r
\r
- ux(a) = INT(RND * 10 + 5)\r
+ ux(a%) = INT(RND * 10 + 5)\r
\r
' Ensure that the worm starts in an empty space.\r
- FOR b = ux(a) TO ux(a) + 10\r
- IF buf(b, uy(a)) <> 0 THEN\r
+ FOR b = ux(a%) TO ux(a%) + 10\r
+ IF buf(b, uy(a%)) <> 0 THEN\r
GOTO 9\r
END IF\r
NEXT b\r
\r
' Set the initial direction of the worm.\r
- uxp(a) = 1\r
+ uxp(a%) = 1\r
\r
- uyp(a) = 0\r
+ uyp(a%) = 0\r
\r
- ussl(a) = 3\r
+ ussl(a%) = 3\r
\r
stat\r
END SUB\r
\r
uy(5) = 25\r
\r
- FOR a = 1 TO ussm\r
+ FOR a = 1 TO playerCount\r
ux(a) = 15\r
\r
uxp(a) = 1\r
\r
SUB subt (b%)\r
' This subroutine updates the worm's position on the grid.\r
- a = ussp(b) - ussl(b)\r
+ a = ussp(b%) - ussl(b%)\r
\r
IF a < 1 THEN\r
a = a + 2000\r
stat\r
END IF\r
\r
- FOR a = 1 TO ussm\r
+ FOR a = 1 TO playerCount\r
prc a\r
NEXT a\r
END SUB\r