Author Topic: Antbot v1.4  (Read 4274 times)

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Antbot v1.4
« on: May 01, 2008, 07:48:05 PM »
This version really had a lot of changes implemented. The idea originally came from Numsgil.
Guards are now active; they patrol the edge of the hive, and tell the queen when an enemy scout is trying to steal food.
The queen organizes raids and attacks against other hives.
If the queen is angry, she sends the drones to attack other hives.
I am now using every single I/O channel (I might need more)    

'Antbot v1.4
''A hivebot by Bacillus

'''''''''''''
'I/O CHANNELS
'''''''''''''
''I/O 1-species conspec
''I/O 2-type recognition
''I/O 3-status report and queen communication channel
''I/O 4-hive conspec
''I/O 5-andrenaline level
''I/O 6-food timer-measures time elapsed since worker last saw food
''I/O 7-X coordinate of last food sighting
''I/O 8-Y coordinate of last food sighting
''I/O 9-status timer-shows how long a decision by the queen lasts
''I/O 10-Hostility-Factor on which queen decides to attack or not

'''''
'VARS
'''''
''Young Queen-collects energy to form her own colony. Chance-1 in 1000
''Queen-spawns smaller ants
''Drone-Poisons enemies, collects nrg from workers & other species,
''relays back to queen. Chance-1 in 5
''Worker-Finds food, brings it back to queen, and shares location
''of food with other workers. Chance-1 in 2
''Scout-Moves quickly to pull in veggies. Chance-1 in 5
''Guard-Protects the queen and reports enemy raids. Chance-1 in 10

def youngqueen 0
def queen 1
def drone 2
def worker 3
def scout 4
def guard 5

''Default-Ants act normally
''Raid-Ants attempt to steal food from other hives
''Attack-Ants will attack other hives
''Report-A guard status of going back to the queen and reporting a theft

def default 0
def raid 10
def attack 20
def report 30

''''''''''''''''''''''''
'CUSTOM MEMORY LOCATIONS
''''''''''''''''''''''''
''Status-Influences behaviour of ants
''Hostility-How angry a hive is
''Temp-initialization purposes
''Type-The Ant's job in the colony
''Queenxpos and Queenypos-Queen's coordinates
''Dumpdist-The distance from the queen at which a scout should dump a veggie
''Hiveid-The id of the hive this ant belongs to
''Andrenaline-The amount of andrenaline a drone has
''Memtimer-The time elapsed since worker last saw food
''Foodxpos and Foodypos-the coordinates of the last seen food
def statustimer 987
def status 988
def hostility 989
def temp 990
def type 991
def queenxpos 992
def queenypos 993
def dumpdist 994
def hiveid 995
def andrenaline 996
def memtimer 997
def foodxpos 998
def foodypos 999

'Initialization
''What type of ant am I?
''Set eyes and conspec
cond
*.robage 0 =
start
1000 rnd .temp store
.youngqueen *.temp sgn -- abs .type mult store
.drone *.temp sgn .type mult store
.scout *.temp 200 sub sgn 0 floor .type mult store
.guard *.temp 400 sub sgn 0 floor .type mult store
.worker *.temp 500 sub sgn 0 floor .type mult store

1235 .out1 store

-436 .eye9dir store
-327 .eye8dir store
-218 .eye7dir store
-109 .eye6dir store
109 .eye4dir store
218 .eye3dir store
327 .eye2dir store
436 .eye1dir store
105 .eye1width store
105 .eye2width store
105 .eye3width store
105 .eye4width store
105 .eye5width store
105 .eye6width store
105 .eye7width store
105 .eye8width store
105 .eye9width store
stop

'First generation is always a queen
start
.youngqueen .type store
*.thisgene .delgene store
stop

'OCULUS
'Update bot
cond
start
*.hiveid .out4 store
*.andrenaline .out5 store
*.type .out2 store
*.memtimer .out6 store
*.foodxpos .out7 store
*.foodypos .out8 store
*.status .out3 store
*.statustimer .out9 store
*.hostility .out10 store
*.nrg 3 div *.body sub dup .strbody store - .fdbody store
-4 *.eye1 *.eye9 sub sgn 0 floor mult *.eye1 *.eye8 sub sgn 0 floor mult *.eye1 *.eye7 sub sgn 0

floor mult *.eye1 *.eye6 sub sgn 0 floor mult *.eye1 *.eye5 sub sgn 0 floor mult *.eye1 *.eye4 sub

sgn 0 floor mult *.eye1 *.eye3 sub sgn 0 floor mult *.eye1 *.eye2 sub sgn 0 floor mult 4 *.eye9

*.eye8 sub sgn 0 floor mult *.eye9 *.eye7 sub sgn 0 floor mult *.eye9 *.eye6 sub sgn 0 floor mult
*.eye9 *.eye5 sub sgn 0 floor mult *.eye9 *.eye4 sub sgn 0 floor mult *.eye9 *.eye3 sub sgn 0 floor

mult *.eye9 *.eye2 sub sgn 0 floor mult *.eye9 *.eye1 sub sgn ++ sgn mult add -3 *.eye2 *.eye9 sub

sgn ++ sgn mult *.eye2 *.eye8 sub sgn 0 floor mult *.eye2 *.eye7 sub sgn 0 floor mult *.eye2 *.eye6

sub sgn 0 floor mult *.eye2 *.eye5 sub sgn 0 floor mult *.eye2 *.eye4 sub sgn 0 floor mult *.eye2

*.eye3 sub sgn 0 floor mult *.eye2 *.eye1 sub sgn ++ sgn mult add 3 *.eye8 *.eye9 sub sgn ++ sgn

mult *.eye8 *.eye7 sub sgn 0 floor mult *.eye8 *.eye6 sub sgn 0 floor mult *.eye8 *.eye5 sub sgn 0

floor mult *.eye8 *.eye4 sub sgn 0 floor mult *.eye8 *.eye3 sub sgn 0 floor mult *.eye8 *.eye2 sub

sgn ++ sgn mult *.eye8 *.eye1 sub sgn ++ sgn mult add -2 *.eye3 *.eye9 sub sgn ++ sgn mult *.eye3

*.eye8 sub sgn ++ sgn mult *.eye3 *.eye7 sub sgn 0 floor mult *.eye3 *.eye6 sub sgn 0 floor mult
*.eye3 *.eye5 sub sgn 0 floor mult *.eye3 *.eye4 sub sgn 0 floor mult *.eye3 *.eye2 sub sgn ++ sgn

mult *.eye3 *.eye1 sub sgn ++ sgn mult add 2 *.eye7 *.eye9 sub sgn ++ sgn mult *.eye7 *.eye8 sub

sgn ++ sgn mult *.eye7 *.eye7 sub sgn 0 floor mult *.eye7 *.eye6 sub sgn 0 floor mult *.eye7 *.eye5

sub sgn 0 floor mult *.eye7 *.eye4 sub sgn ++ sgn mult *.eye7 *.eye2 sub sgn ++ sgn mult *.eye7

*.eye1 sub sgn ++ sgn mult add -1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn

mult *.eye4 *.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn 0 floor mult *.eye4 *.eye5 sub sgn 0

floor mult *.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub

sgn ++ sgn mult add 1 *.eye4 *.eye9 sub sgn ++ sgn mult *.eye4 *.eye8 sub sgn ++ sgn mult *.eye4

*.eye7 sub sgn ++ sgn mult *.eye4 *.eye6 sub sgn ++ sgn mult *.eye4 *.eye5 sub sgn 0 floor mult
*.eye4 *.eye3 sub sgn ++ sgn mult *.eye4 *.eye2 sub sgn ++ sgn mult *.eye4 *.eye1 sub sgn ++ sgn

mult add 0 *.eye5 *.eye9 sub sgn ++ sgn mult *.eye5 *.eye8 sub sgn ++ sgn mult *.eye5 *.eye7 sub

sgn ++ sgn mult *.eye5 *.eye6 sub sgn ++ sgn mult *.eye5 *.eye4 sub sgn ++ sgn mult *.eye5 *.eye3

sub sgn ++ sgn mult *.eye5 *.eye2 sub sgn ++ sgn mult *.eye5 *.eye1 sub sgn ++ sgn mult add

.focuseye store

12 *.type .scout sub sgn abs -- abs 3 mult ++ mult *.vel sub .up store
*.type .queen sub sgn abs -- abs .fixpos store
*.tiepres .tienum store
500 rnd 1500 add .dumpdist *.type .scout sub sgn abs -- abs mult store
*.andrenaline *.venom sub .strvenom store
.andrenaline *.andrenaline sgn mult dec
.memtimer *.memtimer sgn mult dec
.statustimer *.statustimer sgn mult dec
-2 .venval store
.shoot .vloc store
.paralyzed .memloc store
stop

'I'm too small!!
cond
*.body 150 <
start
175 *.body sub .strbody store
stop

'Some idiot has tied to me!!
cond
*.numties 0 !=
*.type .scout !=
start
*.tiepres .deltie store
stop

'I am a guard and should only turn towards enemy conspecs
cond
 *.type .guard =
 *.eyef 0 !=
 *.refnrg 0 >
 *.in1 *.out1 =
 *.in4 *.hiveid != and
 *.in1 *.out1 !=
 *.nrg 1000 < and or
start
 *.refxpos *.refypos angle .setaim store
stop

'I am a drone and should turn towards workers and queens as well as ants of other hives
cond
*.eyef 0 !=
*.type .drone =
*.nrg 15000 <
*.in2 .scout !=
*.in1 *.out1 = and
*.in2 .youngqueen !=
*.in1 *.out1 = and and
*.in2 .drone !=
*.in1 *.out1 = and and
*.refnrg 0 >
start
*.refxpos *.refypos angle .setaim store
stop

'I'm a worker/young queen, no point turning towards conspecs
cond
*.eyef 0 !=
*.type .worker =
*.body 1000 < and
*.type .youngqueen = or
*.out1 *.in1 !=
*.refnrg 0 >
start
*.refxpos *.refypos angle .setaim store
stop

'I am a young queen and are big and fat, so I mature
cond
*.type .youngqueen =
*.body 10000 >
start
.fixpos inc
.queen .type store
*.xpos .queenxpos store
*.ypos .queenypos store
32000 rnd .hiveid store
stop

'I have no hive and you are a queen, I'll join yours
cond
*.queenxpos 0 =
*.queenypos 0 =
*.type .queen !=
*.type .youngqueen !=
*.in2 .queen =
start
*.refxpos .queenxpos store
*.refypos .queenypos store
*.in4 .hiveid store
stop

'Queen update cycle
''Turn so I can make more ants
''Make some shell so I don't die easily
''Randomly decide to raid another hive
cond
*.type .queen =
start
20 .aimdx store
*.nrg 20000 sub sgn 0 floor 5 mult .mkshell store
10000 rnd dup sgn -- abs .raid mult .status store .statustimer store
stop

''If another hive has stolen more than 10 times, attack.
''Attacks can last for up to 2500 cycles.
cond
 *.type .queen =
 *.hostility 10 >
start
 0 .hostility store
 .attack .status store
 2500 rnd .statustimer store
stop

'Read instructions from the queen
cond
 *.in1 *.out1 =
 *.in4 *.hiveid =
 *.in2 .queen =
 *.type .queen !=
 *.type .youngqueen !=
start
 *.in3 .status store
 *.in9 .statustimer store
stop

