Last active
April 16, 2016 13:58
-
-
Save evilstreak/5c36daf76727aa109f245e613e4fba8c to your computer and use it in GitHub Desktop.
State Machine robot scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BAKER BOT | |
// | |
// This bot will bake bread and then drop it all | |
// off in the beacon. Build an oven and give the | |
// bot lots of grain and wood. | |
// go to the oven | |
moveto(oven); | |
// bake bread until we run out of ingredients | |
while (count(grain) >= 10 && count(wood) >= 2) { | |
// burn coal or wood to boost low power levels | |
while (powerlevel() < 60) { | |
if (has(coal)) { | |
burn(coal); | |
} | |
else if (has(wood)) { | |
burn(wood); | |
} | |
else { | |
print("I'm running out of power!"); | |
break; | |
} | |
} | |
// add two wood to stoke the fire | |
use(wood); | |
use(wood); | |
// put the bread into the oven | |
make(bread); | |
// wait long enough for the bread to finish | |
wait(15); | |
// pick up the bread | |
gather(bread); | |
} | |
// drop off the bread | |
moveto(beacon); | |
// turn around so we can drop things into the beacon | |
turnleft(); | |
turnleft(); | |
dropall(bread); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// COALMINER BOT | |
// | |
// This bot will collect 20 coal and then return to | |
// the beacon. Make sure the coalmine is excavated | |
// and accessible. | |
// find the coalmine | |
moveto(coalmine); | |
// mine coal until the robot has 20 coal | |
while (count(coal) < 20) { | |
// burn coal to boost low power levels | |
while (powerlevel() < 40 && has(coal)) { | |
burn(coal); | |
} | |
// mine one lump of coal | |
excavate(); | |
} | |
// return home | |
moveto(beacon); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FLOWER PICKER BOT | |
// | |
// This bot will pick flowers until 4pm and then | |
// come home and plant them all near the beacon. | |
// pick flowers until it's 4pm | |
while (timeofday() < 16) { | |
// burn coal or wood to boost low power levels | |
while (powerlevel() < 60) { | |
if (has(coal)) { | |
burn(coal); | |
} | |
else if (has(wood)) { | |
burn(wood); | |
} | |
else { | |
print("I'm running out of power!"); | |
break; | |
} | |
} | |
// try to find a flower | |
if (moveto(flower)) { | |
// we found one, so pick it | |
punch(); | |
gather(); | |
} | |
else { | |
// we didn't find one, so explore | |
explore(); | |
} | |
} | |
// time to head back | |
moveto(beacon); | |
// plant flowers until they're all gone | |
while (has(flower)) { | |
// wander away from the beacon a bit | |
wander(); | |
// find a spot of bare ground | |
moveto(ground); | |
// plant the flower | |
use(flower); | |
// go back to the beacon | |
moveto(beacon); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HARVESTER BOT | |
// | |
// This bot will harvest all ripe wheat and then | |
// drop it off in the beacon. As long as you give | |
// the bot enough wood and iron it'll make its | |
// own sickles. | |
// keep working while there's still wheat on the map | |
while (distanceto(wheat) < 10000) { | |
// burn coal or wood to boost low power levels | |
while (powerlevel() < 60) { | |
if (has(coal)) { | |
burn(coal); | |
} | |
else if (has(wood)) { | |
burn(wood); | |
} | |
else { | |
print("I'm running out of power!"); | |
break; | |
} | |
} | |
// make a sickle if we need to | |
if (!has(sickle) && has(wood) && has(iron)) { | |
moveto(workbench); | |
make(sickle); | |
} | |
// move to the wheat | |
moveto(wheat); | |
// cut it down | |
while (probe() == wheat) { | |
if (has(sickle)) { | |
use(sickle); | |
} | |
else { | |
punch(); | |
} | |
} | |
gather(); | |
// replant the seeds | |
if (probe() == ground && has(wheatseeds)) { | |
use(wheatseeds); | |
} | |
} | |
// go drop off the wheat | |
moveto(beacon); | |
// turn around so we can drop things into the beacon | |
turnleft(); | |
turnleft(); | |
dropall(wheat); | |
// wheat drops two seeds sometimes, so the robot | |
// might have spare seeds to drop off | |
if (has(wheatseeds)) { | |
dropall(wheatseeds); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LUMBERJACK BOT | |
// | |
// This bot will collect 50 wood and drop it into | |
// the beacon. If you give the bot an axe it will | |
// use it to chop down the trees. | |
// chop down trees until the robot has 50 wood | |
while (count(wood) < 50) { | |
// burn wood to boost low power levels | |
while (powerlevel() < 30 && has(wood)) { | |
burn(wood); | |
} | |
// find a tree | |
moveto(tree); | |
// keep chopping until the tree is gone | |
while (probe() == tree) { | |
if (has(axe)) { | |
use(axe); | |
} | |
else { | |
punch(); | |
} | |
} | |
// collect the wood | |
gather(wood); | |
} | |
// go to the beacon to drop off the wood | |
moveto(beacon); | |
// turn around so we can drop things into the beacon | |
turnleft(); | |
turnleft(); | |
dropall(wood); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment