SolvedHow-toUpdated
The Farmer Was Replaced: RoboCulture 101: Python for Beginners
Short answer
✨ Updated for Release 1.0 ✨ Goal: To equip beginners with the foundational knowledge to ask informed questions and understand advanced programming tutorials (e.g., on YouTube). About This Guide: This workbook is for individuals new to coding who may face an experience paradox, where you have to…
Steam Community guide by chaosbreaker.
🌾 🌾 🌾 PART I: Introduction 🌾 🌾 🌾 🌾
⚜️ PART I -- intro
We delve into creating tiny programs by following the game documentation.
How to Use This Workbook Effectively:
The tasks are presented first, and the corresponding answer key is located at the end.
Before consulting the answer key, make a genuine attempt to solve each task or at least formulate a guess to engage your mind.
Initially, the tasks will provide explicit instructions. From PART II, you will receive more hints and broader goals to encourage problem-solving.
Complete Task 5 and then restart the game.
After finishing Task 10, restart the game again.
If you are brand new to coding and find The Farmer Was Replaced too hard I recommend these, in order of difficulty, easy to hard:
- Lightbot -- mobile and Flash -- demo/Flash $0 Flash --> https://lightbot.com/flash.html
- One Dreamer -- Steam -- demo $0
- Modulo Code -- Microsoft Store -- $0
- May's Journey -- Steam -- $0
- Sam & MaRU -- Steam -- $10
📝 T01 - Hello Farm! | First Program
Task T01
Explore functions and crop growth cycle works
🔓 Goals - Loop tech.
Note:
📺 What are Functions? Coding for Kids | Kodable -- https://youtu.be/3JIZ40yuZL0?si=LF4RG9XB4xx-0oLq
- Comments are preceded by # -- read [ i ] ➡️ Programming ➡️ Comments
- Functions are small reusable of code appended by “()”.
- Loops unlock cost -- [ Unlocks ] ➡️ (mouse over) [ Loops ] ➡️ 5 🌾 Hay
- Read First Program -- [ i ] ➡️ General Info ➡️ First Program
- Read First Program -- [ i ] ➡️ Built-in Functions
Field -- what the field looks like before reaping -- one plot with 🌾[Grass]:
🌾
- First Program doc shows two functions harvest() and do_a_flip() while pet_the_piggy() is under Built-in Functions
- Create Program P01 - Hello Farm!
- i. Prepend the harvest functions with pet_the_piggy()
- ii. Define (type out) harvest() five times (refer to aforementioned First Program).
- iii. Append harvest functions with do_a_flip()3. Observe that the Hay Items (inventory) on the upper left of the screen is 5
- Loop unlock requirements met -- unlock Loops in the tech tree -- [ Unlocks ] ➡️ (click) Loops .
- Observe that unlocking tech can trigger an info window popup -- While Loop.
Starter code -- copy the following into the code editor:
#📝 Program P01 -- Hello Farm!
#Explore built-in functions
#Unlock Goal - Loops
#read [ i ] ➡️ General Info ➡️ First Program
#Reaping Phase
#Reap 5 Hay
#Write you code below
#pet the pig
#harvest 5 times
#do a flip
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T02 - Mean While | Loops
📝 Task 02
Explore While loops
🔓 Goals - Speed tech.
Note:
📺 Coding Basics: While Loops & Do While Loops | Programming for Beginners | Transcode
📰 the game does not offer do-while. https://youtu.be/v-K-4KuA8mQ?si=XBo_7OdGcgmU30gn
- Unlock costs for Loops -- [ Unlocks ] ➡️ (mouse over) [ Speed ] ➡️ 20 🌾 Hay
- Read While Loop doc -- [ i ] ➡️ Unlocks ➡️ Loops
Field:
🌾
- Refer to the While loop doc to create Program P02 Mean While
- i. Define two while loops, one that performs a flip under False conditions and another that harvests under True conditions.
- ii. Hint -- While Loop, the examples near the end of doc.
- iii. Observe that while False code block is not triggered, no flips are performed.
- iv. Observe that an infinite loop occurs and you only escape by terminating the program.2. Stop program when the reaping goal of 20 Hay is met.
- Unlock Speed in the tech tree, triggering Speed Upgrade doc popup
Starter code -- copy the following into the code editor:
#📝 Program P02 -- Mean While
#Explore While Loop
#Unlock Goal - Speed
#Reaping Phase
#Reap 20 Hay
#Write your code below:
#Define -- a while loop, while in False conditions, performs a flip
while False:
do_a_flip()
#Define -- a while loop, while in True conditions, harvest
while True:
harvest()
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T03 - Iffy Lube | Speed
📝 Task 03
Explore if statements and can_harvest() function
🔓 Goals - Expand tech.
Note:
📺 Coding Basics: If Statements, If Else, Else - Coding Tutorial For Java, C, and C++! | Transcode
📰 the concept is same for Pyhton
https://youtu.be/HQ3dCWjfRZ4?si=k7f7vkuCIDcqDIA2
- Verify Expand tech unlock cost of 30 🌾 Hay.
- Read Speed -- [ i ] ➡️ Unlocks ➡️ Speed
- From this point, read the new tech unlock docs without reminder -- commonly known in the tech field as RTFM (read the fine manual).
Field:
🌾
- Create Program P03 Iffy Lube.
- i. Define a function that if harvest is possible, harvests or else performs a flip.
- ii. Hint -- Read the fine manual (RTFM) -- [ i ] ➡️ Unlocks ➡️ Speed
- iii. Observe that harvesting is always successful since no premature harvest is performed.
- iv. Note that infinite loops will keep occurring until we find a fix. 2. Stop when the reaping goal of 30 Hay is met.
- Unlock Expand tech triggering Expand 1 doc popup.
Starter code -- copy the following into the code editor:
#📝 Program P03 -- Iffy Lube
#Explore if statements
#Unlock Goal - Expand
#Reaping Phase
#Reap 30 Hay
#Write your code below:
#Define a function that if harvest is possible, harvests or else performs a flip.
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T04 - On The Move | Expand
📝 Task 04
Explore the movement function
🔓 Goals - Plant tech
Note:
What is Python? Why Python is So Popular? | Programming with Mosh
https://youtu.be/Y8Tko2YC5hA?si=wI23ZwrjuEbd8g2k
- Plant tech unlock cost is 50 🌾 Hay
- Read Expand 1 doc -- [ i ] ➡️ Unlocks ➡️ Expand
- Create and run Program P04 -- The Haymaker
- i. Check if harvest is possible, harvest, then move South.
- ii. Hint -- It’s similar to previous program, P032. Stop program to break the infinite loop when 50 Hay is harvested.
- Unlock Plant tech, triggering Plant popup.
Starter code -- copy the following into the code editor:
#📝 Program P04 -- On The Move
#Explore movement
#Unlock Goal - Plant
#you wrap back when going over the edge
#Reaping Phase
#Reap 30 Hay
#Write code below:
#while, if harvest is possible, harvest, then move South.
#hint -- similar to previous program, P03
#else not needed since moving to new plot ensures harvest ready
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
🌲 🌲 🌲 PART II: Alea Iacta Est 🌲 🌲 🌲 🌲
⚜️ PART II -- Alea Iacta Est
You have unlocked enough techs that you can make more complex and clever programs.
📝 T05 - Bush League | Plant
📝 Task 05
Explore the Plant tech
🔓 Goals - Operators & Debug
Note:
- Operator tech unlock cost is 150 Hay and 10 Wood
- Debug tech unlock cost is 50 🌾 Hay and 50 🌳 Wood
- Read Expand 1 doc -- [ i ] ➡️ Unlocks ➡️ Plant
We now have two phases Sowing and Reaping. Sowing is for prepping the field and practice coding but will at least have clear() to reset the field while reaping is for harvesting. The programs in the Answer Keys will have these to denote phases:
#,,, SOWING PHASE ,,,,,,,
#||| REAPING PHASE |||||||
Wood takes longer than Hay to grow. Therefore we will allocate two square plots for 🌳 Bush and one for 🌾 Grass.
Field:
🌾
🌳
🌳
- Create Program P05 Bush League
- i. Harvest then sow Bush twice, and harvest Grass once (see the Field above).
- ii. Hint -- three separate harvests, repeated2. Stop program when 200 Hay and 60 Wood is harvested.
- Unlock both Operators tech and Debug triggering doc popups.
Starter code -- copy the following into the code editor:
#📝 Task 05 Program P05 -- Bush League
#,,, SOWING PHASE ,,,,,,,
#clear the field
clear()
#||| REAPING PHASE |||||||
#reaping goal 100 Hay and 100 Wood
#write your code below
Harvest then sow Bush twice, and harvest Grass once (see the Field above).
Hint -- three separate harvests, repeated
#while loop here
#1st plot -- check harvest ready
#harvest
#🌳 sow bush
#move North to 2nd plot
#2nd plot -- check harvest ready
#harvest
#🌳 sow bush
#move North to 3rd plot
#3rd plot -- check harvest ready
#harvest
#🌾no sowing -- keep grass
#move North. wrapping around to 1st plot
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T06 - Press Zero For | Operators & Debug
📝 Task 06
Explore Operators & Debug
🔓 Goals - Senses
Note:
📺 Evaluating compound boolean expressions | Intro to CS - Python | Khan Academy https://youtu.be/p7pJMvD2sag?si=lklqRtUcQbHjqsCC
- Senses tech unlock costs of 100 🌾 Hay
- Have the Operators doc handy -- [ i ] ➡️ Programming ➡️ Operators
- Have the Debug doc handy -- [ i ] ➡️ Programming ➡️ Debug
- Starter code -- Practice -- copy & paste then predict the outcome:
#📝 Task 06 -- Program P06 -- Press Zero for
#Explore Operators and Debug
#Unlock Goal - Senses
#PRACTICE 1 -- 👨🏫 Modulo Operator, an Arithmetic Operator
#You can check if a number is odd or even since even number do not have remainders.
#even numbers have 0 remainder
#odd number have >0 remainders
👨🏫Print() -- you can print to the screen as a way to double check things.
if 4 % 2 == 0:
print("even number")
else:
print("odd number")
move(North)
if 5 % 2 == 0:
print("even number")
else:
print("odd number")
move(South)
#--- [||] PAUSE --- [|>] Run the program then proceed
#PRACTICE 2 -- 👨🏫 Comparison Operators,
if 1 > 0:
print(1 > 0)
move(North)
if 0 != 5:
print(0 != 5)
move(North)
if 0 == 0:
print(0 == 0)
move(North)
#--- [||] PAUSE --- [|>] Run the program then proceed
#End of practice -- continue to the next section of code, Sowing and Reaping.
2. Finish up by creating the reaping phase and copy
- i. Create code to harvest two Grass and one Bush (see above pic)
- ii. Hint -- Bush need to be replanted. 3. 6. Unlock Senses, triggering Senses doc popup.
Add the following code to the starter code:
#Append the following code to the starter code:
,,, SOWING PHASE ,,,,,,,
#PRACTICE 3 -- 👨🏫 Logic Operators
#Observe how logic operators work.
#guess which plot will grow Bush
clear()
if not False:
plant(Entities.Bush)
print("not False -->", not False)
move(North)
if True and False:
plant(Entities.Bush)
print("True and False -->", True and False)
move(North)
if True or False:
plant(Entities.Bush)
print("True or False -->", True or False)
#--- [||] PAUSE --- [|>] Run the program then proceed
#||| REAPING PHASE |||||||
#Reap 100 Hay
#The field should look like this after the Sowing Phase above :
#🌾 Grass
#🌳 Bush
#🌾 Grass
#Create a while loop to harvest then move North, harvesting Grass, Bush, then Grass.
#Hint -- Bush need to be replanted.
#write code below:
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T07 - Sensitivity Training | Sense & Debug
📝 Task 07
Explore Sense & Debug
🔓 Goals - Expand 2, Speed 2, Grass 2, Carrot, Hats, and Watering.
Note:
📺 Python Program to Check Even or Odd Number Using Modulus Operator | Python for Beginners | ProgramGuru
https://youtu.be/hZcC6R8vZYs?si=04d0EDL7Itp54DAE
- Carrot and Hat tech unlock cost is 50 🌾 Hay and 50 🌳 Wood
- infinite while loops can be exited by meeting conditions or via break.
- Read Break -- [ i ] ➡️ Programming ➡️ Break.
- Read Senses doc -- [ i ] ➡️ Unlocks ➡️ Senses
- Read Debug doc -- [ i ] ➡️ Unlocks ➡️ Debug
Starter code -- copy the following into the code editor:
#📝 Program P07 -- Sensitivity Training
#Explore Senses
#Unlock Goal - Carrot, Hats, Expand 2, Grass 2, Speed 2
#,,, SOWING PHASE ,,,,,,,
#* We used the modulo operator, % figure out odd or even numbers in Program P06.
#* Use get_pos_y() with modulo operator to plant Bush only in even numbered y-axis.
#* after reaching y-axis 2, move north to y-axis 0, then break out the loop
#* How to stop loops early -- [ i ] ➡️ Programming ➡️ Break
#* print() your location and modulo remainders after each move to help troubleshoot
#Create a while loop to create this field:
#🌳 bush
#🌾 grass
#🌳 bush
clear() #reset your field
#write code to prep field for harvest below:
#--- [||] PAUSE --- [|>] Run the program then proceed
#||| REAPING PHASE |||||||
#Reaping goal -- 350 Hay and 90 Wood
add 350 and 90 to your existing inventory to get your harvest goal
print(num_items(Items.Hay) + 350, "Hay", num_items(Items.Wood) + 90, "Wood", "required" )
#verify printed goals -- [ i ] ➡️ Output ➡️ output.txt (click link to open file)
#Create a while loop reap:
#* identify Entities.Bush, harvest then replant bush or else harvest hay.
#* If both 50 Hay and 50 Wood beyond your inventory is harvested, exit loop.
#Write code below:
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T08 - Gone Loopy | Hats, Carrot, Expand 2 (For Loop)
Explore for loops, Hats and Carrot
🔓 Goals - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables
📺 For loops in Python are easy 🔁 | Fundraiser Bro Code -- https://youtu.be/KWgYha0clzw?si=hSQHRRTx3FbwmKIL
- Create red dot on the left margin to put pause [||] points
- Have the Expand II doc handy -- [ i ] ➡️ Unlocks ➡️ Expand 2
Here is how the relationship between ground, plant and crop works. There is a ground (Grassland and Soil) type that hosts plant (entity--Grass and Bush) type that yields crops (items--Hay and Wood). Use following functions to check for ground and plant type and item quantity.: - get_ground_type()
- get_entity_type()
- num_items()
#Program P08 -- Gone Loopy
#Explore Hats, Carrot, Expand 2
#Unlock Goal - Expand 3, Speed 3, Grass 3, Carrot 2, Trees, Watering, Variables
#have the Output window handy -- General Info --> Output
#Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot
»»---------------► PRACTICE
#reset the field
clear()
#get_world_size() returns the length of the field
print(get_world_size(), "-- field length")
move(North)
print((get_world_size() + get_world_size()), "-- field length 2X")
#change hats for pure esthetics
change_hat(Hats.Brown_Hat)
#while loop that runs while Hay inventory is less than 987654321.
#observe the the increase in Hay
#example using if aconditional to break out of loop
while num_items(Items.Hay) < 987654321:
print(num_items(Items.Hay), "- before harvest")
harvest()
do_a_flip()
print(num_items(Items.Hay), "- after harvest")
if num_items(Items.Hay) > 0:
print("Break condition met--exit")
break
#carrots require ground prep, till() --> Grounds.Soil
#entity check: check the enitity, if not Carrot, till
if get_entity_type() != Entities.Carrot:
print(get_entity_type())
till()
#ground check: check the ground, if Soil, plant carrot
if get_ground_type() == Grounds.Soil:
print(get_ground_type())
plant(Entities.Carrot)
#--- [||] PAUSE --- [|>] Run the program then proceed
continued below ...
➿ Let us practice using for loops.
... continued from above
#For Loops
#create a for loop named y-loop to traverse columns, y-axis
#y_counter is an interger variable to count loops
#y-loop - code block: print y_counter variable then move north, repeat 3 times
#note - choosing range 3 will make y == 0, 1, 2
for y_counter in range(3):
print("y ==", y_counter , "-- loop number", y_counter + 1)
move(North)
#--- [||] PAUSE --- [|>] Run the program then proceed
#create a for loop named x-loop to traverse rows
#use x_counter as the variable and get_world_size() for range
#code block: print get_pos_x then moves east, repeat 3 times
for x_counter in range(get_world_size()):
print("x-axis is", x_counter )
move(East)
#reset field
clear()
#--- [||] PAUSE --- [|>] Run the program then proceed
#Traverse the entire field
#Move N, N, N, and E, repeat 3 times by putting x-loop within y-loop (nesting).
#x_counter and y_counter are variables and use get_world_size() for range
#outer x loop code block: wear purple hat, print x position, move east
#inner y loop code block: wear green hat, print y position, move north
for x_counter in range(get_world_size()):
for y_counter in range(get_world_size()):
change_hat(Hats.Green_Hat)
print(get_pos_y(), "-- y-axis, Inner loop number", y_counter + 1)
move(North)
change_hat(Hats.Purple_Hat)
print(get_pos_x(), "-- x-axis, Outer loop number", x_counter + 1)
move(East)
#--- [||] PAUSE --- [|>] Run the program then proceed
continued below ...
Finally prep the field and harvest.
... continued from above
#,,, SOWING PHASE ,,,,,,,
#prep the field with a nested for loop
#carrots are more needed than wood, plant carrots in column 0 and 2
#outer loop -- prints x-axis, calls an inner loop, then moves east
#inner loop -- checks for x-axis, plants carrots or bush, then move north
#field prep goal
#🥕🌳🥕 | Carrot | Bush | Carrot |
#🥕🌳🥕 | Carrot | Bush | Carrot |
#🥕🌳🥕 | Carrot | Bush | Carrot |
#write your code here
#--- [||] PAUSE --- [|>] Run the program then proceed
#||| REAPING PHASE |||||||
#reaping goals 80 Wood and 125 Carrot
#Expand 3 - 30 Wood 20 Carrot
#Speed 3 - 50 Wood 50 Carrot
#Grass 3 - 500 Wood
#Carrot 2 - 250 Wood
#Trees - 50 Wood 70 Carrot
#Watering - 50 Wood
#Variables - 35 Carrot
======================
880 Wood 175 Carrot
#--- [||] PAUSE --- [|>] Run the program then proceed
#create a nested for loop within a while true loop.
#if your Wood AND Carrot reach reaping goals, then break out of loop
#write your code here
#Check your code with the:
#🗝️ 🗝️ 🗝️ Part III: Answer Key 🗝️ 🗝️ 🗝️ 🗝️
📝 T09 -- Large Order | 🔓 Trees, Watering, and Variables
Program P09 -- Large Order
Explore Trees, Watering, and Variables
Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions
📺 Coding Basics: Variables | Programming for Beginners | Transcode https://youtu.be/ghCbURMWBD8?si=WEfD2m3nSP3SWRJ2
[ i ] ➡️ Unlocks ➡️ Watering
[ i ] ➡️ Built-in Functions ➡️ get_water
[ i ] ➡️ Items ➡️ Water
[ i ] ➡️ Unlocks ➡️ Trees
[ i ] ➡️ Entities ➡️ Tree
[ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator
[ i ] ➡️ Unlocks ➡️ Variables
Carrots require tilled soil, 2 Hay and 2 Wood. We can use variables to and seeds have costs. We are no longer over harvesting, and harvest goals are the exact unlock costs.
🌲Trees are different from 🌳 Bush, it grows best when staggered like below:
🌲🌾🌲
🌾🌲🌾
🌲🌾🌲
Program P09 -- Large Order
#Explore Trees, Watering, and Variables
#Unlock Goal - Pumpkin, Fertilizer, Lists, & Functions
#have the Output window handy -- General Info --> Output
#Note planting carrot costs 1 Hay and 1 Wood, Entities --> Carrot
»»---------------► PRACTICE
#reset the field
clear()
Watering
[ i ] ➡️ Unlocks ➡️ Watering
[ i ] ➡️ Built-in Functions ➡️ get_water
[ i ] ➡️ Items ➡️ Water
while True:
print(get_water() )
use_item(Items.Water)
move(North)
if get_water() > 0.25:
print(get_water() )
break
#--- [||] PAUSE --- [|>] Run the program then proceed
clear()
#variables
[ i ] ➡️ Unlocks ➡️ Variables
farmside = get_world_size()
#odds & evens
[ i ] ➡️ Entities ➡️ Operators ➡️ % Modulo Operator
for y_counter in range( farmside ):
move(North)
if get_pos_y() % 2 == 0:
print("even number")
plant(Entities.Tree)
move(East)
for y_counter in range( farmside ):
move(North)
if get_pos_y() % 2 > 0:
print("odd number")
plant(Entities.Tree)
#--- [||] PAUSE --- [|>] Run the program then proceed
#using varibles to making a for loop
max_loop = 3
loop = 0
while loop < max_loop:
pet_the_piggy()
#imcrement counter ➡️ reassign loop as loop number plus one
loop = loop + 1
print(loop)
#--- [||] PAUSE --- [|>] Run the program then proceed
continued below ⬇️ ...
Trees will take the most space since Wood is a requirement to sow Carrots.
... continued from above ⬆️
#,,, SOWING PHASE ,,,,,,,
Trees
[ i ] ➡️ Unlocks ➡️ Trees
[ i ] ➡️ Entities ➡️ Tree
#Field prep visual map: