Skip to content

feat: add TicTacToe and Connect Four games - #7773

Open
aniketShukla1605 wants to merge 2 commits into
TheAlgorithms:masterfrom
aniketShukla1605:feature/add-tictactoe-connect-four
Open

aniketShukla1605 wants to merge 2 commits into
TheAlgorithms:masterfrom
aniketShukla1605:feature/add-tictactoe-connect-four

Conversation

@aniketShukla1605

Copy link
Copy Markdown

Description

This PR adds two classic board games to the puzzlesandgames package:

1. TicTacToe

  • Implemented a standard 3×3 two-player game.
  • Added move validation and automatic player turn management.
  • Implemented horizontal, vertical, and diagonal win detection.
  • Added draw and game-over detection.
  • Implemented an optimal move finder using the Negamax form of the Minimax algorithm.
  • Added defensive board copying.

2. Connect Four

  • Implemented a standard 6×7 two-player game.
  • Added disc placement with gravity-based positioning.
  • Implemented move validation and player turn management.
  • Added horizontal, vertical, and diagonal win detection.
  • Added draw and game-over detection.
  • Optimized win detection by checking the four directions through the last placed disc.
  • Added defensive board copying.

Tests

Added JUnit 5 test classes covering game initialization, valid and invalid moves, winning conditions, draws, game-over handling, and game-specific functionality.

Validation

  • Maven tests (mvn clean test)
  • Checkstyle
  • PMD
  • SpotBugs

Related Issue

Closes #7772

@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.50%. Comparing base (f4d6708) to head (ecbce0e).

Files with missing lines Patch % Lines
...com/thealgorithms/puzzlesandgames/ConnectFour.java 95.74% 1 Missing and 1 partial ⚠️
...a/com/thealgorithms/puzzlesandgames/TicTacToe.java 97.10% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7773      +/-   ##
============================================
+ Coverage     82.45%   82.50%   +0.05%     
- Complexity     8511     8581      +70     
============================================
  Files           847      849       +2     
  Lines         26291    26407     +116     
  Branches       5134     5163      +29     
============================================
+ Hits          21677    21787     +110     
- Misses         3825     3826       +1     
- Partials        789      794       +5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[FEATURE REQUEST] Add TicTacToe and Connect Four games to puzzlesandgames package

2 participants