Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO; use Ada.Text_IO;
- with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
- with Ada.Numerics.Discrete_Random;
- procedure U2015_2 is
- type Nail_Line is array(1..10) of Boolean;
- type Nail_Line_Mirror is array(1..9) of Boolean;
- type Nail_Board is array(1..20) of Nail_Line;
- type Nail_Board_Mirror is array(1..20) of Nail_Line_Mirror;
- function Randomizer(Max : in Integer) return Integer is
- subtype Random_Number is
- Integer range 1..Max;
- package Randomized is
- new Ada.Numerics.Discrete_Random(Random_Number);
- use Randomized;
- G : Generator;
- N : Integer;
- begin
- Reset(G);
- N := Random(G);
- return N;
- end Randomizer;
- function Check_Position(Board : in Nail_Board; Y,X : in Integer) return Boolean is
- begin
- if Board(Y)(X) = True then
- return False;
- end if;
- if X = 1 then
- if Board(Y)(X+1) = False then
- return True;
- else return False;
- end if;
- elsif X = 10 then
- if Board(Y)(X-1) = False then
- return True;
- else return False;
- end if;
- elsif Board(Y)(X+1) = False and Board(Y)(X-1) = False then
- return True;
- else
- return False;
- end if;
- end Check_Position;
- procedure Set_Nails(Board : out Nail_Board; Mirror : out Nail_Board_Mirror) is
- Nail_Counter : Integer := 0;
- X, Y : Integer;
- begin
- while Nail_Counter < 70 loop
- Y := Randomizer(20);
- if Nail_Counter = 69 then
- X := 10;
- else
- X := Randomizer(10);
- end if;
- if Check_Position(Board,Y,X) = True then
- Board(Y)(X) := True;
- if X = 10 then
- Nail_Counter := Nail_Counter+1;
- else
- Mirror(Y)(10-X) := True;
- Nail_Counter := Nail_Counter+2;
- end if;
- end if;
- end loop;
- Put("Antal spikar: ");
- Put(Nail_Counter,0);
- end Set_Nails;
- procedure Print_Board is
- My_Nail_Board : Nail_Board := (others => (others => False));
- My_Nail_Board_Mirror : Nail_Board_Mirror := (others => (others => False));
- begin
- Set_Nails(My_Nail_Board, My_Nail_Board_Mirror);
- New_Line;
- for Y in 1..20 loop
- Put("|");
- for X in 1..10 loop
- if My_Nail_Board(Y)(X) = True then
- Put(".");
- else
- Put(" ");
- end if;
- end loop;
- for X in 1..9 loop
- if My_Nail_Board_Mirror(Y)(X) = True then
- Put(".");
- else
- Put(" ");
- end if;
- end loop;
- Put_Line("|");
- end loop;
- Put_Line("| |WIN| |WIN| |");
- Put_Line("|___|___|___|___|___|");
- end Print_Board;
- begin
- Print_Board;
- end U2015_2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement