Exemple #1
0
        private static IEnumerable <Tile> AddHooks(IEnumerable <string> binaryStrings)
        {
            var results = new List <Tile>();

            IEnumerable <string> encodedDigits = binaryStrings.ToList();

            foreach (var shouldCarry in new[] { true, false })
            {
                foreach (var binaryString in encodedDigits)
                {
                    var hook = new RightHook(binaryString, binaryString.Length * 4, shouldCarry);

                    results.AddRange(hook.Tiles());
                }
            }

            var sample   = encodedDigits.First();
            var leftHook = new LeftHook(sample, sample.Length);

            results.AddRange(leftHook.Tiles());

            return(results);
        }
Exemple #2
0
        private List <Tile> CreateDigits(int offset, string value)
        {
            var bitsPerDigit = (height - 1) / 4;

            var binary = string.Concat(Enumerable.Repeat("0", bitsPerDigit));

            var left = new Tile($"Seed {offset}, Left")
            {
                West = new Glue($"Seed {offset - 1}"),
                East = new Glue($"Seed {offset}, Left -> Middle")
            };


            var middle = new Tile($"Seed {offset}, Middle")
            {
                West = left.East,
                East = new Glue($"Seed {offset}, Middle -> Right")
            };

            var id = Guid.NewGuid();

            var right = new Tile($"Seed {offset}, Right")
            {
                West  = middle.East,
                North = new Glue(id.ToString())
            };


            var bits = new List <Tile>();

            for (var i = 0; i < value.Length; i++)
            {
                var bit = value[i] == '0' ? (AbstractBit) new ZeroBit(binary, i, $"Seed {offset}, Bit {i}", "Seed") :
                          new OneBit(binary, i, $"Seed {offset}, Bit {i}", "Seed");

                var tilesZ = bit.Tiles().ToList();

                tilesZ.Last().South = new Glue(id.ToString());

                id = Guid.NewGuid();

                tilesZ.First().North = new Glue(id.ToString());

                bits.AddRange(tilesZ);
            }


            var hook = new RightHook($"Seed {offset}, Hook", height - 1, true)
            {
                NorthGlue = new Glue(id.ToString())
            };

            var hooktiles = hook.Tiles();

            hook.AttachTop(new Glue(id.ToString()));
            hook.AttachEast(new Glue($"Seed {offset}"));
            var hookTiles = hooktiles.ToList();

            foreach (var t in hookTiles)
            {
                if (t.Name.Contains("HookBottom"))
                {
                    t.South = new Glue();
                }
            }
            hookTiles.RemoveAt(0);

            var tileToConcat = hookTiles.FirstOrDefault(t => t.South is null);

            if (tileToConcat != null)
            {
                tileToConcat.South = new Glue();
            }


            var tiles = new List <Tile> {
                left, middle, right
            };

            tiles.AddRange(hookTiles);
            tiles.AddRange(bits);

            return(tiles);
        }