The Farmer Was Replaced Code — Copy-Paste Harvest Scripts

Paste the first script below to start harvesting. Then use the tree, carrot, and watering examples. Dedicated carrot walkthrough: carrot code page

Example 1: Basic Auto Harvest

The simplest automation script that continuously harvests mature grass.

python
# Basic Auto Harvest - The simplest automation script
# This continuously checks and harvests mature crops
while True:
    if can_harvest():
        harvest()
    # The game will automatically pause between iterations

📊 Code Analysis

6
Lines
0
Functions
1
Loops
1
Conditions

Example 2: 3×3 Farm Auto Traversal

Automatically traverse all tiles and harvest.

python
# 3x3 Farm Auto Traversal - Systematic farming pattern
# This script moves in a grid pattern to cover the entire farm
while True:
    # Always check for harvestable crops first
    if can_harvest():
        harvest()

    # Move to the next tile (East direction)
    move(East)

    # When reaching the end of a row, move to the next row (North)
    # get_world_size() returns the size of your farm (usually 3x3 or 5x5)
    if get_pos_x() == get_world_size() - 1:
        move(North)

Example 3: Multi-Crop Automation (Grass + Bush + Carrot)

Plant different crops based on column position.

python
# Multi-Crop Automation - Different crops per column
# Demonstrates conditional logic and resource management
while True:
    # Always harvest what's ready first
    if can_harvest():
        harvest()

    # Get current position (x-coordinate)
    x = get_pos_x()

    # Column-based planting strategy:
    if x == 0:
        # Column 0: Let grass grow naturally (free resource)
        pass  # No action needed
    elif x == 1:
        # Column 1: Plant bushes for wood
        plant(Entities.Bush)
    elif x == 2:
        # Column 2: Plant carrots (requires soil preparation)
        # Check if ground is soil, if not, till it
        if get_ground_type() != Grounds.Soil:
            till()
        # Ensure we have carrot seeds before planting
        if num_items(Items.Carrot_Seed) < 1:
            trade(Items.Carrot_Seed)  # Buy seeds if needed
        plant(Entities.Carrot)

    # Move to next column
    move(East)
    # When reaching end of row, move to next row
    if x == get_world_size() - 1:
        move(North)

Example 4: Tree Checkerboard Planting

Trees need checkerboard planting to avoid adjacency. Dedicated walkthrough: tree code page

python
# Checkerboard Planting Pattern - Space-efficient farming
# Trees cannot be planted adjacent to each other, so use checkerboard pattern
while True:
    # Harvest any mature crops
    if can_harvest():
        harvest()

    # Get current coordinates
    x = get_pos_x()  # Current column (0, 1, 2, etc.)
    y = get_pos_y()  # Current row (0, 1, 2, etc.)

    # Checkerboard logic: Plant trees on "black squares", bushes on "white squares"
    # This ensures no two trees are adjacent (trees need space to grow)
    if (x % 2 == 0 and y % 2 == 0) or (x % 2 == 1 and y % 2 == 1):
        # "Black squares" - plant trees
        plant(Entities.Tree)
    else:
        # "White squares" - plant bushes
        plant(Entities.Bush)

    # Move to next tile
    move(East)
    # Wrap to next row when reaching end of current row
    if x == get_world_size() - 1:
        move(North)

Example 5: Resource Priority Management

Intelligent resource management, prioritize collecting scarce resources.

python
# Resource Priority Management - Smart resource allocation
# Automatically adjusts farming strategy based on current inventory levels
while True:
    # Always harvest first - this is our primary action
    if can_harvest():
        harvest()

    # Get current position for planting decisions
    x = get_pos_x()

    # Resource-based planting strategy with priorities:

    # PRIORITY 1: Ensure hay supply (essential for trading and feeding)
    if num_items(Items.Hay) < 500:
        # Don't plant anything - let grass grow naturally for free hay
        pass  # No action needed

    # PRIORITY 2: Maintain wood supply (needed for various upgrades)
    elif num_items(Items.Wood) < 300:
        # Plant bushes to generate wood
        plant(Entities.Bush)

    # PRIORITY 3: Build carrot reserves (for food and advanced trading)
    elif num_items(Items.Carrot) < 200:
        # Plant carrots (requires soil preparation)
        if get_ground_type() != Grounds.Soil:
            till()  # Prepare soil if needed
        if num_items(Items.Carrot_Seed) == 0:
            trade(Items.Carrot_Seed)  # Buy seeds if we don't have any
        plant(Entities.Carrot)

    # Move to next tile in systematic pattern
    move(East)
    if x == get_world_size() - 1:
        move(North)

Example 6: Auto Watering System

Automated watering system, speeds up crop growth up to 5x.

python
# Auto Watering System - Advanced crop acceleration
# Maintains water tanks and accelerates crop growth up to 5x speed
while True:
    # WATER MANAGEMENT: Ensure adequate water supply
    # Water tanks are essential for speeding up crop growth
    if num_items(Items.Water_Tank) < 100:
        # Trade for empty tanks if we don't have enough
        trade(Items.Empty_Tank)

    # WATER APPLICATION: Use water when crops need it
    # get_water() returns hydration level (0.0 to 1.0)
    # 0.75 means crops are 75% hydrated - water when below this
    if get_water() < 0.75:
        use_item(Items.Water_Tank)  # Apply water to current tile

    # HARVEST: Always check for mature crops first
    if can_harvest():
        harvest()

    # PLANTING: Maintain carrot crop cycle
    # Prepare soil if needed (carrots require tilled soil)
    if get_ground_type() != Grounds.Soil:
        till()  # Convert turf/grass to soil
    # Ensure we have seeds before planting
    if num_items(Items.Carrot_Seed) < 1:
        trade(Items.Carrot_Seed)  # Purchase seeds if needed
    plant(Entities.Carrot)  # Plant carrot seeds

    # MOVEMENT: Continue systematic traversal
    move(East)
    if get_pos_x() == get_world_size() - 1:
        move(North)

Example 7: Function Encapsulation

Use functions to make code clearer and more readable.

python
# Function Encapsulation - Code organization and reusability
# Break down complex logic into reusable functions

# FUNCTION: Handle movement to next tile in grid pattern
def move_to_next():
    """Move to the next tile, wrapping to next row when reaching end"""
    x = get_pos_x()
    move(East)  # Always try to move east first
    # If we reached the end of current row, move north to next row
    if x == get_world_size() - 1:
        move(North)

# FUNCTION: Handle carrot planting with all necessary preparations
def plant_carrot():
    """Plant a carrot with soil preparation and seed management"""
    # Ensure we have proper soil for carrots
    if get_ground_type() != Grounds.Soil:
        till()  # Prepare soil if needed
    # Ensure we have carrot seeds
    if num_items(Items.Carrot_Seed) < 1:
        trade(Items.Carrot_Seed)  # Buy seeds if we don't have any
    # Plant the carrot
    plant(Entities.Carrot)

# MAIN PROGRAM: Clean, readable logic using our functions
while True:
    # Harvest any mature crops (always do this first)
    if can_harvest():
        harvest()

    # Maintain carrot production if inventory is low
    if num_items(Items.Carrot) < 100:
        plant_carrot()  # Use our function for clean code

    # Move to next position using our movement function
    move_to_next()  # Clean, reusable movement logic

Example 8: Sunflower Energy Optimization

Harvest only the flower with the most petals. Then scan again. Full explanation: sunflower code page

python
def go_to(x, y):
    while get_pos_x() != x:
        if get_pos_x() < x:
            move(East)
        else:
            move(West)
    while get_pos_y() != y:
        if get_pos_y() < y:
            move(North)
        else:
            move(South)

size = get_world_size()
best = 0
bx = 0
by = 0
found = False
for y in range(size):
    for x in range(size):
        go_to(x, y)
        if get_entity_type() == Entities.Sunflower and can_harvest():
            petals = measure()
            if (not found) or petals > best:
                best = petals
                bx = x
                by = y
                found = True
if found:
    go_to(bx, by)
    harvest()