5 kyu

Tic-Tac-Toe Checker

11,294 of 26,298eugene-bulkin
Description
Loading description...
Arrays
Algorithms
  • Please sign in or sign up to leave a comment.
  • Fireblats Avatar

    This kata would've been a lot better, and a bit tougher, if draws also counted games that had empty spaces but were unwinnable.

  • tobiasoe Avatar

    not as simple as i thought

  • Aleksei-Uzin Avatar

    [[1,1,1],[0,2,2],[0,0,0]]: expected -1 to equal 1.

    The test expects -1, although the correct answer is 1.

  • theo99j123 Avatar

    would it not also be a cat's game(no win con) before all tiles has been filled? eg: [[1, 2, 2], [2, 1, 1], [0, 0, 2]]

  • anton.l Avatar

    Nice kata!

  • tobeannouncd Avatar
  • truanthh Avatar

    This comment has been hidden.

  • DanRHenry Avatar

    Failures in the attempt here complete with correct results in vs code.

  • Torqquemada__ Avatar

    In my opinion this cata not contain enough tests (I go it on Python), it's too easy to hardcode and pass it. For example there have place lack of tests for 'O', i make very simple one check for 'O' in row, and successful pass it. It's not check on columns or diagonal for 'O', or diagonal from right to left for 'X'

  • Roman1SPB Avatar

    There are no tests in Python for antidiagonal(counterdiagonal) - board[0][2] - board[1][1] - board[2][0]

  • Siskiz Avatar

    Finally, first cata, who give me real good brainstorm

  • user4604364 Avatar

    this is such a whatever challenge lmao

  • Salmancode76 Avatar

    There is no vertical check for X or O, but it was a good challenge.

  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • floaty Avatar

    Sould be 6 or 7 kyu to my mind :)

  • LetsDoThizz Avatar

    This comment has been hidden.

  • Jordan-J-Brown Avatar

    This comment has been hidden.

  • AlexisBacasen Avatar

    I like this problem

  • AlexanderPsk Avatar

    Don't undestand how i can get error "Failed asserting that 0 is identical to -1." if my code return -1 ONLY if there is no win AND there is zeroes(at least one) in array. If array has zero how correct answer can be 0?

  • JJRG Avatar

    something is not working in the COBOL kata. All my results are correct but it says no

  • quod_42 Avatar

    Why flat is not a function? This method i use for array

  • Rostyslav-Stetsyk Avatar

    TypeError: board.flat is not a function. What? Array.prototype.flat() The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

  • lxg95 Avatar

    This comment has been hidden.

  • DuckLovers Avatar

    For the following board: [['[0,1,1]', '[2,0,2]', '[2,1,0]']]: 0 should equal -1

    why is this in string not in integer. All of the test is pass but not this one because it's a string

  • Zboube Avatar

    there is no tests for first line is {0,0,0}

  • trashy_incel Avatar

    C translation (author gone)

  • catmikaaa Avatar

    This comment has been hidden.

  • FernandoM5 Avatar

    JavaScript: when I run the test cases [[2,1,2],[2,1,1],[1,2,1]] and [[1,2,1],[1,1,2],[2,1,2]] on my device it runs just fine andreturns the expected 0 but onthe Kata it returns -1. Anyone know how to fix that or what the problem might be?

  • ttvpro007 Avatar

    This comment has been hidden.

  • Aqamarine228 Avatar

    Solidity: constantly getting erorr Expected: -1, instead got: 0, even if all cases with same error from comments works fine with my code

  • starfruity Avatar

    pretty fun, would like to revisit to see if i can do it better

  • JustAccount Avatar

    I guess undefined beheviour in random tests should be tested. For instance if board [[2 1 2] [2 1 1] [2 1 1]] is generated, where both "X" and "O" won should not exist. Or at least this should be some other case and function should be expected to return 3. Also task explicitly states that input board would be valid tick-tack-toe board. P.S. I am talking about task in Golang, tests for other languages may be written correctly

  • rickansen Avatar

    nice kata! imagine the horror if we would have to validate the board too haha

  • bshore Avatar
  • OdysseusNotAjax Avatar

    This was fun! I think there's a missing test case to look for a winning column though, i.e. [[1,2,0],[1,0,2],[1,2,0]]. I completed the task and only noticed when reviewing my solution.

  • stevenvuong Avatar

    Is there a problem with this test case? For the following board: [[0,0,2],[0,0,0],[1,0,1]] - Expected: -1, instead got: 0 I change the output to an array to see what was going on, but the result still output 0, even though other cases output the array properly?

  • ivphpan Avatar

    This is kata is crashed on php. board: [ [1,2,1], [1,1,2], [2,1,2] ] my function return 0; test required -1;

    Test messsage: Failed asserting that 1 matches expected -1.

  • akar-0 Avatar

    COBOL translation (author is inactive).

  • akar-0 Avatar

    Ruby: random tests generate incorrect boards, for example: [[0, 2, 2], [1, 1, 0], [0, 2, 2]].

  • akar-0 Avatar

    This comment has been hidden.

  • aliem-r Avatar

    This comment has been hidden.

  • user1430804 Avatar

    This comment has been hidden.

  • Paradus_Hex Avatar

    The flat() method is not working!

  • safhac Avatar

    This comment has been hidden.

  • RNOH Avatar

    nice kata!

  • KyryloRiznychenko Avatar

    Hello all, when I test my code throught testRandomized I got errors

    for example

    1. Here won the X player but the test wrote, that result must be -1 1 2 0 0 1 2 0 0 1

    or next situation

    1. Here won the O player, but the test want get 0 2 1 1 0 1 1 2 2 2
  • XOmniverse Avatar

    According to the random tests, this should have given a -1

    [[2,1,2], [2,1,1], [1,2,1]]

    I am extremely confused by this. The above board is finished (no blank spaces) and nobody has won. Why wouldn't 0 be the correct response?

  • FerPC92 Avatar

    Javascript test cases need's to check for column winners, my solution passes withouth check it , despites than that, great kata!

  • WestwardLand968 Avatar

    This comment has been hidden.

  • ejini战神 Avatar
    • Ruby 3.0 should be enabled (Refer this & this for more detail)
  • Luksonaッ Avatar

    i love how many different solutions are there!

  • czarus05 Avatar

    This comment has been hidden.

  • Luckkkky Avatar

    This comment has been hidden.

  • Chrono79 Avatar

    The log is called after the user's function in javascript tests so when they mutated it, the error message seems wrong. Move the user's function call to the bottom.

  • szasza31 Avatar

    javascript: Problem with test. Result should be -1, not 1.

    Testing board: [[0,1,2],[0,1,2],[0,0,1]]
    [0,1,2]
    [0,1,2]
    [0,0,1]
    
    Expected: 1, instead got: -1
    
  • nono_villar Avatar

    Hi, I'm in a bind and I need to see the code.

    Can someone share it?

    thanks

  • penguinsunited Avatar

    Fun to revisit something I've done before, but the ambiguity of the -1 condition description soured it for me.

    In case this helps: You are being asked to comment on the snapshot of the game you are given. It could be finished, it could be unfinished. Your return is just commenting on the current state available.

  • Kikazuru Avatar

    This comment has been hidden.

  • JasonMRoos Avatar

    Why do I so rarely see a neatly organized object-oriented solution? Always procedural, procedural, procedural, and never a custom data structure in the mix. Makes me sad.

  • Kinrany Avatar

    Problem statement is self-contradictory.

    It says that -1 should be returned if there are empty cells, but it also says that 1 or 2 should be returned if there's a winner.

    It is possible to win before running out of cells.

  • rabbit_binary7 Avatar

    What is the expected output if board is[[1,2,1], [1,2,2], [1,2,2]]? The description is not clear!

  • akozyreva Avatar

    This comment has been hidden.

  • dmitry.kabanov Avatar

    Hi! One important test case is missing from the test suite: the one, where the winning combination on the diagonal runnung from the top right to the bottom left corner. I missed this check in my code initially and tests passed anyway. Example board:

    [[0, 2, 1],
     [2, 1, 2],
     [1, 0, 2]]
    
  • torburg Avatar

    func should return 0 if there is zero value anywhere in the array, am i right?

  • mike2r Avatar

    I enjoyed this kata, just a minor edge case issue:

    C# could do with an extra test - my first solution passes when it shouldn't, for example it would return this board as a win for player 1:

    int[,] board = new int[,] { { 0, 0, 1 }, { 0, 0, 0 }, { 1, 0, 0 } };

    (ie I forgot to check the centre square when checking for a bottom-left to top-right diagonal)

  • Blind4Basics Avatar

    ruby: the random generator needs some constraints:

    Testing board: [[2, 1, 2], [2, 1, 1], [2, 1, 0]]
    [2, 1, 2]
    [2, 1, 1]
    [2, 1, 0]
    
    Expected: 2, instead got: 1
    

    And I don't get this type of case (last fixed test and happens in the random ones too):

    [0, 1, 1]
    [2, 0, 2]
    [2, 1, 0]
    
    Expected: 0, instead got: -1
    
  • LeighMathieson Avatar

    This comment has been hidden.

  • ikarus_wont_fall Avatar

    Test cases dont match the description of the Kata. It shall be assumed that any 0 on the board will mean that the game is unsolved, so returning -1.

    For the following board: [[2,2,2],[0,1,1],[1,0,0]] - Expected: 2, instead got: -1
    For the following board: [[1,1,1],[0,2,2],[0,0,0]] - Expected: 1, instead got: -1
    

    I fail 2 further tests all including remaining 0`s, the others all pass. Whats the matter here?

  • donaldsebleung Avatar

    Solidity Translation Kumited - please carefully review and approve :D

  • donaldsebleung Avatar

    PHP Translation Kumited - please carefully review and approve :D

  • dsurdaneta Avatar

    This comment has been hidden.

  • AlexBella Avatar

    Can we use NumPy or pandas libraires for this? List of lists are very annoying to handle in Python, so it would help a lot.

  • MurKit Avatar

    Would be good to mention in the description that input list may go in the form of list of strings, like this:

    [['[0,0,2]', '[0,0,0]', '[1,0,1]']]

  • JustyFY Avatar

    I loved the exercise :)! Keep up the good work.

  • Just David Avatar

    I've noticed a potential border case alluded to but not responded to by other commenters. Consider the cases a = [[1, 2, 1], [1, 2, 2], [2, 1, 0]] b = [[2, 1, 1], [1, 2, 2], [2, 1, 0]] My code returns isSolved(a) = 0, isSolved(b) = -1 Other successful code returns isSolved(a) = -1, isSolved(b) = -1

    The distinction is whether you can call a cat's game before the last square is occupied if those moves wouldn't matter anyway. Perhaps this is a matter of opinion, but that should be clarified in the instructions and test cases. As is, code producing differing results is accepted.

    Honestly, I don't feel that my code does all I wish it to. In some cases(i think, havent fully investigated), the answer depends on whose turn it is, but since this information isn't included in the game state, I have had to pretend that either player might go next.

    Anyway, I had fun, thanks.

  • lupo72 Avatar

    This comment has been hidden.

  • Xlander Avatar

    This comment has been hidden.

  • robly18 Avatar

    I think it would be best to clarify if an unwinnable state counts as a draw.

  • jmc04 Avatar

    It seems to have a wrong test case: For the following board: [['[2,1,2]', '[2,1,1]', '[1,2,1]']]: 0 should equal -1. How that board could be 'not solved'? (maybe I just don't know tic-tac-toe rules)

  • nickie Avatar

    At least in Python, it seems that you're missing test cases where there is a winning column. My previous submission was wrong and yet accepted. I think there should be winning triples (both of 1 and 2) in all six possible places.

  • uls Avatar

    This comment has been hidden.

  • Fragment Avatar

    I wrote some test-cases for my code, perhaps they're useful?

    Let me know if this should be a spoiler. I could make them more concise, but meh.

    Link: http://pastebin.com/gRxefvTk

    Example:

    # X Diagonal
    
    test.expect(isSolved([[1,3,3],
                          [3,1,3],
                          [3,3,1]]) is 1)
    
    test.expect(isSolved([[3,3,1],
                          [3,1,3],
                          [1,3,3]]) is 1)
    
    # Cat's Game
    
    test.expect(isSolved([[1,2,1],
                          [2,1,2],
                          [2,1,2]]) is 0)
    
  • nitish712 Avatar

    This comment has been hidden.

  • SteveRuble Avatar

    This comment has been hidden.

  • rmunn Avatar

    The supplied test case currently has a // comment, which is valid Javascript but invalid Python. Should be a # comment instead. Trivial to change, but a Python newbie might not know it.

  • oddone Avatar

    This comment has been hidden.

  • Garash Avatar

    This comment has been hidden.

  • Juzzz Avatar

    This was a fun kata!

    I can't believe that no one tried to create a solution to solve any board size (considering the rows and columns in equal length). My solution is far from the best, but any board size is supported :).

    In my opinion, supporting any size was a lot of fun to work out.

  • ssineriz Avatar

    Unbelievable how many approaches there are on this relatively simple kata!

  • delfuego Avatar

    This comment has been hidden.

  • iamggreen Avatar

    The code that is automatically populated in the test fixture does not actually call the isSolved method.

    Test.expect([[0,0,1],
                 [0,1,2],
                 [2,1,0]] === -1);
    

    should be

    Test.expect(isSolved[[0,0,1],
                         [0,1,2],
                         [2,1,0]])) === -1);