Author Topic: Ant-bot 2 (IB)(PY)-01.10.04  (Read 3678 times)

Offline Jez

  • Bot Overlord
  • ****
  • Posts: 788
    • View Profile
Ant-bot 2 (IB)(PY)-01.10.04
« on: January 13, 2007, 10:58:46 AM »
'Topic: Ant bot
'PY

' Ant-Bot2
' By PY
' Oct 1 2004
' Designed for V2.33 with angle function

def type 50
' type 0 = worker
' type 1 = warrior
' type 2 = queen
def robid 51
' robid 1000 = makes new queen
' robid 900 - 999 makes warrior
' robid < 900 makes new worker
def queenx 52
def queeny 53
def newmom 54
def hfh 55
' Head For Home that is
' hfh 0 = search for food
' hfh 1 = head for home
' hfh 2 = feed the queen
def queenid 56
def feeding 57
def counter 58


' initialize at birth
cond
*.robage 0 =
start
1000 rnd .robid store
.tie inc
stop

cond
*.robage 0 =
*.robid 1000 =
start
2 .type store
stop

cond
*.robage 0 =
*.robid 990 >
*.robid 1000 !=
start
1 .type store
stop

' Copy queen's ID into out1
cond
*.robage 1 =
*.eye5 0 !=
start
*.in1 .out1 store
*.in2 .queenid store
stop

' make new robots into queens at start of sim
' or when breeding ties go wrong
cond
*.robage 2 =
*.numties 0 =
start
2 .type store
1 .fixpos store
32000 rnd 1 add .queenid store
*.queenid .out2 store
32000 rnd 1 add .out1 store
stop

' Queen programs young with her position
cond
*.type 2 =
*.tiepres 1 =
*.newmom 44 =
start
1 .tienum store
*.xpos .tieval store
.queenx .tieloc store
stop

cond
*.type 2 =
*.tiepres 1 =
*.newmom 43 =
start
1 .tienum store
*.ypos .tieval store
.queeny .tieloc store
stop

' sever birth tie. Off you go little worker
cond
*.type 2 =
*.newmom 42 =
start
.deltie inc
stop

' Adjust counters
cond
*.newmom 0 >
start
.newmom dec
stop

cond
start
.counter inc
stop

cond
*.counter 50 >
start
0 .counter store
stop

cond
*.type 0 =
*.counter 20 =
*.hfh 2 !=
*.feeding 0 =
start
1 .fixpos store
stop

cond
*.type 0 =
*.counter 21 =
*.hfh 1 =
start
0 .fixpos store
stop

' rotate as queen
cond
*.type 2 =
start
20 .aimdx store
stop

' initial reproduction for young queen
' need some little worker ants quickly
cond
*.eye5 30 <
*.type 2 =
*.nrg 2000 >
*.robage 100 <
*.newmom 0 =
start
' give away 500 body only.
' clear stack first though
mult mult
32000 *.body div .repro store
46 .newmom store
stop

' Reproduce as queen
cond
*.eye5 30 <
*.type 2 =
*.nrg 5000 >
*.body 5000 >
*.newmom 0 =
start
' give away 500 body only.
' clear stack first though
mult
32000 *.body div .repro store
46 .newmom store
stop

' Queen's defences
cond
*.type 2 =
*.poison 500 <
*.nrg 2000 >
start
10 .strpoison store
.shoot .ploc store
stop

' Queen shoots back
cond
*.type 2 =
*.eye5 30 >
*.in1 *.out1 !=
*.newmom 0 =
start
-1 .shoot store
0 .aimdx store
stop

' Queeny gets fat
cond
*.type 2 =
*.body 32000 <
*.nrg 2000 >
start
10 .strbody store
stop

' Queen gets low on energy
cond
*.type 2 =
*.nrg 500 <
start
10 .fdbody store
stop

cond
*.type 2 =
*.body 32000 <
*.nrg 4500 >
start
100 .strbody store
stop

