Better Chess through Genetic Programming

6,367 views

Published on

A tutorial on genetic programming with applications to chess.

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,367
On SlideShare
0
From Embeds
0
Number of Embeds
47
Actions
Shares
0
Downloads
199
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Better Chess through Genetic Programming

  1. 1. Better Chess Through Genetic Programming Christopher Swenson [email_address]
  2. 2. Overview <ul><li>The Problem </li></ul><ul><li>The Solution </li></ul><ul><li>How the Solution works </li></ul><ul><ul><li> minimax strategy </li></ul></ul><ul><ul><li>Genetic Programming </li></ul></ul>
  3. 3. Programming Chess <ul><li>Easy to learn, difficult to master games </li></ul><ul><li>Until recently, almost impossible for computers to play at the grandmaster level </li></ul><ul><ul><li>State space incredible 2 8000 raw, 2 600 with pruning </li></ul></ul><ul><ul><li>Programming for chess is an expensive process, requiring chess experts to work with programmers for years </li></ul></ul><ul><li>Requirements </li></ul><ul><ul><li>Cheap </li></ul></ul><ul><ul><li>Fast </li></ul></ul><ul><ul><li>Minimize development time </li></ul></ul>
  4. 4. Solution <ul><li>Use a standard technique (  minimax) </li></ul><ul><ul><li>Looks at all possible future moves to a certain depth </li></ul></ul><ul><ul><ul><li>4 ≈ Novice </li></ul></ul></ul><ul><ul><ul><li>8 ≈ Expert </li></ul></ul></ul><ul><ul><ul><li>12 ≈ Grandmaster </li></ul></ul></ul><ul><ul><li>Branch factor for chess is around 40, 7–8 with good pruning techniques (8 12 ≈ 70 billion) </li></ul></ul><ul><ul><li>Requires an “evaluation function” for choosing which future is preferable </li></ul></ul><ul><li>Evaluation function: </li></ul><ul><ul><li>Gives a board a numerical score (utility) </li></ul></ul><ul><ul><li>This is the real meat of  </li></ul></ul>
  5. 5.  Minimax <ul><li> – Keeps track of best move for us to make (we want to max imize the utility the worst situation we can get ourselves into) </li></ul><ul><li> – Keeps track of best move for opponent to make (we want to mini mize the utility of our opponent’s best situation) </li></ul><ul><li>Works by looking at all possible decisions you could make, by estimating all possible decision your opponent could make, etc </li></ul>
  6. 6. Minimax Tree
  7. 7. Evaluation Functions <ul><li>Just a simple function to give a board a score </li></ul><ul><li>Evaluate the leaf nodes, and then let  minimax determine which path is optimal </li></ul><ul><li>For chess, should incorporate which pieces are still on the board, position, etc </li></ul><ul><li>This is where the hard work comes in </li></ul>
  8. 8. Example
  9. 9. Genetic Algorithms <ul><li>Method allowing you to generate near-optimal solutions with little knowledge, using the properties of evolution </li></ul><ul><li>Solutions guaranteed to reach near optimality over time (Schema Theorem) </li></ul><ul><li>Solutions represented as fixed-length “chromosomes” </li></ul><ul><ul><li>Crossover operations  offspring </li></ul></ul><ul><ul><li>Mutations  variation </li></ul></ul><ul><li>Best suited for ≥ NP problems </li></ul><ul><ul><li>Traveling Salesperson Problem </li></ul></ul>
  10. 10. Genetic Programming <ul><li>John Koza, late 1980s </li></ul><ul><li>Extension of Genetic Algorithms, with variable length chromosomes (programs) </li></ul><ul><li>Express programs as LISP-like trees </li></ul><ul><ul><ul><li>4 + 5 </li></ul></ul></ul>
  11. 11. Crossover Function A Function B (# Queens x 9) + (# Pawns) # Knights / 2 Select two functions from gene pool at random
  12. 12. Crossover (cont’d.) Function A Function B (# Queens x 9) + (# Pawns) # Knights / 2 Select a node on each function at random for crossover
  13. 13. Crossover (cont’d.) New Function A New Function B (# Queens x 9) + (# Knights / 2) # Pawns Swap
  14. 14. Gene Pool <ul><li>100 Generations </li></ul><ul><li>512 Chromosomes in the Gene Pool / Generation </li></ul><ul><li>The next generation is determined by randomly selecting two chromosomes, mutating and crossing them over, and letting them play a chess match </li></ul><ul><li>Each time the best is calculated by holding a tournament </li></ul>
  15. 15. Why Genetic Programming? <ul><li>Advantages </li></ul><ul><ul><li>Easy to program </li></ul></ul><ul><ul><li>Fast </li></ul></ul><ul><ul><li>Shown to work in other research </li></ul></ul><ul><li>Disadvantages </li></ul><ul><ul><li>Problems with depth on first several moves </li></ul></ul><ul><ul><li>Limited by expressivity of “function set” (genes) </li></ul></ul><ul><ul><li>High amount of branching </li></ul></ul><ul><ul><li>Strategy often complex </li></ul></ul>
  16. 16. Simpler Task <ul><li>Vinciperdi – aka “Loser’s Chess” </li></ul><ul><li>Same as chess, but to win you must lose all of your pieces or force your opponent to checkmate you </li></ul><ul><li>If there is a capture available, you must make it </li></ul>
  17. 17. Why Loser’s Chess? <ul><li>Simpler than regular chess </li></ul><ul><ul><li>Branching reduced by forced captures </li></ul></ul><ul><li>Faster than regular chess </li></ul><ul><ul><li>Openings lead to captures very fast </li></ul></ul><ul><ul><li>Games tend to be end fast, since captures occur almost every move </li></ul></ul><ul><li>A simple evaluation function set is sufficient for most modeling </li></ul><ul><li>Much of the work for Loser’s Chess can be extended to regular chess </li></ul>
  18. 18. Work So Far <ul><li>In Spring 2003, I began implementation of these concepts in Java </li></ul><ul><li>Implemented multi-threaded genetic programming library and  minimax tree searching </li></ul><ul><li>Picked up work again in Fall 2004, starting with implementing rules for Loser’s Chess </li></ul><ul><li>Currently at about 4,000 lines of source code </li></ul>
  19. 19. Preliminary Results <ul><li>Difficult to judge progress </li></ul><ul><li>Program generates incredibly complicated solutions (hundreds of points) </li></ul><ul><li>Takes long time to run (several days for 100 generations) due to the complexity of calculations on a chess board (~ 2 hours / generation) </li></ul><ul><li>Each generation increases the average complexity in the gene pool, and therefore increases execution time </li></ul>
  20. 20. Some Example Chromosomes for Normal Chess <ul><li>1 st generation – 15 points </li></ul><ul><ul><li>*(+(*(# Pawns, 7),+(1,# Attacked Pieces)),-(*(# Attacking Pieces,# Attacked Pieces),+(# Queens, 5))) </li></ul></ul><ul><li>8 th generation – 15 points </li></ul><ul><ul><li>+(-(/(# Rooks, 15),+(# Queens, # Attacking Pieces)),*(*(# Attacking Pieces, # Attacked Pieces),*(# Bishops, # Queens))) </li></ul></ul>
  21. 21. 8 th Generation (White) vs. 1 st Generation (Black)
  22. 22. But What About Humans? <ul><li>These programs are designed to play each other, and therefore many flaws may go undiscovered until humans play some of the games </li></ul><ul><li>It is possible to incorporate a Java Chess Applet into the genetic functions, allowing human players to affect the outcome </li></ul>
  23. 23. Future Work <ul><li>More Expressivity in Function Set </li></ul><ul><ul><li>Conditionals </li></ul></ul><ul><ul><li>Better Chess functions </li></ul></ul><ul><ul><li>Time </li></ul></ul><ul><li> pruning </li></ul><ul><li>Human Java Applet interface </li></ul><ul><li>FICS interface (freechess.org) </li></ul><ul><li>Parallel computing ability </li></ul><ul><ul><li>Use FICS? </li></ul></ul>

×