-
Notifications
You must be signed in to change notification settings - Fork 0
/
xomain.asm
1362 lines (1189 loc) · 26.9 KB
/
xomain.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
;Adam Cohen Hillel ExEgol Project
;Build At: April 2015
;Herzog School, Kfar Sava
;Gvahim
;
IDEAL
;-------------------------------------------------------------
; PRINT_Vertical_LINE - print on Screen A vertical (|) Line
;-------------------------------------------------------------
; Input:
; xstart
; ystart
; len
; Output:
; vertical Line On Screen
; Registers Used
; BX, CX, AX, DX
;
;----------------------------------------------------------
MACRO PRINT_Vertical_LINE xstart, ystart, len
local @@PrintAnahiLineLoop
mov cx, len
xor bx, bx
@@PrintAnahiLineLoop:
push cx
push bx
add bx, ystart
mov dx,bx ;dx - y
mov cx, xstart ;cx - x
mov bh,0h
mov al,[colorLine]
mov ah,0ch
int 10h
pop bx
push bx
add bx, ystart
mov dx,bx ;dx - y
mov cx, xstart+1 ;cx - x
mov bh,0h
int 10h
pop bx
inc bx
pop cx
loop @@PrintAnahiLineLoop
ENDM PRINT_Vertical_LINE
;-------------------------------------------------------------
; PRINT_Horizontal_LINE - print on Screen A Horizontal (-) Line
;-------------------------------------------------------------
; Input:
; xstart
; ystart
; len
; Output:
; Horizontal Line On Screen
; Registers Used
; BX, CX, AX, DX
;
;----------------------------------------------------------
MACRO PRINT_Horizontal_LINE xstart, ystart, len
local @@PrintOfkeLineLoop
mov cx, len
xor bx, bx
@@PrintOfkeLineLoop:
push cx
push bx
add bx, xstart
mov dx,ystart ;dx - y
mov cx, bx ;cx - x
mov bh,0h
mov al,[colorLine]
mov ah,0ch
int 10h
pop bx
push bx
add bx, xstart
mov dx, ystart +1 ;dx - y
mov cx, bx ;cx - x
mov bh,0h
int 10h
pop bx
inc bx
pop cx
loop @@PrintOfkeLineLoop
ENDM PRINT_Horizontal_LINE
macro PUSH_PARAMS
xor ah,ah
mov al,[tempT+0]
push ax
mov al,[tempT+1]
push ax
mov al,[tempT+2]
push ax
mov al,[tempT+3]
push ax
mov al,[tempT+4]
push ax
mov al,[tempT+5]
push ax
mov al,[tempT+6]
push ax
mov al,[tempT+7]
push ax
mov al,[tempT+8]
push ax
push dx
endm
macro GET_PARAMS
mov dx,[bp+4]
mov ax,[bp+6]
mov [tempT+8],al
mov ax,[bp+8]
mov [tempT+7],al
mov ax,[bp+10]
mov [tempT+6],al
mov ax,[bp+12]
mov [tempT+5],al
mov ax,[bp+14]
mov [tempT+4],al
mov ax,[bp+16]
mov [tempT+3],al
mov ax,[bp+18]
mov [tempT+2],al
mov ax,[bp+20]
mov [tempT+1],al
mov ax,[bp+22]
mov [tempT+0],al
endm
CurrentScore equ [byte bp-2] ; check if -3 is the right one
MODEL small
STACK 100h
DATASEG
; --------------------------
BoolXORO db 'X'
TheMatz db "---"
db "---"
db "---"
tempT db "---------"
maxScore db ?
OwinMessage db 13,10,10," ********* O Is The Winner *********$"
XwinMessage db 13,10,10," ********* X Is The Winner *********$"
NoWin db 13,10,10," ********There is no winner *********$"
oneTriple db "---"
OisPlaying db 13,10,10," O Is Now Playing$"
XisPlaying db 13,10,10," X Is Now Playing$"
PressRorE db 13,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,"* PRESS 'e' to exit OR 'r' to restart *$"
OpenMessage db 13,10,10,"TIC-TAC-TOI is a game for two players",10
db "who take turns marking the spaces in a",10,"3*3 grid.",10
db "The player who succeeds in placing three respective marks in a ",10
db "horizontal, vertical, or diagonal row",10,"wins the game.",10,10,10
db "Press 1 for two players,",10
db "Press 2 for play against the computer $"
PlaceOnMat1 dw '-'
PlaceOnMat2 dw '-'
countIfWin db 0
CheckIfTeko db 0
colorLine db 02h
TheCircle db "----------*******--------|"
db "-------**-------**-------|"
db "-----**-----------**-----|"
db "----*---------------*----|"
db "---*-----------------*---|"
db "--*-------------------*--|"
db "--*-------------------*--|"
db "-*---------------------*-|"
db "-*---------------------*-|"
db "*-----------------------*|"
db "*-----------------------*|"
db "*-----------------------*|"
db "*-----------------------*|"
db "*-----------------------*|"
db "*-----------------------*|"
db "*-----------------------*|"
db "-*---------------------*-|"
db "-*---------------------*-|"
db "--*-------------------*--|"
db "--*-------------------*--|"
db "---*-----------------*---|"
db "----*---------------*----|"
db "-----**-----------**-----|"
db "-------**-------**-------|"
db "---------*******---------|"
x dw 0
y dw 0
FirstPos dw 0
PlayerOrComputer db 1
; --------------------------
CODESEG
start:
mov ax, @data
mov ds, ax
; --------------------------
; Graphic mode
mov ax, 13h
int 10h
;Show Start Message
mov dx,offset OpenMessage
mov ah,9
int 21h
;Peska Kelet From Keyboard
mov ah,00h
int 16h
;If Pressed 1 is Against Computer, If PRESSED 2 TWO PLAYERS
cmp al, '1'
je AgaisntComputer
mov [PlayerOrComputer], 2
jmp PreStart
AgaisntComputer:
mov [PlayerOrComputer], 1
PreStart:
; Graphic mode
mov ax, 13h
int 10h
call PrintGameBoard
;Initializes the mouse
mov ax,0h
int 33h
TheStart:
call Print_Game_State
;Show mouse
mov ax,1h
int 33h
cmp [PlayerOrComputer], 1
je MouseLP
cmp [BoolXORO], 'O'
jne ThePlayerTurn
call PcTurn
call PcMakeTheTurn
jmp CheckIfSomeoneWin
ThePlayerTurn:
MouseLP:
;The Mouse Button Press Piska
mov ax,5h
int 33h
cmp bx, 01h ; check left mouse click
jne MouseLP
call MakeCircleOrExPosition
cmp al, 's'
je TheStart
;Hide Mouse Before Print:
;
mov ax, 02h
int 33h
;-------------------------------------------------------------
;Loop Of Game If There is Winner Or Not, if game is done or Replay!!!
;-------------------------------------------------------------
cmp [BoolXORO], 'O'
je JmpToprintO
push dx
push cx
;Check If There is alerady value in that place
mov ax, [PlaceOnMat2]
mov bx, [PlaceOnMat1]
dec ax
dec bx
call ReadCell
cmp cl, '-'
jne containPlay
;------------------
mov [BoolXORO], 'O'
pop cx
pop dx
;print X
call Print_X_Symbol_Proc
;Enter the value to the array
call InputCell
jmp CheckIfSomeoneWin
JmpToprintO:
push dx
push cx
;Check If There is alerady value in that place
mov ax, [PlaceOnMat2]
mov bx, [PlaceOnMat1]
dec ax
dec bx
call ReadCell
cmp cl, '-'
jne containPlay
;-------------------
mov [BoolXORO], 'X'
;Enter the value to the array
call InputCell
pop cx
pop dx
;Print O
call PrintCircle
CheckIfSomeoneWin:
call CheckWin
mov dx,offset NoWin
cmp al,'X'
jz Xwin
cmp al,'O'
jz Owin
mov al, [CheckIfTeko]
cmp al, 8
je Results
inc al
mov [CheckIfTeko], al
jmp containPlay
Xwin:
mov dx,offset XwinMessage
jmp Results
Owin:
mov dx,offset OwinMessage
jmp Results
results:
call ClearScreenText
mov [BoolXORO], '-'
;Peska Print to screen "xxxx $"
mov ah,9
int 21h
jmp EndGame
containPlay:
jmp TheStart
EndGame:
call Print_Game_State
;Peska Kelet From Keyboard
; Wait for key press
mov ah,00h
int 16h
;------
cmp al, 'e'
je ExitFromGame
cmp al, 'r'
je ResetTheGame
jmp EndGame
ResetTheGame:
call ResetTheGameProc
jmp PreStart
ExitFromGame:
; Return to text mode
mov ah, 0
mov al, 2
int 10h
;-------------------------------------------------------------
;-------------------------------------------------------------
exit:
mov ax, 4c00h
int 21h
;========================================
;Description: Print Game state, who is now playing
;========================================
proc Print_Game_State
mov dx,offset PressRorE
cmp [BoolXORO], 'X'
jz PrintXisPlaying
cmp [BoolXORO], 'O'
jz PrintOisPlaying
jmp PrintGameState
PrintXisPlaying:
call ClearScreenText
mov dx,offset XisPlaying
jmp PrintGameState
PrintOisPlaying:
call ClearScreenText
mov dx,offset OisPlaying
jmp PrintGameState
PrintGameState:
mov ah,9
int 21h
ret
endp Print_Game_State
;========================================
;Description: Read one byte from 2D array
;Input: ax = row
; bx = col
;Output: cl = Cell value
;========================================
proc ReadCell
push ax
push bx
mov si,3
mul si
add ax , bx
mov si,ax
mov bx, offset TheMatz
mov cl,[bx + si]
pop bx
pop ax
ret
endp ReadCell
;========================================
;Description: Put one byte on 2D array
;Input: ax = row
; bx = col
;========================================
proc InputCell
push ax
push bx
mov si,3
mul si
add ax , bx
mov si, ax
mov bx, offset TheMatz
cmp [BoolXORO], 'O'
je EnterOtoArray
mov [byte bx + si],'O'
jmp endEnterToArr
EnterOtoArray:
mov [byte bx + si],'X'
endEnterToArr:
pop bx
pop ax
ret
endp InputCell
;=============================================================
; Cehck if There is a Winner in TheMatz
;=============================================================
; output:
; al='-' no win
; al ='X' X win
; al ='O' O win
;=============================================================
proc CheckWin
push cx
push bx
;Now check 3 rows
mov cx,3
mov bx , offset TheMatz ; check first row
NextRow:
call CheckTriple
cmp al,'-'
jnz WinFound
add bx, 3 ; check next row
loop NextRow
; Now check 3 Columns
mov cx,0
nextCol:
mov bx,offset TheMatz
add bx,cx
call getCol ; set first column into oneTriple
mov bx , offset oneTriple ; check first row
call CheckTriple
cmp al,'-'
jnz WinFound
inc cx
cmp cx,3
jnz nextCol
; Now check 2 Diagonals
mov bx,offset TheMatz
call get1Diagonal ; set first diagonal into oneTriple
mov bx , offset oneTriple ; check first row
call CheckTriple
cmp al,'-'
jnz WinFound
mov bx,offset TheMatz
add bx,2
call get2Diagonal ; set first diagonal into oneTriple
mov bx , offset oneTriple ; check first row
call CheckTriple
cmp al,'-'
jnz WinFound
jmp NoWinFound
WinFound:
;
;
NoWinFound:
;
;
pop bx
pop cx
ret
endp CheckWin
;----------------------------------------------------------
; Enter to oneTriple the colums values
;----------------------------------------------------------
; Input:
; input bx =index cell to start col (array + 0 ,1,2)
; Output:
; output = oneTriple
; Registers Used:
; AX BH
;
;----------------------------------------------------------
proc getCol
push ax
mov al,[byte bx ]
mov [byte oneTriple],al
mov al,[byte bx +3 ]
mov [byte oneTriple +1],al
mov al,[byte bx +6 ]
mov [byte oneTriple +2],al
pop ax
ret
endp getCol
;----------------------------------------------------------
; Enter to oneTriple the Diagonal values
;----------------------------------------------------------
; Input:
; bx =index cell to start
; Output:
; output = oneTriple
; Registers Used:
; AX BH
;
;----------------------------------------------------------
proc get1Diagonal
stop:
push ax
mov al,[byte bx ]
mov [byte oneTriple],al
mov al,[byte bx +4 ]
mov [byte oneTriple +1],al
mov al,[byte bx +8 ]
mov [byte oneTriple +2],al
pop ax
ret
endp get1Diagonal
;----------------------------------------------------------
; Enter to oneTriple the Diagonal values
;----------------------------------------------------------
; Input:
; bx =index cell to start
; Output:
; output = oneTriple
; Registers Used:
; AX BH
;
;----------------------------------------------------------
proc get2Diagonal
push ax
mov al,[byte bx ]
mov [byte oneTriple],al
mov al,[byte bx + 2 ]
mov [byte oneTriple +1],al
mov al,[byte bx +4 ]
mov [byte oneTriple +2],al
pop ax
ret
endp get2Diagonal
;----------------------------------------------------------
; Check araay (3) if all equals
;----------------------------------------------------------
; Input:
; bx = Triple Offset - addrsss of 3 bytes that contain 3 symboles
; Output:
; al='-' no win al ='X' X win al ='O' O win
; Registers Used:
; AX BH
;----------------------------------------------------------
proc CheckTriple
mov ah,[byte bx] ; mov first
cmp ah,'-'
jz @@NoWin
mov al,[byte bx+1]
cmp al,ah
jne @@NoWin
mov al,[byte bx+2]
cmp al,ah
jne @@NoWin
jmp Win
@@NoWin:
mov al,'-'
Win:
ret
endp CheckTriple
;----------------------------------------------------------
; Print X to the screen
;----------------------------------------------------------
; Input:
; cx - X axis
; dx - Y axis
; Output:
; O print to screen
; Registers Used:
; AX ES DI CX DX BH
; Description:
;
; print X to screen. start pos: (cx,dx)
;
;----------------------------------------------------------
proc Print_X_Symbol_Proc
push ax
push bx
mov bx, cx
mov ax, dx
mov si, cx
add si, 20
mov cx, 20
@@PrintXLineLoopProc:
push cx
push bx
push ax
push si
mov dx,ax ;dx - y
mov cx, bx ;cx - x
mov bh,0h
mov al,0ch
mov ah,0ch
int 10h
pop si
pop ax
pop bx
push bx
push ax
push si
mov dx,ax ;dx - y
mov cx, si ;cx - x
mov bh,0h
mov al,0ch
mov ah,0ch
int 10h
pop si
pop ax
pop bx
inc ax
inc bx
dec si
pop cx
loop @@PrintXLineLoopProc
pop bx
pop ax
ret
endp Print_X_Symbol_Proc
;----------------------------------------------------------
; Print O to the screen
;----------------------------------------------------------
; Input:
; cx - X axis
; dx - Y axis
; Output:
; O print to screen
; Registers Used:
; AX ES DI CX DX BH
; Description:
;
; print O to screen. start pos: (cx,dx)
;
;----------------------------------------------------------
proc PrintCircle
push cx
push bx
push dx
mov [x], cx
mov [y], dx
mov [FirstPos], cx
mov cx, 650
mov bx, offset TheCircle
PrintCircleLoop:
push cx
push bx
cmp [byte bx], '-'
je prnitBlackDot
cmp [byte bx], '*'
je prnitRedDot
;Next Line
inc [y]
mov cx, [FirstPos]
mov [x], cx
jmp endTheSongle
prnitRedDot:
mov bh,0h
mov cx,[x]
mov dx,[y]
mov al,0Bh
mov ah,0ch
int 10h
jmp endTheSongle
prnitBlackDot:
mov bh,0h
mov cx,[x]
mov dx,[y]
mov al,0h
mov ah,0ch
int 10h
endTheSongle:
pop bx
inc bx
inc [x]
pop cx
loop PrintCircleLoop
pop dx
pop bx
pop cx
ret
endp PrintCircle
;----------------------------------------------------------
; Procedure Clear Screen Text Mode
;----------------------------------------------------------
; Input:
; None
; Output:
; Screen , and Cursor
; Registers Used:
; AX ES DI CX DX BH
; Description:
;
; Color Black all Screen 80 X 24 and bring Cursor to start
;
;----------------------------------------------------------
Proc ClearScreenText
push ax
push cx
push bx
push dx
mov ax,0B800h
mov es,ax ; es:di - video memory
xor di,di
mov cx,80*24
mov al,00d ; ASCII
mov ah,02h ; color 2 is green
;mov es:[di],ax ;add di,2 Stores a byte, word from the AL, AX
rep stosw
;move Cursor to top left
xor DX,DX
mov dl, 0
mov bh, 0
mov ah, 2 ; change cursor position
int 10h
pop dx
pop bx
pop cx
pop ax
ret
endp ClearScreenText
;----------------------------------------------------------
; Print Game Board, Grapicha
;----------------------------------------------------------
; Input:
; None
; Output:
; Screen
;----------------------------------------------------------
proc PrintGameBoard
;-------------------------------------------------------------
;Print The Limits of the screen
;-------------------------------------------------------------
mov [colorLine], 0ah
PRINT_Horizontal_LINE 0, 0, 320 ;Ofke Line UP
PRINT_Horizontal_LINE 0, 198, 320 ;Ofke Line Down
PRINT_Vertical_LINE 0, 0, 200 ; Anahi Line Left
PRINT_Vertical_LINE 318, 0, 200 ; Anahi Line Right
mov [colorLine], 0bh
PRINT_Horizontal_LINE 0, 5, 320 ;Ofke Line UP 2
PRINT_Horizontal_LINE 0, 193, 320 ;Ofke Line Down 2
PRINT_Vertical_LINE 5, 0, 200 ; Anahi Line Left 2
PRINT_Vertical_LINE 313, 0, 200 ; Anahi Line Right 2
mov [colorLine], 0Ch
PRINT_Horizontal_LINE 0, 10, 320 ;Ofke Line UP 2
PRINT_Horizontal_LINE 0, 187, 320 ;Ofke Line Down 2
PRINT_Vertical_LINE 10, 0, 200 ; Anahi Line Left 2
PRINT_Vertical_LINE 307, 0, 200 ; Anahi Line Right 2
;-------------------------------------------------------------
;-------------------------------------------------------------
;Print The Game Board
;-------------------------------------------------------------
mov [colorLine], 0Dh
PRINT_Horizontal_LINE 64, 40, 192 ;
PRINT_Horizontal_LINE 64, 160, 192 ;
PRINT_Vertical_LINE 64, 40, 120 ;
PRINT_Vertical_LINE 256, 40, 120 ;
PRINT_Vertical_LINE 59, 45, 110 ;
PRINT_Vertical_LINE 261, 45, 110 ;
PRINT_Vertical_LINE 54, 50, 100 ;
PRINT_Vertical_LINE 266, 50, 100 ;
PRINT_Vertical_LINE 49, 55, 90 ;
PRINT_Vertical_LINE 271, 55,90 ;
PRINT_Vertical_LINE 44, 60, 80 ;
PRINT_Vertical_LINE 276, 60,80 ;
PRINT_Vertical_LINE 39, 65, 70 ;
PRINT_Vertical_LINE 281, 65,70 ;
PRINT_Vertical_LINE 34, 70, 60 ;
PRINT_Vertical_LINE 286, 70,60 ;
PRINT_Vertical_LINE 29, 75, 50 ;
PRINT_Vertical_LINE 291, 75,50 ;
PRINT_Vertical_LINE 24, 80, 40 ;
PRINT_Vertical_LINE 296, 80,40 ;
PRINT_Vertical_LINE 19, 85, 30 ;
PRINT_Vertical_LINE 301, 85,30 ;
mov [colorLine], 0Eh
PRINT_Horizontal_LINE 64, 80, 192 ;
PRINT_Horizontal_LINE 64, 120, 192 ;
PRINT_Vertical_LINE 128, 40, 120 ;
PRINT_Vertical_LINE 192, 40, 120 ;
;-------------------------------------------------------------
ret
endp PrintGameBoard
;===***description**=======================================
;This Proc Reset The game to his first values
;==========================================================
proc ResetTheGameProc
mov [BoolXORO], 'X'
mov [CheckIfTeko], 0
mov bx, offset TheMatz
mov si, offset tempT
mov cx, 9
ReserArrayAfterPressesReset:
mov [byte bx],'-'
mov [byte si], '-'
inc bx
inc si
loop ReserArrayAfterPressesReset
mov [PlaceOnMat1], '-'
mov [PlaceOnMat2], '-'
mov ah, 0
mov al, 2
int 10h
ret
endp ResetTheGameProc
; output : si the place to put the compute decision
proc PcTurn
mov cx,9
xor bx,bx
mov [maxScore],-128
xor si,si
@@NextCell:
cmp [byte TheMatz +bx],'-'
je @@Cont1
jmp @@NextLoop
@@Cont1:
mov dl,1 ; 1 = player -1 = PC
mov dh,6 ; depth
call BuildTempMat
mov [tempT +bx],'O'
push bx
push cx
PUSH_PARAMS ; dl = turn dh = depth ,
call miniMax ; input 11 words in stack output ah = score
pop cx
pop bx
mov [tempT +bx],'-'
cmp [maxScore],ah
jnl @@NextLoop
mov [maxScore],ah
mov si,bx
@@NextLoop:
inc bx
dec cx
cmp cx,0
jz @@Cont2
jmp @@NextCell
@@Cont2:
ret
endp PcTurn
;===***NameProc**==========================================
;MiniMax
;==========================================================
;===***description**=======================================
;This Proc Find the best place for the computer to put the circle,
;The Proc tries every option than posibily and give for any option a score
;the best score will be the one the computer will do
;==========================================================
; input: STRACK:: dl = turn
; dh = depth
; 10 words [tempT]
;==========================================================
proc miniMax
push bp
mov bp,sp
sub sp,2
GET_PARAMS
;call print_temp
;stop:
cmp dh,0 ;depth
jg @@NextCheck1
jmp GetScoreofCurrentMat
@@NextCheck1:
call CheckFull ; bx = 1 = full
cmp bx,1 ; schec if full
jnz @@NextCheck2
jmp GetScoreofCurrentMat
@@NextCheck2:
call CheckWin2
cmp al,'-'
jz @@NextCheck3
jmp GetScoreofCurrentMat
@@NextCheck3:
; preparations for minimax call ------------------------------------
;------------------------------------
;------------------------------------
;------------------------------------
mov CurrentScore,-128
cmp dl,1 ;Payer turn = dl = 1
jne @@Cont2