Skip to content
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

Merged
merged 13 commits into from
Jan 17, 2025
Merged

Detect winner #4

merged 13 commits into from
Jan 17, 2025

Conversation

fzaninotto
Copy link
Member

No description provided.

fzaninotto and others added 6 commits January 16, 2025 18:24
…game). Added victoryState model to handle fourLine's winner coordinates. Updated winner tests to test fourLineCoordinates. Added winner detection and fourLine display.
Copy link
Contributor

@atilbian atilbian left a 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.

Comment on lines +399 to +448
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,
});
});
Copy link
Contributor

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

Copy link
Contributor

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...)

src/connect4.ts Outdated Show resolved Hide resolved
src/layout/cliLayout.ts Show resolved Hide resolved
src/layout/cliLayout.ts Show resolved Hide resolved
@atilbian atilbian merged commit 7cf89a3 into main Jan 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants