Implementation and Analysis of Search Algorithms
in Single-Player Connect Four Game
Anmol Rajpurohit
Harsh Bahua
Krish Furia
Fall 2015
University of California, Irvine
Outline
● Motivation
● Game & Rules
● Analysis & Previous Work
● Problem Statement & Algorithms
● Heuristics & Evaluation
● Comparative Analysis & Conclusion
Image Source: http://www.business.mcmaster.ca/mktg/nbontis/shape011.jpg
Motivation
● Implementation enhances understanding of algorithms
● Thorough analysis of algorithms
● Understanding the role of Heuristics and its variations
● Role & Impact of optimization
● Comparative study
● Love for Games
Image Source: http://hunterphoenixcoaching.com/wp-content/uploads/2013/05/motivation-300x300.jpg
Connect Four
● Centuries Old Game
● Vertical Grid/Board
● Most Common - 6 Rows & 7 Columns
● Initially Board - Empty
● 42 discs - 21 of each color
● Players choose color of disc
● Players take turn to drop their color discs in columns
○ Takes lowest unoccupied row of that column
Image Source: https://upload.wikimedia.org/wikipedia/commons/a/ad/Connect_Four.gif
Rules
● Simple
● Place disc in any 1 of 7 columns - Takes lowest row available
● Once the column is full no player can choose to drop disc in that column
● Winner: Player who connects four of one's own discs(same color) next to
each other first in any of following manner:
○ Vertically
○ Horizontally
○ Diagonally
● Game Tie possible
Image Source: http://synergyexpert.com/wp-content/uploads/2015/06/Rules5.jpg
Mathematical Analysis
● 4,531,985,219,092 positions[1] for all games populated with 0-42 pieces
● Perfect Information
● Adversarial
● Zero-Sum Game
● Final outcomes of game:
○ Win/Lose
○ Tie
Image Source: https://dl.mandiant.com/EE/library/MIRcon2014/MIRcon_2014_Mgmt_Track_Application_Game_Theory.pdf
Previous Work
● 1998 - James D. Allen & Victor Allis individually found the following:
○ First player has a winning strategy to the game
● Victor gave Knowledge Based Approach[2]
● James described Winning Strategies[3]
● John Trump - Brute force approach [4]
○ 8 ply database - 40,000 hours of computation
○ Any position in tree can be evaluated in seconds
● Work by James & Victor proved - First player win game
● Demonstrated first player win in Perfect Play
Problem Statement
● Develop AI component which
○ makes best move on computer’s behalf
● State Description
○ 6 x 7 two-dimensional matrix/board
○ Each location has disc of certain color or its empty
● Initial State
○ Empty board
● Goal State
○ Board with first four connecting pieces – vertically, horizontally, or diagonally
○ Board is full and no one is able to connect, then Tie
● Search Space
○ Large search space
● Operation
○ Place a disc Image Source: http://www.dnaevolution.com.au/images/what_we_do1.jpg
Algorithms Implemented / Analyzed
● Minimax Algorithm
○ Tries to minimize whatever value the opponent is
trying to maximize
○ Opponent tries to maximize its value
● Alpha Beta Pruning
○ Optimization of Minimax algorithm
○ Avoids searching subtrees of moves, which won't
be selected
○ α is maximum lower bound of possible solutions
○ β is minimum upper bound of possible solutions
○ Sub-trees/nodes are pruned if the current estimate of
node(based on heuristics) does not lie between α and β
● Cut-off
○ Limit depth of game tree to get next move quickly Image Source: http://connect4me102b.weebly.com/about.html
The above diagram is just for illustration purpose. It does
not represent actual numbers as per our implementation.
Approach
● Depth First Search
● Algorithm works in following order:
a. Offensive
b. Defensive
c. Apply Minimax
● Five difficulty levels (depth cutoff)
● For each computer move our algorithm
computes the best move
● Worst Branching Factor: 7
● Implemented 6 x 7 Board but is scalable.
Difficulty Level Depth of Game
Tree explored
1 2
2 4
3 6
4 8
5 10
Heuristics
● Explore all possibilities
○ Rows - 4 possible space -> 24 combinations
■ [1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7] for one row
○ Columns - 3 possible space -> 21 combinations
■ [1,8,15,22], [8,15,22,29], [15,22,29,36] for one
column
○ Diagonals -> 24 combinations
■ 12 for major diagonal
■ 12 for minor diagonal
● Total possible spaces = 69
36 37 38 39 40 41 42
29 30 31 32 33 34 35
22 23 24 25 26 27 28
15 16 17 18 19 20 21
8 9 10 11 12 13 14
1 2 3 4 5 6 7
Heuristics
● For a particular space the heuristic is calculated in following manner
○ If count of pieces by C and P are equal
■ If computer’s turn then 1
■ If player’s turn then -1
○ If count of pieces by C > P
■ If computer’s turn then (C’s count + 1) – P’s count
■ If player’s turn then C’s count – P’s count
○ If count of pieces by computer is less than player
■ If computer’s turn then C’s count– P’s count
■ If player’s turn then C’s count – (P’s count +1)
● Count is determined using
○ Linear equation ( y = 2x)
○ Exponential ( y = 2x
)
○ Score is zero for count = 0
Image Source: https://citelighter-cards.s3.amazonaws.com/p16nqvblds4c4kcfmpuc1c19h40_79793.jpg
Evaluation: Number of Board Analyzed
Depth Linear w/
AlphaBeta
Exponential w/
AlphaBeta
No
AlphaBeta
2 58 58 73
4 1,002 1,112 2,817
6 13,000 17,000 137,000
8 152,000 300,000 6,500,000
10 1,900,000 3,900,000 305 million
Evaluation: Execution Time
Depth Linear w/
AlphaBeta
Exponential w/
AlphaBeta
No
AlphaBeta
2 0 0 0
4 0.005 0.004 0.007
6 0.015 0.017 0.08
8 0.088 0.097 0.89
10 0.329 0.6 34.7
12 4.033 6.38 >300
Evaluation: 10 Plays
Difficulty
Level
Win Loss Draw
Beginner 8 1 1
Intermediate 6 4 0
Advanced 4 5 1
Expert 4 6 0
Ultra 2 7 1
Evaluation: 10 Plays
Difficulty
Level
Win Loss Draw
Beginner 6 2 2
Intermediate 6 4 0
Advanced 5 3 2
Expert 1 7 2
Ultra 1 8 1
Evaluation
Conclusion
● Exponential heuristics works better than Linear heuristics.
● Exponential heuristics explores more number of nodes hence increasing
computation time.
● Computation time of exponential heuristics is more but time required is less
than 1 sec for depth of up to 10.
● Using Alpha-Beta pruning can save explore 10 to 100 times less nodes as
compared to not using Alpha-Beta pruning.
Future Work
● Improve UI
● Multi-Threaded Programming
● Leverage Transposition Table
● More heuristics
● Analysis with sufficiently large board size
Thank You!
Image Source: http://usercontent2.hubimg.com/6800731_f520.jpg

