Evolving Game Development With Genetic Algorithms

A presentation at React Alicante 2024 in September 2024 in Alicante, Spain by Kevin Maes

Slide 1

Slide 1

Slide 2

Slide 2

Slide 3

Slide 3

Kevin Maes linkedin.com/in/kevinmaes @kvmaes

Slide 4

Slide 4

Slide 5

Slide 5

oxomuseo.com

Slide 6

Slide 6

Museo Videojuego Malaga Atari 2600 Nintendo

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Slide 11

Slide 11

Egg drop

Slide 12

Slide 12

Egg drop

Slide 13

Slide 13

React + Konva

Slide 14

Slide 14

Konva

Slide 15

Slide 15

Konva

Slide 16

Slide 16

Game Mechanics • Who are the characters? • How will they move? • How will they interact? • How will the player interact with the game?

Slide 17

Slide 17

First Prototypes

Slide 18

Slide 18

Slide 19

Slide 19

Konva Tween

Slide 20

Slide 20

Slide 21

Slide 21

Slide 22

Slide 22

Slide 23

Slide 23

Slide 24

Slide 24

Slide 25

Slide 25

Konva Hit Detection • Pixel-level - User clicks, can include color detection • Bounding Box - Fast, less-precise • Shape-level - Basic shapes like rectangles, circles, polygons • Custom Hit Detection - Irregular or dynamic shapes • Group - Detects hits on any grouped objects <Group>…</Group>

Slide 26

Slide 26

Slide 27

Slide 27

state.new

Slide 28

Slide 28

state.new state.new

Slide 29

Slide 29

Egg drop State machines

Slide 30

Slide 30

Egg drop State machines Sorry, bad yolk!

Slide 31

Slide 31

Slide 32

Slide 32

Slide 33

Slide 33

Vector Graphics

Slide 34

Slide 34

Vector Graphics?

Slide 35

Slide 35

Slide 36

Slide 36

Slide 37

Slide 37

Slide 38

Slide 38

Slide 39

Slide 39

Konva Animation

Slide 40

Slide 40

Slide 41

Slide 41

Slide 42

Slide 42

Open AI Casting Call for Hens

Slide 43

Slide 43

Slide 44

Slide 44

Slide 45

Slide 45

Slide 46

Slide 46

Slide 47

Slide 47

Slide 48

Slide 48

Slide 49

Slide 49

Slide 50

Slide 50

Slide 51

Slide 51

Slide 52

Slide 52

Texture Packer

Slide 53

Slide 53

Slide 54

Slide 54

Slide 55

Slide 55

Slide 56

Slide 56

Slide 57

Slide 57

Slide 58

Slide 58

Slide 59

Slide 59

Slide 60

Slide 60

Slide 61

Slide 61

What about fonts? Arial in a game is so sad

Slide 62

Slide 62

Arco The quick yellow chick jumps over the lazy chef.

Slide 63

Slide 63

Arco The quick yellow chick jumps over the lazy chef.

Slide 64

Slide 64

Arco

Slide 65

Slide 65

Arco FOUT - Flash of unstyled text FOIT - Flash of invisible text FOFT - Flash of faux text

Slide 66

Slide 66

Arco

Slide 67

Slide 67

Arco new FontFaceObserver(‘Arco’);

Slide 68

Slide 68

Slide 69

Slide 69

Second Game Video Here

Slide 70

Slide 70

Slide 71

Slide 71

Slide 72

Slide 72

Slide 73

Slide 73

Genetic Algorithms Desired behavior Optimal design Solve complex search problems

Slide 74

Slide 74

States of a genetic algorithm

Slide 75

Slide 75

Population Initialization Many “individuals” Each with a potential solution Stored in their “DNA”

Slide 76

Slide 76

Evaluation & Fitness Evaluate performance Reward behavior Punishment Weighted criteria

Slide 77

Slide 77

Selection Roulette Wheel Selection 4% 28% 3% 1% 6% 8% 11% 22% 17%

Slide 78

Slide 78

Crossover x total population size

Slide 79

Slide 79

Mutation • Need to maintain variation • Avoid “local optima” • Strive for the “global optimum” • Mutation rate • Mutation amount

Slide 80

Slide 80

Genetic Algorithms in Egg Drop

Slide 81

Slide 81

Hendividual

Slide 82

Slide 82

Slide 83

Slide 83

Evaluation & Fitness Evaluate performance Reward behavior Punishment Weighted criteria Hens that lay more eggs Hens whose eggs go uncaught Hens whose black eggs get caught Hens who don’t lay any eggs at all

Slide 84

Slide 84

Slide 85

Slide 85

Tweak the ga

Slide 86

Slide 86

Build the game Tweak the ga or

Slide 87

Slide 87

Slide 88

Slide 88

Slide 89

Slide 89

Slide 90

Slide 90

Overcome small population size Add genes (traits) Selection Tweak Fitness • Introduce elitism Crossover Introduce elitism • Hybrid averaging/selection Introduce elitism Increase rate

Slide 91

Slide 91

Roulette Wheel Selection 4% 28% 3% 1% 6% 8% 11% 22% 17%

Slide 92

Slide 92

Hendividual DNA (genes) Genotype Phenotype 0.97 0.32 0.37 0.28 0.83 0.04 0.26 0.98 { speed, color, size, … }

Slide 93

Slide 93

Hendividual DNA (genes) Parent 1 0.97 0.62 0.13 0.28 0.83 0.04 0.71 0.56 0.09 0.96 0.43 0.26 0.98 Parent 2 0.12 0.32 0.37

Slide 94

Slide 94

Hendividual DNA (genes) Parent 1 0.97 0.62 0.13 0.28 0.83 0.04 0.71 0.56 0.09 0.96 0.43 0.26 0.98 Parent 2 0.12 0.32 0.37

Slide 95

Slide 95

Hendividual DNA (genes) Parent 1 0.97 0.62 0.13 0.28 0.83 0.04 0.71 0.56 0.37 0.09 0.96 0.43 0.26 0.98 0.37 0.28 0.83 0.04 0.26 0.98 Parent 2 0.12 0.32 Child Agnostic of Phenotype values 0.97 0.32

Slide 96

Slide 96

Child 0.97 0.32 0.37 0.28 0.83 0.04 0.26 0.98

Slide 97

Slide 97

Slide 98

Slide 98

Slide 99

Slide 99

https://github.com/kevinmaes/eggdrop

Slide 100

Slide 100

Slide 101

Slide 101

Slide 102

Slide 102

Summary 1. Genetic algorithms 2. How to create a game 3. How to include a ga

Slide 103

Slide 103

Get this book! The Nature of Code Daniel Shiffman thecodingtrain.com/

Slide 104

Slide 104

Slide 105

Slide 105

linkedin.com/in/kevinmaes @kvmaes github.com/kevinmaes Kevin Maes