April Fools Contest, 2017
Some Game is a popular game played amongst a group of people. In this adaption of Some Game, new players will make some moves upon an by board. Every square initially contains a . Player makes the first move. After this move, player makes the second move. This goes on until the final player (with number ) has made a move. Afterwards, player can move again. A move consists of player putting on any square with label .
Some Game will end when one player forms a row, column, diagonal or knight hop with a length of or greater, containing only that player's number. If there are ties, the lowest number player wins. To make the board seem infinite, the players have glued the left and right ends of the board together (like a cylinder). Also, they have glued the top and bottom edges of the board together. Some Game will still end if the winning sequence goes across the glue.
Some Game will also end when there are no more valid moves. Moves are not permitted after Some Game ends.
For reference, a knight hop will be shown below. The initial square is A
, and paths from A
to any B
are knight hops.
.......
..B.B..
.B...B.
...A...
.B...B.
..B.B..
.......
In the next few cases, .
are unimportant squares, and 1
are squares with label .
A B C D
1.. 1.. ... .....
.1. ... 1.1 .1...
..1 .1. ... .....
..1..
....1
In example A, player will win if is , or , or so on.
In example B, player will win if is .
In example C, player will win if is .
In example D, player will win if is . Note that knight hops must continue in the same direction, so if is or greater, player would not win.
The standard input stream contains sets of data. In every test case/set of data, the players have gotten tired and have simultaneously quit (Some Game is very tiring). You will work with arbitrary boards of Some Game, plus some extra info. Line 1 contains the extra info, which are , , , and in this arrangement, and are also integers. There are players playing Some Game (). and are defined above (). The winning threshold, (), is non-negative. The next lines of input each contain integers. Every integer on these lines will be between and inclusive, and represents the state of the square on the board when the players have quit. If the Some Game game is still ongoing, or the board is full without a winner, print NO WINNERS
. If player <x>
has won, print PLAYER <x>
, where <x>
is an integer in the range . If the state of the board is impossible, print ERROR
. Make sure to print an empty line between each line of output. Your task is to read this data and print the correct lines of output.
Sample Input
The sample input contains sets of data.
1 3 3 4
1 0 0
0 1 0
0 0 1
1 3 3 2
1 0 0
0 0 0
0 1 0
2 3 3 2
2 2 2
1 0 1
0 0 0
2 5 5 3
0 0 0 2 0
0 1 0 0 0
0 0 2 0 0
2 0 1 0 0
0 0 0 0 1
Sample Output
PLAYER 1
PLAYER 1
ERROR
NO WINNERS
Comments