-
Notifications
You must be signed in to change notification settings - Fork 0
/
SALVO.BAS
367 lines (367 loc) · 8.88 KB
/
SALVO.BAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
5 RANDOMIZE
999 PRINT CHR$(26):WIDTH 80
1000 PRINT TAB(33);"SALVO":PRINT
1010 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
1020 PRINT:PRINT:PRINT
1021 INPUT "DO YOU WANT INSTRUCTIONS";ANS$
1022 IF LEFT$(ANS$,1)="Y" THEN GOSUB 20000
1025 PRINT "PLEASE STAND BY....":PRINT
1030 REM
1040 DIM A(10,10),B(10,10),C(7),D(7),E(12),F(12),G(12),H(12),K(10,10)
1050 Z8=0
1060 FOR W=1 TO 12
1070 E(W)=-1
1080 H(W)=-1
1090 NEXT W
1100 FOR X=1 TO 10
1110 FOR Y=1 TO 10
1120 B(X,Y)=0
1130 NEXT Y
1140 NEXT X
1150 FOR X=1 TO 12
1160 F(X)=0
1170 G(X)=0
1180 NEXT X
1190 FOR X=1 TO 10
1200 FOR Y=1 TO 10
1210 A(X,Y)=0
1220 NEXT Y
1230 NEXT X
1240 FOR K=4 TO 1 STEP -1
1250 U6=0
1260 GOSUB 2910
1270 DEF FNA(K)=(5-K)*3-2*INT(K/4)+SGN(K-1)-1
1280 DEF FNB(K)=K+INT(K/4)-SGN(K-1)
1290 IF V+V2+V*V2=0 THEN 1260
1300 IF Y+V*FNB(K)>10 THEN 1260
1310 IF Y+V*FNB(K)<1 THEN 1260
1320 IF X+V2*FNB(K)>10 THEN 1260
1330 IF X+V2*FNB(K)<1 THEN 1260
1340 U6=U6+1
1350 IF U6>25 THEN 1190
1360 FOR Z=0 TO FNB(K)
1370 F(Z+FNA(K))=X+V2*Z
1380 G(Z+FNA(K))=Y+V*Z
1390 NEXT Z
1400 U8=FNA(K)
1405 IF U8>U8+FNB(K) THEN 1460
1410 FOR Z2= U8 TO U8+FNB(K)
1415 IF U8<2 THEN 1450
1420 FOR Z3=1 TO U8-1
1430 IF SQR((F(Z3)-F(Z2))^2 + (G(Z3)-G(Z2))^2) < 3.59 THEN 1260
1440 NEXT Z3
1450 NEXT Z2
1460 FOR Z=0 TO FNB(K)
1470 A(F(Z+U8),G(Z+U8))=.5+SGN(K-1)*(K-1.5)
1480 NEXT Z
1490 NEXT K
1500 PRINT:PRINT "ENTER COORDINATES FOR...":PRINT
1510 PRINT "BATTLESHIP"
1515 PRINT "----------"
1520 FOR X=1 TO 5
1530 INPUT Y,Z
1540 B(Y,Z)=3
1550 NEXT X
1560 PRINT:PRINT "CRUISER"
1565 PRINT "-------"
1570 FOR X=1 TO 3
1580 INPUT Y,Z
1590 B(Y,Z)=2
1600 NEXT X
1610 PRINT:PRINT "DESTROYER<A>"
1615 PRINT "------------"
1620 FOR X=1 TO 2
1630 INPUT Y,Z
1640 B(Y,Z)=1
1650 NEXT X
1660 PRINT:PRINT "DESTROYER<B>"
1665 PRINT "------------"
1670 FOR X=1 TO 2
1680 INPUT Y,Z
1690 B(Y,Z)=.5
1700 NEXT X
1710 PRINT:PRINT "DO YOU WANT TO START";
1720 INPUT J$
1730 IF J$<>"WHERE ARE YOUR SHIPS?" THEN 1890
1740 PRINT:PRINT "BATTLESHIP"
1745 PRINT "----------"
1750 FOR Z=1 TO 5
1760 PRINT F(Z);G(Z)
1770 NEXT Z
1780 PRINT:PRINT "CRUISER"
1785 PRINT "-------"
1790 PRINT F(6);G(6)
1800 PRINT F(7);G(7)
1810 PRINT F(8);G(8)
1820 PRINT:PRINT "DESTROYER<A>"
1825 PRINT "------------"
1830 PRINT F(9);G(9)
1840 PRINT F(10);G(10)
1850 PRINT:PRINT "DESTROYER<B>"
1855 PRINT "------------"
1860 PRINT F(11);G(11)
1870 PRINT F(12);G(12)
1880 GOTO 1710
1890 C=0
1900 PRINT:PRINT "DO YOU WANT TO SEE MY SHOTS";
1910 INPUT K$
1920 PRINT
1930 IF LEFT$(J$,1)<>"Y" THEN 2620
1940 REM*******************START
1950 IF LEFT$(J$,1)<>"Y" THEN 1990
1960 C=C+1
1970 PRINT
1980 PRINT "TURN";C
1985 PRINT "-------"
1990 A=0
2000 FOR W=.5 TO 3 STEP .5
2010 FOR X=1 TO 10
2020 FOR Y=1 TO 10
2030 IF B(X,Y)=W THEN 2070
2040 NEXT Y
2050 NEXT X
2060 GOTO 2080
2070 A=A+INT(W+.5)
2080 NEXT W
2090 FOR W=1 TO 7
2100 C(W)=0
2110 D(W)=0
2120 F(W)=0
2130 G(W)=0
2140 NEXT W
2150 P3=0
2160 FOR X=1 TO 10
2170 FOR Y=1 TO 10
2180 IF A(X,Y)>10 THEN 2200
2190 P3=P3+1
2200 NEXT Y
2210 NEXT X
2220 PRINT "YOU HAVE";A;"SHOTS."
2230 IF P3>=A THEN 2260
2240 PRINT "YOU HAVE MORE SHOTS THAN THERE ARE BLANK SQUARES."
2250 GOTO 2890
2260 IF A<>0 THEN 2290
2270 PRINT "I HAVE WON."
2280 FOR XX=1 TO 2000:NEXT:RUN "MENU"
2290 FOR W=1 TO A
2300 INPUT X,Y
2310 IF X<>INT(X) THEN 2370
2320 IF X>10 THEN 2370
2330 IF X<1 THEN 2370
2340 IF Y<>INT(Y) THEN 2370
2350 IF Y>10 THEN 2370
2360 IF Y>=1 THEN 2390
2370 PRINT "ILLEGAL, ENTER AGAIN."
2380 GOTO 2300
2390 IF A(X,Y)>10 THEN 2440
2400 C(W)=X
2410 D(W)=Y
2420 NEXT W
2430 GOTO 2460
2440 PRINT "YOU SHOT THERE BEFORE ON TURN";A(X,Y)-10;CHR$(8);"."
2450 GOTO 2300
2460 FOR W=1 TO A
2470 IF A(C(W),D(W))=3 THEN 2540
2480 IF A(C(W),D(W))=2 THEN 2560
2490 IF A(C(W),D(W))=1 THEN 2580
2500 IF A(C(W),D(W))=.5 THEN 2600
2510 A(C(W),D(W))=10+C
2520 NEXT W
2530 GOTO 2620
2540 PRINT "YOU HIT MY BATTLESHIP."
2550 GOTO 2510
2560 PRINT "YOU HIT MY CRUISER."
2570 GOTO 2510
2580 PRINT "YOU HIT MY DESTROYER<A>."
2590 GOTO 2510
2600 PRINT "YOU HIT MY DESTROYER<B>."
2610 GOTO 2510
2620 A=0
2630 IF LEFT$(J$,1)="Y" THEN 2670
2640 C=C+1
2650 PRINT
2660 PRINT "TURN";C
2665 PRINT "-------"
2670 A=0
2680 FOR W=.5 TO 3 STEP .5
2690 FOR X=1 TO 10
2700 FOR Y=1 TO 10
2710 IF A(X,Y)=W THEN 2750
2720 NEXT Y
2730 NEXT X
2740 GOTO 2760
2750 A=A+INT(W+.5)
2760 NEXT W
2770 P3=0
2780 FOR X=1 TO 10
2790 FOR Y=1 TO 10
2800 IF A(X,Y)>10 THEN 2820
2810 P3=P3+1
2820 NEXT Y
2830 NEXT X
2840 PRINT "I HAVE";A;"SHOTS."
2850 IF P3>A THEN 2880
2860 PRINT "I HAVE MORE SHOTS THAN BLANK SQUARES."
2870 GOTO 2270
2880 IF A<>0 THEN 2960
2890 PRINT "YOU HAVE WON."
2900 FOR XX=1 TO 2000:NEXT:RUN "MENU"
2910 X=INT(RND(1)*10+1)
2920 Y=INT(RND(1)*10+1)
2930 V=INT(3*RND(1)-1)
2940 V2=INT(3*RND(1)-1)
2950 RETURN
2960 FOR W=1 TO 12
2970 IF H(W)>0 THEN 3800
2980 NEXT W
2990 REM*******************RANDOM
3000 W=0
3010 R3=0
3020 GOSUB 2910
3030 RESTORE
3040 R2=0
3050 R3=R3+1
3060 IF R3>100 THEN 3010
3070 IF X>10 THEN 3110
3080 IF X>0 THEN 3120
3090 X=1+INT(RND(1)*2.5)
3100 GOTO 3120
3110 X=10-INT(RND(1)*2.5)
3120 IF Y>10 THEN 3160
3130 IF Y>0 THEN 3270
3140 Y=1+INT(RND(1)*2.5)
3150 GOTO 3270
3160 Y=10-INT(RND(1)*2.5)
3170 GOTO 3270
3180 F(W)=X
3190 G(W)=Y
3200 IF W=A THEN 3380
3210 IF R2=6 THEN 3030
3220 READ X1,Y1
3230 R2=R2+1
3240 DATA 1,1,-1,1,1,-3,1,1,0,2,-1,1
3250 X=X+X1
3260 Y=Y+Y1
3270 IF X>10 THEN 3210
3280 IF X<1 THEN 3210
3290 IF Y>10 THEN 3210
3300 IF Y<1 THEN 3210
3310 IF B(X,Y)>10 THEN 3210
3320 FOR Q9=1 TO W
3330 IF F(Q9)<>X THEN 3350
3340 IF G(Q9)=Y THEN 3210
3350 NEXT Q9
3360 W=W+1
3370 GOTO 3180
3380 IF LEFT$(K$,1)<>"Y" THEN 3420
3390 FOR Z5=1 TO A
3400 PRINT F(Z5);G(Z5)
3410 NEXT Z5
3420 FOR W=1 TO A
3430 IF B(F(W),G(W))=3 THEN 3500
3440 IF B(F(W),G(W))=2 THEN 3520
3450 IF B(F(W),G(W))=1 THEN 3560
3460 IF B(F(W),G(W))=.5 THEN 3540
3470 B(F(W),G(W))=10+C
3480 NEXT W
3490 GOTO 1950
3500 PRINT "I HIT YOUR BATTLESHIP"
3510 GOTO 3570
3520 PRINT "I HIT YOUR CRUISER"
3530 GOTO 3570
3540 PRINT "I HIT YOUR DESTROYER<B>"
3550 GOTO 3570
3560 PRINT "I HIT YOUR DESTROYER<A>"
3570 FOR Q=1 TO 12
3580 IF E(Q)<>-1 THEN 3730
3590 E(Q)=10+C
3600 H(Q)=B(F(W),G(W))
3610 M3=0
3620 FOR M2=1 TO 12
3630 IF H(M2)<>H(Q) THEN 3650
3640 M3=M3+1
3650 NEXT M2
3660 IF M3<>INT(H(Q)+.5)+1+INT(INT(H(Q)+.5)/3) THEN 3470
3670 FOR M2=1 TO 12
3680 IF H(M2)<>H(Q) THEN 3710
3690 E(M2)=-1
3700 H(M2)=-1
3710 NEXT M2
3720 GOTO 3470
3730 NEXT Q
3740 PRINT "PROGRAM ABORT:"
3750 FOR Q=1 TO 12
3760 PRINT "E(";Q;") =";E(Q)
3770 PRINT "H(";Q;") =";H(Q)
3780 NEXT Q
3790 FOR XX=1 TO 2000:NEXT:RUN "MENU"
3800 REM************************USINGEARRAY
3810 FOR R=1 TO 10
3820 FOR S=1 TO 10
3830 K(R,S)=0
3840 NEXT S
3850 NEXT R
3860 FOR U=1 TO 12
3870 IF E(U)<10 THEN 4020
3880 FOR R=1 TO 10
3890 FOR S=1 TO 10
3900 IF B(R,S)<10 THEN 3930
3910 K(R,S)=-10000000#
3920 GOTO 4000
3930 FOR M=SGN(1-R) TO SGN(10-R)
3940 FOR N=SGN(1-S) TO SGN(10-S)
3950 IF N+M+N*M=0 THEN 3980
3960 IF B(R+M,S+N)<>E(U) THEN 3980
3970 K(R,S)=K(R,S)+E(U)-S*INT(H(U)+.5)
3980 NEXT N
3990 NEXT M
4000 NEXT S
4010 NEXT R
4020 NEXT U
4030 FOR R=1 TO A
4040 F(R)=R
4050 G(R)=R
4060 NEXT R
4070 FOR R=1 TO 10
4080 FOR S=1 TO 10
4090 Q9=1
4100 FOR M=1 TO A
4110 IF K(F(M),G(M))>=K(F(Q9),G(Q9)) THEN 4130
4120 Q9=M
4130 NEXT M
4131 IF R>A THEN 4140
4132 IF R=S THEN 4210
4140 IF K(R,S)<K(F(Q9),G(Q9)) THEN 4210
4150 FOR M=1 TO A
4160 IF F(M)<>R THEN 4190
4170 IF G(M)=S THEN 4210
4180 NEXT M
4190 F(Q9)=R
4200 G(Q9)=S
4210 NEXT S
4220 NEXT R
4230 GOTO 3380
4240 RUN "MENU"
20000 PRINT CHR$(26)
20010 PRINT " SALVO IS PLAYED ON A 10X10 GRID USING AN X,Y COORDINATE"
20020 PRINT "SYSTEM. THE PLAYER HAS 4 SHIPS: BATTLESHIP (5 SQUARES),"
20030 PRINT "CRUISER (3 SQUARES), AND TWO DESTROYERS (2 SQUARES EACH)."
20040 PRINT "THE SHIPS MUST BE PLACED HORIZONTALLY, VERTICALLY, OR"
20050 PRINT "DIAGONALLY AND MUST NOT OVERLAP. THE SHIPS DO NOT MOVE"
20060 PRINT "DURING THE GAME."
20070 PRINT
20080 PRINT " AS LONG AS ANY SQUARE OF A BATTLESHIP STILL SURVIVES,"
20090 PRINT "THE PLAYER IS ALLOWED THREE SHOTS, FOR A CRUISER TWO"
20100 PRINT "SHOTS, AND FOR EACH DESTROYER ONE SHOT. THUS, AT THE "
20110 PRINT "BEGINNING OF THE GAME THE PLAYER HAS 3+2+1+1 = 7 SHOTS."
20120 PRINT "THE PLAYER ENTERS ALL OF HIS SHOTS AND THE COMPUTER"
20130 PRINT "TELLS WHAT WAS HIT. A SHOT IS ENTERED BY ITS GRID"
20140 PRINT "COORDINATES, X,Y. THE WINNER IS THE ONE WHO SINKS ALL"
20150 PRINT "OF THE OPPONENT'S SHIPS."
20160 PRINT
20170 PRINT " NOTE: YOUR SHIPS AND THE COMPUTERS SHIPS ARE LOCATED"
20180 PRINT "ON TWO SEPARATE 10X10 BOARDS."
20190 PRINT:PRINT
20200 LINE INPUT "ENTER 'RETURN' TO START THE GAME. ";RESP$:PRINT CHR$(26)
20210 RETURN