Example #1
0
        public TileList Clone()
        {
            var foo = new TileList();

            foreach (var tile in this)
            {
                Add(tile);
            }
            return(foo);
        }
Example #2
0
        private static List <Tile> GetCorners(TileList list)
        {
            List <Tile> corners = new List <Tile>();

            foreach (var tile in list)
            {
                int neighbours = tile.GetPossibleNeighbours(list);
                if (neighbours == 2)
                {
                    corners.Add(tile);
                }
            }
            return(corners);
        }
Example #3
0
        public static void Task1()
        {
            Console.WriteLine("AOC2020_Day20_1");

            TileList list = new TileList();

            list.Load();

            long mult = 1;

            foreach (var tile in GetCorners(list))
            {
                int neighbours = tile.GetPossibleNeighbours(list);
                Console.WriteLine("tile : {0}", tile.TileNum);
                mult *= tile.TileNum;
            }

            Console.WriteLine("Mult : {0}", mult);
        }
Example #4
0
        public int GetPossibleNeighbours(TileList list)
        {
            int neighbours = 0;

            foreach (var tile in list)
            {
                if (TileNum == tile.TileNum)
                {
                    continue;
                }
                foreach (var side in Sides)
                {
                    if (tile.ContainsSide(side))
                    {
                        neighbours++;
                    }
                }
            }
            return(neighbours);
        }
Example #5
0
        public static void Task2()
        {
            Console.WriteLine("AOC2020_Day20_2");

            TileList list = new TileList();

            list.Load();


            // proste vemu prvni roh
            var TopLeft = GetCorners(list)[0];


            // zrotuji jej tak aby mel vlevo a vpravo volno...
            while (
                list.FindMatchingTileBySide(TopLeft, TopLeft.t) != null ||
                list.FindMatchingTileBySide(TopLeft, TopLeft.l) != null
                )
            {
                TopLeft.Rotate();
            }

            // mapa spravne zorientocanych tilu
            Tile [,] tmap = new Tile[12, 12];
            tmap[0, 0]    = TopLeft;

            int cnt = Convert.ToInt32(Math.Sqrt(list.Count));

            // vyplnim mapu
            for (int j = 0; j < cnt; j++)
            {
                for (int i = 1; i < cnt; i++)
                {
                    // najdu tile pod nim a zrotuji tak aby byl side na vrsku...
                    Tile top = tmap[j, i - 1];
                    tmap[j, i] = list.FindMatchingTileBySide(top, top.b);
                    tmap[j, i].MakeTopside(top.b);

                    // najdu tile mapravo a zrotuji tak aby byl side na vnalevo
                    Tile left = tmap[i - 1, j];
                    tmap[i, j] = list.FindMatchingTileBySide(left, left.r);
                    tmap[i, j].MakeLeftside(left.r);
                }
            }

            // jedna mapa
            var map = new char[cnt * 8, cnt * 8];

            for (int ty = 0; ty < cnt; ty++)
            {
                for (int tx = 0; tx < cnt; tx++)
                {
                    // najdu tile pod nim a zrotuji tak aby byl side na vrsku...
                    Tile t = tmap[tx, ty];

                    for (int y = 1; y < 9; y++)
                    {
                        for (int x = 1; x < 9; x++)
                        {
                            map[tx * 8 + x - 1, ty *8 + y - 1] = t.map[x, y];
                        }
                    }
                }
            }

            var monster = new Monster();

            monster.Load();

            for (int i = 0; i < 8; i++)
            {
                monster.TestMonsters(ref map);
                if ((i + 1) % 4 == 0)
                {
                    Arr2dManipulation.FlipH(ref map);
                }
                else
                {
                    Arr2dManipulation.Rotate(ref map);
                }
            }

            Console.WriteLine("# : {0}", Arr2dManipulation.GetHaspCount(map));
        }