// 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; } } } }
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); }
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); }
public static BefungeCommand Dig(byte v, CodeTag tag) { if (v < 10) { return(new BefungeCommand(BefungeCommandType.Other, '0' + v, tag)); } else { throw new ArgumentException(); } }
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); }
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); }
public static BefungeCommand If_Horizontal_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.IfHorizontal, tag)); }
public static BefungeCommand If_Vertical_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.IfVertical, tag)); }
public BefungeCommand(BefungeCommandType t, CodeTag p) : this(t, 0, p) { //-- }
public static BefungeCommand PC_Random_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.PCRandom, tag)); }
public static BefungeCommand Stop_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Stop, tag)); }
public static BefungeCommand Chr(int v, CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Other, v, tag)); }
public static BefungeCommand Modulo_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Modulo, tag)); }
public static BefungeCommand In_Int_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.InInt, tag)); }
public static BefungeCommand Add_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Add, tag)); }
public static BefungeCommand Div_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Div, tag)); }
public static BefungeCommand Walkway_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Walkway, tag)); }
public static BefungeCommand Unused_tagged(CodeTag tag) { throw new InternalCodeGenException(); // There is nothing like an tagged unused ... }
public BefungeCommand(BefungeCommandType t, int p, CodeTag g) { Type = t; Param = p; Tag = g; }
public static BefungeCommand PC_Jump_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.PCJump, tag)); }
public bool HasTag(CodeTag tag) { return(tag != null && tagCache.Contains(tag)); }
public static BefungeCommand Reflect_Get_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.ReflectGet, tag)); }
public static BefungeCommand GreaterThan_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.GreaterThan, tag)); }
public static BefungeCommand In_ASCII_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.InASCII, tag)); }
public static BefungeCommand PC_Left_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.PCLeft, tag)); }
public static BefungeCommand Digit_9_tagged(CodeTag tag) { return(Dig(9, tag)); }
public static BefungeCommand PC_Down_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.PCDown, tag)); }
public static BefungeCommand Not_tagged(CodeTag tag) { return(new BefungeCommand(BefungeCommandType.Not, tag)); }
public BefungeCommand CopyWithTag(CodeTag g) { return(new BefungeCommand(Type, Param, g)); }