Example #1
0
        internal void FindSeaMonsters()
        {
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.FlipHorizontal(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            _SeaMonster = RotationHelper.RotateLeft(_SeaMonster);
            FindSeaMonsters(_SeaMonster);

            PrintGrid();
        }
Example #2
0
        internal void JoinTo(Tile tileAbove, Tile tileLeft)
        {
            if (tileAbove != null)
            {
                _Grid = RotationHelper.JoinToBottom(_Grid, tileAbove.BottomEdge, TopEdge, LeftEdge, BottomEdge, RightEdge);
            }

            if (tileLeft != null)
            {
                _Grid = RotationHelper.JoinToLeft(_Grid, tileLeft.RightEdge, TopEdge, LeftEdge, BottomEdge, RightEdge);
            }
        }
Example #3
0
        private Dictionary <Point, Tile> PlaceTiles()
        {
            var corners     = FindCornerTiles();
            var tileArray   = new Dictionary <Point, Tile>();
            var placedTiles = new HashSet <int>();
            var cornerTile  = _Tiles[corners[0]];

            tileArray[new Point(0, 0)] = cornerTile;
            cornerTile.Grid            = RotationHelper.FlipHorizontal(cornerTile.Grid);

            placedTiles.Add(corners[0]);

            int x = 1, y = 0;

            while (placedTiles.Count != _Tiles.Count)
            {
                var tileIdToPlace = 0;

                var  pointAbove = new Point(x, y - 1);
                Tile tileAbove  = tileArray.ContainsKey(pointAbove) ? tileArray[pointAbove] : null;

                var  pointLeft = new Point(x - 1, y);
                Tile tileLeft  = tileArray.ContainsKey(pointLeft) ? tileArray[pointLeft] : null;

                if (tileAbove != null && tileLeft != null)
                {
                    tileIdToPlace = FindCommonTileId(placedTiles, tileAbove, tileLeft);
                }
                else if (x == 0 || y == 0)
                {
                    var singleTile = tileAbove != null ? tileAbove : tileLeft;
                    tileIdToPlace = FindUnplacedTileId(placedTiles, singleTile);
                }
                if (tileIdToPlace != 0)
                {
                    placedTiles.Add(tileIdToPlace);
                    tileArray[new Point(x, y)] = _Tiles[tileIdToPlace];
                    _Tiles[tileIdToPlace].JoinTo(tileAbove, tileLeft);

                    (x, y) = GetNextPointToPlace(x, y, _SideLength);
                }
                else
                {
                    throw new Exception($"No tile find to place at ({x},{y})");
                }
            }
            return(tileArray);
        }