Slide 1

Slide 1 text

GameplayKit: beyond games

Slide 2

Slide 2 text

General goodies • Components & En--es • Random Numbers • State Machine

Slide 3

Slide 3 text

Components & En,,es: Inheritance

Slide 4

Slide 4 text

Components & En,,es: Composi,on

Slide 5

Slide 5 text

Components & En,,es

Slide 6

Slide 6 text

Random numbers Distribu(ons: Standard, Shuffled, Gaussian Sources: Mersenne Twister, Arc4, Linear Congruen5al

Slide 7

Slide 7 text

State Machine • Disclaimer: The "S" word. • "GameplayKit: State Machine for non-game Apps" invasivecode.com/weblog/gameplaykit-state-machine by @vicentevicens

Slide 8

Slide 8 text

State Machine: 101

Slide 9

Slide 9 text

State Machine: 1021 1 How are video game AIs programmed? Is it a just a long series of "If Then" statements? reddit.com/r/ explainlikeimfive/comments/2r6g74/eli5howarevideogameaisprogrammedisit_a/?limit=500

Slide 10

Slide 10 text

Markov Chains

Slide 11

Slide 11 text

Markov Chains Modeling weather condi0ons, simula0ng stock exchange

Slide 12

Slide 12 text

Demo Swi$Doc.org: Swi$ 3.0

Slide 13

Slide 13 text

class MarkovChainMachine: GKStateMachine { let outcomesMap: [[GKState]: [Double: GKState]] var buffer: [GKState] func enterNextState() { let next = nextState() enterState(next) buffer.removeFirst() buffer.append(next) } func nextState() -> GKState { let random = ... return nextState(buffer, random) } }

Slide 14

Slide 14 text

MinMax • Widely used in turn-by-turn games • Applicable for 1+ player • Increasing depth of predic

Slide 15

Slide 15 text

Demo Sol: a Smart(er) Weather App

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

MinMax suggestions.register(AddCity.self) { history in switch history.filter({ $0 is AddCity }).count { case 0: return best case 1..<3: return good + 1 default: return nil } }

Slide 18

Slide 18 text

MinMax var history: [GKState] // GKGameModel func scoreForPlayer(player: GKGameModelPlayer) -> Int { var maxScore = Int.min for predicate in predicates { if let result = predicate.score(history: history) { if maxScore < result { maxScore = result } } } return maxScore }

Slide 19

Slide 19 text

Pathfinding

Slide 20

Slide 20 text

Pathfinding

Slide 21

Slide 21 text

Demo In App Naviga+on

Slide 22

Slide 22 text

Pathfinding func setupGraph() { root.addConnectionsToNodes([privacy, facebook], bidirectional: true) facebook.addConnectionsToNodes([facebookSettings, facebookAccount], bidirectional: true) facebookSettings.addConnectionsToNodes([facebookLocation], bidirectional: true) privacy.addConnectionsToNodes([bluetooth, location], bidirectional: true) location.addConnectionsToNodes([facebookLocation], bidirectional: true) graph.addNodes([ root, privacy, facebook, bluetooth, location, facebookSettings, facebookLocation, facebookAccount ]) favorite = facebookLocation }

Slide 23

Slide 23 text

Pathfinding func goToFavoriteNode() { let current = currentViewController.node let path = root.findPathFromNode(current, toNode: favorite) navigate(path) }

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

GameplayKit: beyond games • GameplayKit reimplemented github.com/mohiji/JLFGameplayKit • This presenta>on github.com/zats/Presenta>ons • @zats Thank you!