Title: [FEATURE REQUEST] Add TicTacToe and Connect Four games to puzzlesandgames package · Issue #7772 · TheAlgorithms/Java · GitHub
Open Graph Title: [FEATURE REQUEST] Add TicTacToe and Connect Four games to puzzlesandgames package · Issue #7772 · TheAlgorithms/Java
X Title: [FEATURE REQUEST] Add TicTacToe and Connect Four games to puzzlesandgames package · Issue #7772 · TheAlgorithms/Java
Description: Title Add TicTacToe and Connect Four implementations with game logic and optimal move finder Description I would like to propose adding two classic board games, TicTacToe and Connect Four, to the puzzlesandgames package. Both implementat...
Open Graph Description: Title Add TicTacToe and Connect Four implementations with game logic and optimal move finder Description I would like to propose adding two classic board games, TicTacToe and Connect Four, to the p...
X Description: Title Add TicTacToe and Connect Four implementations with game logic and optimal move finder Description I would like to propose adding two classic board games, TicTacToe and Connect Four, to the p...
Opengraph URL: https://github.com/TheAlgorithms/Java/issues/7772
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[FEATURE REQUEST] Add TicTacToe and Connect Four games to puzzlesandgames package","articleBody":"### Title\nAdd TicTacToe and Connect Four implementations with game logic and optimal move finder\n\n### Description\n\nI would like to propose adding two classic board games, **TicTacToe** and **Connect Four**, to the `puzzlesandgames` package.\n\nBoth implementations will provide core game functionality, including board management, player turn handling, move validation, win detection, and game-over conditions.\n\n### Motivation\n\nThese additions would expand the existing puzzles and games collection with interactive game-logic implementations while demonstrating 2D array manipulation, recursion, game-state management, adversarial search, and efficient win detection.\n\n### Issue details\n\n### Proposed Implementations\n\n#### 1. TicTacToe\n\nA two-player TicTacToe implementation featuring:\n\n- Standard 3×3 game board.\n- Two players using `X` and `O`, with `X` moving first.\n- Move placement with validation for occupied and out-of-range cells.\n- Automatic player turn switching.\n- Detection of horizontal, vertical, and diagonal wins.\n- Draw and game-over detection.\n- Retrieval of the current board, winner, and active player.\n- Defensive copying when returning the board.\n- An optimal move finder using the **Negamax form of the Minimax algorithm**, ensuring perfect-play decisions.\n\n#### 2. Connect Four\n\nA two-player Connect Four implementation featuring:\n\n- Standard 6×7 game board.\n- Two players using Red (`R`) and Yellow (`Y`), with Red moving first.\n- Disc placement using column selection, with discs falling to the lowest available position.\n- Validation for invalid and full columns.\n- Automatic player turn switching.\n- Detection of horizontal, vertical, and both diagonal winning combinations.\n- Draw and game-over detection.\n- Retrieval of the current board, winner, and active player.\n- Defensive copying when returning the board.\n- Efficient win detection by examining the four directions through the last placed disc.\n\n### Unit Tests\n\nBoth implementations will include JUnit 5 test classes covering:\n\n- Initial board and player state.\n- Valid and invalid moves.\n- Player turn switching.\n- Horizontal, vertical, and diagonal wins.\n- Draw conditions.\n- Game-over handling.\n- Board defensive copying.\n- Game-specific functionality, including optimal move selection in TicTacToe and disc stacking in Connect Four.\n\n### Proposed File Structure\n\n`src/main/java/com/thealgorithms/puzzlesandgames/`\n- `TicTacToe.java`\n- `ConnectFour.java`\n\n`src/test/java/com/thealgorithms/puzzlesandgames/`\n- `TicTacToeTest.java`\n- `ConnectFourTest.java`\n\n\n### Additional Information\n\n_No response_","author":{"url":"https://github.com/aniketShukla1605","@type":"Person","name":"aniketShukla1605"},"datePublished":"2026-11-23T05:40:18Z","url":"https://github.com/TheAlgorithms/Java/issues/7772"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:eafa9866-d425-3716-7e86-69da31198cd3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8B68:2490A6:5006C5:6D1BF3:6B06075E |
| html-safe-nonce | 2329134c826ca58923d14a8797607d40a5971865cccd8da35ebdd025c2b09353 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QjY4OjI0OTBBNjo1MDA2QzU6NkQxQkYzOjZCMDYwNzVFIiwidmlzaXRvcl9pZCI6IjEwNjU1Njc1OTI0OTgyMDI0NjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 485f7798e9067a8df34b4694500f81a817ef3448deec9e88dddff8ff216540e2 |
| hovercard-subject-tag | issue:6553064841 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/TheAlgorithms/Java/7772/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c7115500bb91d909d526e00068456964e98751188c2374fe7f6c6ea4a446ad70/TheAlgorithms/Java/issues/7772 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c7115500bb91d909d526e00068456964e98751188c2374fe7f6c6ea4a446ad70/TheAlgorithms/Java/issues/7772 |
| og:image:alt | Title Add TicTacToe and Connect Four implementations with game logic and optimal move finder Description I would like to propose adding two classic board games, TicTacToe and Connect Four, to the p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aniketShukla1605 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 47127d2f2009e000f3401193f8b4163109ac669adad0804de1ee0e6333ca7b9e |
| turbo-cache-control | no-preview |
| go-import | github.com/TheAlgorithms/Java git https://github.com/TheAlgorithms/Java.git |
| octolytics-dimension-user_id | 20487725 |
| octolytics-dimension-user_login | TheAlgorithms |
| octolytics-dimension-repository_id | 63477660 |
| octolytics-dimension-repository_nwo | TheAlgorithms/Java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 63477660 |
| octolytics-dimension-repository_network_root_nwo | TheAlgorithms/Java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0760ea46a027ba5099cdef7abd54f27865eb4f44 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width