private static int loadParams(Instruction instruction, string parms, IOrganismo o, int pos) { string[] pars = parms.Split(','); for (int i = 0; i < pars.Length; i++) { string par = pars[i].Trim(); if (par.Length > 0) { char p = par.ToCharArray()[0]; if (p >= 'A' && p <= 'Z') { o.setMemory(o.sp() + pos + i, ALifeConsts.getLetterNumber(p)); } else { o.setMemory(o.sp() + pos + i, int.Parse(par)); } } else { pos--; } } return(pos + pars.Length); }
private void randomizeInstruction(IOrganismo o) { int memPos = Utils.RandomInt(-10, 10); int index = o.ip + memPos; if (index < o.sp()) { index = o.sp(); } int inst = o.getMemory(index); inst = changeInstruction(inst); o.setMemory(index, inst); }
public override void executa(IOrganismo o) { int memSize = o.getReg(getByteOrganismo(o, 1)); if (o.child != null) { mundo.dealloc(o.child); o.clearChild(); o.fatalError(); return; } memSize = ALifeConsts.validateMemorySize(o, memSize); if (memSize == 0) { o.fatalError(); return; } IOrganismo child = mundo.alloc(memSize, o); if (child.isAlive()) { o.addFitness(); o.setChild(child); o.setReg(getByteOrganismo(o, 2), child.sp()); } else { o.error(); o.setReg(getByteOrganismo(o, 2), 0); } }
private void DrawOwner(IOrganismo o, int cor) { int ini = o.sp(); int size = o.getMemorySize(); for (int i = ini; i < ini + size; i++) { int calcIndex = ALifeConsts.calcIndex(i, memorySize); DrawPixel(calcIndex, 255, false); } }
private static int loadInstruction(string line, IWorld mundo, IOrganismo o, int pos) { if (line.StartsWith("#")) { return(pos); } if (line.Contains("=")) { line = line.Substring(line.IndexOf("=") + 1).Trim(); } if (line.Contains("//")) { line = line.Substring(0, line.IndexOf("//")).Trim(); } line += " "; int indexOf = line.IndexOf(" "); string param = line.Substring(indexOf).Trim(); string instrCode = line.Substring(0, indexOf).Trim(); Instruction instruction = mundo.getInstruction(instrCode); int step = 1; if (instruction == null) { o.setMemory(o.sp() + pos, int.Parse(instrCode)); } else { o.setMemory(o.sp() + pos, instruction.getId()); step = instruction.getStep(); } pos++; if (step > 1) { pos = loadParams(instruction, param, o, pos); } return(pos); }
public void deallocate(IOrganismo child) { int sp = child.sp(); lastDeallocate = sp; for (int i = 0; i < child.getMemorySize(); i++) { if (getMemoryOwner(sp + i) > 0) { setMemoryOwner(sp + i, -1); //setMemory(sp + i, 0); allocatedMemory--; } } }
public void UpdateRows() { if (Rows == null) { Rows = GetRows("dataGridOrgs"); } for (int rowLine = 0; rowLine < Rows.Count; rowLine++) { IOrganismo o = Rows[rowLine].Cells[0].Value as IOrganismo; if (o != null) { int colIndex = 1; Rows[rowLine].Cells[colIndex++].Value = o.oid; Rows[rowLine].Cells[colIndex++].Value = o.hash(); Rows[rowLine].Cells[colIndex++].Value = o.getMemorySize(); Rows[rowLine].Cells[colIndex++].Value = o.getError(); Rows[rowLine].Cells[colIndex++].Value = o.sp(); } } }