' worker trades body for energy
cond
*.type 0 =
*.body 100 >
start
100 .fdbody store
stop

' worker selects direction to head after birth
cond
*.robage 10 =
start
1256 rnd .setaim store
stop

' All ants reset in1 and out1 if nothing is visible
cond
*.eye5 0 =
*.in1 0 !=
start
0 .in1 store
0 .in2 store
stop

' worker has collected enough food
cond
*.type 0 =
*.nrg 20000 >
*.hfh 0 =
start
1 .hfh store
0 .fixpos store
0 .feeding store
stop

' Head for home
cond
*.type 0 =
*.hfh 1 =
start
*.queenx *.queeny angle .setaim store
stop

' set worker velocity
cond
*.type 0 =
*.robage 5 >
*.numties 0 =
*.vel 10 <
*.fixed 0 =
*.eye5 51 <
start
10 *.vel sub .up store
stop

' what if sated worker is blocked
' choose a new random direction and accelerate in it
cond
*.type 0 =
*.hfh 1 =
*.eye5 41 >
*.in2 *.queenid !=
start
2 .sx store
stop


' worker searches for food
cond
*.type 0 =
*.hfh 0 =
*.in1 *.out1 !=
*.eye3 *.eye7 !=
*.eye5 50 <
start
*.eye3 *.eye7 sub .aimsx store
'1 .fixpos store
stop

' worker searches for food
cond
*.type 0 =
*.hfh 0 =
*.in1 *.out1 !=
*.eye4 *.eye6 !=
*.eye5 40 <
start
*.eye4 *.eye6 sub .aimsx store
'1 .fixpos store
stop

' worker avoids conspecs
cond
*.robage 10 >
*.type 0 =
*.hfh 0 =
*.in1 *.out1 =
*.eye5 40 >
start
200 .aimsx store
stop

' worker avoids queen while searching for food
cond
*.robage 100 >
*.type 0 =
*.hfh 0 =
*.in1 *.out1 =
*.in2 *.queenid =
start
628 .aimsx store
stop


' worker finds food
cond
*.type 0 =
*.hfh 0 =
*.eye5 40 >
*.in1 *.out1 !=
*.feeding 0 =
start
1 .fixpos store
.feeding inc
stop

' worker shoots food
cond
*.type 0 =
*.hfh 0 =
*.eye5 40 >
*.in1 *.out1 !=
start
-1 .shoot store
stop

' worker stops feeding
cond
*.type 0 =
*.feeding 0 >
*.eye5 41 <
*.fixed 0 !=
start
.feeding dec
0 .fixang store
stop

' worker runs out of energy while returning to queen
cond
*.type 0 =
*.hfh 1 =
*.nrg 3000 <
start
0 .hfh store
1256 rnd .setaim store
stop

' worker reaches queen
cond
*.type 0 =
*.hfh 1 =
*.in2 *.queenid =
*.eye5 50 >
start
2 .hfh store
1 .fixpos store
stop

' worker feeds queen
cond
*.type 0 =
*.hfh 2 =
*.nrg 3500 >
*.in2 *.queenid store
start
mult mult
500 .shootval store
-2 .shoot store
stop

' worker stops feeding queen
cond
*.type 0 =
*.hfh 2 =
*.nrg 3501 <
start
0 .hfh store
0.fixpos store
stop

' worker (or warrior) unfixes his position after birth or feeding the queen
cond
*.type 2 !=
*.hfh 0 =
*.fixed 0 !=
*.feeding 0 =
start
0 .fixpos store
stop

' worker reaches queen's position to find her gone
cond
*.type 0 =
*.hfh 1 =
*.xpos *.queenx =
*.ypos *.queeny =
*.in2 *.queenid !=
start
' becomes new queen
1 .fixpos store
*.queenid .out2 store
2 .type store
stop

' get rid of waste. all types
cond
*.waste 100 >
start
100 .shootval store
-4 .shoot store
stop
end
If you try and take a cat apart to see how it works, the first thing you have in your hands is a non-working cat.
Douglas Adams