Evolving Game Development With Genetic Algorithms

A presentation at What The Stack 2024 in September 2024 in Skopje, North Macedonia by Kevin Maes

Slide 1

Slide 1

Evolving Game Development With Genetic Algorithms Здраво Kevin Maes | What The Stack - September 14, 2024

Slide 2

Slide 2

Kevin Maes linkedin.com/in/kevinmaes @kvmaes

Slide 3

Slide 3

Slide 4

Slide 4

Genetic Algorithms Adaptation in Natural and Arti cial Systems “general theories of adaptive processes apply across biological, cognitive, social, and computational systems” fi John H. Holland

Slide 5

Slide 5

Why genetic algorithms? Desired behavior Optimal design Solve complex search problems

Slide 6

Slide 6

There’s a GA for that! • Designing ef cient network topologies • Automated software testing • Evolving game strategies • Scheduling Problems fi • Complex hardware design

Slide 7

Slide 7

States of a genetic algorithm

Slide 8

Slide 8

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

Slide 9

Slide 9

Evaluation & Fitness Evaluate performance Reward behavior Punishment Weighted criteria

Slide 10

Slide 10

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

Slide 11

Slide 11

Crossover x total population size

Slide 12

Slide 12

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

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

oxomuseo.com

Slide 16

Slide 16

Museo Videojuego Malaga Atari 2600 Nintendo

Slide 17

Slide 17

Slide 18

Slide 18

Slide 19

Slide 19

Slide 20

Slide 20

Slide 21

Slide 21

Egg drop

Slide 22

Slide 22

Egg drop

Slide 23

Slide 23

React + Konva

Slide 24

Slide 24

Konva

Slide 25

Slide 25

Konva

Slide 26

Slide 26

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

Slide 27

Slide 27

First Prototypes

Slide 28

Slide 28

Slide 29

Slide 29

Konva Tween

Slide 30

Slide 30

Slide 31

Slide 31

Slide 32

Slide 32

Slide 33

Slide 33

Slide 34

Slide 34

Slide 35

Slide 35

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 36

Slide 36

Slide 37

Slide 37

state.new

Slide 38

Slide 38

state.new state.new

Slide 39

Slide 39

Egg drop State machines

Slide 40

Slide 40

Egg drop State machines

Slide 41

Slide 41

Slide 42

Slide 42

Slide 43

Slide 43

Slide 44

Slide 44

Vector Graphics

Slide 45

Slide 45

Vector Graphics?

Slide 46

Slide 46

Slide 47

Slide 47

Slide 48

Slide 48

Slide 49

Slide 49

Slide 50

Slide 50

Konva Animation

Slide 51

Slide 51

Slide 52

Slide 52

Slide 53

Slide 53

Open AI Casting Call for Hens

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

Slide 62

Slide 62

Slide 63

Slide 63

Texture Packer

Slide 64

Slide 64

Slide 65

Slide 65

Slide 66

Slide 66

Slide 67

Slide 67

Slide 68

Slide 68

Slide 69

Slide 69

Slide 70

Slide 70

What about fonts? Arial in a game is so sad

Slide 71

Slide 71

Arco The quick yellow chick jumps over the lazy chef.

Slide 72

Slide 72

Arco The quick yellow chick jumps over the lazy chef.

Slide 73

Slide 73

Arco

Slide 74

Slide 74

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

Slide 75

Slide 75

Arco new FontFaceObserver(‘Arco’);

Slide 76

Slide 76

Slide 77

Slide 77

Second Game Video Here

Slide 78

Slide 78

Slide 79

Slide 79

Slide 80

Slide 80

Slide 81

Slide 81

Genetic Algorithm in Egg Drop

Slide 82

Slide 82

Hendividual

Slide 83

Slide 83

Slide 84

Slide 84

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 85

Slide 85

Slide 86

Slide 86

Tweak the ga

Slide 87

Slide 87

Build the game Tweak the ga or

Slide 88

Slide 88

Slide 89

Slide 89

Slide 90

Slide 90

Slide 91

Slide 91

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

Slide 92

Slide 92

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

Slide 93

Slide 93

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 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.09 0.96 0.43 0.26 0.98 Parent 2 0.12 0.32 0.37

Slide 96

Slide 96

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 97

Slide 97

Slide 98

Slide 98

Child 0.97 0.32 0.37 0.28 0.83 0.04 0.26 0.98

Slide 99

Slide 99

Slide 100

Slide 100

Slide 101

Slide 101

https://github.com/kevinmaes/eggdrop

Slide 102

Slide 102

Slide 103

Slide 103

Slide 104

Slide 104

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

Slide 105

Slide 105

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

Slide 106

Slide 106

Slide 107

Slide 107

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