井字游戏学生项目

时间:2019-04-14 14:48:13

标签: vhdl

问题是输出与ifs不匹配。我想举个例子,如果行A的所有内容均为1,则输出应为11,但并非如此。

library ieee;  
 use ieee.std_logic_1164.all;  
 use ieee.numeric_std.all;  

 entity galo_ports is  
  port( LinA : in unsigned(2 downto 0); 
    LinB : in unsigned(2 downto 0);
    LinC : in unsigned(2 downto 0);

    output : out unsigned(1 downto 0)); 
 end galo_ports;

ARCHITECTURE main OF galo_ports IS
SIGNAL values: std_logic_vector(1 downto 0);
SIGNAL condition1A: boolean;
SIGNAL condition2A: boolean;
SIGNAL condition3A: boolean;
SIGNAL condition1B: boolean;
SIGNAL condition2B: boolean;
SIGNAL condition3B: boolean;
SIGNAL condition1C: boolean;
SIGNAL condition2C: boolean;
SIGNAL condition3C: boolean;
SIGNAL condition1COL1: boolean;
SIGNAL condition2COL1: boolean;
SIGNAL condition3COL1: boolean;
SIGNAL condition1COL2: boolean;
SIGNAL condition2COL2: boolean;
SIGNAL condition3COL2: boolean;
SIGNAL condition1COL3: boolean;
SIGNAL condition2COL3: boolean;
SIGNAL condition3COL3: boolean;
SIGNAL condition1DIG1: boolean;
SIGNAL condition2DIG1: boolean;
SIGNAL condition3DIG1: boolean;
SIGNAL condition1DIG2: boolean;
SIGNAL condition2DIG2: boolean;
SIGNAL condition3DIG2: boolean;
BEGIN
values <= "10";

--CONDIÇÃOES:
--LINHA 1
condition1A <= LinA(0) = LinA(1) and LinA(1) = LinA(2);
condition2A <= LinA(0) = values(0) or LinA(0) = values(1);
condition3A <= LinA(0) = values(1);
--LINHA 2
condition1B <= LinB(0) = LinB(1) and LinB(1) = LinB(2);
condition2B <= LinB(0) = values(0) or LinB(0) = values(1);
condition3B <= LinB(0) = values(1);
--LINHA 3
condition1C <= LinC(0) = LinC(1) and LinC(1) = LinC(2);
condition2C <= LinC(0) = values(0) or LinC(0) = values(1);
condition3C <= LinC(0) = values(1);
--COLUNA 1
condition1COL1 <= LinA(0) = LinB(0) and LinB(0) = LinC(0);
condition2COL1 <= LinA(0) = values(0) or LinA(0) = values(1);
condition3COL1 <= LinA(0) = values(1);
--COLUNA 2
condition1COL2 <= LinA(1) = LinB(1) and LinB(1) = LinC(1);
condition2COL2 <= LinA(1) = values(0) or LinA(1) = values(1);
condition3COL2 <= LinA(1) = values(1);
--COLUNA 3
condition1COL3 <= LinA(2) = LinB(2) and LinB(2) = LinC(2);
condition2COL3 <= LinB(2) = values(0) or LinA(2) = values(1);
condition3COL3 <= LinB(2) = values(1);
--DIAGONAL 1
condition1DIG1 <= LinA(0) = LinB(1) and LinB(1) = LinC(2);
condition2DIG1 <= LinA(0) = values(0) or LinA(0) = values(1);
condition3DIG1 <= LinA(0) = values(1);
--DIAGONAL 2
condition1DIG2 <= LinA(2) = LinB(1) and LinB(1) = LinC(0);
condition2DIG2 <= LinA(2) = values(0) or LinA(2) = values(1);
condition3DIG2 <= LinA(2) = values(1);
    PROCESS(LinA, LinB, LinC)
    BEGIN
        --LINHA 1
        IF condition1A=TRUE and condition2A=TRUE and condition3A=TRUE THEN output <= "11";
        END IF;
        --LINHA 2
        IF (condition1B) and (condition2B) and (condition3B) THEN output <= "11"; ELSE output <="00";
        END IF;
        --LINHA 3
        IF condition1C and condition2C and condition3C THEN output <= "11";
        END IF;
        --COLUNA 1
        IF condition1COL1 and condition2COL1 and condition3COL1 THEN output <= "11";
        END IF;
        --COLUNA 2
        IF condition1COL2 and condition2COL2 and condition3COL2 THEN output <= "11";
        END IF;
        --COLUNA 3
        IF condition1COL3 and condition2COL3 and condition3COL3 THEN output <= "11";
        END IF;
        --DIAGONAL 1
        IF condition1DIG1 and condition2DIG1 and condition3DIG1 THEN output <= "11";
        END IF;
        --DIAGONAL 2
        IF condition1DIG2 and condition2DIG2 and condition3DIG2 THEN output <= "11";
        END IF;

    END PROCESS;
END main;

游戏包含9个位置的棋盘,每个玩家在房子里自由移动,方法是将其标记为“ 0”(玩家A)或“ 1”(玩家B)。

胜利是授予可以水平,垂直或对角放置3个“ 0”或3个“ 1”的玩家的。

如果没有玩家能够达到所定义的目标,则解决方案应在出口处指示哪个玩家获胜或向平局发出信号。

1 个答案:

答案 0 :(得分:0)

我删除了原来的答案,因为@ pm101指出这完全不正确。

编译设计后,警告指出明显的原因:

  galo_ports.vhd(142)上的

VHDL流程声明警告:信号   “ condition1A”在流程语句中读取,但不在   流程声明的敏感度列表

conditionXXXlinAlinB更改时,linC信号的值将更新。但是,该过程同时执行,并且那些条件信号的值尚未更新。如果要模拟设计,您会看到output的值有滞后性:输入更改时会更新,但可能会显示先前输入的游戏结果。

修复过程敏感性列表以包含所有条件信号。然后,当您的conditionXXX信号改变并且条件表达式被正确求值时,将执行该过程。像这样:

PROCESS(condition1A, condition2A, condition3A, condition1B, condition2B, condition3B, condition1C, condition2C, condition3C, condition1COl1, condition2COL1, condition3COL1, condition1COL2, condition2COL2, condition3COL2, condition1COL3, condition2COL3, condition3COL3, condition1DIG1, condition2DIG1, condition3DIG1, condition1DIG2, condition2DIG2, condition3DIG2)

此外,我将用IF语句将该条件列表包装到一个ELSIF块中。然后,在ELSE语句中,还必须定义没有赢家(或0是赢家)时output的值:

  --LINHA 1
  IF condition1A=TRUE and condition2A=TRUE and condition3A=TRUE THEN output <= "11";
  --LINHA 2
  ELSIF (condition1B) and (condition2B) and (condition3B) THEN output <= "11";
  --LINHA 3
  ELSIF condition1C and condition2C and condition3C THEN output <= "11";
  --COLUNA 1
  ELSIF condition1COL1 and condition2COL1 and condition3COL1 THEN output <= "11";
  --COLUNA 2
  ELSIF condition1COL2 and condition2COL2 and condition3COL2 THEN output <= "11";
  --COLUNA 3
  ELSIF condition1COL3 and condition2COL3 and condition3COL3 THEN output <= "11";
  --DIAGONAL 1
  ELSIF condition1DIG1 and condition2DIG1 and condition3DIG1 THEN output <= "11";
  --DIAGONAL 2
  ELSIF condition1DIG2 and condition2DIG2 and condition3DIG2 THEN output <= "11";
  ELSE output <= "00"; -- 0 wins or no winner. 
  END IF;