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); } }
public override void run() { lastSize = organismos.Count; base.run(); float error = 0; bool _checkTick = (tick % 500 == 0); for (int i = organismos.Count - 1; i >= 0; i--) { try { IOrganismo o = organismos[i]; error = runOrganismo(error, _checkTick, o); } catch (Exception e) { Log.fatal(e.Message); } } if (_checkTick) { checkTick(error, totalMemory, maxMemory, minMemory); } while (getMemoryUsePerc() > settings.memoryUseLimitPerc) { KillFirst(); } }
public override void executa(IOrganismo o) { int pos = getByteOrganismo(o, 1); o.push(o.ip + 1); o.ip = pos; }
public void reset(int memSize, int sp) { id = ++orgsCount; childId = 0; colorCode = 0; setMemorySize(memSize); setStartPoint(sp); initBuffer(); initStacks(); ip = sp; clearChild(); _parent = null; hasStarted = false; _error = 0; age = 0; alive = true; bonusEnergy = 0; _wroteFlag = true; lastChildCount = 0; childlessCounter = 0; childCount = 0; somaInsts = 0; currTask = 0; }
public override void executa(IOrganismo o) { int a = o.getReg(getByteOrganismo(o, 2)); int b = o.getReg(getByteOrganismo(o, 1)); o.setReg(getByteOrganismo(o, 1), ~(a | b)); }
public override void executa(IOrganismo o) { int inst = getByteOrganismo(o, 1); inst = mundo.getMutation().mutateInstruction(inst, o); o.setReg(getByteOrganismo(o, 2), inst); }
public void TestIterativo() { startP = 1000; InitWorldTierra(); cpu = world.cpu() as CPU; cpu.lastDeallocate = startP; IOrganismo org = world.criaOrganismo("ancestor_test.txt"); Assert.IsTrue(org.getMemorySize() == ORG_SIZE, org.getMemorySize() + " <> " + ORG_SIZE); org.setReg(R_C, 10); org.setReg(R_A, 15); Assert.IsTrue(org.getReg(R_C) == 10); Assert.IsTrue(org.getReg(R_A) == 15); int ip = startP; IList <string> instrunctionsRun = new List <string>(); //jmp depois do divide while (org.ip != 1050) { ip = org.ip - startP; PreTests(ip, org); Instruction inst = org.run(); instrunctionsRun.Add(ip + " :: " + inst.getDescription(org, startP + ip)); PostTests(ip, org); } }
public static void loadRegs(string line, IOrganismo o) { if (line == null) { return; } if (line.StartsWith("#REGS: ")) { string[] pars = line.Split(' '); for (int i = 0; i < pars.Length; i++) { string par = pars[i].Trim(); if (par.Contains("[")) { par = par.Substring(0, par.IndexOf("[")).Trim(); } if (par.Contains("X:")) { string letter = par.Substring(0, 1); string val = par.Substring(par.IndexOf(":") + 1); o.setReg(ALifeConsts.getLetterNumber(letter.ToCharArray()[0]), int.Parse(val)); } if (par.Contains("SP:")) { string val = par.Substring(par.IndexOf(":") + 1); o.setStartPoint(int.Parse(val)); } if (par.Contains("IP:")) { string val = par.Substring(par.IndexOf(":") + 1); o.ip = int.Parse(val) + 1; } } } }
public float calcMutationChance(float mutationChance, IOrganismo o) { if (settings.mutationType == ALifeConsts.MUTTYPE_OCCUPATION_RATIO) { float ratio = ((float)mundo.size()) / (settings.occupationRatio * settings.maxOrganismos); /* * if (ratio<0.01f){ ratio=0.01f; } */ // return mutationChance2; return(ratio * mutationChance); } if (settings.mutationType == ALifeConsts.MUTTYPE_POSITIONAL_CENTER) { if (o == null) { return(0); } float dif = Math.abs(midPt - o.getY()); float ratio = dif / midPt * mutationChance; return(ratio); } return(0); }
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); }
public virtual void dealloc(IOrganismo o) { //Log.Info("Dealloc: " + o.oid); if (o == null) { return; } organismos.Remove(o); referView.RemoveOrganismo(o); organismosMap.Remove(o.id); if (o.child != null) { dealloc(o.child); } o.clearChild(); killCount++; o.kill(); if (!recycleBin.Contains(o)) { recycleBin.Add(o); } else { Log.error("Program is already present on the recycle bin: " + o.oid); } cpu().deallocate(o); allocated.Remove(o); }
protected float runOrganismo(float error, bool checkTick, IOrganismo o) { // if (o.id==1) // ALifeIO.saveToFile(o); if (isRunnable(o)) { o.run(); int memorySize = o.getMemorySize(); totalMemory += memorySize; if (memorySize > maxMemory) { maxMemory = (int)memorySize; } if (memorySize < minMemory || minMemory == 0) { minMemory = (int)memorySize; } error += o.getError(); if (checkTick) { o.checkTick(); } } else { if (o.parent == null || o.parent.isAlive() == false) { dealloc(o); } } return(error); }
public bool validate(IOrganismo memoryContainer) { if (memoryContainer == null) { memoryContainer = this; } int memorySize2 = getMemorySize(); memorySize2 = CONSTS.validateMemorySize(parent(), memorySize2); if (memorySize2 == 0) { parent().criticalError(); return false; } bool hasMal = false; bool hasDivide = false; bool hasRequireTemplate = false; int sp = sp(); int i = 0; int step = 1; while (i < memorySize2) { Instruction inst = memoryContainer.getInstructionAt(sp + i); if (inst != null) { step = inst.getStep(); if ((inst instanceof MalInstruction) || (inst instanceof ConnectInstruction)) { hasMal = true; } if ((inst instanceof DivideInstruction) || (inst instanceof DisconnectInstruction)) { hasDivide = true; } if (inst.requiresTemplate()) { hasRequireTemplate = true; } } else { step = 1; } i += step; } if (!hasMal || !hasDivide) { return false; } else { addFitness(); return true; } }
public override void executa(IOrganismo o) { int v = o.getReg(getByteOrganismo(o, 1)); v ^= 1; o.setReg(getByteOrganismo(o, 1), v); }
public void clearParent() { if (_parent != null && _parent.child == this) { _parent.clearChild(); } _parent = null; }
public void allocate(int sp, int memSize, IOrganismo o) { for (int i = 0; i < memSize; i++) { setMemoryOwner(sp + i, o.id); } allocatedMemory += memSize; }
public override void executa(IOrganismo o) { int inst = o.getMemory(o.ip + 1); inst = mundo.getMutation().mutateInstruction(inst, o); int regVal = o.getReg(getByteOrganismo(o, 2)); o.setMemory(regVal, inst); }
public override void executa(IOrganismo o) { int v = o.getReg(getByteOrganismo(o, 1)); if (v != 0) { o.next(1); } }
internal static void saveToFile(IOrganismo organismo) { /* string orgCode = organismo.ToString(); * string path = ALifeConsts.GENEBANK_PATH +"saved\\" + organismo.hash() + ".txt"; * Directory.CreateDirectory(ALifeConsts.GENEBANK_PATH + "saved\\"); * path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path); * File.WriteAllText(path, orgCode); * Log.Info("Salvando organismo "+path);*/ }
public override void dealloc(IOrganismo o) { base.dealloc(o); if (o == null) { return; } _cpu.deallocate(o); allocated.Remove(o); }
public override void executa(IOrganismo o) { int vf = o.getReg(getByteOrganismo(o, 1)); int vt = o.getReg(getByteOrganismo(o, 2)); if (vt < vf) { o.next(1); } }
private void randomizeInstruction(IOrganismo o) { int memPos = CRJavaUtils.randomInt(-10, 10); int index = o.ip() + memPos; int inst = o.getMemory(index); inst = changeInstruction(inst); o.setMemory(index, inst); }
public void AddOrganismo(IOrganismo o) { DataGridViewRowCollection Rows = GetRows("dataGridOrgs"); int rowLine = Rows.Count - 1; Rows.Add(); int colIndex = 0; Rows[rowLine].Cells[colIndex++].Value = o; }
public void setChild(IOrganismo child) { this._child = child; this.childId = child.id; memoryPoolCount = (child == null ? 1 : 2); if (this.child == this) { Log.fatal("Erro!!!"); } }
protected override IOrganismo instantiateOrganismo(int memSize, int sp) { IOrganismo o = getFromRecycle(memSize, sp); if (o == null) { o = new OrganismoTierra(this, memSize, sp); } return(o); }
public float calcMutationChance(float mutationChance, IOrganismo o) { if (settings.mutationType == ALifeConsts.MUTTYPE_OCCUPATION_RATIO) { float ratio = ((float)mundo.size()) / (settings.occupationRatio * settings.maxOrganismos); return(ratio * mutationChance); } return(0); }
private void returnPos(IOrganismo o, int pos) { if (pos >= 0) { o.setReg(getByteOrganismo(o, 1), pos); } else { o.error(); } }
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 void returnPos(IOrganismo o, int pos) { if (pos >= 0) { o.ip = pos - 1; } else { o.error(); } }
public IOrganismo criaOrganismo(int memSize) { int sp = getValidStartingPoint(memSize, null); if (sp >= 0) { IOrganismo o = instantiateOrganismo(memSize, sp); // addOrganismo(memSize, sp, o); return(o); } return(null); }