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.5.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

connect_four_game-0.1.5-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: connect_four_game-0.1.5.tar.gz
  • Upload date:
  • Size: 6.8 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.5.tar.gz
Algorithm Hash digest
SHA256 a761c20995e154afdbbdb154a0f0d0f170e1c489a7322905d26c9e6b1ac2cde9
MD5 0d14b8358d23fac67b967f834c8d600c
BLAKE2b-256 6f2eedc3feaffb34d7951391164aa13bd2e16f12b2cff1d621061a61bfe8a69e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for connect_four_game-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 feb1415747057a798eb0729f65280c5f1ff9304f2da33b911a7f75b42d3810d3
MD5 4e17f5597a7e6b6fc475cb4d44437839
BLAKE2b-256 95a997b6c929286ed7f60e7ef48458dffada1b2b66d634145d551990f8945f94

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