Пример #1
0
        // x1, y1 included -- x2, y2 excluded
        public void Fill(int x1, int y1, int x2, int y2, BefungeCommand c, CodeTag topleftTag = null, bool skipExactCopies = false)
        {
            if (x1 >= x2)
            {
                return;
            }
            if (y1 >= y2)
            {
                return;
            }

            for (int x = x1; x < x2; x++)
            {
                for (int y = y1; y < y2; y++)
                {
                    if (skipExactCopies && c.EqualsTagLess(this[x, y]))
                    {
                        // Do nothing - skiped
                    }
                    else if (x == x1 && y == y1 && topleftTag != null)
                    {
                        this[x, y] = c.CopyWithTag(topleftTag);
                    }
                    else
                    {
                        this[x, y] = c;
                    }
                }
            }
        }
Пример #2
0
        public static CodePiece DoCompressHorizontally(CodePiece l, CodePiece r)
        {
            if (l.Width == 0 || r.Width == 0)
            {
                return(null);
            }

            CodePiece connect = new CodePiece();

            int xL = l.MaxX - 1;
            int xR = r.MinX;

            for (int y = Math.Min(l.MinY, r.MinY); y < Math.Max(l.MaxY, r.MaxY); y++)
            {
                CodeTag tag = null;

                if (l[xL, y].Tag != null && r[xR, y].Tag != null)
                {
                    return(null);                    // Can't compress - two tags would need to be merged
                }

                tag = l[xL, y].Tag ?? r[xR, y].Tag;

                if (l[xL, y].Type == BefungeCommandType.NOP && r[xR, y].Type == BefungeCommandType.NOP)
                {
                    connect[0, y] = new BefungeCommand(BefungeCommandType.NOP, tag);
                }
                else if (l[xL, y].Type != BefungeCommandType.NOP && r[xR, y].Type != BefungeCommandType.NOP)
                {
                    if (l[xL, y].Type == r[xR, y].Type && l[xL, y].Param == r[xR, y].Param && l[xL, y].IsCompressable())
                    {
                        connect[0, y] = new BefungeCommand(l[xL, y].Type, l[xL, y].Param, tag);
                    }
                    else
                    {
                        return(null);                        // Can't compress - two commands are colliding
                    }
                }
                else if (l[xL, y].Type != BefungeCommandType.NOP)
                {
                    connect[0, y] = new BefungeCommand(l[xL, y].Type, l[xL, y].Param, tag);
                }
                else if (r[xR, y].Type != BefungeCommandType.NOP)
                {
                    connect[0, y] = new BefungeCommand(r[xR, y].Type, r[xR, y].Param, tag);
                }
                else
                {
                    throw new WTFException();
                }
            }

            return(connect);
        }
Пример #3
0
        public static CodePiece DoCompressVertically(CodePiece t, CodePiece b)
        {
            if (t.Width == 0 || b.Width == 0)
            {
                return(null);
            }

            CodePiece connect = new CodePiece();

            int yT = t.MaxY - 1;
            int yB = b.MinY;

            for (int x = Math.Min(t.MinX, b.MinX); x < Math.Max(t.MaxX, b.MaxX); x++)
            {
                CodeTag tag = null;

                if (t[x, yT].Tag != null && b[x, yB].Tag != null)
                {
                    return(null);                    // Can't compress - two tags would need to be merged
                }

                tag = t[x, yT].Tag ?? b[x, yB].Tag;

                if (t[x, yT].Type == BefungeCommandType.NOP && b[x, yB].Type == BefungeCommandType.NOP)
                {
                    connect[x, 0] = new BefungeCommand(BefungeCommandType.NOP, tag);
                }
                else if (t[x, yT].Type != BefungeCommandType.NOP && b[x, yB].Type != BefungeCommandType.NOP)
                {
                    if (t[x, yT].Type == b[x, yB].Type && t[x, yT].Param == b[x, yB].Param && t[x, yT].IsCompressable())
                    {
                        connect[x, 0] = new BefungeCommand(t[x, yT].Type, t[x, yT].Param, tag);
                    }
                    else
                    {
                        return(null);                        // Can't compress - two commands are colliding
                    }
                }
                else if (t[x, yT].Type != BefungeCommandType.NOP)
                {
                    connect[x, 0] = new BefungeCommand(t[x, yT].Type, t[x, yT].Param, tag);
                }
                else if (b[x, yB].Type != BefungeCommandType.NOP)
                {
                    connect[x, 0] = new BefungeCommand(b[x, yB].Type, b[x, yB].Param, tag);
                }
                else
                {
                    throw new WTFException();
                }
            }

            return(connect);
        }
