Hanh Nguyen
Hanh Nguyen

Reputation: 1

Fail to pass some Gomoku/Caro game test cases

This is the question: Gomoku or Caro is a board game where each player alternatively places a stone of his color at an empty intersection of the board. A player wins the game if he is the first player who creates (i) an unbroken line (either horizontal, vertical, or diagonal) of exactly five stones, and (ii) this line is not blocked at either end by stones of the other player. We can use a nested Python list to represent a state of the game as in the examples below is represented by [[“”, “b”, “”, “”], [“”, “b”, “w”, “”], [“”, “”, “”, “”]] where “”, “b”, “w” represent the empty intersection, the black stone intersection, and the white stone intersection respectively. is represented by [[“”, “”, “”, “”, “”, “”], [“”, “b”, “w”, “”, “”, “”], [“”, “”, “b”, “”, “”, “”], [“”, “”, “”, “w”, “”, “”]] In this homework, your goal is to check who is the winner of a given game state. More specifically, your task is to write a function named “get_winner” that gets a nested list representing a Gomoku/Caro game state and returns either “black”, “white”, or “none” if the black stone player is the winner, the white stone player is the winner, other there is no winner respectively. Here we assume that there is no case that both players are winners. This is my case testing result on Gradescope: I passed all the test cases in the given question but failed to pass these 2 test cases which are not mentioned in the question above

Test 10 (0/2) Test Failed: 'black' != 'none' -black +none

Test 11 (0/2) Test Failed: 'none' != 'black' -none +black

I do not know why I failed these test cases and what are these test cases because Gradescope hide them. Does my code satisfy all the requirements of the question and why I fail these two cases? Is there any situation that my code have not fulfilled all the possible cases of this Gomoku game, please help me figure that situation and modify the code if possible.

Upvotes: -1

Views: 156

Answers (1)

DerSchinken
DerSchinken

Reputation: 181

(ii) this line is not blocked at either end by stones of the other player.

This appears to be the problem, your programm only checks if the line is blocked at both ends by the other player.
Example:

print(get_winner([
    ["w", " ", " ", " ", " ", " ", " "],
    [" ", "b", " ", " ", " ", " ", " "],
    [" ", " ", "b", " ", " ", " ", " "],
    [" ", " ", " ", "b", " ", " ", " "],
    [" ", " ", " ", " ", "b", " ", " "],
    [" ", " ", " ", " ", " ", "b", " "],
    [" ", " ", " ", " ", " ", " ", " "],
    [" ", " ", " ", " ", " ", " ", " "]
]))

w is at one end of the line so this should be none, but instead your programm says that black won.
(this example comes to the same result if you try it horizontally or vertically.)

Edit:
Also the diagonal checking is not working as expected

print(get_winner([
    ["b", " ", " ", " ", " ", " ", " "],
    [" ", "b", " ", " ", " ", " ", " "],
    [" ", " ", "b", " ", " ", " ", " "],
    [" ", " ", " ", "b", " ", " ", " "],
    [" ", " ", " ", " ", "w", " ", " "],
    [" ", " ", " ", " ", " ", "b", " "],
    [" ", " ", " ", " ", " ", " ", "w"],
    [" ", " ", " ", " ", " ", " ", " "]
]))

This should certainly say none but instead black is the winner, which violates both rules
this only happens on diagonal lines tho

Upvotes: 0

Related Questions