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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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