JavaRush/Courses/Claude Code SELF/The agent plays a game by itself

The agent plays a game by itself

Open

1. Putting it all together

Tommy already has everything he needs in hand. The game is built and checked against the list — a real chess game on chess.js, all seven points hold up. The agent markers are in place. He tried Playwright under Alex’s guidance. Now it is time to put everything together cleanly and by hand: seat the agent at the board and finally play.

Let’s recap what game came out of it — here is the starting position, black at the top, white at the bottom:

8  ♜  ♞  ♝  ♛  ♚  ♝  ♞  ♜   ← black (the agent will play them)
7  ♟  ♟  ♟  ♟  ♟  ♟  ♟  ♟
6  ·  ·  ·  ·  ·  ·  ·  ·
5  ·  ·  ·  ·  ·  ·  ·  ·
4  ·  ·  ·  ·  ·  ·  ·  ·
3  ·  ·  ·  ·  ·  ·  ·  ·
2  ♙  ♙  ♙  ♙  ♙  ♙  ♙  ♙
1  ♖  ♘  ♗  ♕  ♔  ♗  ♘  ♖   ← white (Tommy plays them)
   a  b  c  d  e  f  g  h

   Turn: white        [ New game ]

He will play white, the agent will play black. And on the board, invisible to the eye, live those same markers: data-turn — whose turn it is, data-game-over — whether the game is over. That is what the agent will read.

2. Step 1 — connect Playwright to the project

First things first — the browser goes to the agent. Tommy connects Playwright with one command, just as Alex taught him, and does not forget to restart the session:

claude mcp add playwright -- npx -y @playwright/mcp@latest
claude mcp list        # check: playwright → ✓ Connected
claude                 # restart the agent in the project folder

Tommy waits for the line playwright → ✓ Connected. It shows up — the browser is connected, the agent has hands. If it had not shown up, the first thing he would have checked was the command and whether he restarted the session (last time he tripped over exactly that — forgot to log out and back in). In the fresh session, he takes a look at what the connection gave him:

/mcp          # for playwright, the browser tools are visible: open page, click, input, screenshot
The /mcp command in Claude Code: the playwright server is connected (✔ connected); on the right, its list of tools — open a page, click, type text, take a screenshot and more.

In the list for playwright are browser tools: open, click, type, take a screenshot. That is it, the hand is in place.

3. Step 2 — Tommy sits down to play against the agent

Tommy gives the agent a short prompt — who to play as and which marker to watch for turn order:

Through Playwright, open my game game.html.
You play black. Watch data-turn on the board: as soon as it says "b" —
make a black move and wait again. Keep playing until data-game-over appears.

He hits Enter — and on the screen a browser window opens on its own, the very Playwright one. There is his board, pieces in place. Tommy moves closer — he is the one playing now, as white, right here, live.

He moves the white pawn e2–e4. The turn passes to black. A short pause — the kind where you still do not know whether it will work or freeze. And then, in the window, the cursor comes to life on its own: rolls over to the black pawn, picks it up, carries it to e7–e5, lets go. The data-turn marker is now "w" again — Tommy’s turn.

“Whoa,” he blurts out. “It answered me!”

He moves a knight. The agent moves one of its own. Tommy leans into the screen, forgetting about tea, and plays the game like a real duel: his move — the opponent’s reply, his move — reply. The black cursor moves by itself, without a single touch from his side, as if somebody really were sitting across from him. An opponent out of thin air — exactly the picture he had drawn for himself that morning. A couple of times the agent plays a little weakly, sets itself up — not a grandmaster, what can you do — but it moves on its own, by the rules, patiently waiting for its turn according to the marker.

The game rolls toward the climax. Tommy drives the black king into a corner and delivers mate — chess.js recognizes it right away, and Checkmate. White wins pops up above the board, while data-game-over="true" appears on the board. The agent sees the marker and stops: the game is over.

“I won!” Tommy leans back. And then he catches himself: “Hold on. I was not playing a finished game against a computer toy. I was playing my game — against the agent, who was sitting at the board by itself. I ended up with an opponent. Out of nothing.”

Everything before this was about “I built it”: I put together the snake game, shipped the landing page, dragged in earthquakes. And this is the first time it is about the fact that somebody else is there. Not a person, not a bot hardwired into the game ahead of time, but his agent — it sat down on the other side and played.

4. Step 3 — and now let it play itself

One game is not enough for Tommy. And then a greedier thought hits him:

“Listen, what if I just leave? Let it play for both sides — white and black — and I will just see how it ends.”

That is what /goal is for — Alex showed it in the afternoon. But the order matters: the agent gets to work as soon as the goal is set. So first — what to do, as a separate message:

Play both sides in turn — both white and black, by the rules,
until the game is over. Start when I set the goal.

And then — the goal itself:

/goal the agent read data-game-over="true" on the board and reported it in the chat — or 100 moves have been played

“Go on, finish it yourself,” he says and heads off to the kitchen. If the game is going on without him, he has to stock up properly. Tommy pours tea into a mug the size of a small bucket and loads the office courier robot with chips, chocolate bars, donuts, and a case of cola on top.

“It’s playing the whole game in there — so I need enough for my tea to last the whole game too.”

In the office kitchen, Tommy rests his hand on a huge mug of tea and drops a bag of chips into the courier robot, already heaped with snacks and a case of cola: “It’s playing the whole game in there — so I need enough for my tea to last the whole game too.”

He doesn’t go to check on the board even once. You trusted it — that means you trusted it.

