한글로 보기

JavaScript · Agent-friendly · No sign-up required

Turn your strategy into code, then test it in battle

Read the rules and design a strategy. Implement it yourself or hand it to your coding agent. Then improve it through battles against AI or online opponents.

Choose a game
Two code windows facing off in a CodeBattle match

It starts with six lines

You don't play the game here. You write the code that plays it. Below is an entire rock-paper-scissors strategy. Paste it into the editor on that screen and it runs.

Throw whatever beats their last throw
var next = 2;              // rock on the first turn

function onGameStart() {}
function onRoundStart() {}

function onTurnStart() {
	return next;           // 1 scissors · 2 rock · 3 paper
}

function onTurnEnd(result) {
	next = result.opponentchoice % 3 + 1;
}

function onRoundEnd() {}
function onGameEnd() {}

Put this code in a battle

LEVEL 1
wins all 20 games
LEVEL 2
loses all 20 games

LEVEL 1 never looks at your previous move, so this strategy catches it every time. LEVEL 2 does the opposite: it reads the regularity and turns it back on you. So you rewrite. That is Code Battle.

Twenty games is 100 rounds and 10,000 turns. A test in the repository re-checks these numbers against the real rule engine.

Try it in rock-paper-scissors
  1. Read the rules and the callback contract in the sample code.
  2. Implement your strategy yourself, or hand it to a coding agent. Each game screen has a spec-copy button you can feed straight to an agent.
  3. Battle the AI, an online opponent or the Code Arena, then read the log and fix it.

A GAME is several ROUNDs, and a ROUND is several TURNs. Each TURN's choice decides the ROUND and the GAME. Anything you send to printLog() appears in the log area at the bottom of the screen.

1 Code Battle

Battle AI or online opponents with one strategy code

Available now. You can play right away without signing in.

Rock Scissors Paper Game

  • Scissors win Paper, Rock wins Scissors, and Paper wins Rock.
  • Choose one of the Scissors(1), Rock(2), or Paper(3) for each TURN, and gain 1 point if you win with Scissors, 2 points if you win with Rock and 3 points if you win with Paper.

Five in a Row (Omok) Game

  • A game in which you put five consecutive stones in one direction of horizontal, vertical, or diagonal in 15x15 grid intersections.
  • Each TURN receives the last coordinates of the opponent, and then determines my coordinates and returns.

Bulls and Cows Game

  • The opponent and I each have their own 3 digits number, and it is a game to win by guessing the opponent's number first. If both sides guess the number at the same time, the larger number wins.
  • Determine the opponent's number for each TURN, and receive the result that if the matching digits are in their right positions, they are 'bulls', if in different positions, they are 'cows'

Sutda Game

  • You and your opponent will each receive 2 cards (Hwatu card), and it is a game where you win or lose with a combination of 2 cards.
  • You get money when the game starts, you get 2 cards and 1 opponent card at the start of the round, and you have to choose raise or call or die on each turn.
Developer event cases

Two strategy codes head to head at a developer event

Run as a Code Battle session at an internal developer event three years in a row. A new game each year, and 16 finalists each year. The qualifier and final screens from those runs still open today.

See how to run it

1:1 Fighting Tournament

  • The game used for the Code Battle session at a 2021 internal developer event. Online qualifiers led to a 16-player final on stage on the day.
  • For each TURN, you select an punch_or_kick and an hitting_area(head, body, or leg), and if you win, you get points according to the punch_or_kick and hitting_area.

Code Baseball Classic

  • The game used for the Code Battle session at a 2022 internal developer event. Online qualifiers led to a 16-player final on stage on the day.
  • It is a code battle game that stands for real baseball. There is a 3X3 strike zone, and every TURN you choose where to throw or where to hit, which will be a home run, a hit, a strike, and a ball according to the rules.

Number Cards Battle

  • The game used for the Code Battle session at a 2023 internal developer event. Online qualifiers led to a 16-player final on stage on the day.
  • The gameplay is almost the same as Sutda. You are given two number cards each and can see one of your opponent's cards. This is a method in which two players bet against each other, and the side with the higher card pair takes the coins they bet on.