-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock-paper-scissors.asm
123 lines (95 loc) · 2.23 KB
/
rock-paper-scissors.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
org &9c40
km_wait_char equ &bb06
kl_time_please equ &bd0d
txt_output equ &bb5a
getmove:
call km_wait_char
cp &52
jp z, saveplayermove
cp &53
jp z, saveplayermove
cp &50
jp z, saveplayermove
jp nz, getmove
saveplayermove:
ld hl, playermove
ld (hl), a
jp computerturn
computerturn:
call kl_time_please
ld a, l
ld bc, MoveTable
ld h, &00
add hl, bc ; MoveTable address+random offset
ld a, (hl) ; Store move
add &50 ; convert it to Rock/Paper/Scissors move.
MoveTable: db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
db 2,3,0,2,3,0,2,3,0,2,3,0,2,3,0,2
db 3,0,2,3,0,2,3,0,2,3,0,2,3,0,2,3
db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
db 2,3,0,2,3,0,2,3,0,2,3,0,2,3,0,2
db 3,0,2,3,0,2,3,0,2,3,0,2,3,0,2,3
db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
db 2,3,0,2,3,0,2,3,0,2,3,0,2,3,0,2
db 3,0,2,3,0,2,3,0,2,3,0,2,3,0,2,3
db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
db 2,3,0,2,3,0,2,3,0,2,3,0,2,3,0,2
db 3,0,2,3,0,2,3,0,2,3,0,2,3,0,2,3
db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
db 2,3,0,2,3,0,2,3,0,2,3,0,2,3,0,2
db 3,0,2,3,0,2,3,0,2,3,0,2,3,0,2,3
db 0,2,3,0,2,3,0,2,3,0,2,3,0,2,3,0
jp savecomputerturn
savecomputerturn:
ld hl, computermove
ld (hl), a
jp whowins
whowins:
; all ties will set Z.
; Player - Computer
;
; 50 - 50 P
; 52 - 52 R
; 53 - 53 S
;
; Result=PlayerMove-ComputerMove
; 50 - 52 = fe
; 50 - 53 = fd
; 52 - 50 = 02
; 52 - 53 = ff
; 53 - 50 = 03
; 53 - 52 = 01
ld hl, playermove
ld b, (hl)
ld hl, computermove
ld c, (hl)
ld a, b
sub c
cp &00
jp z, tie
cp &fe
jp z, userwins
cp &fd
jp z, computerwins
cp &02
jp z, computerwins
cp &ff
jp z, userwins
cp &03
jp z, userwins
cp &01
jp z, computerwins
tie:
ld a,'T'
call txt_output
ret
userwins:
ld a,'U'
call txt_output
ret
computerwins:
ld a, 'C'
call txt_output
ret
playermove: db 0
computermove: db 0