Codecraft Works Battle Scripts
Sign in

Tic-Tac-Toe

About the game

Tic-Tac-Toe is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a diagonal, horizontal, or vertical row is the winner.

Games played on three-in-a-row boards can be traced back to ancient Egypt, where such game boards have been found on roofing tiles dating from around 1300 BC. An early variation of tic-tac-toe was played in the Roman Empire, around the first century BC. It was called terni lapilli (three pebbles at a time) and instead of having any number of pieces, each player only had three, thus they had to move them around to empty spaces to keep playing.

What your script does

Each turn your script is handed the board as a 3×3 grid of characters — a space for empty, 'X' or 'O' for a taken square — and which of the two marks it is playing. It picks a row and a column and submits that move. That's the whole contract: read the board, submit one move, return.

Write one

You start from a script that plays random legal moves, so it works from the first run — it just isn't clever yet. Available in Python and Java.

Sign in to enter the Forge