LIBRARY ieee; USE ieee.std_logic_1164.ALL; USE ieee.std_logic_arith.ALL; USE ieee.std_logic_unsigned.ALL; ENTITY housePlayer IS PORT ( clock : IN STD_LOGIC; -- clock signal reset : IN STD_LOGIC; -- global reset turn : IN STD_LOGIC; -- signals player's turn -- signals that card has been issued on the bus issued : IN STD_LOGIC; card : IN STD_LOGIC_VECTOR(3 DOWNTO 0); -- Dealer's showing card dealerShow : IN STD_LOGIC_VECTOR(3 DOWNTO 0); -- card stats - read only NumA, Num2, Num3, Num4, Num5 : IN STD_LOGIC_VECTOR(4 DOWNTO 0); Num6, Num7, Num8, Num9, Num10 : IN STD_LOGIC_VECTOR(4 DOWNTO 0); NumJ, NumQ, NumK : IN STD_LOGIC_VECTOR(4 DOWNTO 0); -- Number of Hands remaining numHands : IN STD_LOGIC_VECTOR(6 DOWNTO 0); -- Player's balance balance : IN STD_LOGIC_VECTOR(9 DOWNTO 0); balanceRdy : in STD_LOGIC; -- from bank hit : OUT STD_LOGIC; -- Signal a 'Hit' command stand : OUT STD_LOGIC; -- Signal a 'Stand' command -- Player's bet amount bet : OUT STD_LOGIC_VECTOR(9 DOWNTO 0)); END housePlayer; ARCHITECTURE behavior OF housePlayer IS signal state : std_logic_vector(3 downto 0) := "0000"; signal total : std_logic_vector(5 downto 0) := "000000"; signal ace : std_logic := '0'; BEGIN -- behavior main: process (clock, reset) variable myBet : std_logic_vector(9 downto 0) := (others => '0'); variable myBalance : std_logic_vector(9 downto 0) := (others => '0'); begin -- process main if reset = '1' then -- asynchronous reset (active low) elsif clock'event and clock = '1' then -- rising clock edge if turn = '1' then case state is when "0000" => -- Bet Mode -- House player is stupid and bets 0 all the time myBet := (others => '0'); -- use smarts to set this bet <= myBet; total <= (others => '0'); ace <= '0'; -- when bet is decided set stand flag stand <= '1'; state <= "0001"; when "0001" => -- Card 1 stand <= '0'; -- unset stand flag if issued = '1' then -- Update card total if card = "0001" then -- if ace ace <= '1'; total <= "001011"; state <= "0010"; else total(3 downto 0) <= card; state <= "0010"; end if; end if; when "0010" => -- Card 2 if issued = '1' then --How long is issued up? if card = "0001" then -- if ace ace <= '1'; total <= total + "1011"; state <= "0011"; else total <= total + card; state <= "0011"; end if; end if; when "0011" => -- Game Interaction if total > "010000" then if total > "010101" and ace = '1' then -- bust? -- account for aces ace <= '0'; total <= total - "1010"; state <= "0011"; -- spin a loop else stand <= '1'; state <= "0100"; end if; else -- hit <= '1'; if issued = '1' then hit <='0'; total <= total + card; else hit <= '1'; end if; end if; when "0100" => -- Settle me up stand <= '0'; if balanceRdy = '1' then state <= "0000"; -- keep up with your balance here and interpret your winnings -- based on your bet myBalance := balance; else state <="0100"; end if; when others => null; end case; else bet <= (others => 'Z'); -- must protect shared buses -- Not my turn but I can watch game -- could write parallel state machine to know what the state is when it -- is not your turn in order to watch other players. end if; end if; end process main; END behavior;