Files
048-the-coockie-factory/docs/wiki/Step-5-Five-Minute-Run.md
Tirsvad 314f8b4d77 Add wiki in English, Danish and Bahasa Malaysia and the wiki publish workflow
Nine pages per language (home, description, install, one page per
lecture step with its screenshot and what was gained, appendix) plus the
sidebar. Doxygen now runs without warnings. The publish workflow is the
framework template, unchanged.

Task: MIL-005#1
Task: MIL-005#2
Task: MIL-005#3
Task: MIL-005#4
Task: MIL-005#5
Closes #24
Closes #25
Closes #26
Closes #27
Closes #28
2026-10-28 17:03:46 +08:00

28 lines
1.4 KiB
Markdown

# Step 5: the five-minute run
🌐 **English** · [Dansk](Step-5-Five-Minute-Run-da) · [Bahasa Melayu](Step-5-Five-Minute-Run-ms)
`run_bot` plays for 300 seconds in one loop: a burst of 20 clicks, then every 5 seconds a visit to the store. At the end `get_cps` reads the cookies per second. The run in the screenshot reached **16.6 cookies per second** with 26 cursors and 14 grandmas.
**Screenshot**
![Step 5: the five-minute run](https://git.tirsystem.com/Tirsvad-Udemy-100-days-of-code/048-the-coockie-factory/raw/branch/main/docs/images/step-5-result.png)
**Function**
```python
while now - start < duration_seconds:
click_cookie(game, CLICKS_PER_BURST)
now = clock.monotonic()
if now >= next_store_check:
_buy_while_affordable(game)
next_store_check = now + STORE_CHECK_INTERVAL_SECONDS
```
## What we gained
- **One loop, no threads.** The earlier solution used two threads and an extra package. One loop is easier to read, needs no extra dependency and is easy to test.
- **Inject the clock.** `run_bot` receives a `Clock`, so a fake clock tests a 300 second run in milliseconds.
- **Run the GUI in Docker.** Headless Chromium in a container never takes your mouse or keyboard, and the screenshots and the log come out as files.
- **Where to go next.** Buy by cost per cookie per second, buy the upgrade crates, and click the golden cookie: each is a new function behind the same ports.