'Passive Drones and workers feed the queen
cond
*.in1 *.out1 =
*.in4 *.hiveid =
*.type .drone =
*.status .attack != and
*.type .worker = or
*.in2 .queen =
*.nrg 500 >
*.eye5 40 >
start
*.nrg 1500 sub 1000 ceil .shootval store
-2 .shoot store
*.refxpos .queenxpos store
*.refypos .queenypos store
stop

'The queen is dead, I am a huge drone sitting in her place, I think I'll become the new queen.
cond
*.type .drone =
*.queenxpos *.queenypos dist 15 <
*.in2 .queen !=
*.nrg 30000 >=
start
.fixpos inc
.queen .type store
stop

'Drones harvest food from workers to bring to the queen so workers can keep harvesting.
cond
*.hiveid *.in4 =
*.type .drone =
*.in2 .worker =
*.eye5 40 >
*.refnrg 1000 >
start
-1 .shoot store
stop

'I am a drone near a queen, but have no food, so I'll move away.
cond
*.in1 *.out1 =
*.in2 .queen =
*.type .drone =
*.nrg 500 <=
start
*.maxvel *.velup add .dn store
stop

'I am a huge Drone/Worker, better go and give some of that food I harvested to the Queen.
cond
*.type .drone =
*.nrg 15000 > and
*.type .worker =
*.body 2500 > and or
start
*.queenxpos *.queenypos angle .setaim store
stop

'Oooh, lots of food, let's share!
cond
*.type .worker =
*.in1 *.out1 !=
*.refnrg 20000 >
*.reffixed 0 =
start
10 .memtimer store
*.refxpos .foodxpos store
*.refypos .foodypos store
stop

'You know where food is, I'll remember where.
cond
*.type .worker =
*.in1 *.out1 =
*.in2 .worker =
*.in6 *.memtimer >
start
*.in6 .memtimer store
*.in7 .foodxpos store
*.in8 .foodypos store
stop

'Forget it.
cond
*.type .worker =
*.memtimer 0 =
*.foodxpos 0 !=
*.foodypos 0 !=
start
628 .aimdx store
*.maxvel *.veldn add .up store
0 .foodxpos store
0 .foodypos store
stop

'I see no food, but know where some is, so I'll go find it.
cond
*.type .worker =
*.memtimer 0 >
*.in1 *.out1 =
*.eyef 0 = or
start
*.foodxpos *.foodypos angle .setaim store
stop

'I am a scout and my cargo is near the queen, I'll dump it and go find some more.
''It's fixed, so it won't run away.
cond
*.type .scout =
*.numties 1 =
*.treffixed 0 !=
start
*.tiepres .deltie store
314 .aimdx store
20 .up store
stop

'I am a scout without cargo and see food, let's get it!
cond
*.type .scout =
*.numties 0 =
*.in1 *.out1 !=
*.reffixed 0 =
*.refnrg 0 >
*.eyef 0 >
start
*.refxpos *.refypos angle .setaim store
stop

'I am a scout without cargo and am close to food, so I'll tie to it.
''Only steal fixed food if I was told to raid.
cond
*.type .scout =
*.in1 *.out1 !=
*.nrg 0 >
*.eye5 40 >
*.reffixed 0 =
*.reffixed 0 !=
*.in4 *.hiveid != and
*.status .raid = and or
*.refshoot 0 =
*.numties 0 =
start
.tie inc
stop

'I am a scout with cargo, better bring it back so the others can eat it.
''Might as well take some of the spoils myself so the load isn't as heavy.
''I'll mark this food as our own.
cond
*.type .scout =
*.numties 1 =
start
*.queenxpos *.queenypos angle .setaim store
40 .sharenrg store
1 .sharewaste store
.out4 .tieloc store
*.hiveid .tieval store
stop

'I am a scout and my cargo is near the queen, I'll dump it and go find some more.
''Let's fix it in place so it doesn't run away.
cond
*.type .scout =
*.numties 1 =
*.queenxpos *.queenypos dist *.dumpdist <
start
.fixpos .tieloc store
.tieval inc
stop

