Ejemplo n.º 1
0
        private void SetUp()
        {
            var id = Guid.NewGuid();

            for (var i = 0; i < height; i++)
            {
                var tile = Tile(i);

                tile.North = i == 0 ? GlueFactory.PreReadRight(signal) : G(id);

                id = Guid.NewGuid();

                if (i + 1 == height)
                {
                    tile.West = G(id);

                    if (signal != Signals.Carry)
                    {
                        tile.South = GlueFactory.LeftWall;
                    }
                }
                else
                {
                    tile.South = G(id);
                }

                tiles.Add(tile);
            }

            var right = Tile(height);

            right.East = G(id);
            id         = Guid.NewGuid();
            right.West = G(id);
            tiles.Add(right);

            var left = Tile(height + 1);

            left.East = right.West;

            left.West = GlueFactory.Reader(signal);

            tiles.Add(left);
        }
Ejemplo n.º 2
0
        private void SetUp()
        {
            var id = Guid.NewGuid();

            for (var i = 0; i < height; i++)
            {
                var tile = Tile(i);

                tile.North = i == 0 ? GlueFactory.PreReadLeft(signal) : G(id);

                id = Guid.NewGuid();

                if (i + 1 == height)
                {
                    tile.Up    = G(id);
                    tile.South = GlueFactory.RightTurn();
                }
                else
                {
                    tile.South = G(id);
                }

                tiles.Add(tile);
            }

            var leftZ1 = Tile(height);

            leftZ1.Down = G(id);
            id          = Guid.NewGuid();

            leftZ1.East = G(id);

            var rightZ1 = Tile(height + 1);

            rightZ1.West = leftZ1.East;
            rightZ1.East = GlueFactory.Reader(signal);
            tiles.Add(leftZ1);
            tiles.Add(rightZ1);
        }
Ejemplo n.º 3
0
        private void Setup()
        {
            firstZ0  = Tile($"LR: Z0-1st, B='{bitsRead}', S={signal}");
            secondZ0 = Tile($"LR: Z0-2nd, B='1{bitsRead}', S={signal}");
            thirdZ0  = Tile($"LR: Z0-3rd, B='1{bitsRead}', S={signal}");
            fourthZ0 = Tile($"LR: Z0-4th, B='1{bitsRead}', S={signal}");


            firstZ1  = Tile($"LR: Z1-1st, B='{bitsRead}', S={signal}");
            secondZ1 = Tile($"LR: Z1-2nd, B='0{bitsRead}', S={signal}");
            thirdZ1  = Tile($"LR: Z1-3rd, B='0{bitsRead}', S={signal}");
            fourthZ1 = Tile($"LR: Z1-4th, B='0{bitsRead}', S={signal}");
            fifthZ1  = Tile($"LR: Z1-5th, B='0{bitsRead}', S={signal}");

            tiles = new List <Tile> {
                firstZ0, secondZ0, thirdZ0, fourthZ0, firstZ1, secondZ1, thirdZ1, fourthZ1, fifthZ1
            };

            if (bitsRead.Length == 0)
            {
                firstZ1.West = GlueFactory.Reader(signal);
            }
            else
            {
                firstZ0.South = new Glue($"LR: ReadContinue: {bitsRead}, S={signal}");
            }
            firstZ0.North  = Bind(firstZ0, secondZ0);
            secondZ0.South = firstZ0.North;

            secondZ0.North = Bind(secondZ0, thirdZ0);
            thirdZ0.South  = secondZ0.North;

            thirdZ0.North  = Bind(thirdZ0, fourthZ0);
            fourthZ0.South = thirdZ0.North;

            firstZ0.Up = fourthZ0.Down;

            firstZ0.Up   = Bind(firstZ0, firstZ1);
            firstZ1.Down = firstZ0.Up;

            firstZ1.North  = Bind(firstZ1, secondZ1);
            secondZ1.South = firstZ1.North;

            secondZ1.North = Bind(secondZ1, thirdZ1);
            thirdZ1.South  = secondZ1.North;

            thirdZ1.North = Bind(thirdZ1, fourthZ1);

            fourthZ1.South = thirdZ1.North;
            fourthZ1.Down  = Bind(fourthZ1, fifthZ1);
            fifthZ1.Up     = fourthZ1.Down;

            // final bit
            if (bitsRead.Length + 1 == totalBits)
            {
                var currentValueForFifthZ1  = $"0{bitsRead}";
                var currentValueForFourthZ0 = $"1{bitsRead}";

                fourthZ0.North = GlueFactory.IncrementStopper(currentValueForFourthZ0, signal);
                fifthZ1.North  = GlueFactory.IncrementStopper(currentValueForFifthZ1, signal);
            }
            else
            {
                fourthZ0.North = new Glue($"LR: ReadContinue: 1{bitsRead}, S={signal}");
                fifthZ1.North  = new Glue($"LR: ReadContinue: 0{bitsRead}, S={signal}");
            }
        }
Ejemplo n.º 4
0
        private void Setup()
        {
            firstZ0  = Tile($"R: Z0-1st, B='{bitsRead}', S={signal}");
            secondZ0 = Tile($"R: Z0-2nd, B='{bitsRead}1', S={signal}");
            thirdZ0  = Tile($"R: Z0-3rd, B='{bitsRead}1', S={signal}");
            fourthZ0 = Tile($"R: Z0-4th, B='{bitsRead}1', S={signal}");


            firstZ1  = Tile($"R: Z1-1st, B='{bitsRead}', S={signal}");
            secondZ1 = Tile($"R: Z1-2nd, B='{bitsRead}0', S={signal}");
            thirdZ1  = Tile($"R: Z1-3rd, B='{bitsRead}0', S={signal}");
            fourthZ1 = Tile($"R: Z1-4th, B='{bitsRead}0', S={signal}");
            fifthZ1  = Tile($"R: Z1-5th, B='{bitsRead}0', S={signal}");

            tiles = new List <Tile> {
                firstZ0, secondZ0, thirdZ0, fourthZ0, firstZ1, secondZ1, thirdZ1, fourthZ1, fifthZ1
            };

            if (bitsRead.Length == 0)
            {
                firstZ0.East = GlueFactory.Reader(signal);
            }
            else
            {
                firstZ0.South = new Glue($"ReadContinue: {bitsRead}, S={signal}");
            }

            firstZ0.North  = Bind(firstZ0, secondZ0);
            secondZ0.South = firstZ0.North;

            secondZ0.North = Bind(secondZ0, thirdZ0);
            thirdZ0.South  = secondZ0.North;

            thirdZ0.North  = Bind(thirdZ0, fourthZ0);
            fourthZ0.South = thirdZ0.North;

            firstZ0.Up = fourthZ0.Down;

            firstZ0.Up   = Bind(firstZ0, firstZ1);
            firstZ1.Down = firstZ0.Up;

            firstZ1.North  = Bind(firstZ1, secondZ1);
            secondZ1.South = firstZ1.North;

            secondZ1.North = Bind(secondZ1, thirdZ1);
            thirdZ1.South  = secondZ1.North;

            thirdZ1.North = Bind(thirdZ1, fourthZ1);

            fourthZ1.South = thirdZ1.North;
            fourthZ1.Down  = Bind(fourthZ1, fifthZ1);
            fifthZ1.Up     = fourthZ1.Down;


            // final bit
            if (bitsRead.Length + 1 == totalBits)
            {
                fourthZ0.North = new Glue($"ReadContinue: {bitsRead}1, S={signal}");
                fifthZ1.North  = new Glue($"ReadContinue: {bitsRead}0, S={signal}");


                var currentCarrySignal = signal == Signals.Carry;

                if (currentCarrySignal)
                {
                    var value     = $"{bitsRead}0";
                    var inDecimal = Convert.ToInt32(value, 2);
                    var canIncrementIfLastBitWas0 = inDecimal < baseK - 1;
                    if (canIncrementIfLastBitWas0)
                    {
                        var valueToCreateFifthZ1 = IncrementInBinary(value);
                        fifthZ1.North = GlueFactory.RightHook(valueToCreateFifthZ1, Signals.NoCarry);
                    }
                    else
                    {
                        var allZeros = string.Concat(Enumerable.Repeat("0", totalBits));

                        fifthZ1.North = GlueFactory.RightHook(allZeros, Signals.Carry);
                    }


                    value = $"{bitsRead}1";
                    var canIncrementIfLastBitWas1 = Convert.ToInt32($"{bitsRead}1", 2) < baseK - 1;


                    if (canIncrementIfLastBitWas1)
                    {
                        var valueToCreateFourthZ0 = IncrementInBinary(value);
                        fourthZ0.North = GlueFactory.RightHook(valueToCreateFourthZ0, Signals.NoCarry);
                    }
                    else
                    {
                        var allZeros = string.Concat(Enumerable.Repeat("0", totalBits));
                        fourthZ0.North = GlueFactory.RightHook(allZeros, Signals.Carry);
                    }
                }
                else
                {
                    fourthZ0.North = GlueFactory.RightHook($"{bitsRead}1", Signals.NoCarry);
                    fifthZ1.North  = GlueFactory.RightHook($"{bitsRead}0", Signals.NoCarry);
                }
            }
            else
            {
                fourthZ0.North = new Glue($"ReadContinue: {bitsRead}1, S={signal}");
                fifthZ1.North  = new Glue($"ReadContinue: {bitsRead}0, S={signal}");
            }
        }