Author Topic: Ant-bot 1 (IB)(PY)-30.09.04  (Read 3451 times)

Offline Jez

  • Bot Overlord
  • ****
  • Posts: 788
    • View Profile
Ant-bot 1 (IB)(PY)-30.09.04
« on: January 13, 2007, 10:55:20 AM »
'Topic: Ant bot
'PY

' Ant-Bot 1

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


' 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 900 >
*.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 4 =
start
1 .tienum store
*.xpos .tieval store
.queenx .tieloc store
stop

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

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

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

' Reset counters if they get messed up
cond
*.newmom 0 >
*.numties 0 =
start
.newmom dec
stop

' rotate as queen if field of vision is not clear
cond
*.eye5 30 >
*.type 2 =
start
100 .aimsx store
stop

' Reproduce as queen
cond
*.eye5 30 <
*.type 2 =
*.nrg 5000 >
*.counter 0 =
*.newmom 0 =
start
10 .repro store
6 .newmom store
stop

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

' worker sheds body
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 10000 >
*.hfh 0 =
start
1 .hfh 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 <
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
1256 rnd .setaim store
2 .up store
stop

' worker avoids conspecs
cond
*.robage 10 >
*.type 0 =
*.hfh 0 =
*.in1 *.out1 =
start
1256 rnd .setaim store
stop

' worker searches for food
cond
*.type 0 =
*.hfh 0 =
*.in1 *.out1 !=
*.eye3 *.eye7 !=
*.eye5 30 <
start
*.eye3 *.eye7 sub .aimsx store
*.eye3 *.eye7 sub 4 div .sx store
stop

' worker searches for food
cond
*.type 0 =
*.hfh 0 =
*.in1 *.out1 !=
*.eye4 *.eye6 !=
*.eye5 30 <
start
*.eye4 *.eye6 sub 2 div .aimsx store
*.eye4 *.eye6 sub 8 div .sx store
stop

' worker shoots food
cond
*.type 0 =
*.hfh 0 =
*.eye5 40 >
*.in1 *.out1 !=
start
-1 .shoot 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 3001 <
start
0 .hfh store
stop

' worker (or warrior) unfixes his position after birth or feeding the queen
cond
*.type 2 !=
*.hfh 0 =
*.fixed 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
3 .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