All Tracks Algorithms String Algorithms Manachar’s Algorithm Problem

Tic Tac Toe


Tic-tac-toe is a pencil-and-paper 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 respective marks in a horizontal, vertical, or diagonal row wins the game.

Now you are going to write code to play Tic-tac-toe with others or computer bot.

The input will be an 3x3 matrix consisting only of 0, 1 or 2. Then another line will follow which will contain a number 1 or 2, which is your player id.

In the given matrix, top-left is [0,0] and bottom-right is [2,2]. The x-coordinate increases from left to right, and y-coordinate increases from top to bottom.

The cell marked 0 means it doesn't contain any marks. The cell marked 1 means it contains player 1's mark which is gray in color. The cell marked 2 means it contains player 2's mark which is black in color.

Print the coordinates of the cell (x, y) where you want to play your move.

Starting state
0 0 0
0 0 0
0 0 0

The scores will be calculated by running a tournament of all submissions at the end of the contest. Your last submission will be used while running the tournament. Score will be assigned according to Elo rating system.

Example of a bot which plays the game randomly, while avoiding invalid move:
1 0 0
0 0 0
0 0 0
1 1

This is player 2's turn, and the player moves at cell[1, 1].

The next state of the board after the move is following:

1 0 0
0 2 0
0 0 0

Time Limit: 1.0 sec(s) for all input files combined.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic


Enter your code or Upload your code as file.

    Loading code editor...

    If code editor doesn't load in few seconds, click on the problem again.

    Our compiler wanted to be here!But the mobile is too cramped for it to load. It says it would be more comfortable on the web.

    Your Rating:


    View All Notifications