Connect Four Michelle Chen Felix Chung Annabel Hung Raymond Wong
Overview Why Connect Four? Interesting Game has a mathematical solution Solved by Victor Allis – defined 9 strategic rules
Background Popular children's board game Two person game Each person assigned one of two colors Most common configuration: 7x6 grid Objective - create a line consisting of four pieces of the player's assigned color –line may be horizontal, vertical, or diagonal
Past Implementations GNU's Four-In-A-Row Mustrum Contains a lot of extra features: load and save games, timed play, multiple languages Velena Uses a search tree of about 60,000 positions Source code available for download
Past Implementations Both Velena and Mustrum claim ”perfect play” Computer strategy guarantees best outcome for it no matter the human move
Goal General – create an agent to play against the human player that uses the rules Won't strive for perfect play, but at least challenging enough for a human player
Approach Create a simple user interface Implement user interface and base functionality first Leave remaining weeks in the quarter on exploring implementations for the computer agent
Features and Requirements Graphical User Interface
Features and Requirements Requirements are pretty much a mapping of the Connect Four game rules Computer and human alternates taking the first move at the start of each game Players alternate playing one piece First player to create a horizontal, vertical, or diagonal line of his/her pieces wins a game If all spaces are filled and no one has created the line, then the game ends in a draw
Design/Architecture Player interface Allows multiple implementations of a computer player A Controller or Main class Enforces Connect Four game rules Asks each player to make a turn Determines if a game has ended Initializes, sets ups, and draws the components for the board Implements the mouse listener; listens for mouse clicks on the screen to determine where to play a piece for the human
Design/Architecture Board and Checker classes Contains draw methods that the main class calls Human Player class Allows the main class to determine when to listen for mouse clicks and to let the computer make a move Computer Player class Main subject of focus; implements a subset of the 9 strategic rules that Victor Allis' defined
Implementation Computer Strategy First looks for groups of three where it can win on the current turn Then looks for groups of three where the human can win after its turn; computer plays in that position to prevent a human win If there are no immediate threats to prevent, then it looks for places where it should not play because it will let the human win Afterwards it applies the rules one at a time
Implementation 5 of the 9 rules implemented, with modification Claimeven, Aftereven, Baseinverse, Lowinverse, Vertical Rules are applied one at a time We essentially gave them priorities Computer applies one rule at time to find a suitable move; if the rule fails to find a move, it tries the next rule If none of the rules find a playable move, the computer selects a random column
Implementation How did we select those 5 rules to implement? Claimeven, Lowinverse, Vertical, and Baseinverse are the basic strategies Aftereven is used in conjuction with Claimeven Claimeven only gives a set of empty spots, Aftereven tells the player when to play in those Claimeven spots Lowinverse also returns a set of empty spots Create an Afterlowinverse rule to use in conjuction with Lowinverse
Difficulties/Challenges Determining the controller of Zugzwang Only controller of Zugzwang can use to rules to win Dependent on the current threats of each player Decision: did not include variable, computer assumed to have control at all times
Difficulties/Challenges Combining rules Determining the best set of rules to apply on successive moves to win Highly complex – main issue was time Decision: Apply the rules one at a time, basically giving the rules a priority
Demo Human vs Computer: Any volunteers?
Conclusion Became an exploratory approach to implementing the strategies Computer is adequate Human and computer both able to win (contrary to GNU's Four-In-A-Row) Questions or comments?