Giter Club home page Giter Club logo

connect-four's Introduction

Erik Ackermann

HOW TO RUN:
Requires Python 3
Run the command line game with: "python3 play.py"

The game will then prompt you to make Players (and name them) before you can start playing.  The user may select for human vs human, human vs computer, and even computer vs computer.


EXPLANATION OF OUR IMPLEMENTATION:

Main Module
The main module for our game is play.py, while connect4.py contains all function and object definitions. 

Within connect4.py, the objects that are defined are Game, Player, and AIPlayer. When play.py is executed, an instance of Game is initialized. When the game is initialized, the program asks the user to select a human or computer player for Player 1 (who will be represented in the game with "x") and Player 2 (represented with "o").  For each human player, an instance of Player is initialized and for each computer player, an instance of AIPlayer is initialized.  AIPlayer is a subclass of Player.  When an AIPlayer is initialized, a difficulty value is set represents the level to which the minimax algorithm searches.

After a game is played, the program prompts the user to play again.  The program tracks wins/losses/ties over multiple rounds and displays these statistics after each game.

When a Four-in-a-row is made, the characters representing the pieces in that streak are capitalized.  This makes it clear why the game ended.

minimax.py is a module which contains an implementation of the minimax algorithm for Connect 4.  This module also has methods for creating state objects (states of the board) as well as functions for checking characteristic of a given state.  An example characteristic is the number of streaks of length k.  There is a method which counts this number, and which takes a search length parameter.


OUR HEURISTIC FOR MINIMAX:

The heuristic in minimax is used to evaluate the relative "goodness" of a board configuration.  The heuristic we developed is as follows:
    goodness = (my four-in-a-rows)*100000 + (my three-in-a-rows)*100 + (my two-in-a-rows)
    OR
    if my opponent has 1 or more four in a rows, then goodness = -100000

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.