Пример #4
0
 public static BefungeCommand Dig(byte v, CodeTag tag)
 {
     if (v < 10)
     {
         return(new BefungeCommand(BefungeCommandType.Other, '0' + v, tag));
     }
     else
     {
         throw new ArgumentException();
     }
 }
Пример #5
0
        public void SetTag(int x, int y, CodeTag tag, bool force = false)
        {
            BefungeCommand cmd = this[x, y];

            if (cmd.HasTag() && !force)
            {
                throw new InvalidCodeManipulationException("Tryed to remove existing Tag: " + cmd.Tag + " with: " + tag);
            }

            BefungeCommand newcmd = new BefungeCommand(cmd.Type, cmd.Param, tag);

            ForceSet(x, y, newcmd);
        }
Пример #6
0
        public TagLocation FindTag(CodeTag tag)
        {
            if (!tagCache.Contains(tag))
            {
                return(null);
            }

            for (int x = MinX; x < MaxX; x++)
            {
                for (int y = MinY; y < MaxY; y++)
                {
                    if (this[x, y].Tag == tag)
                    {
                        return(new TagLocation(x, y, this[x, y]));
                    }
                }
            }

            return(null);
        }
Пример #7
0
 public static BefungeCommand If_Horizontal_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.IfHorizontal, tag));
 }
Пример #8
0
 public static BefungeCommand If_Vertical_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.IfVertical, tag));
 }
Пример #9
0
 public BefungeCommand(BefungeCommandType t, CodeTag p)
     : this(t, 0, p)
 {
     //--
 }
Пример #10
0
 public static BefungeCommand PC_Random_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.PCRandom, tag));
 }
Пример #11
0
 public static BefungeCommand Stop_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Stop, tag));
 }
Пример #12
0
 public static BefungeCommand Chr(int v, CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Other, v, tag));
 }
Пример #13
0
 public static BefungeCommand Modulo_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Modulo, tag));
 }
Пример #14
0
 public static BefungeCommand In_Int_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.InInt, tag));
 }
Пример #15
0
 public static BefungeCommand Add_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Add, tag));
 }
Пример #16
0
 public static BefungeCommand Div_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Div, tag));
 }
Пример #17
0
 public static BefungeCommand Walkway_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Walkway, tag));
 }
Пример #18
0
 public static BefungeCommand Unused_tagged(CodeTag tag)
 {
     throw new InternalCodeGenException();             // There is nothing like an tagged unused ...
 }
Пример #19
0
 public BefungeCommand(BefungeCommandType t, int p, CodeTag g)
 {
     Type  = t;
     Param = p;
     Tag   = g;
 }
Пример #20
0
 public static BefungeCommand PC_Jump_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.PCJump, tag));
 }
Пример #21
0
 public bool HasTag(CodeTag tag)
 {
     return(tag != null && tagCache.Contains(tag));
 }
Пример #22
0
 public static BefungeCommand Reflect_Get_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.ReflectGet, tag));
 }
Пример #23
0
 public static BefungeCommand GreaterThan_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.GreaterThan, tag));
 }
Пример #24
0
 public static BefungeCommand In_ASCII_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.InASCII, tag));
 }
Пример #25
0
 public static BefungeCommand PC_Left_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.PCLeft, tag));
 }
Пример #26
0
 public static BefungeCommand Digit_9_tagged(CodeTag tag)
 {
     return(Dig(9, tag));
 }
Пример #27
0
 public static BefungeCommand PC_Down_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.PCDown, tag));
 }
Пример #28
0
 public static BefungeCommand Not_tagged(CodeTag tag)
 {
     return(new BefungeCommand(BefungeCommandType.Not, tag));
 }
Пример #29
0
 public BefungeCommand CopyWithTag(CodeTag g)
 {
     return(new BefungeCommand(Type, Param, g));
 }