{"id":27141443,"url":"https://github.com/cyberytti/tictactoe_ai","last_synced_at":"2026-05-10T16:32:32.433Z","repository":{"id":286646551,"uuid":"962080642","full_name":"cyberytti/tictactoe_AI","owner":"cyberytti","description":"Play classic Tic-Tac-Toe against an intelligent AI opponent in your terminal.","archived":false,"fork":false,"pushed_at":"2025-04-07T16:18:38.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T01:02:59.800Z","etag":null,"topics":["cli","cli-app","gaming","gaming-bot","groq","langchain","langchain-python","pydantic","python3","tictactoe","tictactoe-python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cyberytti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-04-07T16:06:43.000Z","updated_at":"2025-04-07T16:24:23.000Z","dependencies_parsed_at":"2025-04-07T17:25:29.829Z","dependency_job_id":"e6462948-d795-4271-a4ea-013cf19f8d79","html_url":"https://github.com/cyberytti/tictactoe_AI","commit_stats":null,"previous_names":["cyberytti/tictactoe_ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cyberytti/tictactoe_AI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberytti%2Ftictactoe_AI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberytti%2Ftictactoe_AI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberytti%2Ftictactoe_AI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberytti%2Ftictactoe_AI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cyberytti","download_url":"https://codeload.github.com/cyberytti/tictactoe_AI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cyberytti%2Ftictactoe_AI/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267834802,"owners_count":24151642,"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","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cli","cli-app","gaming","gaming-bot","groq","langchain","langchain-python","pydantic","python3","tictactoe","tictactoe-python"],"created_at":"2025-04-08T06:49:32.300Z","updated_at":"2026-05-10T16:32:32.381Z","avatar_url":"https://github.com/cyberytti.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tic-Tac-Toe AI 🤖\n\nPlay the classic game of Tic-Tac-Toe against an intelligent AI opponent powered by a Large Language Model (LLM) via the Groq API! This AI doesn't just make a move; it analyzes the board and provides its reasoning. 🤔\n\n## ✨ Features\n\n*   **Classic Tic-Tac-Toe Gameplay:** Standard 3x3 grid rules.\n*   **Human vs. AI:** Play as 'X' against the AI 'O'.\n*   **LLM-Powered AI:** Utilizes Groq's fast inference API with the `qwen-2.5-32b` model for strategic decision-making.\n*   **AI Reasoning:** The AI explains *why* it chose a specific move, offering insights into its strategy. 🧠\n*   **Randomized Start:** Either the Human ('X') or the AI ('O') can start the game randomly.\n*   **Clear CLI:** Simple and intuitive command-line interface.\n*   **Input Validation:** Prevents invalid moves by the human player.\n*   **Win/Tie Detection:** Automatically detects and announces game outcomes. 🏆🤝\n\n## 🛠️ Tech Stack\n\n*   **Python 🐍:** Core programming language.\n*   **Langchain (`langchain_groq`) 🦜🔗:** Framework for interacting with the LLM.\n*   **Groq API ⚡:** Provides fast LLM inference capabilities.\n*   **Pydantic 🤖:** Used for defining the structured output format expected from the LLM.\n\n## ⚙️ Setup \u0026 Installation\n\n1.  **Clone the Repository:**\n    ```bash\n    git clone https://github.com/cyberytti/tictactoe_AI\n    cd tictactoe_AI\n    ```\n\n2.  **Install Dependencies:**\n    Make sure you have Python 3 installed. Then, install the required packages:\n    ```bash\n    pip install requirements.txt\n    ```\n    *(Note: `groq` might be needed directly or as a dependency of `langchain_groq`)*\n\n3.  **Configure API Key 🔑:**\n    *   Sign up and get an API key from [GroqCloud](https://console.groq.com/keys).\n    *   Open the file `tictactoe_AI/player.py`.\n    *   Find the line: `API_KEY=\"enter your Groq api-key\"`\n    *   Replace `\"enter your Groq api-key\"` with your actual Groq API key.\n\n## ▶️ How to Play\n\n1.  **Run the Game:**\n    Navigate to the project's root directory (`tictactoe_AI`) in your terminal and run:\n    ```bash\n    python tictactoe_game.py\n    ```\n\n2.  **Follow Prompts:**\n    *   The game will display the numbered board layout (1-9).\n    *   It will announce whether you ('X') or the Computer ('O') starts.\n    *   When it's your turn, enter the number (1-9) corresponding to the empty square where you want to place your 'X'.\n    *   When it's the AI's turn, it will pause briefly to think, then print the position it chose and its detailed reasoning.\n    *   The game board updates after each move.\n\n3.  **Game End:**\n    The game continues until a player gets three in a row (horizontally, vertically, or diagonally) or the board is full (resulting in a tie). The outcome will be announced. 🎉\n\n## 💡 How the AI Works\n\nThe AI's logic resides in `player.py`:\n\n1.  **Board Analysis:** The current state of the Tic-Tac-Toe board is formatted.\n2.  **Available Moves:** Empty squares are identified as potential moves.\n3.  **Prompt Engineering:** A detailed system prompt is constructed and sent to the Groq LLM. This prompt instructs the AI on the rules of Tic-Tac-Toe, its objective ('O'), winning/blocking strategies, and the desired output format (move number and reasoning).\n4.  **LLM Interaction:** The `ChatGroq` client (using Langchain) sends the prompt and current game state to the specified LLM (`qwen-2.5-32b`).\n5.  **Structured Output:** The LLM is asked to return its response in a specific JSON structure (defined using Pydantic), containing the chosen `move` (1-9) and the `reasoning`.\n6.  **Move Execution:** The game script receives the AI's move and reasoning, updates the board, and displays the information to the user.\n7.  **Fallback:** Basic error handling is included. If the LLM call fails, the AI defaults to picking the first available move.\n\n## 🤝 Contributing\n\nContributions are welcome! If you have suggestions for improvements or find any bugs, please feel free to open an issue or submit a pull request.\n\n## 📄 License\n\nThis project is licensed under the Apache License 2.0. You can find the full license text here: [LICENSE](https://github.com/cyberytti/tictactoe_AI/blob/main/LICENSE)\n\n---\n\nEnjoy playing against the AI!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberytti%2Ftictactoe_ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcyberytti%2Ftictactoe_ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcyberytti%2Ftictactoe_ai/lists"}