4
1
EDITS:
- Added link to the plain-text (multiple strings) test data
- Added BLANK,EDGE and TIE2 test cases (see Test Data section) (11/25)
- Updated the JSON test cases (some lines were ill-formatted) (11/24)
Renju match gone bad ! (well, technically these guys are playing Go, but who cares) Wikisource
TL;DR
Take a 15x15 grid of characters (made of '.', '0' and '*'), as an input, replace one of '.' s with '*', in such a way that an unbroken horizontal, vertical or diagonal line of exactly five '*' chars is formed.
* * *
* * *
****** * * *
* * *
* * *
Output the coordinates of your '*', or string - 'T' if there is no solution.
Creating a line of more than 5 '*' long (directly or indirectly) is not allowed, this is called an "overline".
Some examples of overlines:
****.** - replacing . with * will result in a horizontal overline
*.*** - replacing . with * will result in a diagonal overline
*
*
*
*
*
Full Version
Abstract
Renju - is an abstract strategy board game (a simpler version of it is also known as Gomoku).
The game is played with black and white stones on a 15×15 gridded Go board.
Black plays first if white did not just win, and players alternate in placing a stone of their color on an empty intersection. The winner is the first player to get an unbroken row of five stones horizontally, vertically, or diagonally.
Computer search by L. Victor Allis has shown that on a 15×15 board, black wins with perfect play. This applies regardless of whether overlines are considered as wins.
Renju eliminates the "Perfect Win" situation in Gomoku by adding special conditions for the first player (Black).
(c) Wikipedia
Objective
Consider you are a part of a Renju match, you are playing black, and there is just one turn left for you to win.
Take the current board position as an input, identify one of the winning moves (if there is one), and output it (see below for the data formats and restrictions).
Sample input board:
A B C D E F G H J K L M N O P . - vacant spot (intersection)
15 . . . . . . . . . . . . . . . 15 0 - white stone
14 . . . . . . . . . . . . . . . 14 * - black stone
13 . . . . . . . . . . . . . . . 13 X - the winning move
12 . . . . . . . . . . . . . . . 12
11 . . . . . . . . . . . . . . . 11
10 . . . . . . . 0 . . . . . . . 10
9 . . . . . . . * . . . . . . . 9
8 . . . . . . . * . . . . . . . 8
7 . . . 0 . . . * . . . . . . . 7
6 . . . 0 0 . . * . . . . . . . 6
5 . . . . . . . X . . . . . . . 5
4 . . . . . . . . . . . . . . . 4
3 . . . . . . . . . . . . . . . 3
2 . . . . . . . . . . . . . . . 2
1 . . . . . . . . . . . . . . . 1
A B C D E F G H J K L M N O P
(axis labels are for illustration purposes only and are not part of the input)
Sample output:
H5
Rules
For the purpose of this challenge, only the following subset of Renju rules apply:
You can place your stone on any vacant intersection (spot);
Player who achieved an unbroken row of five stones horizontally, vertically, or diagonally, wins;
Black (you) may not make a move which will result (directly or indirectly) in creation of an "overline" i.e. six or more black stones in a row.
Data Formats
Input data is a 15x15 grid of characters (".","*","0"]), ASCII-encoded, in any acceptable format, e.g. a two-dimensional character array or a newline separated set of strings e.t.c.
You may not however modify the input alphabet in any way.
Output data is a string, denoting the alpha-numeric board position, as illustrated by the sample board above.
Note that original horizontal axis numeration (A..P), does not include 'I', you MAY use 'A..O' instead, w/o penalty.
If there is no winning move available, output "T" instead.
Scoring
This is code-golf, so the shortest answer in bytes wins !
Some Tests Cases
Tie
Input:
A B C D E F G H J K L M N O P
15 . . . . . . . . . . . . . . . 15
14 . . . . . . . . . . . . . . . 14
13 . . . . . . . . . . . . . . . 13
12 . . . . . . . . . . . . . . . 12
11 . . . . . . . . . . . . . . . 11
10 . . . . . . . 0 . . . . . . . 10
9 . . . . . . . * . . . . . . . 9
8 . . . . . . . * . . . . . . . 8
7 . . . 0 . . . * . . . . . . . 7
6 . . . 0 0 . . * . . . . . . . 6
5 . . . . . . . Z . . . . . . . 5
4 . . . . . . . * . . . . . . . 4
3 . . . . . . . . . . . . . . . 3
2 . . . . . . . . . . . . . . . 2
1 . . . . . . . . . . . . . . . 1
A B C D E F G H J K L M N O P
Output:
"T", the only "winning move" is H5 (denoted with "Z"), but that would create an overline H4-H9
Overline
Input:
A B C D E F G H J K L M N O P
15 . . . . . . . . . . . . . . . 15
14 . . . . . . . . . . . . . . . 14
13 . . . . . . . . . . . . . . . 13
12 . . . . . . . . . . . . . . . 12
11 . . . . . . . . . . . . . . . 11
10 . . . . . . . . . . . . . . . 10
9 . . . . . 0 . . . . 0 . . . . 9
8 . . 0 . . . . . . * 0 0 . . . 8
7 . . 0 . . . . . * . . 0 . . . 7
6 . . 0 * . 0 . * . . 0 0 . . . 6
5 . . 0 . * . * X * * * . . . . 5
4 . . . . . Z . . . . . . . . . 4
3 . . . . . . * . . . . . . . . 3
2 . . . . . . . * . . . . . . . 2
1 . . . . . . . . * . . . . . . 1
A B C D E F G H J K L M N O P
Output:
"H5", the other possible winning move is "F4", but that would result in J1-D6 diagonal overline.
Multiple winning moves
Input:
A B C D E F G H J K L M N O P
15 . * * * . . * * * . . . . . . 15
14 . * . . . . . * . . * . . . . 14
13 . * . . . . . . . . . . . * . 13
12 . . . . . 0 0 0 0 0 0 0 . * . 12
11 . . . . 0 . . X . . . 0 . * * 11
10 . . . . 0 X * * * * X 0 . . * 10
9 . . . . 0 . . * . . . 0 . * * 9
8 . . . . 0 0 . * . . 0 0 . * . 8
7 . . . . . 0 . * . . 0 . . * . 7
6 . . . . . 0 . X . . 0 . . . . 6
5 . . . . . 0 0 0 0 0 0 . . . * 5
4 . . . . . . . . . . . . . . . 4
3 . . . . . . . . . . . . . . . 3
2 . . . . . . . . . . . . . . . 2
1 . . . . . . . . . . . . . . . 1
A B C D E F G H J K L M N O P
Output:
"H6" or "H11" or "F10" or "L10" (one of)
Test Data
The test data in a bit more machine-friendly form (JSON) is available HERE
Added BLANK,EDGE and TIE2 test cases: UPDATED TEST SUITE
You can use the following JS snippet to convert it to multiline strings, if necessary:
for(B in RENJU) { console.log(B+"\n"+RENJU[B].map(l=>l.join``).join`\n`); }
or just download them here
1I'd recommend giving the test cases as they'd appear to the program, not in the form that's clearest for a human to see. That will make it much easier to test submissions. – None – 2016-11-23T20:18:52.807
@ais523 - I've posted JSON-formatted input data for the test cases to the Pastebin (see my update) – zeppelin – 2016-11-23T21:07:05.060
Jesus George! Can we please have columns from
A
toO
instead ofA
toH
andJ
toP
!?! – Titus – 2016-11-25T12:26:56.830@Titus, sure, I'll update the rules now to allow for this – zeppelin – 2016-11-25T12:43:03.857