text
stringlengths
0
234
end Reset_Board;
procedure Print_Board is
Small_String : String(1..6);
begin -- Print_Board
Clear;
Attribute_On(1);
Pretty_Print_Line_Window(Owner_Type'Image(Owner_Type'Val(Turn)));
for I in reverse Our_Board'Range loop
Pretty_Print_Line_Window(" -------------------------------------------------------------------------");
Pretty_Print_Line_Window(" | | | | | | | | | ");
Pretty_Print_Window(Integer'Image(Integer(I) + 1) & " | ");
for J of Our_Board(I) loop
if J /= Empty_Piece then
if J.Owner = Player_1 then
Attribute_On(2);
end if;
Put(To=>Small_String, Item=>J.Name);
Pretty_Print_Window(Small_String);
Attribute_On(1);
else
Pretty_Print_Window(" ");
end if;
Pretty_Print_Window(" | ");
end loop;
Pretty_Print_Line_Window(ASCII.lf & " | | | | | | | | | ");
end loop;
Pretty_Print_Line_Window(" -------------------------------------------------------------------------");
Pretty_Print_Line_Window(" A B C D E F G H ");
Refresh;
end Print_Board;
procedure Move (From, To : in Cordinate_Type) is
begin -- Move
if Our_Board(From.Y)(From.X).Owner /= Owner_Type'Val(Turn) then -- check if it's their piece
raise Not_Allowed;
end if;
case Our_Board(From.Y)(From.X).Name is
-- check to see if move if possible
when Pawn => --since the pawn move logic is so complex, it's best to do it all here
declare
Turn_Test : Integer;
function "+" (Left: in Position; Right : in Integer) return Position is
(Position(Integer(Left) + Right));
begin
Turn_Test := (if Turn = 0 then -1 else 1);
if Integer(From.X - To.X) = 0 then -- advance
if Our_Board(To.Y)(To.X).Owner = None and -- can't attack forward
then (Integer(From.Y - To.Y) = Turn_Test or (Integer(From.Y - To.Y) = Turn_Test*2 and Our_Board(From.Y)(From.X).Has_Moved = No and Our_Board(To.Y + Turn_Test)(To.X).Owner = None)) then --check if move is valid
Take_Space(From, To);
else
raise Not_Allowed;
end if;
elsif Integer(From.X - To.X) in -1..1 then -- attack move
if Integer(From.Y - To.Y) = Turn_Test then --check if move is valid
if Our_Board(To.Y)(To.X).Owner /= None then
Take_Space(From, To);
elsif Our_Board(Last_Moved.Y)(Last_Moved.X).Name = Pawn and -- en passent
then Last_Moved = (X=>To.X, Y=>To.Y + Turn_Test) then
Our_Board(Last_Moved.Y)(Last_Moved.X) := Empty_Piece;
Take_Space(From, To);
else
raise Not_Allowed;
end if;
else
raise Not_Allowed;
end if;
else
raise Not_Allowed;
end if;
Function Definition: procedure Chess is
Function Body: -- pragma Suppress(All_Checks);
type Game_Options is (None, Network, Local);
procedure Print_and_Clear (Item : in String) with Inline is
begin
Attribute_On(3);
Pretty_Print_Line_Window(Item);
Refresh;
delay 1.0;
Print_Board;
end Print_and_Clear;
Player_Select_Request : Cordinate_Type;
Player_Move_Request : Cordinate_Type;
Temp : Byte;
Game_Status : Game_Options := None;
Port : Port_Type := 0;
Is_Host : Boolean := False;
-- Address_String : String (1..15) := (others=>' ');
Address_String : String := "192.168.1.53";
Client : Socket_Type;
Address : Sock_Addr_Type;
Channel : Stream_Access;