All Tracks Problem

Isola
Tag(s):

Easy-Medium

Problem
Editorial
Analytics
Isola is a two-player board game. It is played on a 7x7 grid which is initially filled with squares on each cell. Both players have one piece; it is in the middle position of the row closest to his/her side of the board. Players can place their piece on squares only.



A move consists of two subsequent actions:

1. Moving one's piece to a neighboring (horizontally, vertically, or diagonally) position that contains a square but not the opponent's piece.
2. Removing any square with no piece on it.

The player who cannot move his/her piece loses the game.

Now you are going to write code to play Isola with others or computer bot. The program you submit will run for each move played by your player in the game.

Input
The input will be an 7x7 matrix consisting only of 0, 1, 2 and -1. Then another line will follow which will contain a number 1 or 2, which is your player id. The difference between player 1 and 2 is that player 1 plays first in start of the game.

In the given matrix, top-left is [0,0] and bottom-right is [6,6]. The coordinate of a cell is represented by [row, column]. Rows increases from top to bottom and column increases from left to right.

The cell marked 0 means it contains a square which is yellow in color. The cell marked 1 means it contains player 1's piece which is blue in color. The cell marked 2 means it contains player 2's piece which is red in color. The cell marked -1 means it doesn't contain the square. The board is brown in color.

Output
Print the coordinates of the neighbor cell [row, column] where you want to move your piece. In next line, print the coordinates of any cell to remove the square.

Starting state
0 0 0 2 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 0 0

Scoring
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: https://code.hackerearth.com/6f1718R
SAMPLE INPUT
0 0 0  2 0 0 0
0 0 0 -1 0 0 0
0 0 0  0 0 0 0
0 0 0  0 0 0 0
0 0 0  0 0 0 0
0 0 0  0 1 0 0
0 0 0  0 0 0 0
2
SAMPLE OUTPUT
0 2
4 4
Explanation
This is player 2's turn, and the player moves his/her piece to cell [0, 2] and removes the square at cell [4, 4].

After his/her move the state of game becomes:
0 0 2  0  0 0 0
0 0 0 -1  0 0 0
0 0 0  0  0 0 0
0 0 0  0  0 0 0
0 0 0  0 -1 0 0
0 0 0  0  1 0 0
0 0 0  0  0 0 0

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

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

Notifications
View All Notifications