public string RealExecute(FungeContext fungeContext) { var n = fungeContext.GetTopStackTopValues(1)[0]; if (n < 0) { return("UB in \")\" : top stack value negative"); } var values = fungeContext.GetTopStackTopValues(n).Reverse().ToArray(); var accum = values.Aggregate(0, (current, value) => current * 256 + value); var fps = fungeContext.SupportedFingerPrints; var fp = fps.Find(f => f.FingerPrintHash == accum); if (fp == null) { fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect(); return(null); } foreach (var(key, _) in fp.KeyBinding) { _fpc.Find(c => c.Name == key)?.UnloadTopAlias(); } return(null); }
public string RealExecute(FungeContext fungeContext) { if (fungeContext.CurrentThread.Stacks.Count < 2) { fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect(); return(null); } //get n values from toss var n = fungeContext.GetTopStackTopValues(1)[0]; var values = n > 0 ? fungeContext.GetTopStackTopValues(n) : new int[0]; //remove toss fungeContext.CurrentThread.Stacks.Pop(); // restore offset var storageOffset = fungeContext.GetTopStackTopValues(fungeContext.Dimension); fungeContext.CurrentThread.StorageOffset = new DeltaVector(storageOffset.Reverse().ToArray()); // if (n < 0) { fungeContext.GetTopStackTopValues(-n); } else { foreach (var value in values.Reverse()) { fungeContext.CurrentThread.Stacks.Peek().Push(value); } } return(null); }
public string RealExecute(FungeContext fungeContext) { var n = fungeContext.GetTopStackTopValues(1)[0]; var newStack = new Stack <int>(); if (n > 0) { var values = fungeContext.GetTopStackTopValues(n).Reverse().ToArray(); foreach (var value in values) { newStack.Push(value); } } if (n < 0) { foreach (var i in Enumerable.Repeat(0, -n)) { fungeContext.CurrentThread.Stacks.Peek().Push(i); } } var currentThread = fungeContext.CurrentThread; var storageOffset = currentThread.StorageOffset; for (int i = 0; i < fungeContext.Dimension; i++) { fungeContext.CurrentThread.Stacks.Peek().Push(storageOffset.Coords(fungeContext.Dimension)[i]); } currentThread.StorageOffset = currentThread.CurrentPosition + currentThread.DeltaVector; fungeContext.CurrentThread.Stacks.Push(newStack); return(null); }
protected override string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(2); fungeContext.PushToTopStack(values[1] > values[0] ? 1 : 0); return(null); }
public string RealExecute(FungeContext fungeContext) { var value = fungeContext.GetTopStackTopValues(1)[0]; fungeContext.CurrentThread.DeltaVector = value == 0 ? new DeltaVector(1, 0, 0) : new DeltaVector(-1, 0, 0); return(null); }
protected override string RealExecute(FungeContext fungeContext) { var value = fungeContext.GetTopStackTopValues(1)[0]; fungeContext.SetDeltaVector(value == 0 ? Direction.SOUTH : Direction.NORTH); return(null); }
public string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(1); _writer.Write(values[0]); return(null); }
public string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(fungeContext.Dimension); fungeContext.CurrentThreadDeltaVector = new DeltaVector(values.Reverse().ToArray()); return(null); }
protected override string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(1); _writer.Write((char)values[0]); return(null); }
public string RealExecute(FungeContext fungeContext) { var n = fungeContext.GetTopStackTopValues(1)[0]; if (n == 0) { fungeContext.MoveCurrentThread(); return(null); } if (n < 0) { return("k command behavior not specified when n is negative"); } var nextPos = fungeContext.CurrentThread.CurrentPosition; while (true) { nextPos += fungeContext.CurrentThreadDeltaVector; var nextCommand = fungeContext.GetCellValue(nextPos); if (nextCommand == ';' || nextCommand == ' ') { continue; } var command = _commands.Find(c => c.Name == nextCommand); for (int i = 0; i < n; i++) { command?.Execute(fungeContext); } return(null); } }
public string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(1); fungeContext.PushToTopStack(values[0] == 0 ? 1 : 0); return(null); }
protected override string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(fungeContext.Dimension); fungeContext.CurrentDirectionVector = new DeltaVector(values.Reverse().ToArray()); return(null); }
public string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(fungeContext.Dimension + 1); var targetCell = new DeltaVector(values.Reverse().Skip(1).ToArray()) + fungeContext.CurrentThread.StorageOffset; fungeContext.ModifyCell(targetCell, values.Last()); return(null); }
private static string AFunc(FungeContext context) { var complexes = context.GetTopStackTopValues(4); context.PushToTopStack(complexes[0] + complexes[2]); context.PushToTopStack(complexes[1] + complexes[3]); return(null); }
public string RealExecute(FungeContext fungeContext) { var b = fungeContext.GetTopStackTopValues(1)[0]; var dv = b > 0 ? new DeltaVector(0, 0, -1) : new DeltaVector(0, 0, 1); fungeContext.CurrentThreadDeltaVector = dv; return(null); }
public string RealExecute(FungeContext fungeContext) { var value = fungeContext.GetTopStackTopValues(1)[0]; fungeContext.ModifyCell(fungeContext.CurrentThread.CurrentPosition + fungeContext.CurrentThreadDeltaVector, value); fungeContext.MoveCurrentThread(); return(null); }
public string RealExecute(FungeContext fungeContext) { var coords = fungeContext.GetTopStackTopValues(fungeContext.Dimension); var value = fungeContext.GetCellValue(new DeltaVector(coords.Reverse().ToArray()) + fungeContext.CurrentThread.StorageOffset); fungeContext.PushToTopStack(value); return(null); }
public string RealExecute(FungeContext fungeContext) { if (fungeContext.CurrentThread.Stacks.Count == 1) { fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect(); return(null); } var n = fungeContext.GetTopStackTopValues(1)[0]; if (n == 0) { return(null); } if (n > 0) { var top = fungeContext.CurrentThread.Stacks.Pop(); var values = fungeContext.GetTopStackTopValues(n); foreach (var value in values) { top.Push(value); } fungeContext.CurrentThread.Stacks.Push(top); } else { var values = fungeContext.GetTopStackTopValues(-n); var top = fungeContext.CurrentThread.Stacks.Pop(); foreach (var value in values) { fungeContext.CurrentThread.Stacks.Peek().Push(value); } fungeContext.CurrentThread.Stacks.Push(top); } return(null); }
public string RealExecute(FungeContext fungeContext) { var n = fungeContext.GetTopStackTopValues(1)[0]; var delta = n < 0 ? fungeContext.CurrentThreadDeltaVector.Reflect() : fungeContext.CurrentThreadDeltaVector; for (int i = 0; i < Math.Abs(n); i++) { fungeContext.CurrentThread.CurrentPosition += delta; } return(null); }
protected override string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(2); if (values[0] == values[1]) { return(null); } var currentDelta = fungeContext.CurrentDirectionVector; fungeContext.CurrentDirectionVector = currentDelta.Rotate(values[1] > values[0] ? Direction.EAST : Direction.WEST); return(null); }
public string RealExecute(FungeContext fungeContext) { var filename = fungeContext.PopString(); var flag = fungeContext.GetTopStackTopValues(1)[0]; var va = new DeltaVector(fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray()) + fungeContext.CurrentThread.StorageOffset; var vb = fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray(); try { using var fw = new StreamWriter(File.OpenWrite(filename)); for (var y = va.Y; y < vb[1] + va.Y; y++) { var line = new List <char>(); for (var x = va.X; x < va.X + vb[0]; x++) { var c = fungeContext.GetCellValue(new DeltaVector(x, y, 0)); line.Add((char)c); } var resString = new string(line.ToArray()); if ((flag & 1) == 1) { resString = resString.Trim(); } fw.WriteLine(resString); } } catch { fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect(); } return(null); }
public string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(2); if (values[0] == values[1]) { return(null); } var currentDelta = fungeContext.CurrentThreadDeltaVector; fungeContext.CurrentThreadDeltaVector = currentDelta.Rotate(values[1] > values[0] ? Direction.East : Direction.West); return(null); }
protected override string RealExecute(FungeContext fungeContext) { var values = fungeContext.GetTopStackTopValues(2); try { fungeContext.PushToTopStack(_func(values[1], values[0])); } catch (DivideByZeroException) { fungeContext.PushToTopStack(0); return("Divided by zero!"); } return(null); }
public string RealExecute(FungeContext fungeContext) { //todo var value = fungeContext.GetTopStackTopValues(1)[0]; var values = Enumerable.Repeat(GetFlagsInfo(fungeContext.Settings), 1) .Append(sizeof(int)) .Append(FungeContext.HandPrint.Aggregate(0, (cur, c) => cur * 5 + c)) .Append(FungeContext.NumericVersion) .Append(1) //use system(); .Append(Path.DirectorySeparatorChar) .Append(fungeContext.Dimension) .Append(fungeContext.CurrentThread.Id) .Append(0) //teamId not supported .Concat(fungeContext.CurrentThread.CurrentPosition.Coords(fungeContext.Dimension).Reverse()) .Concat(fungeContext.CurrentThreadDeltaVector.Coords(fungeContext.Dimension).Reverse()) .Concat(fungeContext.CurrentThread.StorageOffset.Coords(fungeContext.Dimension).Reverse()) .Concat(fungeContext.GetLeastPoint().Coords(fungeContext.Dimension).Reverse()) .Concat(fungeContext.GetGreatestPoint().Coords(fungeContext.Dimension).Reverse()) .Append((DateTime.Now.Year - 1900) * 256 * 256 + DateTime.Now.Month * 256 + DateTime.Now.Day) .Append(DateTime.Now.Hour * 256 * 256 + DateTime.Now.Minute * 256 + DateTime.Now.Second) .Append(fungeContext.CurrentThread.Stacks.Count) .Concat(fungeContext.CurrentThread.Stacks.Select(s => s.Count).Reverse()).ToArray(); if (value > 0) { if (value > values.Length) { fungeContext.PushToTopStack(values[value - values.Length - 1]); } else { fungeContext.PushToTopStack(values[value - 1]); } } else { foreach (var i in values.Reverse()) { fungeContext.PushToTopStack(i); } } return(null); }
public string RealExecute(FungeContext fungeContext) { fungeContext.Threads.ForEach(t => t.Alive = false); fungeContext.ExitCode = fungeContext.GetTopStackTopValues(1)[0]; return(null); }
public string RealExecute(FungeContext fungeContext) { var filename = fungeContext.PopString(); var flag = fungeContext.GetTopStackTopValues(1)[0]; var vec = new DeltaVector(fungeContext.GetTopStackTopValues(fungeContext.Dimension).Reverse().ToArray()); if (!File.Exists(filename)) { fungeContext.CurrentThreadDeltaVector = fungeContext.CurrentThreadDeltaVector.Reflect(); return(null); } var y = 0; int maxX = 0; if ((flag & 1) == 1) { using var fs = File.OpenRead(filename); using var reader = new BinaryReader(fs); var target = vec + fungeContext.CurrentThread.StorageOffset; while (reader.BaseStream.Position != reader.BaseStream.Length) { var c = reader.Read(); fungeContext.ModifyCell(target, c); target.X += 1; } maxX = (int)(reader.BaseStream.Length + fungeContext.CurrentThread.StorageOffset.X); } else { foreach (var line in File.ReadLines(filename)) { for (var x = 0; x < line.Length; x++) { if (line[x] == ' ' || line[x] == '\f') { continue; } fungeContext.ModifyCell( new DeltaVector(x, y, 0) + vec + fungeContext.CurrentThread.StorageOffset, line[x]); } if (line.Length > maxX) { maxX = line.Length; } y++; } } fungeContext.PushToTopStack(maxX); fungeContext.PushToTopStack(y); foreach (var c in vec.Coords(fungeContext.Dimension)) { fungeContext.PushToTopStack(c); } return(null); }
protected override string RealExecute(FungeContext fungeContext) { fungeContext.GetTopStackTopValues(1); return(null); }
public string RealExecute(FungeContext fungeContext) { fungeContext.GetTopStackTopValues(1); return(null); }