This site requires JavaScript, please enable it in your browser!
Greenfoot back
fejfo
fejfo wrote ...

2015/4/30

Randomize java code

fejfo fejfo

2015/4/30

#
for an evolving AI ( my dna project dna project I wan't to randomize java code completely but I don't know if this is possible. whit randomise I don't mean via
Greenfoot.getRandomNumber(options);
but extulla randomise the code it runs it self example : this :
if(Greenfoot.getRandomNumber(100) < 20) {
    //do stuff
}
becomes this :
if(Greenfoot.getRandomNumber(99) < 22) {
    //do stuff
}
or something like that I had a few ideas on how to do this: 1. keep a sourceversion and complie to randomise the code I would copy the source version of the code, read it in, change some stuff what I read, write it back, try to compile it if this fails : delete the copy of the source version and start over. if this works overwirte the jar file of the program plausible problems : -- maby I can't accces the jar file while it's executing -- how do I complie the code ? 2. make a kind of program language set the code up to look in a seperate file with code in and then execute methods based on that code. if you try to copy : copy the file randomise it , check if it's still valid if it is : overwrite the real file with the modified file if it isn't try again with is the easies and with one will work is there an even easier way to do this ?
Super_Hippo Super_Hippo

2015/4/30

#
You could save the parameters of the random method in a variable and change them after some time. So maybe:
private int a = 100;
private int b = 20;

//
if(Greenfoot.getRandomNumber(a) < b)
{
    //do stuff
}

//
a += Greenfoot.getRandomNumber(5) - 2;
b += Greenfoot.getRandomNumber(3) - 1;
Of course you have to check that a is greater than 0.
fejfo fejfo

2015/5/1

#
thanks I didn't think it would be this easy. I thought I wanted to randomize the methods called them self to but at a closer look this is not needed thanks
You need to login to post a reply.