Skip to main content

Example PyPI (Python Package Index) Package

Project description

Installation

pip install connect-four-game

Usage

Human vs Human

from connect_four_game import Game, Agent

if __name__ == '__main__':
  red_agent = Agent('RED TEAM', 'red')
  blue_agent = Agent('BLUE TEAM', 'blue')
  lcm = Game(red_agent, blue_agent)
  lcm.start_game()

AI vs AI

from connect_four_game import Game

COLUMN_COUNT = 12 # normally 7
ROW_COUNT = 9 # normally 6

if __name__ == '__main__':
  red_rl_agent = RLAgent('red') # RLAgent is not included in the package
  blue_rl_agent = RLAgent('blue')
  game = Game(red_rl_agent, blue_rl_agent, row_count=ROW_COUNT, column_count=COLUMN_COUNT)
  game.start_game()

Example of an RL Agent which randomly chooses columns

import random
from connect_four_game import BaseAgent
import numpy as np

class RLAgent(BaseAgent):
  def __init__(self, color: str, initial_exploration_rate=0.9):
    self.name = f'RL-Agent-{color.capitalize()}'
    self.color = color
    self.symbol = color[0].capitalize()

  def choose_action(self):
    return random.randint(0, len(self.game.grid[0]) - 1)

  def place_block(self):
    column = self.choose_action()
    return self.board.place_block(column, self.symbol)

  def post_evaluation_hook(self):
    print('This method is called after each move has been evaluated')

Human vs AI

On the way...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

connect_four_game-0.1.6.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

connect_four_game-0.1.6-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file connect_four_game-0.1.6.tar.gz.

File metadata

  • Download URL: connect_four_game-0.1.6.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.17

File hashes

Hashes for connect_four_game-0.1.6.tar.gz
Algorithm Hash digest
SHA256 18ace31b0f6b39083ec56d8ad2862c6a6a7b82b90fb1cd439998772d9997bf5d
MD5 90a0ee80ef25c567674c5e53153c959e
BLAKE2b-256 ccadcbb4417b8620bd683d76d5933eee21b1a71b4b7843d26c050aa520e9c1cb

See more details on using hashes here.

File details

Details for the file connect_four_game-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for connect_four_game-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 53fee8ce16fc3d3336dab1479c9c0ff437f53ec95e10f1c2436fb4ab0b411ee1
MD5 52c7c44c41a6ec053d37dc16f30e4531
BLAKE2b-256 39a67c34d9afab25ed1e09d8b3e99edb5f528b36a00e32a596e734dd401810f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page