-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect winner #4
Conversation
7ea1e80
to
ae7e231
Compare
…game). Added victoryState model to handle fourLine's winner coordinates. Updated winner tests to test fourLineCoordinates. Added winner detection and fourLine display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: This is perfectly working, nice ! Just a little detail: If you start a game with a full board, you won't know whether it's a draw or a win.
describe("getWinner", () => { | ||
it("should return false for isDraw with an empty board", () => { | ||
expect( | ||
getWinner([ | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 0, 0, 0, 0, 0, 0], | ||
]), | ||
).toStrictEqual({ | ||
player: PlayerNum.empty, | ||
fourLineCoordinates: [], | ||
isDraw: false, | ||
}); | ||
}); | ||
|
||
it("should return false for an ongoing board", () => { | ||
expect( | ||
getWinner([ | ||
[0, 0, 0, 0, 1, 0, 0], | ||
[0, 0, 0, 0, 2, 0, 0], | ||
[0, 2, 1, 0, 2, 0, 0], | ||
[0, 2, 1, 1, 2, 0, 2], | ||
[0, 1, 1, 2, 1, 1, 1], | ||
[0, 2, 2, 1, 1, 2, 2], | ||
]), | ||
).toStrictEqual({ | ||
player: PlayerNum.empty, | ||
fourLineCoordinates: [], | ||
isDraw: false, | ||
}); | ||
}); | ||
it("should return true for a full board without winner", () => { | ||
expect( | ||
getWinner([ | ||
[1, 1, 2, 2, 1, 1, 2], | ||
[2, 2, 1, 1, 2, 2, 1], | ||
[1, 1, 2, 2, 1, 1, 2], | ||
[2, 2, 1, 1, 2, 2, 1], | ||
[1, 1, 2, 2, 1, 1, 2], | ||
[2, 2, 1, 1, 2, 2, 1], | ||
]), | ||
).toStrictEqual({ | ||
player: PlayerNum.empty, | ||
fourLineCoordinates: [], | ||
isDraw: true, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: As it is duplicated with above tests I think we could remove these tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ? this test the ability to check draw game vs full board (maybe I can remove the first two...)
No description provided.