-
Notifications
You must be signed in to change notification settings - Fork 0
/
tictactoe.asm
2487 lines (2156 loc) · 45.7 KB
/
tictactoe.asm
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!to "TICTACTOE.PRG", cbm
!zone main{
*=$0801 ;Assembled code should start at $0801
; (where BASIC programs start)
; The real program starts at $0810 = 2064
!byte $0C,$08 ; $080C - pointer to next line of BASIC code
!byte $0A,$00 ; 2-byte line number ($000A = 10)
!byte $9E ; SYS BASIC token
!byte $20 ; [space]
!byte $32,$30,$36,$34 ; $32="2",$30="0",$36="6",$34="4"
; (ASCII encoded nums for dec starting addr)
!byte $00 ; End of Line
!byte $00,$00 ; This is address $080C containing
; 2-byte pointer to next line of BASIC code
; ($0000 = end of program)
*=$0810 ; Here starts the real program
;Define constants
PLOT=$FFF0
CHROUT=$FFD2
CHRIN=$FFCF
GETIN=$FFE4
SWITCH=$FF5F
COLPORT=$0376
COLUMNS=$0386
TMP0=$00
TMP1=$01
TMP2=$02
TMP3=$03
TMP4=$04
TMP5=$05
TMP6=$06
TMP7=$07
TMP8=$08
TMP9=$09
QUIT=$0A
PLYR=$0B
TURN=$0C
;PETDraw Chars
Space=" "
GHLine=96
GVLine=125
MidInter=123
LefInter=171
BotInter=177
RigInter=179
TopInter=178
TLcorner=176
TRcorner=174
BLcorner=173
BRcorner=189
Xses=88
Oses=79
startagain:
jsr initscr
jsr resetcounter
jsr welcome
lda QUIT
bne .endgame
lda PLYR
beq +
jsr initscr
jsr Welcome_2
lda QUIT
bne .endgame
+ jsr gboard
jsr gameloop
lda QUIT
bne .endgame
jsr endloop
lda QUIT
bne .endgame
.endgame ;End program by doing a reset
lda #0 ; Set ROM page to 0
sta $9F60
jmp ($FFFC) ; Jump to address stored at $FFFC
rts ;End of program
;************************************************************************
;Make Welcome screen 2, where user can choose to play as X or O
;************************************************************************
Welcome_2:
lda #$01
sta COLPORT
ldx #3
stx TMP8
ldy #2
sty TMP9
jsr GoXY
ldx #<.ttt1
ldy #>.ttt1
jsr PrintStr
jsr .nxtline
ldx #<.ttt2
ldy #>.ttt2
jsr PrintStr
jsr .nxtline
ldx #<.ttt3
ldy #>.ttt3
jsr PrintStr
jsr .nxtline
ldx #<.ttt4
ldy #>.ttt4
jsr PrintStr
jsr .nxtline
ldx #<.ttt5
ldy #>.ttt5
jsr PrintStr
inc TMP9
jsr .nxtline
jsr .nxtline
ldx #<.grt10
ldy #>.grt10
jsr PrintStr
jsr .nxtline
jsr .nxtline
ldx #<.grt11
ldy #>.grt11
jsr PrintStr
jsr .nxtline
jsr X_or_O
jsr initscr
rts
;************************************************************************
;Find out if user wants to play as X or O
;************************************************************************
X_or_O
inc .rndnum
jsr GETIN
cmp #'Q'
bne @x
lda #1
sta QUIT
jmp @end_x_or_o
@x cmp #'1'
bne @o
jmp @end_x_or_o
@o cmp#'2'
bne X_or_O
lda #1
sta TURN
inc PLYR
@end_x_or_o
rts
;************************************************************************
;*Make A.I. functions *
;************************************************************************
;INPUT: PLYR and .count
;************************************************************************
;OUTPUT: A loaded with "keypress"
;************************************************************************
ai_move:
tax ;Transfer A (GETIN) to X
lda PLYR ;We need to check if AI may move
cmp #1
bcs + ;If PLYR>0 AI may move
jmp Ai_no_move
+ lda TURN ;If TURN is 0 then we wait for human
bne +
jmp Ai_no_move
+ lda PLYR
cmp #1 ;If PLYR=1 AI is O else AI is X
beq @cnt8 ;If PLYR=2 then no need to check .count = 9
lda .count
cmp #9 ;If count is 9 then take center tile
bne @cnt8
@cntr_tl
lda .keypress +4 ;Load keypress number into A
jmp End_ai
;************************************************************************
;If AI moves second then its first objective is to get center tile
;if it is not available then just choose a random tile
;************************************************************************
;INPUT: .Occ_place, .count and A
;************************************************************************
;OUTPUT: A loaded with keypress
;************************************************************************
@cnt8
lda .count
cmp #8 ;Is .count 8
bne @remaining_moves ;If not then continue on
lda .Occ_place +4 ;Load state of center tile
beq + ;If not available choose random tile
jmp Rnd_tl
+ jmp @cntr_tl ;If available then choose it
;************************************************************************
;Function that defines how AI should move, if not one of the first two moves
;************************************************************************
;INPLUT: .rndnum and A
;************************************************************************
;OUTPUT: A loaded with relevant keypress
;************************************************************************
@remaining_moves
lda .rndnum ;If rndnum is over 13
and #$0F ;Then choose random tile
cmp #13 ;Otherwise AI always wins
bcc @chk_nw_1 ;AI chooses random approx. 20% of the moves
jmp Rnd_tl ;Gives a win ratio of approx. 60/40
;************************************************************************
;Check if AI is close to a win
;************************************************************************
@chk_nw_1
jsr Reset_scores ;Reset Human_score and Ai_score
ldx #1 ;Load X with number 1 so that we can load
jsr Load_near_wins ;the right scenario
jsr Check_nw ;Check if AI has two matches of scenario
lda Ai_score
cmp #2
bne @chk_nw_2 ;If scenario 1 is not matched then check next
lda .Occ_place +6 ;Is the tile available so we can win?
bne @chk_nw_2 ;If we cannot then check next scenario
lda .keypress +6 ;Load A with the number for matching keypress
jmp End_ai ;Go back to gameloop with keypress loaded
@chk_nw_2
jsr Reset_scores
ldx #2
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_3
lda .Occ_place +8
bne @chk_nw_3
lda .keypress +8
jmp End_ai
@chk_nw_3
jsr Reset_scores
ldx #3
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_4
lda .Occ_place +2
bne @chk_nw_4
lda .keypress +2
jmp End_ai
@chk_nw_4
jsr Reset_scores
ldx #4
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_5
lda .Occ_place +0
bne @chk_nw_5
lda .keypress +0
jmp End_ai
@chk_nw_5
jsr Reset_scores
ldx #5
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_6
lda .Occ_place +6
bne @chk_nw_6
lda .keypress +6
jmp End_ai
@chk_nw_6
jsr Reset_scores
ldx #6
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_7
lda .Occ_place +7
bne @chk_nw_7
lda .keypress +7
jmp End_ai
@chk_nw_7
jsr Reset_scores
ldx #7
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_8
lda .Occ_place +8
bne @chk_nw_8
lda .keypress +8
jmp End_ai
@chk_nw_8
jsr Reset_scores
ldx #8
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_9
lda .Occ_place +2
bne @chk_nw_9
lda .keypress +2
jmp End_ai
@chk_nw_9
jsr Reset_scores
ldx #9
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_10
lda .Occ_place +5
bne @chk_nw_10
lda .keypress +5
jmp End_ai
@chk_nw_10
jsr Reset_scores
ldx #10
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_12
lda .Occ_place +8
bne @chk_nw_11
lda .keypress +8
jmp End_ai
@chk_nw_11
jsr Reset_scores
ldx #11
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_12
lda .Occ_place +0
bne @chk_nw_12
lda .keypress +0
jmp End_ai
@chk_nw_12
jsr Reset_scores
ldx #12
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_13
lda .Occ_place +3
bne @chk_nw_13
lda .keypress +3
jmp End_ai
@chk_nw_13
jsr Reset_scores
ldx #13
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_14
lda .Occ_place +6
bne @chk_nw_14
lda .keypress +6
jmp End_ai
@chk_nw_14
jsr Reset_scores
ldx #14
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_15
lda .Occ_place +0
bne @chk_nw_15
lda .keypress +0
jmp End_ai
@chk_nw_15
jsr Reset_scores
ldx #15
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_16
lda .Occ_place +1
bne @chk_nw_16
lda .keypress +1
jmp End_ai
@chk_nw_16
jsr Reset_scores
ldx #16
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_17
lda .Occ_place +2
bne @chk_nw_17
lda .keypress +2
jmp End_ai
@chk_nw_17
jsr Reset_scores
ldx #17
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_18
lda .Occ_place +3
bne @chk_nw_18
lda .keypress +3
jmp End_ai
@chk_nw_18
jsr Reset_scores
ldx #18
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_19
lda .Occ_place +1
bne @chk_nw_19
lda .keypress +1
jmp End_ai
@chk_nw_19
jsr Reset_scores
ldx #19
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_20
lda .Occ_place +5
bne @chk_nw_20
lda .keypress +5
jmp End_ai
@chk_nw_20
jsr Reset_scores
ldx #20
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_21
lda .Occ_place +7
bne @chk_nw_21
lda .keypress +7
jmp End_ai
@chk_nw_21
jsr Reset_scores
ldx #21
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_nw_22
lda .Occ_place +4
bne @chk_nw_22
lda .keypress +4
jmp End_ai
@chk_nw_22
jsr Reset_scores
ldx #22
jsr Load_near_wins
jsr Check_nw
lda Ai_score
cmp #2
bne @chk_human_1
lda .Occ_place +3
bne @chk_human_1
lda .keypress +3
jmp End_ai
;************************************************************************
;Check if human is close to a win
;************************************************************************
@chk_human_1
jsr Reset_scores ;Reset human and ai score
ldx #1 ;Load X with 1 so we can load 1st scenario
jsr Load_near_wins ;Go load near win scenario into ZP
jsr Check_nw ;Check for matches
lda Human_score ;Is human close to this win?
cmp #2
bne @chk_human_2 ;If not then check next scenario
lda .Occ_place +6 ;Is the tile available so we can block the win
bne @chk_human_2 ;If not then check next scenario
lda .keypress +6 ;Load A with the relevant keypress number
jmp End_ai ;Go back to gameloop and block the win
@chk_human_2
jsr Reset_scores
ldx #2
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_3
lda .Occ_place +8
bne @chk_human_3
lda .keypress +8
jmp End_ai
@chk_human_3
jsr Reset_scores
ldx #3
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_4
lda .Occ_place +2
bne @chk_human_4
lda .keypress +2
jmp End_ai
@chk_human_4
jsr Reset_scores
ldx #4
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_5
lda .Occ_place +0
bne @chk_human_5
lda .keypress +0
jmp End_ai
@chk_human_5
jsr Reset_scores
ldx #5
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_6
lda .Occ_place +6
bne @chk_human_6
lda .keypress +6
jmp End_ai
@chk_human_6
jsr Reset_scores
ldx #6
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_7
lda .Occ_place +7
bne @chk_human_7
lda .keypress +7
jmp End_ai
@chk_human_7
jsr Reset_scores
ldx #7
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_8
lda .Occ_place +8
bne @chk_human_8
lda .keypress +8
jmp End_ai
@chk_human_8
jsr Reset_scores
ldx #8
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_9
lda .Occ_place +2
bne @chk_human_9
lda .keypress +2
jmp End_ai
@chk_human_9
jsr Reset_scores
ldx #9
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_10
lda .Occ_place +5
bne @chk_human_10
lda .keypress +5
jmp End_ai
@chk_human_10
jsr Reset_scores
ldx #10
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_11
lda .Occ_place +8
bne @chk_human_11
lda .keypress +8
jmp End_ai
@chk_human_11
jsr Reset_scores
ldx #11
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_12
lda .Occ_place +0
bne @chk_human_12
lda .keypress +0
jmp End_ai
@chk_human_12
jsr Reset_scores
ldx #12
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_13
lda .Occ_place +3
bne @chk_human_13
lda .keypress +3
jmp End_ai
@chk_human_13
jsr Reset_scores
ldx #13
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_14
lda .Occ_place +6
bne @chk_human_14
lda .keypress +6
jmp End_ai
@chk_human_14
jsr Reset_scores
ldx #14
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_15
lda .Occ_place +0
bne @chk_human_15
lda .keypress +0
jmp End_ai
@chk_human_15
jsr Reset_scores
ldx #15
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_16
lda .Occ_place +1
bne @chk_human_16
lda .keypress +1
jmp End_ai
@chk_human_16
jsr Reset_scores
ldx #16
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_17
lda .Occ_place +2
bne @chk_human_17
lda .keypress +2
jmp End_ai
@chk_human_17
jsr Reset_scores
ldx #17
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_18
lda .Occ_place +3
bne @chk_human_18
lda .keypress +3
jmp End_ai
@chk_human_18
jsr Reset_scores
ldx #18
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_19
lda .Occ_place +1
bne @chk_human_19
lda .keypress +1
jmp End_ai
@chk_human_19
jsr Reset_scores
ldx #19
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_20
lda .Occ_place +5
bne @chk_human_20
lda .keypress +5
jmp End_ai
@chk_human_20
jsr Reset_scores
ldx #20
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_21
lda .Occ_place +7
bne @chk_human_21
lda .keypress +7
jmp End_ai
@chk_human_21
jsr Reset_scores
ldx #21
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
bne @chk_human_22
lda .Occ_place +4
bne @chk_human_22
lda .keypress +4
jmp End_ai
@chk_human_22
jsr Reset_scores
ldx #22
jsr Load_near_wins
jsr Check_nw
lda Human_score
cmp #2
beq +
- jmp Rnd_tl
+ lda .Occ_place +3
bne -
lda .keypress +3
jmp End_ai
;************************************************************************
;Load near win scenarios into TMP0 og TMP1
;************************************************************************
Load_near_wins
cpx #1 ;Check X for requested newar win scenario
bne @nw2 ;If X not 1 then check the next
lda #<.nw1 ;Loading near win scenario
sta TMP0 ;into zeropage
lda #>.nw1
sta TMP1
jmp @end_load_nw ;Go return to the ai function
@nw2 cpx #2
bne @nw3
lda #<.nw2
sta TMP0
lda #>.nw2
sta TMP1
jmp @end_load_nw
@nw3 cpx #3
bne @nw4
lda #<.nw3
sta TMP0
lda #>.nw3
sta TMP1
jmp @end_load_nw
@nw4 cpx #4
bne @nw5
lda #<.nw4
sta TMP0
lda #>.nw4
sta TMP1
jmp @end_load_nw
@nw5 cpx #5
bne @nw6
lda #<.nw5
sta TMP0
lda #>.nw5
sta TMP1
jmp @end_load_nw
@nw6 cpx #6
bne @nw7
lda #<.nw6
sta TMP0
lda #>.nw6
sta TMP1
jmp @end_load_nw
@nw7 cpx #7
bne @nw8
lda #<.nw7
sta TMP0
lda #>.nw7
sta TMP1
jmp @end_load_nw
@nw8 cpx #8
bne @nw9
lda #<.nw8
sta TMP0
lda #>.nw8
sta TMP1
jmp @end_load_nw
@nw9 cpx #9
bne @nw10
lda #<.nw9
sta TMP0
lda #>.nw9
sta TMP1
jmp @end_load_nw
@nw10 cpx #10
bne @nw11
lda #<.nw10
sta TMP0
lda #>.nw10
sta TMP1
jmp @end_load_nw
@nw11 cpx #11
bne @nw12
lda #<.nw11
sta TMP0
lda #>.nw11
sta TMP1
jmp @end_load_nw
@nw12 cpx #12
bne @nw13
lda #<.nw12
sta TMP0
lda #>.nw12
sta TMP1
jmp @end_load_nw
@nw13 cpx #13
bne @nw14
lda #<.nw13
sta TMP0
lda #>.nw13
sta TMP1
jmp @end_load_nw
@nw14 cpx #14
bne @nw15
lda #<.nw14
sta TMP0
lda #>.nw14
sta TMP1
jmp @end_load_nw
@nw15 cpx #15
bne @nw16
lda #<.nw15
sta TMP0
lda #>.nw15
sta TMP1
jmp @end_load_nw
@nw16 cpx #16
bne @nw17
lda #<.nw16
sta TMP0
lda #>.nw16
sta TMP1
jmp @end_load_nw
@nw17 cpx #17
bne @nw18
lda #<.nw17
sta TMP0
lda #>.nw17
sta TMP1
jmp @end_load_nw
@nw18 cpx #18
bne @nw19
lda #<.nw18
sta TMP0
lda #>.nw18
sta TMP1
jmp @end_load_nw
@nw19 cpx #19
bne @nw20
lda #<.nw19
sta TMP0
lda #>.nw19
sta TMP1
jmp @end_load_nw
@nw20 cpx #20
bne @nw21
lda #<.nw20
sta TMP0
lda #>.nw20
sta TMP1
jmp @end_load_nw
@nw21 cpx #21
bne @nw22
lda #<.nw21
sta TMP0
lda #>.nw21
sta TMP1
jmp @end_load_nw
@nw22 lda #<.nw22
sta TMP0
lda #>.nw22
sta TMP1
@end_load_nw
rts
;************************************************************************
;Reset Human_score and Ai_score
;************************************************************************
Reset_scores
ldy #9 ;We need Y as byte counter
lda #0 ;Reset Human_score and Ai_score
sta Human_score
sta Ai_score
rts
;************************************************************************
;Ending AI routine
;************************************************************************
End_ai ;Return to gameloop with AI move
rts
Ai_no_move ;Return to gameloop with no change to A
txa ;Transfer X back to A (GETIN)
rts
;************************************************************************
;This function checks if AI is close to winning if so, then do
;If not then check if human is winning if so, then block