Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static int MAX_STACK = 32;//qtd maxima por pilha

        internal static int validateMemorySize(IOrganismo pai, int memSize)
        {
            if (pai == null)
            {
                return(memSize);
            }
            int maxMem = (int)(ALifeConsts.MAX_MEMORY_CHILD * pai.getMemorySize());
            int minMem = (int)(ALifeConsts.MIN_MEMORY_CHILD * pai.getMemorySize());

            if (memSize > maxMem)
            {
                return(0);
            }
            if (memSize <= minMem)
            {
                return(0);
            }
            return(memSize);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        private int difFromFather(int memorySize)
        {

            int code = somaInstructions() / memorySize;
            int parentSize = _parent.getMemorySize();
            if (parentSize < CONSTS.MIN_MEMORY_CHILD * memorySize)
            {
                parentSize = (int)(CONSTS.MIN_MEMORY_CHILD * memorySize);
            }
            int parentCode = _parent.somaInstructions() / parentSize;
            int dif = code - parentCode;
            return dif;
        }
Esempio n. 6
0
        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--;
                }
            }
        }
Esempio n. 7
0
 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();
         }
     }
 }
Esempio n. 8
0
        public string debugInfo(string prefix)
        {
            string saida = prefix + " = ";

            for (int i = 0; i < CONSTS.REGISTRADORES; i++)
            {
                saida += CONSTS.getLetter(i) + "X:"
                        + CONSTS.numberFormat(getReg(i)) + " ";
            }
            saida += "SP:" + CONSTS.numberFormat(sp()) + " IP:"
                    + CONSTS.numberFormat(ip) + " E:" + ((int)_error)
                    + " ID:" + id;
            if (_child != null)
            {
                saida += " (Child:" + _child.id + " size:"
                        + CONSTS.numberFormat(_child.getMemorySize()) + " )";
            }

            saida += "\n#" + stacks.debugInfo();
            return saida;
        }
Esempio n. 9
0
        public string debugInfo(string prefix)
        {
            string saida = prefix + " = ";

            for (int i = 0; i < ALifeConsts.REGISTRADORES; i++)
            {
                saida += ALifeConsts.getLetter(i) + "X:"
                         + ALifeConsts.numberFormat(getReg(i)) + " ";
            }
            saida += "SP:" + ALifeConsts.numberFormat(sp()) + " IP:"
                     + ALifeConsts.numberFormat(ip) + " E:" + ((int)_error)
                     + " ID:" + id;
            if (_child != null)
            {
                saida += " (Child:" + _child.id + " size:"
                         + ALifeConsts.numberFormat(_child.getMemorySize()) + " )";
            }

            saida += Environment.NewLine + "#" + stacks.debugInfo();
            return(saida);
        }
Esempio n. 10
0
        public void TestOrganismoPassoAPasso()
        {
            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);

            int ipExpected = startP;

            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 tmp = 0;

            //#jAvida Size: 110

            //0=NOP_1
            org.run();
            ipExpected++;
            Assert.IsTrue(org.ip == ipExpected);

            //1=NOP_1
            org.run();
            ipExpected++;
            Assert.IsTrue(org.ip == ipExpected);

            //2=NOP_1
            org.run();
            ipExpected++;
            Assert.IsTrue(org.ip == ipExpected);

            //3=NOP_1
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //4=ZERO C
            org.run();
            ipExpected += 2;
            Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_C) == 0);

            //6=OR C
            org.run();
            ipExpected += 2;
            Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_C) == 1);

            //8=SHL C
            org.run();
            ipExpected += 2;
            Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_C) == 2);

            //10=SHL C
            org.run();
            ipExpected += 2; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_C) == 4);

            //12=ADRB A
            org.run();
            ipExpected += 2; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_A) == startP + 4);

            //14=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //15=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //16=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //17=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //18=SUB A,C,A
            org.run();
            ipExpected += 4; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_A) == startP + 0, org.getReg(R_A) + "<>" + startP + 0);

            //22=MOV A,B
            org.run();
            ipExpected += 3; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_A) == org.getReg(R_B), org.getReg(R_A) + "<>" + org.getReg(R_B));

            //25=ADRF A
            org.run();
            ipExpected += 2; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_A) == startP + 109);

            //27=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //28=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //29=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //30=NOP_1
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //31=INC A
            tmp = org.getReg(R_A);
            org.run();
            ipExpected += 2; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(tmp + 1 == org.getReg(R_A));

            //33=SUB A,B,C
            org.run();
            ipExpected += 4; Assert.IsTrue(org.ip == ipExpected);
            Assert.IsTrue(org.getReg(R_C) == (org.getReg(R_A) - org.getReg(R_B)));

            //37=NOP_1
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //38=NOP_1
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //39=NOP_0
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //40=NOP_1
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == ipExpected);

            //41=MAL C,A
            org.run();
            ipExpected += 3; Assert.IsTrue(org.ip == ipExpected);

            //44=CALL
            org.run();
            ipExpected++; Assert.IsTrue(org.ip == startP + 61);

            //45=NOP_0

            //46=NOP_0

            //47=NOP_1

            //48=NOP_1

            //49=DIVIDE

            //50=JMP

            //51=NOP_0

            //52=NOP_0

            //53=NOP_1

            //54=NOP_0

            //55=IFZ C

            //57=NOP_1

            //58=NOP_1

            //59=NOP_0

            //60=NOP_0

            //61=PUSH A

            //63=PUSH B

            //65=PUSH C

            //67=NOP_1

            //47=NOP_0

            //48=NOP_1

            //49=NOP_0

            //50=MOVI B,A

            //51=DEC C

            //52=IFZ C

            //53=JMP

            //54=NOP_0

            //55=NOP_1

            //56=NOP_0

            //57=NOP_0

            //58=INC A

            //59=INC B

            //60=JMPB

            //61=NOP_0

            //62=NOP_1

            //63=NOP_0

            //64=NOP_1

            //65=IFZ C

            //66=NOP_1

            //67=NOP_0

            //68=NOP_1

            //69=NOP_1

            //70=POP C

            //71=POP B

            //72=POP A

            //73=RET

            //74=NOP_1

            //75=NOP_1

            //76=NOP_1

            //77=NOP_0

            //78=IFZ C
        }