Title: DIM A10
1DIM A(10)
2CLS 1
3let N 0
4PRINT 1 "Press any key when"
5PRINT 1 "you're ready to play"
6lab TARGET1
7let N N 1
8let ky0
9let kykey()
10IF ky0
11 GOTO TARGET1
12ENDIF
13CLS 1
14keyhide
15gosub board
16lab TARGET14
17CLS 1
18FOR N 1 TO 9
19let A(N)0
20NEXT
21 PRINT 1 "I'll have the first move"
22 GOTO TARGET2
23lab end
24end
25lab TARGET6
26GOSUB TARGET3
27IF FLAG 0
28 GOTO TARGET16
29endif
30GOSUB TARGET4
31IF A(X)A(Y) and A(Y)A(Z)andA(X)ltgt0
32 GOTO TARGET13
33ENDIF
34GOSUB TARGET5
35lab TARGET2
36GOSUB TARGET3
37IF FLAG 0
38 GOTO TARGET16
39endif
40GOSUB TARGET4
41IF A(X)A(Y) and A(Y)A(Z)andA(X)ltgt0
42 GOTO TARGET13
43ENDIF
44IF A(5) 0 let A(5)1
45 GOTO TARGET6
46ENDIF
47let D1 let B1
48lab TARGET9
49IF B 1
50 let X 1
51 let Y2
52 let Z 3
53ENDIF
54lab TARGET8
55IF B2
56 let X1
57 let Y4
58 let Z7
59ENDIF
60IF B3
61 let X1
62 let Y5
63 let Z9
64ENDIF
65IF B4
66 let X3
67 let Z7
68ENDIF
69let C1
70lab TARGET7
71IF A(X)D AND A(Y)D AND A(Z)0
72 let A(Z)1
73 GOTO TARGET6
74endif
75IF A(X)D AND A(Y)0 AND A(Z)D
76 let A(Y)1
77 GOTO TARGET6
78endif
79IF A(X)0 AND A(Y)D AND A(Z)D
80 let A(X)1
81 GOTO TARGET6
82endif
83IF B1
84 let XX3
85 let YY3
86 let ZZ3
87ENDIF
88IF B2
89 let XX1
90 let YY1
91 let ZZ1
92ENDIF
93IF Clt3
94 let C C 1
95 GOTO TARGET7
96ENDIF
97IF Blt4
98 let BB1
99 GOTO TARGET8
100ENDIF
101IF Dlt2
102 let DD 1
103 GOTO TARGET9
104ENDIF
105let B 1
106lab TARGET10
107let D rnd(9)
108IF A(C)0
109 let A(C)1
110 GOTO TARGET6
111ENDIF
112let BB1
113IF Blt9
114 GOTO TARGET10
115ENDIF
116let B 0
117lab TARGET11
118let BB1
119IF A(B)0
120 let A(B)1
121 GOTO TARGET6
122ENDIF
123IF Blt9
124 GOTO TARGET11
125ENDIF
126GOSUB TARGET3
127lab TARGET16
128 PRINT 1 ""
129 PRINT 1 "It's a draw!"
130 print 1 "Press any key"
131 print 1 "B to end"
132 gosub key
133 if kk203
134 goto end
135 endif
136 GOTO TARGET12
137sub TARGET4
138let win0
139FOR B 1 TO 4
140IF B 1 and win0
141 let X1
142 let Y2
143 let Z3
144ENDIF
145IF B2 and win0
146 let X1
147 let Y4
148 let Z7
149ENDIF
150IF B3 and win0
151 let X1
152 let Y5
153 let Z9
154ENDIF
155IF B4 and win0
156 let X 3
157 let Z 7
158ENDIF
159FOR C1 TO 3
160IF A(X)A(Y) and A(Y)A(Z)andA(X)ltgt0
161 let win1
162endif
163IF B 1 and win0
164 let XX3
165 let YY3
166 let ZZ3
167ENDIF
168IF B2 and win0
169 let XX1
170 let YY1
171 let ZZ1
172ENDIF
173NEXT
174NEXT
175RETURN
176lab TARGET13
177PRINT 1 ""
178IF A(X)1
179 PRINT 1 "I'm the winner!"
180ENDIF
181IF A(X)2
182 PRINT 1 "You're the winner!"
183ENDIF
184print 1 "Press any key"
185print 1 "B to end"
186gosub key
187 if kk203
188 goto end
189 endif
190lab TARGET12
191GOTO TARGET14
192sub TARGET5
193 PRINT 1 ""
194 PRINT 1 "Enter your move..."
195 print 1 "Using the stylus"
196lab TARGET15
197let p0
198while plt1 or pgt9 or A(p)ltgt0
199 gosub touch
200wend
201let Bp
202let A(B)2
203RETURN
204sub TARGET3
205let FLAG 0
206FOR B1 TO 9
207IF A(B)0
208 let FLAG1
209ENDIF
210let pB
211IF A(B)0
212 gosub drawd
213ENDIF
214if A(B)1
215 gosub drawo
216ENDIF
217IF A(B) 2
218 gosub drawx
219ENDIF
220next
221return
222sub touch
223let st0
224let p0
225while st0
226let ststt()
227wend
228 let sxstx()
229 let systy()
230if sxlt85
231 if sylt64
232 let p1
233 endif
234 if sygt64 and sylt128
235 let p4
236 endif
237 if sygt128
238 let p7
239 endif
240endif
241if sxgt85 and sxlt170
242 if sylt64
243 let p2
244 endif
245 if sygt64 and sylt128
246 let p5
247 endif
248 if sygt128
249 let p8
250 endif
251endif
252if sxgt170
253 if sylt64
254 let p3
255 endif
256 if sygt64 and sylt128
257 let p6
258 endif
259 if sygt128
260 let p9
261 endif
262endif
263return
264sub drawd
265 if p1
266 print 0 at 5,3 " "
267 endif
268 if p4
269 print 0 at 5,10 " "
270 endif
271 if p7
272 print 0 at 5,21 " "
273 endif
274 if p2
275 print 0 at 15,3 " "
276 endif
277 if p5
278 print 0 at 15,10 " "
279 endif
280 if p8
281 print 0 at 15,21 " "
282 endif
283 if p3
284 print 0 at 25,3 " "
285 endif
286 if p6
287 print 0 at 25,10 " "
288 endif
289 if p9
290 print 0 at 25,21 " "
291 endif
292return
293sub drawx
294if p1
295 print 0 at 5,3 "X"
296 endif
297 if p4
298 print 0 at 5,10 "X"
299 endif
300 if p7
301 print 0 at 5,21 "X"
302 endif
303 if p2
304 print 0 at 15,3 "X"
305 endif
306 if p5
307 print 0 at 15,10 "X"
308 endif
309 if p8
310 print 0 at 15,21 "X"
311 endif
312 if p3
313 print 0 at 25,3 "X"
314 endif
315 if p6
316 print 0 at 25,10 "X"
317 endif
318 if p9
319 print 0 at 25,21 "X"
320 endif
321return
322sub drawo
323 if p1
324 print 0 at 5,3 "o"
325 endif
326 if p4
327 print 0 at 5,10 "o"
328 endif
329 if p7
330 print 0 at 5,21 "o"
331 endif
332 if p2
333 print 0 at 15,3 "o"
334 endif
335 if p5
336 print 0 at 15,10 "o"
337 endif
338 if p8
339 print 0 at 15,21 "o"
340 endif
341 if p3
342 print 0 at 25,3 "o"
343 endif
344 if p6
345 print 0 at 25,10 "o"
346 endif
347 if p9
348 print 0 at 25,21 "o"
349 endif
350return
351sub key
352let kk0
353while kk0
354let kkkey()
355wend
356return
357sub board
358 line 0 85,0,85,192,1
359 line 0 170,0,170,192,1
360 line 0 0,64,256,64,1
361 line 0 0,128,256,128,1
362return