More Related Content

PDF
Connect (4|n)
PPTX
Artificial Intelligence gaming techniques
PDF
Introduction to programming - exercises 2
PDF
Games.4
PDF
Game and Search
PPTX
My Ideal Self
PDF
Introduction to Machine Learning and Deep Learning
PDF
10 more lessons learned from building Machine Learning systems
Connect (4|n)
Artificial Intelligence gaming techniques
Introduction to programming - exercises 2
Games.4
Game and Search
My Ideal Self
Introduction to Machine Learning and Deep Learning
10 more lessons learned from building Machine Learning systems

Similar to Implementation and analysis of search algorithms in single player connect four game (20)

PDF
21CSC206T_UNIT3.pptx.pdf ARITIFICIAL INTELLIGENCE
PPT
PDF
AlphaGo and AlphaGo Zero
PDF
Chess Engine
PDF
Introduction to Alphago Zero
PPTX
AI3391 Artificial intelligence Session 15 Min Max Algorithm.pptx
PPTX
Machine Learning- Introduction.pptx
PPTX
Two player games
PPTX
AI3391 Artificial Intelligence Session 18 Monto carlo search tree.pptx
PDF
Minimax.pdf
PPTX
AlphaZero: A General Reinforcement Learning Algorithm that Masters Chess, Sho...
PDF
Deep Learning for Real-Time Atari Game Play Using Offline Monte-Carlo Tree Se...
PDF
Alpha zero - London 2018
PDF
From Alpha Go to Alpha Zero - Vaas Madrid 2018
PPTX
AI- to eat boiled egg and cheese Unit-II.pptx
PDF
Kaggle Lyft Motion Prediction for Autonomous Vehicles 4th Place Solution
PPTX
Parallel Machine Learning- DSGD and SystemML
PPT
Topic - 6 (Game Playing).ppt
PPT
PDF
Notes on Reinforcement Learning - v0.1
21CSC206T_UNIT3.pptx.pdf ARITIFICIAL INTELLIGENCE
AlphaGo and AlphaGo Zero
Chess Engine
Introduction to Alphago Zero
AI3391 Artificial intelligence Session 15 Min Max Algorithm.pptx
Machine Learning- Introduction.pptx
Two player games
AI3391 Artificial Intelligence Session 18 Monto carlo search tree.pptx
Minimax.pdf
AlphaZero: A General Reinforcement Learning Algorithm that Masters Chess, Sho...
Deep Learning for Real-Time Atari Game Play Using Offline Monte-Carlo Tree Se...
Alpha zero - London 2018
From Alpha Go to Alpha Zero - Vaas Madrid 2018
AI- to eat boiled egg and cheese Unit-II.pptx
Kaggle Lyft Motion Prediction for Autonomous Vehicles 4th Place Solution
Parallel Machine Learning- DSGD and SystemML
Topic - 6 (Game Playing).ppt
Notes on Reinforcement Learning - v0.1
Ad

