CSC 380 Final Presentation Connect 4 David Alligood, Scott Swiger, - - PowerPoint PPT Presentation

csc 380 final presentation
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CSC 380 Final Presentation

Connect 4 David Alligood, Scott Swiger, Jo Van Voorhis

slide-2
SLIDE 2

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 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.

slide-3
SLIDE 3

Informal

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.

slide-4
SLIDE 4

Formal

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)

slide-5
SLIDE 5

MinMax

  • Player 1: Maximize score

Player 2: Minimize score

  • Explores each possible move

within the “game tree”

  • Recursive
  • O(b^d)

b= # of possible moves d= max # of turns until end game (depth)

slide-6
SLIDE 6
slide-7
SLIDE 7
slide-8
SLIDE 8

MinMax

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

4,531,985,219,092

board states in Connect 4

slide-9
SLIDE 9

MinMax Heuristic

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

slide-10
SLIDE 10

Alpha - Beta

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.

slide-11
SLIDE 11

Alpha - Beta

  • α = value of best choice so far for MAX (highest-value)
  • β = value of best choice so far for MIN (lowest-value)
  • Each node keeps track of its [α,β] values
  • It also allows to prune the search tree as soon as we know that the score of

the position is greater than beta

  • More efficient depth search than MiniMax
slide-12
SLIDE 12

Alpha Beta Pruning

  • Best Case: O√(b^d) Worst Case: O(b^d)
  • An improvement over minimax in terms of efficiency, as the best case for

MiniMax is AlphaBeta’s worst

  • Branches of the search can be eliminated

○ “Pruning” can be accomplished as soon as the score of the position is greater than beta

  • Initially α= -∞ and β= +∞, meaning that each player starts with their worst

possible state/score

  • <α<β so min will opt for alpha, less than beta greater than alpha
slide-13
SLIDE 13

Alpha Beta Illustration

slide-14
SLIDE 14

Alpha Beta pseudocode

  • We created a solver that follows the Alpha Beta Pruning mechanism which

applies to the connect four game states

slide-15
SLIDE 15

Alpha Beta Implementation

  • The benefit of implementing Alpha Beta lies in that the branches of the

search tree can be eliminated based on depth of game states/player moves (plies) (d) and branching factor (b), or b^d

  • Due to this, a deeper search can be achieved in the same amount of time

that a respective minmax run would achieve

  • Alpha Beta, just as minimax, can be improved upon heuristically, which

searches parts of the tree that would cause early alpha-beta cutoffs

  • This heuristic implementation allows for greater improvement without

sacrificing accuracy

slide-16
SLIDE 16

Our Algorithm

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

slide-17
SLIDE 17

Game Play

Our goal was to produce an algorithm that would move quickly, anticipate the player’s next move, find it’s best move, and

  • verall, do it’s best

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.

slide-18
SLIDE 18
slide-19
SLIDE 19

The Collected Data: 30 Games

slide-20
SLIDE 20
slide-21
SLIDE 21

Run Time is Highly Influenced by Player’s Approach

slide-22
SLIDE 22

Getting the Big O

A x C B x C A x C + B x C = C (A + B)

slide-23
SLIDE 23

To Sum Up Our Algorithm

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.

slide-24
SLIDE 24
slide-25
SLIDE 25

Conclusions

AlphaBeta vs MinMax runtimes Early game vs late game Heuristic impact on effectiveness Preferred algorithm? AlphaBeta seems to be most efficient.

slide-26
SLIDE 26

Future Work

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.

slide-27
SLIDE 27

Questions

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?

slide-28
SLIDE 28

Answers

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