GW-BASIC v3.22

This commit is contained in:
davidly 2024-07-01 15:48:45 -07:00
parent 259b1a1df8
commit b584a463b0
5 changed files with 173 additions and 0 deletions

View File

@ -0,0 +1,31 @@
100 DIGITS% = 200
110 DIM A%( 200 )
120 HIGH% = DIGITS%
130 X% = 0
140 N% = HIGH% - 1
150 IF N% <= 0 GOTO 200
160 A%[ N% ] = 1
170 N% = N% - 1
180 GOTO 150
200 A%[ 1 ] = 2
210 A%[ 0 ] = 0
220 IF HIGH% <= 9 GOTO 400
230 HIGH% = HIGH% - 1
235 N% = HIGH%
240 IF N% = 0 GOTO 300
250 A%[ N% ] = X% MOD N%
255 rem PRINT "a[n-1]"; A%[ N% - 1 ]
260 X% = ( 10 * A%[ N% - 1 ] ) + ( X% \ N% )
265 rem PRINT "x: "; X%, "n: "; N%
270 N% = N% - 1
280 GOTO 240
300 IF X% >= 10 GOTO 330
310 PRINT USING "#"; X%;
320 GOTO 220
330 PRINT USING "##"; X%;
340 GOTO 220
400 PRINT ""
410 PRINT "done"
420 SYSTEM

Binary file not shown.

View File

@ -0,0 +1,22 @@
1 SIZE% = 8190
2 DIM FLAGS%(8191)
3 PRINT "10 iterations"
4 FOR X% = 1 TO 10
5 COUNT% = 0
6 FOR I% = 0 TO SIZE%
7 FLAGS%(I%) = 1
8 NEXT I%
9 FOR I% = 0 TO SIZE%
10 IF FLAGS%(I%) = 0 THEN 18
11 PRIME% = I% + I% + 3
12 K% = I% + PRIME%
13 IF K% > SIZE% THEN 17
14 FLAGS%(K%) = 0
15 K% = K% + PRIME%
16 GOTO 13
17 COUNT% = COUNT% + 1
18 NEXT I%
19 NEXT X%
20 PRINT COUNT%," PRIMES"
21 SYSTEM

View File

@ -0,0 +1,119 @@
1 rem Tic Tac Toe solving app that learns what WOPR learned: you can't win
2 rem Only three starting positions are examined. Others are just reflections of these
3 rem b% -- The board
4 rem al% -- Alpha, for pruning
5 rem be% -- Beta, for pruning
6 rem l% -- Top-level loop iteration
7 rem wi% -- The winning piece (0 none, 1 X, 2, O )
8 rem re% -- Resulting score of 4000/minmax board position. 5 draw, 6 X win, 4 Y win
9 rem sx% -- Stack array for "recursion" X can be P, V, A, or B for those variables.
10 rem v% -- Value of a board position
11 rem st% -- Stack Pointer. Even for alpha/beta pruning Minimize plys, Odd for Maximize
12 rem p% -- Current position where a new piece is played
14 rem rw% -- Row in the Winner function (2000)
15 rem cw% -- Column in the Winner function (2000)
18 rem mc% -- Move count total for debugging. Should be a multiple of 6493
19 rem Note: Can't use real recursion with GOSUB because stack is limited to roughly 5 deep
20 rem BASIC doesn't support goto/gosub using arrays for target line numbers
21 print "date: "; date$
30 dim b%(9)
32 dim sp%(10)
34 dim sv%(10)
36 dim sa%(10)
37 dim sb%(10)
38 mc% = 0
39 print "start time: "; time$
40 for l% = 1 to 10
41 mc% = 0
42 al% = 2
43 be% = 9
44 b%(0) = 1
45 gosub 4000
58 al% = 2
59 be% = 9
60 b%(0) = 0
61 b%(1) = 1
62 gosub 4000
68 al% = 2
69 be% = 9
70 b%(1) = 0
71 b%(4) = 1
72 gosub 4000
73 b%(4) = 0
74 rem print "mc: "; mc%; " l is "; l%
80 next l%
85 print elap$ ; " for "; l% - 1; " iterations"
86 print "end time: "; time$
87 print "final move count "; mc%
90 system
100 end
2000 wi% = b%( 0 )
2010 if 0 = wi% goto 2100
2020 if wi% = b%( 1 ) and wi% = b%( 2 ) then return
2030 if wi% = b%( 3 ) and wi% = b%( 6 ) then return
2100 wi% = b%( 3 )
2110 if 0 = wi% goto 2200
2120 if wi% = b%( 4 ) and wi% = b%( 5 ) then return
2200 wi% = b%( 6 )
2210 if 0 = wi% goto 2300
2220 if wi% = b%( 7 ) and wi% = b%( 8 ) then return
2300 wi% = b%( 1 )
2310 if 0 = wi% goto 2400
2320 if wi% = b%( 4 ) and wi% = b%( 7 ) then return
2400 wi% = b%( 2 )
2410 if 0 = wi% goto 2500
2420 if wi% = b%( 5 ) and wi% = b%( 8 ) then return
2500 wi% = b%( 4 )
2510 if 0 = wi% then return
2520 if wi% = b%( 0 ) and wi% = b%( 8 ) then return
2530 if wi% = b%( 2 ) and wi% = b%( 6 ) then return
2540 wi% = 0
2550 return
4000 rem minmax function to find score of a board position
4010 rem recursion is simulated with gotos
4030 st% = 0
4040 v% = 0
4060 re% = 0
4100 mc% = mc% + 1
4102 rem gosub 3000
4104 if st% < 4 then goto 4150
4105 gosub 2000
4106 if 0 = wi% then goto 4140
4110 if wi% = 1 then re% = 6: goto 4280
4115 re% = 4
4116 goto 4280
4140 if st% = 8 then re% = 5: goto 4280
4150 if st% and 1 then v% = 2 else v% = 9
4160 p% = 0
4180 if 0 <> b%(p%) then goto 4500
4200 if st% and 1 then b%(p%) = 1 else b%(p%) = 2
4210 sp%(st%) = p%
4230 sv%(st%) = v%
4245 sa%(st%) = al%
4246 sb%(st%) = be%
4260 st% = st% + 1
4270 goto 4100
4280 st% = st% - 1
4290 p% = sp%(st%)
4310 v% = sv%(st%)
4325 al% = sa%(st%)
4326 be% = sb%(st%)
4328 b%(p%) = 0
4330 if st% and 1 then goto 4340
4331 if re% = 4 then goto 4530
4332 if re% < v% then v% = re%
4334 if v% < be% then be% = v%
4336 if be% <= al% then goto 4520
4338 goto 4500
4340 if re% = 6 then goto 4530
4341 if re% > v% then v% = re%
4342 if v% > al% then al% = v%
4344 if al% >= be% then goto 4520
4500 p% = p% + 1
4505 if p% < 9 then goto 4180
4520 re% = v%
4530 if st% = 0 then return
4540 goto 4280

View File

@ -0,0 +1 @@
ntvdm -c -p gwbasic %1.bas