Recently uploaded (20)

PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Cost to Outsource Software Development in 2025
PDF
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
PPTX
Computer Software - Technology and Livelihood Education
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
How Tridens DevSecOps Ensures Compliance, Security, and Agility
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
assetexplorer- product-overview - presentation
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
Salesforce Agentforce AI Implementation.pdf
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
Types of Token_ From Utility to Security.pdf
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Autodesk AutoCAD Crack Free Download 2025
Cost to Outsource Software Development in 2025
The Dynamic Duo Transforming Financial Accounting Systems Through Modern Expe...
Computer Software - Technology and Livelihood Education
How to Use SharePoint as an ISO-Compliant Document Management System
CCleaner 6.39.11548 Crack 2025 License Key
Oracle Fusion HCM Cloud Demo for Beginners
How Tridens DevSecOps Ensures Compliance, Security, and Agility
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
assetexplorer- product-overview - presentation
DNT Brochure 2025 – ISV Solutions @ D365
Salesforce Agentforce AI Implementation.pdf
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
iTop VPN Crack Latest Version Full Key 2025
"Secure File Sharing Solutions on AWS".pptx
Types of Token_ From Utility to Security.pdf
MCP Security Tutorial - Beginner to Advanced
Ableton Live Suite for MacOS Crack Full Download (Latest 2025)
Why Generative AI is the Future of Content, Code & Creativity?
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Ad