'I'm not a scout and I see food, let's eat it!
''If the veggie is part of out garden eg a scout pulled it in, to not kill it.
''If it's an enemy, I am a drone, and we were told to attack, do so.
cond
*.eye5 40 >
*.out1 *.in1 !=
*.out1 *.in1 =
*.in4 *.hiveid != and
*.type .drone = and
*.status .attack = and or
*.type .scout !=
*.reffixed 0 =
*.refnrg 0 > and
*.reffixed 0 >
*.refbody 1000 > and or
start
-6 .shoot store
stop

cond
 *.eye5 40 >
 *.out1 *.in1 !=
 *.type .scout !=
 *.reffixed 0 !=
 *.body 1000 <=
 *.nrg 10000 >
start
 -1 .shoot store
stop

'I am a scout/guard, but am too close to the queen, so I'll move away
cond
*.type .scout =
*.type .guard =
*.status .report != and or
*.queenxpos *.queenypos dist 500 <
*.queenxpos *.queenypos angle *.aim %=
start
*.maxvel *.velsx add .dx store
stop

'I am a guard, but am too far away from the hive, I'll turn so I stay within the boundary
cond
 *.type .guard =
 *.queenxpos *.queenypos dist 2000 >
start
 *.queenxpos *.queenypos angle 50 rnd 175 add add .setaim store
stop

'Timer runs out, time to forget what the queen told us.
cond
 *.statustimer 0 =
 *.status .attack =
 *.status .raid = or
start
 .default .status store
stop

'I am a guard and someone's stealing our food, I'll report it to the queen
cond
 *.type .guard =
 *.in1 *.out1 =
 *.in4 *.hiveid !=
 *.in3 .raid =
start
 .report .status store
stop

'I'm reporting a theft
''Step 1-go to the queen
cond
 *.type .guard =
 *.status .report =
start
 *.queenxpos *.queenypos angle .setaim store
 25 .up store
stop

'I'm reporting a theft
''Step 2-tell the queen
cond
 *.type .guard =
 *.status .report =
 *.eyef 40 >
 *.in1 *.out1 =
 *.in4 *.hiveid =
 *.in2 .queen =
start
 *.in10 ++ .shootval store
 .hostility .shoot store
 .default .status store
stop

'I am a drone under attack, take countermeasures
''Part 1:If attacked, make andrenaline.
cond
*.type .drone =
*.shflav -1 =
*.shflav -6 = or
start
*.andrenaline 5 add .andrenaline store
*.shang .setaim store
0 .shflav store
stop

''Part 2:If venom is stored due to andrenaline, spit it at the enemy.
cond
*.eye5 40 >
*.out1 *.in1 !=
*.type .drone =
*.refshoot 0 >
*.venom 0 >
*.memval 0 !=
start
*.venom .shootval store
-3 .shoot store
stop

''Part 3:You're angry, so I'll be as angry as you.
cond
*.in1 *.out1 =
*.in2 .drone =
*.type .drone =
*.in5 *.andrenaline >
start
*.in5 .andrenaline store
stop

'I should really evolve a toilet...
cond
*.waste 200 >
start
*.waste .shootval store
-4 .shoot store
stop

'I am a Queen, so I should really make a colony
cond
*.type .queen =
*.nrg 5000 >
start
5 .repro store
stop
« Last Edit: May 02, 2008, 07:05:21 PM by bacillus »
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Antbot v1.4
« Reply #1 on: May 01, 2008, 08:28:41 PM »
If you're running out of io ports, you might consider combining some.  For instance, combine the type of bot and colony ID in to a single parameter.  To extract the information, you'd just need to do something like *.in1 3 div and *.in1 3 mod, to get hive ID and type Id, respectively (assuming there are 3 types).  To build them you'd do something like: *.Type *.HiveID 3 mult add .out1 store.

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Antbot v1.4
« Reply #2 on: May 01, 2008, 08:39:49 PM »
I think I was messing round with some encoding format that involved encrypting information in bit shifts; the idea was originally for SS bots, where each command had a bit-shift ID that bitshifted left, and then the other part bitshifted it right, so that it was less likely for an error in the coding to influence the bot eg. putting 15323 into .repro accidentally will not affect a bot as much as putting 10 into .repro. The problem is that the value can be anything between 32000 and 0, so it will be impossible to tell when the right values have been attained. I don't have any ideas for uses for new I/O ports anyway, so I don't have to worry about it yet.
What about the new code, it's a really shoddy job I think, especially the guards and the decision-making, any suggestions?

EDIT=> Actually, the species conspec is static, I might try bitshifting that. That would also befuddle conspec imitators (maybe).
« Last Edit: May 01, 2008, 08:46:35 PM by bacillus »
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
Antbot v1.4
« Reply #3 on: May 02, 2008, 05:05:21 AM »
It seems to me like you guy's are using 16 bit values (Since the value range would imply that), so if you want to, you ca doube the amount of keys you can have just by having 2 8 bit keys in one 16 bit value...
I think the & and | opperators should allow that without any problems. Ofcourse it would limit your key range to 0-256 or -127 - 128 or something like that...
So in one end you bitshift (or multiply) your value to move it up 8 bits (I think multiplying is easyer and safer) and ofcourse AND it with a second key.
Then in the other end you just seperate the 2 values by anding with the bits you need...
You could also use even smaler keyvalues if you want more keys, you could have 4 keys in a value ranging 0-16

I'm having a hard time explaining this with words...
I also forgot that this wasn't unsigned integer values when I wrote this example... so it won't work, since it's in the range 0-65536 and not -32000 - 32000


def key1 116
def key2 143

def inkey1 50
def inkey2 51

start
.key1 256 mult .key2 add .out1 store
stop

cond
*.eyef 0 >
start
*.in1 65280 & 256 div .inkey1 store 'Yeah I know this will just kill the bot
*.in1 255 & .inkey2 store
stop

Ofcourse an easy way to make a working version of this is just to use only 6 bit keys (0-64)... then you would be within range :

def key1 34
def key2 56

def inkey1 50
def inkey2 51

start
.key1 64 mult .key2 add .out1 store
stop

cond
*.eyef 0 >
start
*.in1 4032 & 64 div .inkey1 store
*.in1 63 & .inkey2 store
stop

I think it might be easyer to use the full range (0-255) using bitshifts, but I'm not sure...
I'm also not sure I got the syntax right with the & opperator, so don't just copy paste this
Either way you get the idea...

Also want to say I like the idea of shifting the key, I think that would work if timer is the same for all bots (Otherwise you need to sync the bots), then you can just have a small key and shift it each cycle going up and down as far as it can get... but then you can't do both things... you could mix it up if you don't need 20 keys...

Edit : As I suspected I got the syntax wrong, fixed it...
Also forgot to divide the first key... not even sure the value is correct.
« Last Edit: May 02, 2008, 03:50:36 PM by Moonfisher »

Offline fulizer

  • Bot Destroyer
  • ***
  • Posts: 198
    • View Profile
Antbot v1.4
« Reply #4 on: May 02, 2008, 08:44:42 AM »
ive waited a long time for anew antbot and I can only say one thing...
yay!
anyway ill be trying it out soonish (when I get home)
"If this is coffee bring me tea, If this is tea, bring me coffee"

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Antbot v1.4
« Reply #5 on: May 02, 2008, 07:34:40 PM »
Just remember that instructions on how to run this thing properly are posted in "The amazing Antbot".
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Blacksmith

  • Bot Neophyte
  • *
  • Posts: 24
    • View Profile
Antbot v1.4
« Reply #6 on: May 02, 2008, 08:06:58 PM »
er, I cannot find the thread you speak of.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Antbot v1.4
« Reply #7 on: May 02, 2008, 08:32:19 PM »

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Antbot v1.4
« Reply #8 on: May 02, 2008, 08:53:44 PM »
Thanks.
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan