diff --git a/Connect4/connect4_lib/Sources/connect4_lib/Board.swift b/Connect4/connect4_lib/Sources/connect4_lib/Board.swift index 76a1023..a81870a 100644 --- a/Connect4/connect4_lib/Sources/connect4_lib/Board.swift +++ b/Connect4/connect4_lib/Sources/connect4_lib/Board.swift @@ -28,6 +28,9 @@ public struct Board : CustomStringConvertible { for tile in row { if tile != nil { nbFree -= 1 + if (tile != 1 && tile != 2) { + return nil + } } } } diff --git a/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift b/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift index 9ba40d6..0420a5c 100644 --- a/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift +++ b/Connect4/connect4_lib/Tests/connect4_libTests/BoardTest.swift @@ -39,11 +39,12 @@ final class BoardTest: XCTestCase { XCTAssertEqual(orig.count, board?.nbRows) } - expect(withGrid: [[0, 1, 2], [0, 0, 0], [0, 0, 0]], shouldNotBeNil: true) + expect(withGrid: [[nil, nil, nil], [nil, nil, nil], [nil, 1, 2]], shouldNotBeNil: true) expect(withGrid: [], shouldNotBeNil: false) expect(withGrid: [[], []], shouldNotBeNil: false) - expect(withGrid: [[0, 1], [0, 0]], shouldNotBeNil: false) - expect(withGrid: [[0, 1, 2], [0, 0, 0, 0]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil], [nil, 1]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil, nil], [nil, nil, 1, 2]], shouldNotBeNil: false) + expect(withGrid: [[nil, nil, nil], [nil, nil, nil], [nil, 1, 3]], shouldNotBeNil: false) } func testIsFull() throws {