moth/packages/tanks/examples/hard/crashmaster/program

39 lines
1.1 KiB
Plaintext

( Mem 0: Turn number )
0 mget
1 +
0 mset
0 mget 30 % 10 / ( [0..2], changes every 10 turns )
dup 0 = { 80 80 set-speed! } if
dup 1 = { 60 80 set-speed! } if
2 = { 80 60 set-speed! } if
0 set-turret!
fire-ready? set-led!
fire-ready?
{
( Behavior for when we can shoot )
0 sensor? { fire! } if
1 sensor? { 10 10 set-speed! 0 set-turret! } if
2 sensor? { 10 10 set-speed! 0 set-turret! } if
3 sensor? { 0 60 set-speed! get-turret 50 - set-turret! } if
4 sensor? { 60 0 set-speed! get-turret 50 + set-turret! } if
3 sensor? 4 sensor? & { 100 100 set-speed! get-turret set-turret! } if
5 sensor? { 100 40 set-speed! } if
}
{
( Behavior for when we can't shoot )
0 sensor? { 10 20 set-speed! } if
1 sensor? { 10 10 set-speed! } if
2 sensor? { 10 20 set-speed! } if
3 sensor? { 70 50 set-speed! } if
4 sensor? { 50 70 set-speed! } if
3 sensor? 4 sensor? & { -100 20 set-speed! } if
5 sensor? { 100 50 set-speed! } if
}
ifelse