Implementation and analysis of search algorithms in single player connect four game

  • 1. Implementation and Analysis of Search Algorithms in Single-Player Connect Four Game Anmol Rajpurohit Harsh Bahua Krish Furia Fall 2015 University of California, Irvine
  • 2. Outline ● Motivation ● Game & Rules ● Analysis & Previous Work ● Problem Statement & Algorithms ● Heuristics & Evaluation ● Comparative Analysis & Conclusion Image Source: http://www.business.mcmaster.ca/mktg/nbontis/shape011.jpg
  • 3. Motivation ● Implementation enhances understanding of algorithms ● Thorough analysis of algorithms ● Understanding the role of Heuristics and its variations ● Role & Impact of optimization ● Comparative study ● Love for Games Image Source: http://hunterphoenixcoaching.com/wp-content/uploads/2013/05/motivation-300x300.jpg
  • 4. Connect Four ● Centuries Old Game ● Vertical Grid/Board ● Most Common - 6 Rows & 7 Columns ● Initially Board - Empty ● 42 discs - 21 of each color ● Players choose color of disc ● Players take turn to drop their color discs in columns ○ Takes lowest unoccupied row of that column Image Source: https://upload.wikimedia.org/wikipedia/commons/a/ad/Connect_Four.gif
  • 5. Rules ● Simple ● Place disc in any 1 of 7 columns - Takes lowest row available ● Once the column is full no player can choose to drop disc in that column ● Winner: Player who connects four of one's own discs(same color) next to each other first in any of following manner: ○ Vertically ○ Horizontally ○ Diagonally ● Game Tie possible Image Source: http://synergyexpert.com/wp-content/uploads/2015/06/Rules5.jpg
  • 6. Mathematical Analysis ● 4,531,985,219,092 positions[1] for all games populated with 0-42 pieces ● Perfect Information ● Adversarial ● Zero-Sum Game ● Final outcomes of game: ○ Win/Lose ○ Tie Image Source: https://dl.mandiant.com/EE/library/MIRcon2014/MIRcon_2014_Mgmt_Track_Application_Game_Theory.pdf
  • 7. Previous Work ● 1998 - James D. Allen & Victor Allis individually found the following: ○ First player has a winning strategy to the game ● Victor gave Knowledge Based Approach[2] ● James described Winning Strategies[3] ● John Trump - Brute force approach [4] ○ 8 ply database - 40,000 hours of computation ○ Any position in tree can be evaluated in seconds ● Work by James & Victor proved - First player win game ● Demonstrated first player win in Perfect Play
  • 8. Problem Statement ● Develop AI component which ○ makes best move on computer’s behalf ● State Description ○ 6 x 7 two-dimensional matrix/board ○ Each location has disc of certain color or its empty ● Initial State ○ Empty board ● Goal State ○ Board with first four connecting pieces – vertically, horizontally, or diagonally ○ Board is full and no one is able to connect, then Tie ● Search Space ○ Large search space ● Operation ○ Place a disc Image Source: http://www.dnaevolution.com.au/images/what_we_do1.jpg
  • 9. Algorithms Implemented / Analyzed ● Minimax Algorithm ○ Tries to minimize whatever value the opponent is trying to maximize ○ Opponent tries to maximize its value ● Alpha Beta Pruning ○ Optimization of Minimax algorithm ○ Avoids searching subtrees of moves, which won't be selected ○ α is maximum lower bound of possible solutions ○ β is minimum upper bound of possible solutions ○ Sub-trees/nodes are pruned if the current estimate of node(based on heuristics) does not lie between α and β ● Cut-off ○ Limit depth of game tree to get next move quickly Image Source: http://connect4me102b.weebly.com/about.html The above diagram is just for illustration purpose. It does not represent actual numbers as per our implementation.
  • 10. Approach ● Depth First Search ● Algorithm works in following order: a. Offensive b. Defensive c. Apply Minimax ● Five difficulty levels (depth cutoff) ● For each computer move our algorithm computes the best move ● Worst Branching Factor: 7 ● Implemented 6 x 7 Board but is scalable. Difficulty Level Depth of Game Tree explored 1 2 2 4 3 6 4 8 5 10
  • 11. Heuristics ● Explore all possibilities ○ Rows - 4 possible space -> 24 combinations ■ [1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7] for one row ○ Columns - 3 possible space -> 21 combinations ■ [1,8,15,22], [8,15,22,29], [15,22,29,36] for one column ○ Diagonals -> 24 combinations ■ 12 for major diagonal ■ 12 for minor diagonal ● Total possible spaces = 69 36 37 38 39 40 41 42 29 30 31 32 33 34 35 22 23 24 25 26 27 28 15 16 17 18 19 20 21 8 9 10 11 12 13 14 1 2 3 4 5 6 7
  • 12. Heuristics ● For a particular space the heuristic is calculated in following manner ○ If count of pieces by C and P are equal ■ If computer’s turn then 1 ■ If player’s turn then -1 ○ If count of pieces by C > P ■ If computer’s turn then (C’s count + 1) – P’s count ■ If player’s turn then C’s count – P’s count ○ If count of pieces by computer is less than player ■ If computer’s turn then C’s count– P’s count ■ If player’s turn then C’s count – (P’s count +1) ● Count is determined using ○ Linear equation ( y = 2x) ○ Exponential ( y = 2x ) ○ Score is zero for count = 0 Image Source: https://citelighter-cards.s3.amazonaws.com/p16nqvblds4c4kcfmpuc1c19h40_79793.jpg
  • 13. Evaluation: Number of Board Analyzed Depth Linear w/ AlphaBeta Exponential w/ AlphaBeta No AlphaBeta 2 58 58 73 4 1,002 1,112 2,817 6 13,000 17,000 137,000 8 152,000 300,000 6,500,000 10 1,900,000 3,900,000 305 million
  • 14. Evaluation: Execution Time Depth Linear w/ AlphaBeta Exponential w/ AlphaBeta No AlphaBeta 2 0 0 0 4 0.005 0.004 0.007 6 0.015 0.017 0.08 8 0.088 0.097 0.89 10 0.329 0.6 34.7 12 4.033 6.38 >300
  • 15. Evaluation: 10 Plays Difficulty Level Win Loss Draw Beginner 8 1 1 Intermediate 6 4 0 Advanced 4 5 1 Expert 4 6 0 Ultra 2 7 1
  • 16. Evaluation: 10 Plays Difficulty Level Win Loss Draw Beginner 6 2 2 Intermediate 6 4 0 Advanced 5 3 2 Expert 1 7 2 Ultra 1 8 1
  • 18. Conclusion ● Exponential heuristics works better than Linear heuristics. ● Exponential heuristics explores more number of nodes hence increasing computation time. ● Computation time of exponential heuristics is more but time required is less than 1 sec for depth of up to 10. ● Using Alpha-Beta pruning can save explore 10 to 100 times less nodes as compared to not using Alpha-Beta pruning.
  • 19. Future Work ● Improve UI ● Multi-Threaded Programming ● Leverage Transposition Table ● More heuristics ● Analysis with sufficiently large board size
  • 20. Thank You! Image Source: http://usercontent2.hubimg.com/6800731_f520.jpg