Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

AI works...this ROCKS!

  • Loading branch information...
commit b673705bc8b30d951761c23790e89a051869d4e8 1 parent 3b4b1d6
unknown authored
16 AI.vhd
View
@@ -4,10 +4,9 @@ use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity AI is
- Port (
- ai_enabled: in std_logic;
- left_pos: in integer range 0 to 430;
- left_pos_out: out integer range 0 to 430;
+ Port (
+ right_pos: in integer range 0 to 430;
+ right_pos_out: out integer range 0 to 430;
ball_pos: in integer range 0 to 480
);
end AI;
@@ -15,12 +14,11 @@ end AI;
architecture Behavioral of AI is
begin
- process (left_pos, ball_pos, ai_enabled)
+ process (right_pos, ball_pos)
begin
- if ai_enabled ='0' then
- left_pos_out <=left_pos;
- else
- left_pos_out <= ball_pos;
+ if ball_pos < 25 then right_pos_out <= 0;
+ elsif ball_pos > 455 then right_pos_out <= 430;
+ else right_pos_out <= (ball_pos - 25);
end if;
end process;
BIN  Pong.ise
View
Binary file not shown
21 balken.vhd
View
@@ -9,6 +9,8 @@ entity balken is
buttons : in std_logic_vector (3 downto 0);
bar_left : out integer range 0 to 430;
bar_right : out integer range 0 to 430;
+ right_ai: in integer range 0 to 430;
+ ai_enabled: in std_logic;
X : in integer range 0 to 640;
Y : in integer range 0 to 480;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
@@ -24,8 +26,8 @@ architecture Behavioral of balken is
signal hold_intern : std_logic_vector (1 downto 0);
begin
- bar_left <= ltop;
bar_right <= rtop;
+ bar_left <= ltop;
process (rgb_in,X,Y,clk25,reset,ltop,rtop)
begin
@@ -63,13 +65,16 @@ begin
end if;
-- move right
- if (rtop < 2 and buttons(2) = '1')
- or (rtop > 429 and buttons(3) = '1') then
- hold_intern(1) <= '1';
- end if;
- if hold_intern(1) = '0' then
- if buttons(2) = '1' then rtop <= rtop - 1; end if;
- if buttons(3) = '1' then rtop <= rtop + 1; end if;
+ if ai_enabled ='1' then rtop <= right_ai;
+ else
+ if (rtop < 2 and buttons(2) = '1')
+ or (rtop > 429 and buttons(3) = '1') then
+ hold_intern(1) <= '1';
+ end if;
+ if hold_intern(1) = '0' then
+ if buttons(2) = '1' then rtop <= rtop - 1; end if;
+ if buttons(3) = '1' then rtop <= rtop + 1; end if;
+ end if;
end if;
else
speedCount <= '1';
2  process_keys.vhd
View
@@ -54,7 +54,7 @@ begin
ai_key: process (clk25)
begin
if clk25'event and clk25='1' then
- if keys_in(13)='1' and set_inverse_key ='0' then
+ if keys_in(13)='1' and set_ai_key ='0' then
Q_AI <= not (Q_AI);
set_AI_key <= '1';
elsif set_AI_key ='1' and keys_in(13)='0' then set_AI_key <= '0'; end if;
28 vga.vhd
View
@@ -78,6 +78,8 @@ architecture Behavioral of vga is
buttons : in std_logic_vector (3 downto 0);
bar_left : out integer range 0 to 430;
bar_right : out integer range 0 to 430;
+ right_ai: in integer range 0 to 430;
+ ai_enabled: in std_logic;
X : in integer range 0 to 640;
Y : in integer range 0 to 480;
rgb_in : in STD_LOGIC_VECTOR (2 downto 0);
@@ -111,14 +113,13 @@ architecture Behavioral of vga is
component AI is
Port (
- ai_enabled: in std_logic;
- left_pos: in integer range 0 to 430;
- left_pos_out: out integer range 0 to 430;
+ right_pos: in integer range 0 to 430;
+ right_pos_out: out integer range 0 to 430;
ball_pos: in integer range 0 to 480
);
end component;
- signal intermediate_bar_left : integer range 0 to 430; -- to AI
+ signal intermediate_bar_left : integer range 0 to 430; -- output of balken
signal intermediate_bar_right : integer range 0 to 430;
signal intermediate_ball_out : bit;
signal intermediate_X : integer range 0 to 640;
@@ -139,7 +140,7 @@ architecture Behavioral of vga is
signal intermediate_paddlespeed: bit;
signal intermediate_ballpos : integer range 0 to 480;
signal intermediate_ai_enabled : std_logic;
- signal intermediate_bar_left2 : integer range 0 to 430; --after AI
+ signal intermediate_bar_right2 : integer range 0 to 430; -- output of AI
begin
@@ -195,11 +196,19 @@ begin
rgb_in => intermediate_rgb1,
rgb_out => intermediate_rgb2);
+ KI : AI port map (
+ right_pos => intermediate_bar_right,
+ right_pos_out => intermediate_bar_right2,
+ ball_pos => intermediate_ballpos
+ );
+
male_balken : balken port map (
speed => intermediate_paddlespeed,
hold => intermediate_hold,
bar_left => intermediate_bar_left,
bar_right => intermediate_bar_right,
+ right_ai => intermediate_bar_right2,
+ ai_enabled => intermediate_ai_enabled,
buttons => intermediate_keys (3 downto 0),
X => intermediate_X,
Y => intermediate_Y,
@@ -208,17 +217,10 @@ begin
clk25 => intermediate_clk25,
reset => intermediate_reset);
- KI : AI port map (
- ai_enabled => intermediate_ai_enabled,
- left_pos => intermediate_bar_left,
- left_pos_out => intermediate_bar_left2,
- ball_pos => intermediate_ballpos
- );
-
male_ball : ball port map (
speed => intermediate_ballspeed (1 downto 0),
hold => intermediate_hold,
- bar_left => intermediate_bar_left2,
+ bar_left => intermediate_bar_left,
bar_right => intermediate_bar_right,
ball_out => intermediate_ball_out,
X => intermediate_X,
Please sign in to comment.
Something went wrong with that request. Please try again.