# [Community Puzzle] A Game of Go

https://www.codingame.com/training/hard/a-game-of-go

Created by @Tux4711,validated by @IAmNoob,@tyrcho and @Redstrike.
If you have any issues, feel free to ping them.

Hi, nice puzzle but I think there might be a problem on the KO rule test of the validator. I didnâ€™t implemented this rule but upon submission, Iâ€™ve got 100% but on the test 6 on IDE, I fail wich is normal since I do not yet check for KO rule.
Maybe some move that are illegal next so the result is the same â€¦

3 Likes

Hi,
I cannot understand the test 05, non-suicidal move.
For me, the move 6 (w 0 1) is suicidal
for me the move 6 is surrounded left-right-bottom by white. Am I wrong ?

1 Like

This is the board state before playing the 6th move, putting W on (0, 1) is valid :

``````W.WB.
.WB..
WB..W
...WB
...B.
``````

Edit: to expand a little, thereâ€™s a concept called liberty in go. If a group of stones has at least one stone with a free cell as a neighbor, then the group lives. Otherwise it dies.
In this case the cell (1, 0) is free and allows the group to live, so the move is valid.

1 Like

Ok, I got this, it is not suicidal because putting the stone will let it be part of a group, and the group has at lease one liberty.

and then move 7 (B 1 0) is not suicidal because the it encircles the white group at top-left, which is beaten.
So after move 7 I have
â€¦B.
B.Bâ€¦
WBâ€¦W
â€¦WB
â€¦B.
Thanks !

Fun puzzle, enjoyed it a lot. A minor improvement in the problem statement would be to clarify that â€śsurroundedâ€ť means on the 4 orthogonal sides (left, right, up, down) only, not diagonally. As it stands, you have to infer from the examples or read externally-hosted game rules. Thanks for creating it!

Hey guys,

dont have the technical knowledge in javascript to find an easy way to organise the data(matrix of dots, Ws and Bs)

any1 can give me some pointers? I tryed nested arrays, but Iâ€™m struggling to print them now.

The straightforward way is to create an array of arrays, which you can initialize like this :
`const board = [...Array(S)].map(_ => readline().split(''));`
Where `S` is the height of the board.
To print it, simply write something like this :
`board.forEach(row => console.log(row.join(''));`

1 Like

Hi, I pass all the test and everything seems fine. But when I submit I donâ€™t succeed the suicidal moveâ€¦
Any subtlety comes to your mind?
I coded this move so that if all neighboors are from the oposite pion type, it is a suicidal moveâ€¦ It seems to donâ€™t workâ€¦

hello,
Itâ€™s hard to say without knowing the logic of your implementation.
I would advise you to try â€śPLAY TESTCASEâ€ť for the â€śSuicidal moveâ€ť test with displaying each move to the log.
Then I would try to â€śrotateâ€ť and/or mirror this test case in different ways and try your implementation on such changed test casesâ€¦ Maybe you either find when it fails or some idea comes to your mind in the processâ€¦

For example you could try the following in different combinations:

• transpose the field: (S x M) ===> (M x S)
• mirror against diagonals (so that (0,0) becomes (S-1,M-1) or (0,M-1) becomes (S-1,0))
• mirror against vertical center (so that (0,0) becomes (0,M-1)
• mirror against horizontal center (so that (0,0) becomes (S-1,0)

The logic of implementation is the next one:
for the given move to make (exemple B at (0,0)), If a neighboor is of the same type as the move (B in the example) I keep looking for new neighboor of the same type. If at some points one of the pions is in touch with an empty field â€ś.â€ť, it means the group is free which means this canâ€™t be a suicidal moveâ€¦

Thereâ€™s also the case where the move is technically suicidal, but placing the stone allows you to kill an enemy group (which happens first), freeing neighbors for your group.

1 Like

Jst as a rzmark, I have beaten the challenge by removing the rules enforcing â€śyou cannot place a pawn on an occupied cellâ€ť.
It was blocking my way on the â€śNon Suicidalâ€ť final case (not the training).
I dunno if there is a bug or something illogic between the test cases and the challenge casesâ€¦

Sounds reasonable, but implementation may contain bugs, so I would recommend to test for different cases as I described. For example, if you canâ€™t pass â€śSuicidal moveâ€ť then it is likely that the (hidden) â€śSuicidal moveâ€ť test case is the same as your visible â€śSuicidal moveâ€ť test case except for some transformation. Examples of transformations I described in my previous reply.
I wish you good luck!

1 Like

Hi,

All my tests are good except the last one â€śBigger fieldâ€ť.
After the move #3, I obtain this map :

``````....WWB..
...WWB.B.
.W.WBBB..
W.WBWWWB.
BWWBBWBB.
BBBBW.WB.
...BBWWW.
WBW.BBW..
.WB...W..
``````

The next move is B 5 5.

I detected this move as suicidal one, seem effectively the case for me.

Have you the same map than me after move #3: W 6 6.

This is my state of the board for this situation, I didnâ€™t check if yours was exactly the same as itâ€™s hard to read without formatting. B 5 5 is not suicidal because both the white group above it and the white stone left of it get killed.

``````....WWB..
...WWB.B.
.W.WBBB..
W.WBWWWB.
BWWBBWBB.
BBBBW.WB.
...BBWWW.
WBW.BBW..
.WB...W..``````
2 Likes

Thanks, all my tests pass OK now, but not in the final validator, I failed on â€śBigger fieldâ€ť â€¦

Hi,
Maybe That wonâ€™t help, but after a good look around I found something that unlocked me.
My managment of the flood fill algorithm was not good enough to remark if a group of pions were FREE or not for every scenario. So every tests worked well except the last one.
By printing like a mad lad I understood that one of the scenario was not covered properly by checking the neighboorhood value, and what the function returned (and all just for the first move).
What I suggest for anyone stuck like @Arnaud80 or me is to just analyse the first move of the last test case to see whatâ€™s wrong.
If all other test works find in a clean manner, solving the first move of the last test case might be sufficient

1 Like