Genetic Algorithms for Game Programming: Applying Biology to Find Solutions, Essays (university) of Microcomputers

An introduction to genetic algorithms (gas), a problem-solving methodology inspired by the principles of evolutionary biology. The basics of gas, including natural selection, genome representation, fitness heuristic, and crossover. The document also includes examples of ga applications in pathfinding and game programming.

Typology: Essays (university)

2017/2018

Uploaded on 05/10/2018

prinkle-shete
prinkle-shete 🇮🇳

8 documents

1 / 39

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Genetic Algorithms for
Genetic Algorithms for
Game Programming
Game Programming
Steve Gargolinski
Steve Gargolinski
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download Genetic Algorithms for Game Programming: Applying Biology to Find Solutions and more Essays (university) Microcomputers in PDF only on Docsity!

Genetic Algorithms for

Genetic Algorithms for

Game Programming

Game Programming

Steve Gargolinski

Steve Gargolinski

[email protected] [email protected]

[email protected]

[email protected]

The Basic Idea

The Basic Idea

We’re going to develop techniques based

We’re going to develop techniques based

on the principals of evolutionary biology in

on the principals of evolutionary biology in

order to find solutions to problems.

order to find solutions to problems.

How We Evolve

How We Evolve

Natural Selection

Natural Selection

Strong members of a population survive to

Strong members of a population survive to

reproduce, passing on their ‘strong’ traits

reproduce, passing on their ‘strong’ traits

Crossover

Crossover

Some from parent A, some from parent B

Some from parent A, some from parent B

Mutation

Mutation

A strange flipped gene that cannot be traced back

A strange flipped gene that cannot be traced back

to a parent

to a parent

Biology -> Genetic Algorithm

Biology -> Genetic Algorithm

Gene = smallest atom of data

Gene = smallest atom of data

Usually binary, so 0 or 1

Usually binary, so 0 or 1

Genome = string of genes

Genome = string of genes

Genome Pool = set of genomes

Genome Pool = set of genomes

Represents our population

Represents our population

Fitness/Strength Heuristic

Fitness/Strength Heuristic

Turns a binary string into a single floating

Turns a binary string into a single floating

point value based on how close to our

point value based on how close to our

desired result it is.

desired result it is.

Maps back to how well an organism can

Maps back to how well an organism can

survive in an environment.

survive in an environment.

0.0f = terrible

0.0f = terrible

1.0f = absolute solution

1.0f = absolute solution

A Basic Genetic Algorithm

A Basic Genetic Algorithm

Start with a random genome pool of n members.

Start with a random genome pool of n members.

Run strength heuristic on each random genome

Run strength heuristic on each random genome

in the pool.

in the pool.

Randomly’ crossbreed strong members of the

Randomly’ crossbreed strong members of the

population until you have n new genomes.

population until you have n new genomes.

Introduce some mutation.

Introduce some mutation.

Repeat until the strength heuristic returns a

Repeat until the strength heuristic returns a

value within our threshold.

value within our threshold.

Genome Selection

Genome Selection

We now know how to crossover, but which

We now know how to crossover, but which

genomes do we select?

genomes do we select?

Simplest way is random selection

Simplest way is random selection

A better way is to weigh selection based on

A better way is to weigh selection based on

relative strength

relative strength

Roulette Wheel Selection

Roulette Wheel Selection

Pathfinding Example (1)

Pathfinding Example (1)

A* is probably “better”, yeah?

A* is probably “better”, yeah?

Definitely better

Definitely better

Example:

Example:

2D grid

2D grid

Arbitrary number of boundaries

Arbitrary number of boundaries

1 start point

1 start point

1 finish point

1 finish point

Pathfinding Example (3)

Pathfinding Example (3)

Heuristic function:

Heuristic function:

Simulate binary string movement beginning at

Simulate binary string movement beginning at

start point.

start point.

Measure distance from finish (simple,

Measure distance from finish (simple,

Pythagorean)

Pythagorean)

Fitness score = 1 – (distance / max possible

Fitness score = 1 – (distance / max possible

distance)

distance)

Pathfinding Example (4)

Pathfinding Example (4)

start

Genome A: 01 10 01 10 01 00 01 00

01 = Right

10 = Down

01 = Right (Bump)

10 = Down

01 = Right

00 = Up (Bump)

01 = Right

00 = Up

Fitness = 1 - (2 /

finish

Pathfinding Example (6)

Pathfinding Example (6)

Genome A: 01 10 01 10 01 00 01 00

Genome B: 00 01 10 10 11 10 01 01

Genome C: 01 10 01 10 01 00 01 01

This is how we take two genomes and create a new one:

(assumes no mutation for now)

Pathfinding Example (7)

Pathfinding Example (7)

start

01 = Right

10 = Down

01 = Right (Bump)

10 = Down

01 = Right

00 = Up (Bump)

01 = Right

01 = Right

Fitness = 1 – (0 /

finish

Genome C: 01 10 01 10 01 00 01 01

Things We Can Tweak

Things We Can Tweak

Mutation rate

Mutation rate

0.01 is a reasonable starting value

0.01 is a reasonable starting value

Crossover rate

Crossover rate

0.7 or so

0.7 or so

Chromosome length

Chromosome length

Varies a lot based on specific problem

Varies a lot based on specific problem

Population size

Population size

Try maybe 150-

Try maybe 150-

How This is Used in Games

How This is Used in Games

Computationally expensive, becoming

Computationally expensive, becoming

easier to deal with as hardware speeds up

easier to deal with as hardware speeds up

Most of the time is run offline with the

Most of the time is run offline with the

results used in a ‘black box’ fashion in the

results used in a ‘black box’ fashion in the

actual game.

actual game.

Can be used to tune priorities, behaviors,

Can be used to tune priorities, behaviors,

parameters, etc.

parameters, etc.