public virtual int Ejecutar(Historial H) { MemStack Mem = new MemStack(); int ret; Genética.Ejecutar(Mem, H); if (Mem.Count > 0) { ret = Mem.Pop(); return(ret == 0 ? 0 : 1); } return(0); }
public override void Ejecutar(MemStack Mem, Historial H = null) { if (H == null) { throw new Exception(""); } int StackSize = Mem.Count; switch (Instrucción) { case "!": if (StackSize >= 1) { int t = Mem.Pop(); Mem.Push(t == 0 ? 1 : 0); } break; case "+": if (StackSize >= 2) { Mem.Push(Mem.Pop() + Mem.Pop()); } break; case "*": if (StackSize >= 2) { Mem.Push(Mem.Pop() * Mem.Pop()); } break; case "-": if (StackSize >= 2) { Mem.Push(Mem.Pop() - Mem.Pop()); } break; case "%": if (StackSize >= 2) { int o1 = Mem.Pop(); int o2 = Mem.Pop(); if (o2 != 0) { Mem.Push(o1 % o2); } } break; case "?": if (StackSize >= 3) { int a0 = Mem.Pop(); int a1 = Mem.Pop(); int a2 = Mem.Pop(); Mem.Push(a0 != 0 ? a1 : a2); } break; case "<": if (StackSize >= 2) { Mem.Push(Mem.Pop() < Mem.Pop() ? 1 : 0); } break; case "=": if (StackSize >= 2) { Mem.Push(Mem.Pop() == Mem.Pop() ? 1 : 0); } break; case "h": if (StackSize >= 1 && Mem.Peek() <= H.Actual && Mem.Peek() > 0) { Mem.Push(H [1, H.Actual - Mem.Pop()]); } break; case "i": Mem.Push(H.Actual); break; default: int n; if (int.TryParse(Instrucción, out n)) { Mem.Push(n); } break; } }