-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer2.v
213 lines (213 loc) · 7.39 KB
/
Player2.v
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
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 14:15:45 01/24/2024
// Design Name:
// Module Name: player2
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module player2(
action2, action1, place1, lives1, reset, clk, out, control
);
input [2:0] action1, action2;
input [1:0] place1, lives1;
input reset, clk, control;
output [3:0] out;
reg [3:0] state;
reg waitCount = 1'b0;
parameter p1h0 = 4'b0100, p1h1 = 4'b0101, p1h2 = 4'b0110, p1h3 = 4'b0111, p2h0 = 4'b1000, p2h1 = 4'b1001, p2h2 = 4'b1010, p2h3 = 4'b1011,
p3h0 = 4'b1100, p3h1 = 4'b1101, p3h2 = 4'b1110, p3h3 = 4'b1111 ;
parameter kick = 3'b000, punch = 3'b001, sabr = 3'b010, jump = 3'b011, left = 3'b100, right = 3'b101;
always @ (posedge clk or negedge reset)
if (~reset) state = p1h3;
else if (control & ~(state[1:0] == 2'b00) & ~(lives1 == 2'b00)) begin
case (state)
//p1h0:
p1h1: begin
if (action2 == sabr) begin
if (waitCount == 1) state = p1h2;
waitCount = waitCount + 1;
end
else if (action2 == left) begin
if (action1 == kick & place1 == 2'b11) state = p2h0;
else state = p2h1;
waitCount = 0;
end
else waitCount = 0;
end
p1h2: begin
if (action2 == sabr) begin
if (waitCount == 1) state = p1h3;
waitCount = waitCount + 1;
end
else if (action2 == left) begin
if (action1 == kick & place1 == 2'b11) state = p2h1;
else state = p2h2;
waitCount = 0;
end
else waitCount = 0;
end
p1h3: begin
if (action2 == left) begin
if (action1 == kick & place1 == 2'b11) state = p2h2;
else state = p2h3;
end
waitCount = 0;
end
//p2h0:
p2h1: begin
if (action2 == kick) begin
if (action1 == kick & place1 == 2'b11) state = p1h1;
end
else if (action2 == right) state = p1h1;
else if (action2 == left) begin
if (action1 == punch & place1 == 2'b11) state = p3h0;
else if (action1 == kick & place1 != 2'b01) state = p3h0;
else state = p3h1;
end
else if (action2 == punch) begin
if (action1 == kick & place1 == 2'b11) state = p2h0;
end
if (action2 == sabr) begin
//if (action1 == kick & place1 == 2'b11 & waitCount == 1) state = p2h1;
if (action1 == kick & place1 == 2'b11 & waitCount == 0) state = p2h0;
else if (waitCount == 1) state = p2h2;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
p2h2: begin
if (action2 == kick) begin
if (action1 == kick & place1 == 2'b11) state = p1h2;
end
else if (action2 == right) state = p1h2;
else if (action2 == left) begin
if (action1 == punch & place1 == 2'b11) state = p3h0;
else if (action1 == kick & place1 != 2'b01) state = p3h1;
else state = p3h2;
end
else if (action2 == punch) begin
if (action1 == kick & place1 == 2'b11) state = p2h1;
end
if (action2 == sabr) begin
//if (action1 == kick & place1 == 2'b11 & waitCount == 1) state = p2h2;
if (action1 == kick & place1 == 2'b11 & waitCount == 0) state = p2h1;
else if (waitCount == 1) state = p2h3;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
p2h3: begin
if (action2 == kick) begin
if (action1 == kick & place1 == 2'b11) state = p1h3;
end
else if (action2 == right) state = p1h3;
else if (action2 == left) begin
if (action1 == punch & place1 == 2'b11) state = p3h1;
else if (action1 == kick & place1 != 2'b01) state = p3h2;
else state = p3h3;
end
else if (action2 == punch) begin
if (action1 == kick & place1 == 2'b11) state = p2h2;
end
if (action2 == sabr) begin
//if (action1 == kick & place1 == 2'b11 & waitCount == 1) state = p2h3;
if (action1 == kick & place1 == 2'b11 & waitCount == 0) state = p2h2;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
//p3h0:
p3h1: begin
if (action2 == kick) begin
if (action1 == kick & place1 != 2'b01) state = p2h1;
else if (action1 == punch & place1 == 2'b11) state = p3h0;
end
else if (action2 == punch) begin
if (action1 == punch & place1 == 2'b11) state = p2h1;
else if (action1 == kick & place1 == 2'b10) state = p3h0;
end
else if (action2 == right) begin
if (action1 == kick & place1 == 2'b11) state = p2h0;
else state = p2h1;
end
else if (action2 == left) begin
if (action1 == kick & place1 != 2'b01) state = p3h0;
else if (action1 == punch & place1 == 2'b11) state = p3h0;
end
if (action2 == sabr) begin
if (action1 == kick & place1 != 2'b01 & waitCount == 0) state = p3h0;
else if (action1 == punch & place1 == 2'b11 & waitCount == 0) state = p3h0;
else if (action1 == punch & place1 == 2'b11 & waitCount == 1) state = p3h0;
else if (waitCount == 1) state = p3h2;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
p3h2: begin
if (action2 == kick) begin
if (action1 == kick & place1 != 2'b01) state = p2h2;
else if (action1 == punch & place1 == 2'b11) state = p3h0;
end
else if (action2 == punch) begin
if (action1 == punch & place1 == 2'b11) state = p2h2;
else if (action1 == kick & place1 == 2'b10) state = p3h1;
end
else if (action2 == right) begin
if (action1 == kick & place1 == 2'b11) state = p2h1;
else state = p2h2;
end
else if (action2 == left) begin
if (action1 == kick & place1 != 2'b01) state = p3h1;
else if (action1 == punch & place1 == 2'b11) state = p3h0;
end
if (action2 == sabr) begin
if (action1 == kick & place1 != 2'b01 & waitCount == 0) state = p3h1;
else if (action1 == punch & place1 == 2'b11 & waitCount == 0) state = p3h0;
else if (action1 == punch & place1 == 2'b11 & waitCount == 1) state = p3h1;
else if (waitCount == 1) state = p3h3;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
p3h3: begin
if (action2 == kick) begin
if (action1 == kick & place1 != 2'b01) state = p2h3;
else if(action1 == punch & place1 == 2'b11) state = p3h1;
end
else if (action2 == punch) begin
if (action1 == punch & place1 == 2'b11) state = p2h3;
else if (action1 == kick & place1 == 2'b10) state = p3h2;
end
else if (action2 == right) begin
if (action1 == kick & place1 == 2'b11) state = p2h2;
else state = p2h3;
end
else if (action2 == left) begin
if (action1 == kick & place1 != 2'b01) state = p3h2;
else if (action1 == punch & place1 == 2'b11) state = p3h1;
end
if (action2 == sabr) begin
if (action1 == kick & place1 != 2'b01 & waitCount == 0) state = p3h2;
else if (action1 == punch & place1 == 2'b11 & waitCount == 0) state = p3h1;
else if (action1 == punch & place1 == 2'b11 & waitCount == 1) state = p3h2;
waitCount = waitCount + 1;
end
else waitCount = 0;
end
endcase
end
assign out = state;
endmodule