Tendril

Example programs

Complete programs to read, run and take apart. Paste any of them into the game's editor.

Starter

The program every new farm begins with. One bot walks every tile, farms carrots and sells them when its hands are full.

# Start with carrots. Questions are free; actions cost ticks.
# Carrots tire the soil, so clover (bought once) takes turns to heal it.
define pick_crop(s):
    if unlocked(clover) and (s.nitrogen < 25 or s.fatigue > 40):
        return clover
    return carrot

repeat forever:
    for each tile in tiles():
        go_to tile
        if scan().ripe:
            harvest
        if scan().empty:
            s = scan()
            if s.moisture < 25:
                water
            till
            plant pick_crop(s)
        if carried() >= capacity():
            go_to barn
            deposit
            sell carrot, all
            sell clover, all
    go_to barn
    deposit
    sell carrot, all
    sell clover, all
    if not unlocked(clover) and coins() >= unlock_cost(clover):
        unlock clover
    wait 100

Expander

Splits the farm between bots by column, waters dry soil, and plants clover on tired tiles. The first bot researches clover and pumpkin, then keeps hiring bots and buying land in a row to the east.

# A growing farm that looks after its soil. Every bot works its own columns.
define best_crop(s):
    # Clover feeds the soil and rests it, so use it when the tile is tired.
    if unlocked(clover) and (s.nitrogen < 35 or s.fatigue > 45):
        return clover
    if unlocked(pumpkin):
        return pumpkin
    return carrot

define sell_everything():
    go_to barn
    deposit
    sell carrot, all
    sell clover, all
    sell pumpkin, all

repeat forever:
    for each tile in tiles():
        if tile.x % bots() == my_id():
            go_to tile
            if scan().ripe:
                harvest
                if carried() > capacity() - 10:
                    sell_everything()
            if scan().empty:
                s = scan()
                if s.moisture < 45:
                    water
                till
                plant best_crop(s)
    sell_everything()
    # Only the first bot spends: research, then more bots and land.
    if my_id() == 0:
        if not unlocked(clover) and coins() >= unlock_cost(clover):
            unlock clover
        elif not unlocked(pumpkin) and coins() >= unlock_cost(pumpkin):
            unlock pumpkin
        elif bots() < 3 * len(plots()) and coins() >= bot_cost():
            buy_bot
        elif coins() >= plot_cost():
            buy_plot len(plots()), 0
    wait 20

Orders

Fills buyer orders before selling anything, since an order pays double. Also prints the forecast.

# Fulfil contracts before selling surplus carrots.
repeat forever:
    for each tile in tiles():
        go_to tile
        if scan().ripe:
            harvest
        if scan().empty:
            till
            plant carrot
        if carried() >= capacity():
            go_to barn
            deposit
            for each order in orders():
                if stock()[order.crop] >= order.qty:
                    deliver order
    go_to barn
    deposit
    for each order in orders():
        if stock()[order.crop] >= order.qty:
            deliver order
    say "Weather ahead:", forecast(500)
    wait 100

Orchard

Plants berries around a hive. Berries regrow after each harvest, and the hive pollinates them and makes honey. Needs 700 coins of research first.

# Earn research money with the starter, then grow a perennial orchard.
unlock berry
unlock hive
if not unlocked(berry) or not unlocked(hive):
    say "Research berry and hive first (700 coins total)."
    stop
go_to 2, 1
if scan().empty:
    build hive
repeat forever:
    for each tile in [{x: 1, y: 1}, {x: 3, y: 1}, {x: 2, y: 2}]:
        go_to tile
        if scan().empty:
            till
            plant berry
        if scan().ripe:
            harvest
    go_to 2, 1
    harvest
    go_to barn
    deposit
    sell berry, all
    sell honey, all
    wait 200

Compost

Turns a harvest into compost at a composter and feeds it back to the same tile. Needs a composter researched.

# Research composters before starting this example.
unlock composter
if not unlocked(composter):
    say "A composter needs 200 coins of research, then 80 coins to build."
    stop
go_to 2, 0
if scan().empty:
    build composter
repeat forever:
    go_to 1, 0
    if scan().empty:
        till
        plant carrot
    wait 200
    harvest
    go_to 2, 0
    compost
    go_to 1, 0
    fertilize
    say "Soil nitrogen:", scan().nitrogen

Daily

A short route for the 3,000-tick daily challenge: five tiles close to the barn, orders first, then selling.

# A short growing route leaves more time for harvesting and selling.
repeat forever:
    for each tile in [{x: 1, y: 0}, {x: 2, y: 0}, {x: 3, y: 0}, {x: 4, y: 0}, {x: 5, y: 0}]:
        go_to tile
        if scan().ripe:
            harvest
        if scan().empty:
            till
            plant carrot
    go_to barn
    deposit
    for each order in orders():
        if stock()[order.crop] >= order.qty:
            deliver order
    sell carrot, all
    wait 100

Home page farm

The program running on the home page. It rotates clover, carrots and wheat by soil nitrogen, gives each bot its own plot, and keeps buying land and bots with no limit.

# The farm on the home page. Every bot runs this program.
define best_crop():
    soil = scan()
    if soil.nitrogen < 15 and unlocked(clover):
        return clover
    if soil.nitrogen >= 20 and unlocked(wheat):
        return wheat
    return carrot

define next_plot():
    for r from 1 to 100:
        for py from -r to r:
            for px from -r to r:
                if not owns(px * 8, py * 8):
                    if owns(px * 8 - 8, py * 8) or owns(px * 8 + 8, py * 8) or owns(px * 8, py * 8 - 8) or owns(px * 8, py * 8 + 8):
                        return {px: px, py: py}

define grow():
    unlock wheat
    unlock clover
    if bots() < len(plots()):
        buy_bot
    else:
        spot = next_plot()
        buy_plot spot.px, spot.py

define unload():
    go_to barn
    deposit
    for each order in orders():
        if stock()[order.crop] >= order.qty:
            deliver order
    sell carrot, all
    sell wheat, all
    sell clover, all
    if my_id() == 0:
        grow()

repeat forever:
    mine = plots()[my_id() % len(plots())]
    for each tile in tiles():
        if tile.x / 8 == mine.px and tile.y / 8 == mine.py and tile != barn:
            go_to tile
            if scan().ripe:
                harvest
            if scan().empty:
                till
                plant best_crop()
            if carried() >= capacity():
                unload()
    unload()