Darwinbots Forum
Bots and Simulations => DNA - General => Topic started by: MrMound on December 03, 2005, 07:35:40 PM
-
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.
-
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.
-
so it would look somthing like this if I wanted a bot to randomly choose witch direction to move.
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
-
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.
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
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)
-
ok so with the def command you can set any variable you want?
-
umm is .type supposed to show up as a 0 in the dna with that robot?
-
no it should show up as the number of the address ie 50
-
PY made a mistake in the code
def .type 50
should be
def type 50
-
is there a way to make a costom sysvar amount increase by 10 every 10 cycles
-
yes:
cond
*.robage 10 mod 0 =
start
*.type 10 add .type store
stop
-
is there a way to ref a costom sysvar in another bot? like using .type as and example would I be able to see if .type is 2?
-
You mean from the console? have you tried:
? .type
If that doesn't work, you probably need to use the actual memory location.
If you mean the bots themselves, you could use memloc and memval. Are you familiar with them?
-
yes there is a way to do this.
By using .memloc and *.memval, it is possible to read any memory location in a viewed bot.
Something like this would do it.
def type 50
def readtype 51
cond
*.eye5 0 !=
start
.type .memloc store
*.memval .readtype store
stop
this should save whatever value that the viewed robot has in memloc 50, into your own memloc 51. You can then read it in later genes as *.readtype.
Don't quote me on this. It has been a couple of years since I tried this last so I can't remember precisely how it works.
Memloc/memval are probably the least used sysvars in the whole genome. I have never seen a robot use them.
-
this gene should change .type's value to 3 if the nrg is < 10000 right?
cond
*.type 3 =
*.nrg 10000 <
start
1 .type store
stop
I use a gene like this and I think it works but not that one ^.
cond
*.type 1 =
*.nrg 20000 >=
start
3 .type store
stop
-
The gene that you listed will change the type from type 3 to type 1 if energy is less than 10,000.
The second gene will change .type from 1 to 3 if energy is greater than/equal to 20,000
-
does this robot work on your computer and if not is there a reason why
-
Yes it does work with me... but there are two 'errors' in it's DNA. (needn't be bad, but does not help with your goal with this bot)
- Child-bots that are born from a fixed-to-the-spot parent are fixed also, even though they don't have a veggie to feed on.
- Bots that tie to each other don't sever their ties. this is especially the case with parents/children connections. Maybe you could build in a gene that checks whether the bot is tied to anotherbot of it's species, and then delete that tie
-
ok ya its working on my computer now. db was just going haywirer last night. when I restarted my computer it started working
-
yay!