Bots and Simulations > DNA - General
help
MrMound:
I want to make a bot that randomly chooses what it will be(like the multibot vegtable). I want it to choos to be a reproducer, a attacker or a defender. how do I make it choos. I know it has to do something with the .type command and the rnd command but I don't really know how to code it.
Numsgil:
What you'll want to do is decide on a variable to hod type.
def .type 50
would set this up for you.
Then you have in some gene that decides type:
2 rnd 1 add .type store
this will store 1,2 or 3 in type.
Then you simply check if *.type 1 = etc. etc. for other types in each gene that controls multibot behavior.
MrMound:
so it would look somthing like this if I wanted a bot to randomly choose witch direction to move.
--- Code: ---cond
start
def .type 50
stop
cond
*.type > 3
start
2 rnd 1 add .type store
stop
cond
*.type = 1
start
100 .up store
stop
cond
*.type = 2
start
100 .dn store
stop
cond
*.type = 3
start
100 .dx store
stop
end
--- End code ---
PurpleYouko:
Not quite.
The def commands are placed before the start of the actual genome.
def simply sets up a custom sysvar with any name that you choose, to represent a specific memory location. In this case .type becomes the equivalent of memory location 50.
*.type exactly equals *50. it is just easier working with a sysvar than a raw memory location.
Your code should look like this.
--- Code: ---def .type 50
'genome starts here
cond
*.robage 0 =
start
2 rnd 1 add .type store
stop
cond
*.type = 1
start
100 .up store
stop
cond
*.type = 2
start
100 .dn store
stop
cond
*.type = 3
start
100 .dx store
stop
end
--- End code ---
This sets up the ".type" as a custom variable then sets a random value of 1,2 or 3 into it when the robot is born (age = 0). For the rest of the robot's life, .type will contain the same value (unless you change it from another gene at some point)
MrMound:
ok so with the def command you can set any variable you want?
Navigation
[0] Message Index
[#] Next page
Go to full version