Connect-N
Introduction
A simple modified version of Connect Four Game implemented with AI in Python using PyGame.
Project Description
- This repositry contains a simple game made in python similar to Connect 4.
- A bit modified to work with any connect length for any board size.
- Currently supports for variable number of players on a two dimentional board.
- Only three players supported in GUI mode.
- For more players add new colours
COLORvariable in connect_n/pygame_utility.py file. - ID 1 is reserved for AI.
- Currently only supports single AI player in a game.
- Tests in python 3.7 on Windows OS(by developer).
- API: used flask for API development.
- Using flask-migrate for database migration.
- Using httpie for API calls and testing, similar to postman.
Installation
Windows
git clone https://github.com/Kartikei-12/Connect-N
cd Connect-N-master
python -m venv venv
./venv/Scripts/activate
pip install -r requirements.txt
python -m unittest discover --verbose
Linux based OS
git clone https://github.com/Kartikei-12/Connect-N
cd Connect-N-master
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
python -m unittest discover --verbose
Direct Usage
For simple example,
Run main.py as python main.py on windows with virtual environment(./venv/Scripts/activate).
Run main.py as python3 main.py on Ubuntu/Linux with virtual environment(source /venv/Scripts/activate).
API
API Setup(One time)
git clone https://github.com/Kartikei-12/Connect-N
cd Connect-N-master
python -m venv venv
./venv/Scripts/activate
pip install -r requirements.txt
cd connect_n/api/
pip install -r requirements.txt
flask db init
flask db migrate -m "Initial migration"
flask db upgrade
cd ../../
API Usage
Run server with flask run in Connect-N/connect_n/api directory.
API Call: In new terminal do http GET http://127.0.0.1:5000/test
System Requirements
- Python 3
- Pip usually pre-installed with python, check with
pip3 --version. - Python module PyGame installable via pip.
Documentation
Limitation
GUI NOT working inside docker, because no support for pygame inside Docker. Workaround: Code automatically switches to command line interface without raising error connect_n/connect_n.py.
Contributer(s)
Help Needed
- Looking for any algorithm which may be useful for designing AI for turn based games with more than two players.
- Looking for a front end developer for making API front end for web and android.
Additional Resources
- Flask Totorial:
- freecodecamp tutorial
Acknowledgment
- Thanks to Miguel Grinberg for excelent resource on flask and how to learn it.
- Thanks to freecodecamp for the great beginning boost.
Test Report
Start Time: 2019-08-11 19:14:05
Duration: 51.73 s
Summary: Total: 26, Pass: 26
| test_ai.AITests | Status | |
|---|---|---|
| test_get_move | Pass | |
| test_greedy | Pass | |
| test_horizontal_score | Pass | |
| test_negative_digonal_score | Pass | |
| test_positive_digonal_score | Pass | |
| test_string_score | Pass | |
| test_vertical_score | Pass | |
| Total: 7, Pass: 7 -- Duration: 105 ms | ||
| test_api_utility.APIUtility | Status | |
|---|---|---|
| test_compile_response | Pass | |
| Total: 1, Pass: 1 -- Duration: 0 ms | ||
| test_connect_n.ConnectNTests | Status | |
|---|---|---|
| test_add_player | Pass | |
| test_get_strings | Pass | |
| test_get_valid_moves | Pass | |
| test_horizontal_winning_move | Pass | |
| test_is_valid_move | Pass | |
| test_make_move | Pass | |
| test_negative_digonal_winning_move | Pass | |
| test_positive_digonal_winning_move | Pass | |
| test_simulate | Pass | |
| test_version | Pass | |
| test_vertical_winning_move | Pass | |
| Total: 11, Pass: 11 -- Duration: 1 ms | ||
| test_dataset_generate.GenerateDataTests | Status | |
|---|---|---|
| test_generate_save | Pass | |
| test_load | Pass | |
| Total: 2, Pass: 2 -- Duration: 25.66 s | ||
| test_db_user_model.UserModelCase | Status | |
|---|---|---|
| test_check_token | Pass | |
| test_password_hashing | Pass | |
| test_to_dict | Pass | |
| test_token_expiration | Pass | |
| Total: 4, Pass: 4 -- Duration: 2.58 s | ||
| test_pygame_utility.PygameUtilityTests | Status | |
|---|---|---|
| test_play | Pass | View |
pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html |
||
| Total: 1, Pass: 1 -- Duration: 23.39 s | ||
Metadata
Release files for connect-n 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| connect-n-0.0.5.tar.gz | 17.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| connect_n-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.7 kB
Release files / connect-n-0.0.5.tar.gz
| Download URL | connect-n-0.0.5.tar.gz |
|---|---|
| Size | 17.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3bc9c00caf328953ae5472d9ffe12e3178e8245315e62f894a4b49f1bc91df88
|
|
BLAKE2b-256 checksum How to use checksums |
96336243ea0698da3b09fceca1bd8f1119b9b0c3b0eb1fad8cdc98d1617dca82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|
Release files / connect_n-0.0.5-py3-none-any.whl
| Download URL | connect_n-0.0.5-py3-none-any.whl |
|---|---|
| Size | 34.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
263a8b7d77f8226b95cda21b3bf40d55eabf29c9da9e0c30c33f021840797c56
|
|
BLAKE2b-256 checksum How to use checksums |
41b7adc54ce046b7d6e6865b83ba54fb707b7dd3d83dedb9116004a48730b8e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
|