{"id":28100447,"url":"https://github.com/parisa-singh/tic-tac-toe","last_synced_at":"2025-05-13T18:34:55.123Z","repository":{"id":263851033,"uuid":"891589796","full_name":"parisa-singh/tic-tac-toe","owner":"parisa-singh","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-20T15:54:22.000Z","size":0,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-20T16:42:13.094Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parisa-singh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-20T15:47:33.000Z","updated_at":"2024-11-20T15:54:27.000Z","dependencies_parsed_at":"2024-11-20T16:42:15.846Z","dependency_job_id":"480e52cb-fad7-41d3-aa1e-1eb8eaaa09c6","html_url":"https://github.com/parisa-singh/tic-tac-toe","commit_stats":null,"previous_names":["parisa-singh/tic-tac-toe"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisa-singh%2Ftic-tac-toe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisa-singh%2Ftic-tac-toe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisa-singh%2Ftic-tac-toe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parisa-singh%2Ftic-tac-toe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parisa-singh","download_url":"https://codeload.github.com/parisa-singh/tic-tac-toe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254003704,"owners_count":21997928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-13T18:34:54.595Z","updated_at":"2025-05-13T18:34:55.107Z","avatar_url":"https://github.com/parisa-singh.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tic-Tac-Toe Game\n## Overview\n\nThis is a Python implementation of the classic **Tic-Tac-Toe** game. It supports dynamic board sizes (`n x n`) and allows two players to compete by alternately placing their tokens (`X` and `O`). The first player to align their tokens in a row, column, or diagonal wins the game.\n\n## Features\n\n- **Dynamic Board Size**: Specify any board size (e.g., 3x3, 4x4, etc.) at the start of the game.\n- **Interactive Gameplay**: Players are prompted to select their moves until there is a winner or the game ends in a tie.\n- **Winning Conditions**:\n  - Align all tokens in a row.\n  - Align all tokens in a column.\n  - Align all tokens in the main diagonal.\n  - Align all tokens in the anti-diagonal.\n- **Input Validation**: Ensures that players provide valid and available locations.\n\n## Requirements\n\n- Python 3.x\n\n## How to Play\n\n1. **Start the Game**  \n   Run the script in a terminal or IDE. For a standard 3x3 game, the function `play_game(3)` is already called in the script.\n\n2. **Board Initialization**  \n   The game will print an empty board with spaces for tokens.\n\n3. **Player Turns**  \n   - Players alternate turns, starting with `X`.\n   - Each turn, the player is prompted to enter a row and column index to place their token.\n   - The game will validate the input and update the board if the move is valid.\n\n4. **Winning and Tie Conditions**  \n   - A player wins if they align their tokens in a row, column, or diagonal.\n   - If all spaces are filled and no player wins, the game ends in a tie.\n\n## Example Gameplay\n\n### 3x3 Game Initialization\n```\n*** Welcome to 3 by 3 Tic-Tac-Toe ***\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n```\n\n### Player Move\n```\n* X's turn *\nPlease enter a row index between 0 and 2: 1\nPlease enter a column index between 0 and 2: 1\n\n+---+---+---+\n|   |   |   |\n+---+---+---+\n|   | X |   |\n+---+---+---+\n|   |   |   |\n+---+---+---+\n```\n\n---\n\n## Functions Explained\n\n1. **`make_empty_board(n)`**: Creates an `n x n` board filled with empty spaces.\n2. **`print_board(n, board)`**: Displays the current state of the board.\n3. **`get_location(n, board)`**: Prompts the current player for a valid move.\n4. **`row_win(n, board, player)`**: Checks if the player has aligned tokens in any row.\n5. **`col_win(n, board, player)`**: Checks if the player has aligned tokens in any column.\n6. **`diag_win(n, board, player)`**: Checks if the player has aligned tokens in the main diagonal.\n7. **`anti_diag_win(n, board, player)`**: Checks if the player has aligned tokens in the anti-diagonal.\n8. **`has_won(n, board, player)`**: Combines all win conditions to determine if a player has won.\n9. **`play_game(n)`**: Manages the overall gameplay loop.\n\n## Customization\n\nTo play on a different board size, modify the argument in the `play_game()` function.  \nExample: For a 4x4 board, use `play_game(4)`.\n\n## Contributions\n\nFeel free to fork this repository, suggest improvements, or report any issues via GitHub or email.\n\n## License\n\nThis project is open-source and available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisa-singh%2Ftic-tac-toe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparisa-singh%2Ftic-tac-toe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparisa-singh%2Ftic-tac-toe/lists"}