-
Notifications
You must be signed in to change notification settings - Fork 1
/
winning_checker.sv
83 lines (74 loc) · 2.83 KB
/
winning_checker.sv
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
module winning_checker(check_done, winning, main_vector, state, clk);
output reg [5:0] winning = 6'b000_000;
output reg check_done;
input [1:0] main_vector [8:0];
input [2:0] state;
input clk;
parameter s_winning_checker = 3'b011, s_refreshing = 3'b100, s_updating_score = 3'b101;
always @ (posedge clk)
begin
if(state != s_winning_checker)
begin
check_done = 0;
if(state != s_updating_score & state != s_refreshing)
winning = 6'b000_000;
end
else
if(state == s_winning_checker & check_done == 0)
begin
if(main_vector[0] == main_vector[1] & main_vector[1] == main_vector[2] & main_vector[2] == 2'b10)
winning = 6'b110_000;
else
if(main_vector[3] == main_vector[4] & main_vector[4] == main_vector[5] & main_vector[5] == 2'b10)
winning = 6'b110_001;
else
if(main_vector[6] == main_vector[7] & main_vector[7] == main_vector[8] & main_vector[8] == 2'b10)
winning = 6'b110_010;
else
if(main_vector[0] == main_vector[3] & main_vector[3] == main_vector[6] & main_vector[6] == 2'b10)
winning = 6'b110_011;
else
if(main_vector[1] == main_vector[4] & main_vector[4] == main_vector[7] & main_vector[7] == 2'b10)
winning = 6'b110_100;
else
if(main_vector[2] == main_vector[5] & main_vector[5] == main_vector[8] & main_vector[8] == 2'b10)
winning = 6'b110_101;
else
if(main_vector[0] == main_vector[4] & main_vector[4] == main_vector[8] & main_vector[8] == 2'b10)
winning = 6'b110_110;
else
if(main_vector[2] == main_vector[4] & main_vector[4] == main_vector[6] & main_vector[6] == 2'b10)
winning = 6'b110_111;
else
if(main_vector[0] == main_vector[1] & main_vector[1] == main_vector[2] & main_vector[2] == 2'b01)
winning = 6'b111_000;
else
if(main_vector[3] == main_vector[4] & main_vector[4] == main_vector[5] & main_vector[5] == 2'b01)
winning = 6'b111_001;
else
if(main_vector[6] == main_vector[7] & main_vector[7] == main_vector[8] & main_vector[8] == 2'b01)
winning = 6'b111_010;
else
if(main_vector[0] == main_vector[3] & main_vector[3] == main_vector[6] & main_vector[6] == 2'b01)
winning = 6'b111_011;
else
if(main_vector[1] == main_vector[4] & main_vector[4] == main_vector[7] & main_vector[7] == 2'b01)
winning = 6'b111_100;
else
if(main_vector[2] == main_vector[5] & main_vector[5] == main_vector[8] & main_vector[8] == 2'b01)
winning = 6'b111_101;
else
if(main_vector[0] == main_vector[4] & main_vector[4] == main_vector[8] & main_vector[8] == 2'b01)
winning = 6'b111_110;
else
if(main_vector[2] == main_vector[4] & main_vector[4] == main_vector[6] & main_vector[6] == 2'b01)
winning = 6'b111_111;
else
if(main_vector[0] != 2'b00 & main_vector[1] != 2'b00 & main_vector[2] != 2'b00 &
main_vector[3] != 2'b00 & main_vector[4] != 2'b00 & main_vector[5] != 2'b00 &
main_vector[6] != 2'b00 & main_vector[7] != 2'b00 & main_vector[8] != 2'b00 )
winning = 6'b100_000;
check_done = 1;
end
end
endmodule