better chess through genetic programming

23
Better Chess Through Better Chess Through Genetic Programming Genetic Programming Christopher Swenson Christopher Swenson [email protected] [email protected]

Upload: caswenson

Post on 30-Nov-2014

7.036 views

Category:

Technology


2 download

DESCRIPTION

A tutorial on genetic programming with applications to chess.

TRANSCRIPT

Page 1: Better Chess through Genetic Programming

Better Chess ThroughBetter Chess ThroughGenetic ProgrammingGenetic Programming

Christopher SwensonChristopher [email protected]@utulsa.edu

Page 2: Better Chess through Genetic Programming

Overview

The ProblemThe SolutionHow the Solution works

minimax strategyGenetic Programming

Page 3: Better Chess through Genetic Programming

Programming Chess

Easy to learn, difficult to master gamesUntil recently, almost impossible for computers to play at the grandmaster level

State space incredible 28000 raw, 2600 with pruningProgramming for chess is an expensive process, requiring chess experts to work with programmers for years

RequirementsCheapFastMinimize development time

Page 4: Better Chess through Genetic Programming

SolutionUse a standard technique ( minimax)

Looks at all possible future moves to a certain depth4 ≈ Novice8 ≈ Expert12 ≈ Grandmaster

Branch factor for chess is around 40, 7–8 with good pruning techniques (812 ≈ 70 billion)Requires an “evaluation function” for choosing which future is preferable

Evaluation function:Gives a board a numerical score (utility)This is the real meat of

Page 5: Better Chess through Genetic Programming

Minimax

– Keeps track of best move for us to make (we want to maximize the utility the worst situation we can get ourselves into) – Keeps track of best move for opponent to make (we want to minimize the utility of our opponent’s best situation)Works by looking at all possible decisions you could make, by estimating all possible decision your opponent could make, etc

Page 6: Better Chess through Genetic Programming

Minimax Tree

Page 7: Better Chess through Genetic Programming

Evaluation Functions

Just a simple function to give a board a scoreEvaluate the leaf nodes, and then let minimax determine which path is optimalFor chess, should incorporate which pieces are still on the board, position, etcThis is where the hard work comes in

Page 8: Better Chess through Genetic Programming

Example

Page 9: Better Chess through Genetic Programming

Genetic AlgorithmsMethod allowing you to generate near-optimal solutions with little knowledge, using the properties of evolutionSolutions guaranteed to reach near optimality over time (Schema Theorem)Solutions represented as fixed-length “chromosomes”

Crossover operations offspringMutations variation

Best suited for ≥ NP problemsTraveling Salesperson Problem

Page 10: Better Chess through Genetic Programming

Genetic Programming

John Koza, late 1980sExtension of Genetic Algorithms, with variable length chromosomes (programs)Express programs as LISP-like trees

4 + 5 +

4 5

Page 11: Better Chess through Genetic Programming

Crossover

+

X

# Queens 9

# Pawns

/

# Knights 2

Function A Function B

(# Queens x 9) + (# Pawns) # Knights / 2

Select two functions from gene pool at random

Page 12: Better Chess through Genetic Programming

Crossover (cont’d.)

+

X

# Queens 9

# Pawns

/

# Knights 2

Function A Function B

(# Queens x 9) + (# Pawns) # Knights / 2

Select a node on each function at random for crossover

Page 13: Better Chess through Genetic Programming

Crossover (cont’d.)New Function A New Function B

# Pawns+

X

# Queens 9

/

# Knights 2

(# Queens x 9) + (# Knights / 2) # Pawns

Swap

Page 14: Better Chess through Genetic Programming

Gene Pool

100 Generations512 Chromosomes in the Gene Pool / GenerationThe next generation is determined by randomly selecting two chromosomes, mutating and crossing them over, and letting them play a chess matchEach time the best is calculated by holding a tournament

Page 15: Better Chess through Genetic Programming

Why Genetic Programming?

AdvantagesEasy to programFastShown to work in other research

DisadvantagesProblems with depth on first several movesLimited by expressivity of “function set” (genes)High amount of branchingStrategy often complex

Page 16: Better Chess through Genetic Programming

Simpler Task

Vinciperdi – aka “Loser’s Chess”Same as chess, but to win you must lose all of your pieces or force your opponent to checkmate youIf there is a capture available, you must make it

Page 17: Better Chess through Genetic Programming

Why Loser’s Chess?

Simpler than regular chessBranching reduced by forced captures

Faster than regular chessOpenings lead to captures very fastGames tend to be end fast, since captures occur almost every move

A simple evaluation function set is sufficient for most modelingMuch of the work for Loser’s Chess can be extended to regular chess

Page 18: Better Chess through Genetic Programming

Work So Far

In Spring 2003, I began implementation of these concepts in JavaImplemented multi-threaded genetic programming library and minimax tree searchingPicked up work again in Fall 2004, starting with implementing rules for Loser’s ChessCurrently at about 4,000 lines of source code

Page 19: Better Chess through Genetic Programming

Preliminary Results

Difficult to judge progressProgram generates incredibly complicated solutions (hundreds of points)Takes long time to run (several days for 100 generations) due to the complexity of calculations on a chess board (~ 2 hours / generation)Each generation increases the average complexity in the gene pool, and therefore increases execution time

Page 20: Better Chess through Genetic Programming

Some Example Chromosomes for Normal Chess

1st generation – 15 points*(+(*(# Pawns, 7),+(1,# Attacked Pieces)),-(*(# Attacking Pieces,# Attacked Pieces),+(# Queens, 5)))

8th generation – 15 points+(-(/(# Rooks, 15),+(# Queens, # Attacking Pieces)),*(*(# Attacking Pieces, # Attacked Pieces),*(# Bishops, # Queens)))

Page 21: Better Chess through Genetic Programming

8th Generation (White) vs. 1st Generation (Black)

Page 22: Better Chess through Genetic Programming

But What About Humans?

• These programs are designed to play each other, and therefore many flaws may go undiscovered until humans play some of the games

• It is possible to incorporate a Java Chess Applet into the genetic functions, allowing human players to affect the outcome

Page 23: Better Chess through Genetic Programming

Future Work

More Expressivity in Function SetConditionalsBetter Chess functionsTime

pruningHuman Java Applet interfaceFICS interface (freechess.org)Parallel computing ability

Use FICS?