I'm designing the number guessing game,aka mastermind,1A2B
,And I'm stuck.
I'm having problem with how to compare the 2 set of 4-digit numbers and output ? A ? B
.
? A
: when the number's position and value is correct,increase A's value,like,
1234=1234 => 4A0B,1234=1235 => 3A0B ...etc.
? B
: when the numbers value is correct but position is not correct,increase B's value,like
1234=4321 =>0A4B,1234=7843 => 0A2B, 1234=5321 =>0A3B...etc.
Initially I'm thinking to compare both of them by each digit,but then when I use if-else if-else statement to describe it,no matter how I code it,it'll only compare 1 digit,even though I wrote it to compare 2-digit at once...
My biggest question is,how to compare these 2 set of 4-digit numbers and judge its position and value,then output how many A's how many B's.
Codes based on my thoughts and only able to compare 1-digit at a time,even though,I tried code it to compare 2-digit at a time...ultimate goal is to compare 2-set of 4-digit.
Disp_Save
is register for saved answer ;
Segs_R
is register for input display 7seg on the right-hand side.
Segs_L
is register for compared result displaying 7seg on the left-hand side,default displaying 0A0b
.
Css
is Choosing States,in this case,Css<=0;
is return to Keypad detecting state.
if(Disp_Save[3:0]==Segs_R[3:0])
begin
Segs_L<=16'h1A0b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[3:0]==Segs_R[7:4])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[3:0]==Segs_R[11:8])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[3:0]==Segs_R[15:12])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[7:4]==Segs_R[7:4])
begin
Segs_L<=16'h1A0b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[7:4]==Segs_R[3:0])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[7:4]==Segs_R[11:8])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[7:4]==Segs_R[15:12])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[11:8]==Segs_R[11:8])
begin
Segs_L<=16'h1A0b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[11:8]==Segs_R[3:0])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[11:8]==Segs_R[7:4])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[11:8]==Segs_R[15:12])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[15:12]==Segs_R[15:12])
begin
Segs_L<=16'h1A0b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[15:12]==Segs_R[3:0])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[15:12]==Segs_R[7:4])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[15:12]==Segs_R[11:8])
begin
Segs_L<=16'h0A1b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[3:0]==Segs_R[3:0] && Disp_Save[7:4]==Segs_R[7:4])
begin
Segs_L<=16'h2A0b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[7:4]==Segs_R[3:0] && Disp_Save[3:0]==Segs_R[7:4])
begin
Segs_L<=16'h0A2b;
Segs_R<=16'h0;
Css<=0;
end
else if(Disp_Save[3:0]==Segs_R[11:8] && Disp_Save[7:4]==Segs_R[15:12])
begin
Segs_L<=16'h0A2b;
Segs_R<=16'h0;
Css<=0;
end
else
begin
Segs_L<=16'h0A0b;
Segs_R<=16'h0;
Css<=0;
end