CSC 380 Final Presentation
Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis
CSC 380 Final Presentation Connect 4 David Alligood, Scott Swiger, - - PowerPoint PPT Presentation
CSC 380 Final Presentation Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis Intro Connect 4 is a zero-sum game, which means one party wins everything or both parties win nothing; there is no mutual win or loss, but there can be
Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis
Connect 4 is a zero-sum game, which means one party wins everything or both parties win nothing; there is no “mutual” win or loss, but there can be ties, as that would qualify as both parties winning nothing. The sum of one player’s total gain and one player’s total loss = 0, giving it the name “zero-sum” game. Connect 4 is also a game of perfect information, which means no matter whose turn it is, that player is aware of all previous moves. A strong solution to a game means knowing the outcome of the game from any given board position.
We are observing and analyzing the way different algorithms try to get 4 pieces in a row on a Connect 4 board. How does each one decide where to play their piece? Which one is the most accurate? Which one makes the fastest decision? These are the factors we are looking at in order to determine which algorithm is the best at playing Connect 4.
A board, s, represented by a 7x6 multidimensional array, where x = row and y = column of s and where (x, y) = {X, O} is won when one of the following are true: (x, y) = (x, y+1) = (x, y+2) = (x, y+3) (x, y) = (x + 1, y) = (x + 2, y) = (x + 3, y) (x, y) = (x + 1, y+1) = (x + 2, y+2) = (x + 3, y+3)
Player 2: Minimize score
within the “game tree”
b= # of possible moves d= max # of turns until end game (depth)
MinMax problem: In order for the computer to play Connect 4 perfectly with MinMax, the entire game tree must be explored. There are over 4 trillion game states in Connect 4, and the runtime needed to iterate through such a vast tree would take an enormous amount of time. There are
board states in Connect 4
Allow MinMax to score game states with other methods Give scores for every 3 in-a-row and 2 in-a-row ((comp_4s * 10000) + (comp_3s * 100) + (comp_2s * 10)) - ((user_4s * 10000) + (user_3s * 100) + (user_2s * 10)) This allows game states to be scored without having to reach terminal states Loss of perfection, but playable
Board Score: 90
The Alpha Beta algorithm is a tree traversing search algorithm, with the primary goal of decreasing the number of nodes that are visited by the MinMax algorithm, making it an improvement over MinMax. A-B optimizes MinMax by reducing effective depth to more than half that of minmax by “pruning” nodes whose values are compared to that of the initial alpha and beta values, each players worst possible scores, respectively.
the position is greater than beta
MiniMax is AlphaBeta’s worst
○ “Pruning” can be accomplished as soon as the score of the position is greater than beta
possible state/score
applies to the connect four game states
search tree can be eliminated based on depth of game states/player moves (plies) (d) and branching factor (b), or b^d
that a respective minmax run would achieve
searches parts of the tree that would cause early alpha-beta cutoffs
sacrificing accuracy
Every way four, consecutive, like-colored pieces could be positioned on a Connect-4 board can be visualized. Our algorithm recognizes these visualizations through the use of its numeric database.
Horizontal 35 36 37 38 36 37 38 39 37 38 39 40 38 39 40 41 28 29 30 31 29 30 31 32 30 31 32 33 31 32 33 34 21 22 23 24 22 23 24 25 23 24 25 26 24 25 26 27 14 15 16 17 15 16 17 18 16 17 18 19 17 18 19 20 10 11 12 13 9 10 11 12 8 9 10 11 7 8 9 10 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 Vertical 35 28 21 14 28 21 14 7 21 14 7 0 36 29 22 15 29 22 15 8 22 15 8 1 37 30 23 16 30 23 16 9 23 16 9 2 38 31 24 17 31 24 17 10 24 17 10 3 39 32 25 18 32 25 18 11 25 18 11 4 40 33 26 19 33 26 19 12 26 19 12 5 41 34 27 20 34 27 20 13 27 20 13 6 Diagonal 35 29 23 17 28 22 16 10 21 15 9 3 36 30 24 18 29 23 17 11 22 16 10 4 37 31 25 19 30 24 18 12 23 17 11 5 38 32 26 20 31 25 19 13 24 18 12 6 41 33 25 17 34 26 18 10 27 19 11 3 40 32 24 16 33 25 17 9 26 18 10 2 39 31 23 15 32 24 16 8 25 17 9 1 38 30 22 14 31 23 15 7 24 16 8 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
Our goal was to produce an algorithm that would move quickly, anticipate the player’s next move, find it’s best move, and
to win.
How we get our Big O. If there is a move which will result in a win, take it. Else if, there is a move which will prevent the opponent from winning, take it. Else if, there is a move which will set the opponent up for a win, avoid it. Else, randomly make a move in a column that is not full. If it is the beginning of a game, make initial move in the center column.
A x C B x C A x C + B x C = C (A + B)
The Big O, which is Big O(C(A+B)):
A = The number of list in winningBoardStates (lists are eliminated as they contain player’s piece) B = The number of list in originalBoardStates (lists are eliminated as they contain computer’s piece) C = The number of variables in the lists of A and B (which is 4, since we want 4 in a row)
Is highly influenced by the player, as he/she may choose to play in such a way that few list can be eliminated from A, keeping the run times higher.
Worst case: 4(full winningBoardStates + full originalBoardStates) = 4(138) = 552 Best case: 4(one winningBoardStates+ one originalBoardStates) = 4(2) = 8 Both originate from the data file containing the 69 lists of horizontal, vertical, and diagonal positions.
AlphaBeta vs MinMax runtimes Early game vs late game Heuristic impact on effectiveness Preferred algorithm? AlphaBeta seems to be most efficient.
Look into heuristics that are playable, yet perfect / more accurate. Our Algorithm: Add a method to see if there are two in a row horizontally in columns 1-5 to avoid this scenario: See how different depths in the game tree affect gameplay.
1. Why is Connect 4 considered a zero-sum game? 2. What is the worst case complexity for AlphaBeta but best case for MinMax? 3. What is pruning? 4. Why is a heuristic needed in order for MinMax to be playable for Connect 4? 5. What is the downside of a heuristic approach in the case of both MinMax and A-B?
1. Either one player wins everything or both player win nothing. 2. O(b^d) where b = number of possible moves, d = depth. 3. Eliminating branches from a tree that do not need to be searched through. 4. Because it would take way too long for the entire game tree to be iterated through. 5. There is loss of perfection, but the game has an increase in playability