For better or worse (likely worse), in the past couple weeks I got back into games in the midst of PhD applications. After finally maxing out my TownHall 18 on Clash of Clans, I was browsing Steam to find games to spend time on. I 100%'d "1 million coins" in about a couple hours and then stumbled upon "The Farmer Was Replaced", a game I had played before but which at the time did not have any achievements, and since I am a completionist, and have been making some effort to code by hand as an exercise to not forget the basics, I saw it as the perfect game to play.
The Leaderboard
After spending a decent amount of time 100%ing the current game (there's a mining DLC which I did not buy), I was curious to see how much frontier models could optimize a full run of the game and enter the game's leaderboard, with the initial goal of breaking into #1000 global. The leaderboard I went for is called Fastest_Reset, where you start the game from nothing and race to buy the Leaderboard unlock, which costs 2 million bones and 1 million gold (currencies in the game). I fed Claude some known scripts found online (more below), the game rules, ran a few scripts in-game which would create .txt files into my actual drive so Opus could see my current game progress, and pointed it that way with the one goal to crack #1000. Opus was given access to run the game and polish the script iteratively, checking how much we had to improve each step of the way to cut our time down to whatever time the 1000th player had.
Balls's Script
At this point Opus started using a script made by Balls, which on its own achieved a time of 1:15:42.9, reaching rank #486 on the leaderboard. Since that was already inside the top 1000, the goal became the top 100, and after a first round of tweaks I submitted a 1:14:01 that moved me up to #373. Opus found that skipping the hats (you can change the hat in your drone, and are purely cosmetic) saved about 41 seconds, that skipping the unlocks that came with the mining DLC helped too, that capping upgrades at a certain level (Grass 6, Trees 6, Watering 7, Polyculture 3 and Megafarm 4) was faster than buying every level, and that buying Fertilizer 3 before Mazes was also faster, while forcing an extra farm expansion or keeping a bigger power reserve only made the run slower, and at the end managed to get within about 80 seconds of the top 100 solely by optimizing this known script.
Starting From Scratch
At this point I was curious whether 1. starting from the known script was limiting Opus capabilities and 2. whether Opus 5.5 xhigh would be able to start from scratch and come up with a stronger script capable of potentially make top 10 globally. The first two scripts it wrote from scratch were both slower than Balls's (1:42:30 and then 1:27:28). Since I had usage to spare and my weekly limits were reseting soon, I had it spawn 20 subagents to research different parts of the game and optimize it based on what the runs and experiments Opus 5.5 Med had run previously. Seven of them each researched one part of the game (the early game and basic crops, power and sunflowers, bones and the dinosaur, gold and mazes, pumpkins and cactus, how many ticks each line of the game's language costs, and the purchase order and endgame), seven more double checked each of those claims against the game's decompiled code, one lead merged everything into a single plan, one wrote the script, three reviewed it (for API mistakes, deadlocks and speed) and one fixed what they found. That second took about 100 minutes and about 1.6M subagent tokens, and an earlier try with only 7 analysts died because my laptop went to sleep because my laptop charger has not been too reliable recently.
The New Script
After a few hours (including a pause while I gave a presentation at UB Hacking in NY) Opus came up with a new script that (after some debugging runs where it could man my computer via a small PowerShell script that uses Windows APIs to bring the game window to the front, checks that the game really is in front and that the pixels where the run button should be have the right colors, clicks into the game and presses F5 to start the run, and then puts my previous window and mouse cursor back where they were) that optimized the game in a few ways, each of them checked against the game's code. Clips below are from final clip.
The main change was planting one mixed field, carrots and trees in a checkerboard with grass in between (left picture), so almost every plant sits next to the companion it wants and gives 5x the harvest (which the game gives a bonus to). It also waters each crop once right when it's planted and harvests sunflowers from most petals to fewest, which keeps their 8x power bonus (power doubles the drone's speed).
For the bones currency, the dinosaur (a snake game inside the game) heads straight for each apple while its tail is short and then loops over every tile. The script also grows its own Weird Substance for the gold mazes by spreading infection between its trees, and stays on a 16x16 farm instead of buying late upgrades to expand the farm since those would not pay off before the run ends.
This script not only beat Balls script by over 30 minutes (39:56 on the leaderboard against the published 1:15:42), but got Opus to #28 on the global leaderboard with a 39:56.089, up from my previous #373.
Fastest_Reset times up to #28
22:48
24:50
1:00:06
Show as a table
| Run | Time | How it was measured |
|---|---|---|
| Balls's script, as published | 1:15:42.9 | Leaderboard submission, rank #486 |
| First round of tweaks | 1:14:01 | Leaderboard submission, rank #373 |
| Tuned Balls's script | 1:01:25 | simulate(), average of seeds 1 to 3 |
| Own script v1 | 1:42:30 | simulate(), seed 1 |
| Own script v2 | 1:27:28 | simulate(), seed 1 |
| Own script v3 | 40:06 | simulate(), average of seeds 1 to 3 |
| Own script v3, submitted | 39:56.089 | Leaderboard submission, Global Rank #28 |
| Reference, #2 on the leaderboard | 24:50.234 | Leaderboard |
| Reference, #1 on the leaderboard | 22:47.8 | Leaderboard |
| Reference, top 100 cutoff | 1:00:06 | Leaderboard, at the time of the tuning |
simulate() on fixed seeds.Opus on My Screen
Not satisfied with not being the best overall in the world, Opus continued its tests while I used the laptop by quickly taking control of my screen, tabbing into the game, performing a quick action (such as pressing "run" on a script it had just written straight into the game's save folder, which the game reloads on its own) and tabbing out, such that I could keep doing my work (almost) uninterrupted. Each test used the game's own simulate() function on a fixed seed, which plays a roughly 40 minute run in a minute or two of real time and always gives the same result for the same seed.
Letting It Run Overnight
After #28 I told Opus the PC was all its own and to keep going until the top 10, and then to try different algorithms and go for #1. To test ideas without me, it set up a small queue on my laptop that copies a new version of the script into the save folder, writes a runner that calls simulate() on 3 fixed seeds, presses run in the game and saves the results, which by the end took a little over 2 minutes per test. On top of that it ran rounds of 7 subagents, where 6 of them each owned one part of the run (like the early game, power, pumpkins, the snake or the endgame), prototyped their ideas in a homemade emulator of the game's tick costs and then got 5 actual tests each in the queue. The last agent then merged anything that beat the best version by 12 seconds or more and checked it on 9 seeds, and then Opus submitted it with leaderboard_run, which averages 5 fresh runs into one leaderboard time. Somewhere along the way I told it to stop once a full round gained less than 15 seconds.
Each round took somewhere between 2 and 4 hours. Before the first one, Opus copied the upgrade order the top players use, which alone saved about 3 minutes, and the rounds after that added things like four shared mazes for the final gold, better snake loops and a script that loads in under a second instead of four (the setup code runs on the clock too). Round 4 even got faster by skipping an upgrade, since the extra snakes needed to pay for Polyculture 3 cost more time than it saved.
The game gives the exact same time for the same seed every single run, but adding even one function to the script costs a tick when it loads, and since watering and crop growth draw from the same random numbers, that one tick re-rolls the whole run (at one point Opus deleted an unused dictionary entry just to pay for a new function and keep the early game identical).
Fastest_Reset, overnight rounds
22:48
24:50
Show as a table
| Run | Time | How it was measured |
|---|---|---|
| Own script v3 | 39:56.089 | Leaderboard submission, Global Rank #28 |
| Before the rounds | 35:42.884 | Leaderboard submission, rank #18 |
| Round 1 | 32:43.471 | Leaderboard submission, rank #9 |
| Round 2 | 30:17.588 | Leaderboard submission, rank #8 |
| Round 3 | 29:09.601 | Leaderboard submission, rank #5 |
| Round 4 | 28:17.728 | Leaderboard submission, rank #4 |
| Round 5 | 27:38.556 | Leaderboard submission, rank #3 |
| Round 6 | 27:17.436 | Leaderboard submission, rank #3 |
| Round 7, final | 27:14.863 | Leaderboard submission, rank #3 |
| Reference, #2 on the leaderboard | 24:50.234 | Leaderboard |
| Reference, #1 on the leaderboard | 22:47.8 | Leaderboard |
#3 in the World
Round 5 got us to #3 on the evening of November 9, and rounds 6 and 7 kept shaving time off until a resubmission of round 7's version landed a 27:14.863 at around 3am on November 10 (its 10 leaderboard runs averaged about 27:13, and the fastest single one was a 26:35). In about a day and a half of mostly unattended work, the script went from 39:56 to 27:14 and from #28 to #3 out of more than 4,500 players on the board.
Why We Stopped at #3
By the point we got to #3 Opus was optimizing for mere seconds. Our best time was around 27 minutes, and #1 sat at an absurd 4+ MINUTES ahead. While looking into how those players may have done it, Opus found the exact same 24:50.2 for #2 in a snapshot of the leaderboard someone saved on September 29 which is before the game's November 2 patch (which patched some exploits and seemingly did not clear the leaderboard), while #1's run has no date we could find. I have no idea how either of those runs was done but since Opus was optimizing for mere seconds, and the theory that there were powerful exploits that were now patched, #3 felt like a decent place to end the story.
Project Timeline






I plan to write more about random afternoon side projects, like adding Claude Code to my Carplay or recently getting an iPhone app to ~1k users. I found that the "need for perfection" limits the frequency of my posts (both here and on my research Instagram) so forgive any typos in this blog or non coherent story telling lol
Tools used: PowerShell, ffmpeg, TFWR own Python-like language, GPT Image Gen, Claude Opus 5.5.