sprint - exciting insights from translating a classic car racing game to javascript

36
Sprint - Exciting Insights from Translating an Old Videogame to JavaScript Norbert Kehrer ViennaJS Meetup, March 30, 2016

Upload: norbertkehrer

Post on 15-Apr-2017

860 views

Category:

Technology


2 download

TRANSCRIPT

Sprint - Exciting Insights

from Translating an Old

Videogame to JavaScript

Norbert Kehrer

ViennaJS Meetup, March 30, 2016

„Sprint“ is a primitive car-racing game,

but it holds interesting aspects

Atari 1976: Sprint 2

Arcade machine

Very limited hardware

Black-and-white graphics

Many sequels

This is what Sprint looks like

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

The Sprint arcade machine is based on the

6502 microprocessor

ROM: Program and 12 race tracks

RAM 128 bytes

Screen RAM 32 x 28 6502

Special-purpose video

hardware

Game logic Video hardware

Original 6502 code translated to JavaScript

makes up a browser game

ROM: program

and 12 race tracks

RAM 128 bytes

Screen memory 32 x 28 6502

Special-purpose video

hardware

Game logic Video hardware

JavaScript

program

JS simulator of the

video hardware

Browser game

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

Alternative interpretation of the game state

and screen memory makes it a 3D game

Little

Cubes

3D Objects

Camera

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

Atari‘s patented method from 1976 ...

... uses direction vectors

Compare the car´s current direction with

the cell´s direction guidance vector...

... and steer a little bit in that direction

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

Sprint contains twelve tediously

hand-crafted race tracks

Designing new Sprint levels is a lot of work

Design the race track itself

Define all those direction vectors

Test it

Automation is a quite hard robotics problem

Design the race track itself

Define all those direction vectors

Test it

Automatically

by using the

potential field

method

Concepts of the potential field method

Potential field

Vector field

Gradient field

Functions

x

y = f(x)

Scalar fields (potential fields)

1 5

9

13

17

21

25

29

R1

R7

R13

R19

R25

R31

-450

-400

-350

-300

-250

-200

-150

-100

-50

0

z = f(x, y)

Vector fields

x

y z = f (x, y)

The gradient field indicates the direction of

the steepest slope

Source: „Kurs: Mathematik für Anwender (Osnabrück 2011-2012)“

Robot path planing by finding an adequate

potential field

Source: Diemke: „Pfadplanung mit harmonischen

Potentialfeldern“

Sprint levels are gradient fields of

„Bobsled tracks“

The lateral and downhill slope definies the

potential field

The potential field of level 1

1

6

11

16

21

26

31

R1

R6

R11

R16

R21

R26

-1

-0,5

0

0,5

1

Applying the potential field method to Sprint

Obstacles are given (track boundaries)

Calculate a harmonic potential field („bobsled track“)

From that, calculate its gradient field

The result is the vector field for the Sprint level

Level 1 by the Atari Engineers

Level 1, automatically generated

New level, automatically generated

The calculation is not fast, but slow

Complex mathematics

BUT: Unbelievably simple algorithm (Gauss 1823 und

Seidel 1874)

64-bit floating-point numbers are not exact enough

BigNumber library needed

Slow also because of iteration (30 seconds per level)

Fun with Sprint

Make a browser game

Make it 3D

Understand the car AI

Design new levels

Use the methods in other projects

You can use the potential field method

Path planning for robots

Lawn mowers

Vacuum cleaners

Robo soccer

Autonomous cars

Games with moving computer oponents

Car racing

Mario-Kart-like games

Etc.

Summary

Browser Sprint by code translation

3D Sprint by alternative interpretation

Patented vector fields for the car AI

Automatic level generation with the Potential Field Method

Thank you !

http://members.aon.at/nkehrer/