text
stringlengths
0
234
end flip_complete_image;
pragma Warnings (Off, "procedure ""put_line"" is not referenced");
procedure put_line(i : in Complete_Image_Sets.Set) is
pragma Warnings (On, "procedure ""put_line"" is not referenced");
max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;
begin
for y in 0..max loop
for x in 0..max loop
if i.contains(Position'(x=>x, y=>y)) then
TIO.put("#");
else
TIO.put(".");
end if;
end loop;
TIO.new_line;
end loop;
end put_line;
function dragon_pixel(x, y : in Natural) return Boolean is
begin
return complete_image.contains(Position'(x=>x, y=>y));
end dragon_pixel;
function dragon_start(x, y : in Natural) return Boolean is
begin
return
dragon_pixel(x+0, y+1) and then
dragon_pixel(x+1, y+2) and then
dragon_pixel(x+4, y+2) and then
dragon_pixel(x+5, y+1) and then
dragon_pixel(x+6, y+1) and then
dragon_pixel(x+7, y+2) and then
dragon_pixel(x+10, y+2) and then
dragon_pixel(x+11, y+1) and then
dragon_pixel(x+12, y+1) and then
dragon_pixel(x+13, y+2) and then
dragon_pixel(x+16, y+2) and then
dragon_pixel(x+17, y+1) and then
dragon_pixel(x+18, y+0) and then
dragon_pixel(x+18, y+1) and then
dragon_pixel(x+19, y+1);
end dragon_start;
function count_dragon_pixels return Natural is
max : constant Natural := Natural(Ada.Numerics.Elementary_Functions.sqrt(Float(tiles.length)) * 8.0) - 1;
cnt : Natural := 0;
begin
for rot in 0..3 loop
for y in 0..max loop
for x in 0..max loop
if dragon_start(x, y) then
cnt := cnt + 1;
end if;
end loop;
end loop;
TIO.put_line("Found dragons: " & cnt'IMAGE);
if cnt /= 0 then
return cnt * 15;
end if;
TIO.put_line("Rotating...");
rotate_complete_image;
end loop;
TIO.put_line("Flipping...");
flip_complete_image;
return count_dragon_pixels;
end count_dragon_pixels;
procedure layout is
type Candidate is record
id : Natural;
orientation : Configuration;
left, right, up, down : Natural;
end record;
package Natural_Vectors is new Ada.Containers.Vectors
(Index_Type => Natural,
Element_Type => Natural);
use Natural_Vectors;
package Candidate_Maps is new Ada.Containers.Indefinite_Hashed_Maps
(Key_Type => Natural,
Element_Type => Candidate,
Hash => id_hash,
Equivalent_Keys => "=");
use Candidate_Maps;
function update_neighbor_links(id : in Natural; state : in out Candidate_Maps.Map) return Boolean is
c : Candidate := state(id);
es : constant Edge_Array := edges(c.id, c.orientation);
t : constant Tile := tiles(c.id);
begin
for n of t.neighbors loop
if state.contains(n) then
declare
neigh_cand : Candidate := state(n);
neigh_es : constant Edge_Array := edges(neigh_cand.id, neigh_cand.orientation);
begin
if es(0) = neigh_es(2) then
c.up := neigh_cand.id;