{"id":25806112,"url":"https://github.com/sabdikay/connect4","last_synced_at":"2026-06-09T06:32:16.547Z","repository":{"id":271304182,"uuid":"913020372","full_name":"Sabdikay/Connect4","owner":"Sabdikay","description":"This is a simple Connect Four game implemented in Python with ability to play against computer","archived":false,"fork":false,"pushed_at":"2025-01-06T22:15:13.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-28T02:55:58.551Z","etag":null,"topics":["ai-algorithms","alpha-beta-pruning","board-game","connect4","connect4-ai-game","dynamic-programming","game-development","minimax-algorithm","python","text-based-game"],"latest_commit_sha":null,"homepage":"","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/Sabdikay.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":"2025-01-06T21:43:30.000Z","updated_at":"2025-01-07T13:56:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"96aa6200-9285-44e3-8b5b-ad428c4522a1","html_url":"https://github.com/Sabdikay/Connect4","commit_stats":null,"previous_names":["sabdikay/connect4"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Sabdikay/Connect4","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sabdikay%2FConnect4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sabdikay%2FConnect4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sabdikay%2FConnect4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sabdikay%2FConnect4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sabdikay","download_url":"https://codeload.github.com/Sabdikay/Connect4/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sabdikay%2FConnect4/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34095244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"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":["ai-algorithms","alpha-beta-pruning","board-game","connect4","connect4-ai-game","dynamic-programming","game-development","minimax-algorithm","python","text-based-game"],"created_at":"2025-02-27T19:59:30.282Z","updated_at":"2026-06-09T06:32:16.542Z","avatar_url":"https://github.com/Sabdikay.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connect Four in Python\n\nThis repository contains **two versions** of a Connect Four game implemented in Python:\n\n1. **Connect4 (Two Human Players)**  \n2. **Connect4 (AI Player)** featuring a **minimax**-based computer opponent.\n\nBoth versions retain the core Connect Four mechanics but differ in how the second player’s moves are decided.\n\n---\n\n## Table of Contents\n\n1. [Overview](#overview)  \n2. [Features](#features)  \n   - [Connect4 (Two Human Players)](#connect4-two-human-players)  \n   - [Connect4 (AI Player)](#connect4-ai-player)  \n3. [Gameplay Rules](#gameplay-rules)  \n4. [How to Run](#how-to-run)  \n5. [File Structure](#file-structure)\n6. [Future Enhancements](#future-enhancements)\n\n\n---\n\n## Overview\n\nConnect Four is a classic two-player game where you drop discs into one of the columns, attempting to line up **four of your discs** in a row before your opponent does. This repository offers:\n\n- A **traditional 2-player** mode (Human vs. Human).  \n- An **AI-enhanced** mode (Human vs. Computer) using **minimax** with alpha-beta pruning, leveraging the `random` and `math` libraries.  \n\n---\n\n## Features\n\n### Connect4 (Two Human Players)\n\n- **Board Generation**  \n  Creates a 6×7 grid by default using `generateField()`. You can customize row and column sizes via parameters.\n\n- **Turn-Based Input**  \n  Players (Player 0 = `\"R\"`, Player 1 = `\"Y\"`) alternate columns to drop their discs.\n\n- **Winning/Tie Checks**  \n  After each move, checks if **4 in a row** is formed (horizontally, vertically, or diagonally). If the board fills up, the result is a **tie**.\n\n- **Simple Board Drawing**  \n  Displays columns separated by `\" | \"` with a dashed line after each row.\n\n### Connect4 (AI Player)\n\n- **AI Opponent**  \n  In this version, Player 1 is replaced with an **AI** that uses a **minimax** algorithm for strategic column selection.\n\n- **Scoring \u0026 Evaluation**  \n  The AI’s decision-making:\n  - Considers potential winning moves.\n  - Evaluates board states based on the number of aligned discs and the center-column advantage.\n  - Searches multiple moves ahead (controlled by a `depth` parameter).\n\n- **Random Element**  \n  Some fallback decisions may involve the `random` library to break ties among equally strong moves.\n\n- **Still Allows Board Customization**  \n  The same row and column parameters can be adjusted for custom board sizes.\n\n---\n\n## Gameplay Rules\n\n1. **Objective**  \n   Get four of your discs in a row before your opponent does. The row can be:\n   - Horizontal\n   - Vertical\n   - Diagonal (descending or ascending)\n\n2. **Turn Order**  \n   - Player 0 goes first with discs labeled `\"R\"`.  \n   - Player 1 uses discs labeled `\"Y\"`.  \n   - In the AI version, Player 1 is controlled by the minimax algorithm.\n\n3. **Placement Rules**  \n   - Choose a column (1-based index).\n   - The disc drops in the **lowest empty row** of that column.\n   - If the column is full, you’ll be asked to choose another one.\n\n4. **Ending Conditions**  \n   - A player achieves **4 in a row** → that player wins immediately.\n   - The grid is full with no winner → **tie**.\n\n---\n\n## How to Run\n\n1. **Clone the Repository**:\n   ```bash\n   git clone https://github.com/Sabdikay/Connect4.git\n   cd Connect4\n   ```\n\n2. **Run the Desired Version**:\n   - **Two Human Players**:\n     ```bash\n     python Connect4.py\n     ```\n   - **AI Player**:\n     ```bash\n     python Connect4(AI player).py\n     ```\n\n3. **Play the Game**:\n   - Input the column when prompted.\n   - For the AI version, watch as the computer chooses an optimal (or near-optimal) move.\n\n4. **Customize Board Dimensions** (Optional):\n   - In either file, you can call `startGame(nrow, ncol)` with custom values:\n     ```python\n     startGame(8, 9)  # 8 rows, 9 columns\n     ```\n\n---\n\n## File Structure\n\n```\nConnect4/\n├── Connect4.py            # Two Human Players\n├── Connect4(AI player).py # Computer Player using Minimax\n├── README.md              # This README\n```\n\n- **`Connect4.py`**  \n  Implements the standard 2-player logic.\n  \n- **`Connect4(AI player).py`**  \n  Contains the AI logic using minimax with helper functions (`evaluateField`, `minimax`, etc.).\n\n---\n\n## Future Enhancements\n\n- **More Sophisticated AI**: Add a deeper search or a weighting system for more advanced strategic play.  \n- **GUI Version**: Integrate a library like Pygame or tkinter for a graphical interface.  \n- **Logging \u0026 Statistics**: Track win rates, average game length, and other useful data.\n\n---\n\n\n**Enjoy your game of Connect Four, whether you challenge a friend or our AI opponent!**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabdikay%2Fconnect4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsabdikay%2Fconnect4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabdikay%2Fconnect4/lists"}