While he is setting himself up for a break, the game goes on in the window all by itself: a white piece moved, a black one replied, then white again — the cursor darts between the sides, playing against itself. After every move the agent reads the marker and writes in the chat whether data-game-over is up yet, and the /goal checker compares that record with the condition. Tommy comes back with tea, the courier rolling in after him with snacks — and the board already shows mate, Checkmate. White wins above it, and the agent has stopped on its own. The game played out all the way through, without him.

On the left, the agent’s session: the instruction to play both sides, the /goal command with its condition, the agent moving for Black and White, reading data-game-over="true" and getting “Goal achieved”; on the right, the browser with the checkmate — Checkmate. White wins.

The goal has been reached — the mode turned itself off. And if you need to stop the agent earlier, you clear the goal manually:

/goal clear

Tommy sips his tea and looks at the board, finished without a single touch from him.

“I left completely — and it played the whole game itself,” he says, as if tasting the words. Not “I built a game” anymore, and not even “I played against the agent,” but this: set the condition, left, came back — done. So it means you can set a goal and walk away. He entrusted not the moves one by one, but the whole result — and it handled it.

He does not dwell on the fact that, at the same time, he gave the agent the right to decide for itself when the game is over — and he did not even watch how it made that decision. “Set it and leave” — that is the whole superpower, the entire story. Alex’s morning slip about “taking the condition ready-made” does not even come up in his head: everything went too well for him to go looking for a catch now.

One game — three ways to play. You play both sides: you move white and black, you sit at the board, you saw the checkmate. You vs. the agent: you move white, the agent moves black, you sit at the board facing the agent, you and the agent saw the checkmate. Agent plays both sides via /goal: the agent moves white and black, you are in the kitchen with your back to the board, only the agent saw the checkmate — the checker knows about it from the agent’s words in the chat. You trusted it not with single moves, but with the whole result. How to accept a result you didn’t see yourself is a separate skill One game — three ways to play You play both sides a dry run of your game You vs. the agent agent moves by data-turn Agent plays both sides /goal — and you walk away Plays white Plays black Where you are during the game Saw checkmate firsthand you you agent you agent agent at the board, by yourself at the board, facing the agent in the kitchen, back to the board you you agent only the agent the checker knows of the mate from its words in the chat You trusted it not with single moves, but with the whole result. How to accept a result you didn’t see yourself is a separate skill.

5. Step 4 — the same hand on the published landing page

Riding the high, Tommy remembers Alex’s words about the shared browser — and he gets curious. If the agent already knows how to navigate pages, why not look at the one he has long since shipped out into the open. He asks it to quickly go through his landing page from level five:

Through Playwright, open my landing page at [URL from L05] and send a screenshot
of the main screen.

The agent opens the landing page, runs through the short script, and sends the screenshot straight into the chat: right there, working. Nothing flashy — just an ordinary page. But Tommy catches the point: the same hand that played chess touched a completely different page. And it would have touched any page.

“Oh, so this is not just for toys,” he thinks out loud. With the same hand you can quickly take a look at something that is already out there — open it, skim it, send back a screenshot: there it is, alive. Handy. But he does not take the thought any further than “handy” — the day is too much of a win to start digging.

6. What can the agent do now?

Tommy cannot hold back — he catches Oliver by the coffee machine and turns him toward the laptop screen.

“Uncle Oliver, take a look. Remember how you were snickering this morning, saying there is no opponent? There is one now. I played a whole game — against it.” He points at the board. “And then I even went off for tea, and it finished the game by itself on both sides. Here is the screenshot, here is mate.”

Oliver looks at the finished board, at Checkmate. White wins, and squints.

“So it played, it checkmated itself, it announced who won,” Oliver says slowly, listing it off. “Just think about that. Soon that machine of yours will be writing itself a paycheck. It did the work, praised itself, and awarded itself a bonus.”

“Exactly, Oliver. It plays by itself, it announces by itself.” Tommy grins, letting the jab sail past his ears. For him, that is exactly the compliment he earned today. As for Oliver asking this morning whether he would check if it plays fair — that has long since gone out of his head.

The chess game goes into the gallery as a new exhibit — the first game where he finally has someone to play against.

That evening, Tom2036 comes alive again.

Tom2036
online
A short message drops into the chat:

today, I see, you made it to 'the machine plays for me while I drink tea'

And right after that, in the same steady tone as the morning caption under the race car:

let’s see how far you are willing to take this 'set it and walk away' thing.

And that is all. Not a word about where it is headed.

Tommy smirks at the screen.

“Wherever I want, that’s where I’ll take it,” he replies, not to the chat, but to himself.

Another little jab from that murky chat with his future self. Not a warning, surely. The day was a clean win, and he takes exactly one thing away from it: you can set a goal and walk away. Tommy shuts down the chat and does not go back into it again.

1
Task
Claude Code SELF,  9 level,  4 lecture
Locked
Memo to myself about the chess project 📌
Memo to myself about the chess project 📌
1
Task
Claude Code SELF,  9 level,  4 lecture
Locked
Put the agent at the board 🤖
Put the agent at the board 🤖
1
Task
Claude Code SELF,  9 level,  4 lecture
Locked
Hand the Game Over to Autopilot 🔁
Hand the Game Over to Autopilot 🔁
1
Task
Claude Code SELF,  9 level,  4 lecture
Locked
The Same Hand on a Live Landing Page 🌐
The Same Hand on a Live Landing Page 🌐
Комментарии
  • популярные
  • новые
  • старые
Для того, чтобы оставить комментарий Вы должны sign in
This page has no comments yet