/Connect4

Play some connect 4!

Primary LanguagePythonMIT LicenseMIT

Connect4

Play connect 4 against some depth first search oriented AI! Be warned, there's twist: every 10 turns a random piece is removed from the board.

Report

Three trials were carried out for each AI. Blue always represents the AI the statistics correspond to. Red always represents the control group, which is a 'Defense AI' that blocks three in a rows.

Intelligent Agent Pattern

Table

AI Types

  • Defense - Blocks three in a rows, otherwise uses random moves.
  • Defense Agro - Blocks three in a rows and forces a win if it has a three in a row, otherwise uses random moves.
  • Mobile Defense Agro - Blocks three in a rows and forces a win if it has a three in a row, otherwise places pieces in the most mobile locations i.e. locations that open up the most options for future moves.
  • DFS - Generates moves to a specified ply depth using DFS. Each column is evaluated by minimaxing each ply with values generated from the mobile, defensive, and aggressive methods described in the above agents.

Statistics

The charts below represent the data displayed in tables above. The x-axis numbering maps to the following agents:

  • 1 = Defense
  • 2 = Defense Agro
  • 3 = Mobile Defense Agro
  • 4 = DFS (5 ply)

EMPS noDFS DFS Time Outcomes

Sample GUI Output

Version 1:

asdfasdf

Version 2:

TGUI

Notes

  • The "Start AI Battle!" button only works when two AIs are matched against eachother.
  • If you are a player, all you need to do to start playing is click a column on the board.
  • Individual AIvAI games can be stepped through by clicking on the board instead of pressing the "Start AI Battle!" button.
  • Blue goes first. Red goes second.

Sample CLI Output

Mobile Defense Agro Output:

CLI

DFS Output:

CLI

Notes

  • CheckThreeInARow corresponds to the AI deciding to play defensively and block the player from winning.
    • The type of win the AI is blocking is specified directly above the CheckThreeInARow print out.
    • Example of blocking a vertical three in a row in column 5:
      vertical
      CheckThreeInARow: 5
    
  • AGGRO corresponds to the AI making an aggresive move to advance its win condition
    • Example of the AI completing a four in a row in column 1:
      AGGRO: 1
    
  • MOBILE corresponds to the AI placing a piece in a location with as many adjacent slots open as possible.
    • Example of the AI placing a mobile piece in column 3:
      MOBILE: 3
    
  • Column actuator->action evaluations corresponds to the score of each column after the DFS agent has finished evaluating moves to the specified ply.
  • Example of a finished DFS evaluation (the maximum is chosen):
Column actuator->action evaluations:  [4.333333333333329, 6.333333333333329, 6.333333333333329, 6.190476190476186, 76.19047619047628, 0, 4.333333333333329]
DFS chose column: 4

Bugs

  • Don't play as player for red team, its clunky.
  • The code is disgusting :)
  • Probably a lot more :D