game programming by demonstration
TRANSCRIPT
![Page 1: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/1.jpg)
Game Programming by
DemonstrationMikaël Mayer, Viktor Kuncak
![Page 2: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/2.jpg)
How to introduce programming to new users?
My brother Cédric teaching his children how to play on a phone
![Page 3: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/3.jpg)
Motivation
• Millions of smartphone users and gamers
• Few are programmers - because it is hard• requires the programmer to learn complex APIs
• involves debugging, which is time-consuming
• disconnect between the code and the game
• How to make programming more accessible ?
![Page 4: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/4.jpg)
What is more accessible ?
versus
![Page 5: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/5.jpg)
Pong Designer : our approach for game programming by
demonstration.
![Page 6: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/6.jpg)
Games developed
• Pong
• Brick Breaker
• Pacman
• Space invaders
• Pool
• Maze
• ….
![Page 7: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/7.jpg)
Game programming
• Game engines:
Game state at time T
Game state at time T+1
and events until T + 1
Physics, graphics engine
Game logic is conventionally written in languages like C++, Flash, Java, Scala
Game logic
![Page 8: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/8.jpg)
Conventional game programming
1.Find out conditions for the rule to apply• Object-specific, triggers, events, etc.
2.Write code to run when these conditions hold.• Modify state.
3.Rewrite other rules to comply with the new rule.• Run, debug after playing
Game logic
![Page 9: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/9.jpg)
Pong Designer Approach
Can we do the same by demonstration?
![Page 10: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/10.jpg)
Pong Designer Approach
…1.Pause the game2.Prepare game state
• Previous time• Or arrange objects
3.Select events4.Change state5.Validate
• System infers rules• Manual modification
6.Repeat
events
• Create initial state• Start the game and see how it evolves
• Default behaviors apply
Demonstrating game logicContinuously run the gameand refine the behavior
Create initial state
![Page 11: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/11.jpg)
Main techniques
• Touch-based interface
• Access to 5 seconds history
• Visualization and modification of everything
• Automatic rule inference
• Incremental addition of demonstrations
![Page 12: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/12.jpg)
Changes are visual
• Game state
Change numbers, text, color, speed, position
Events are visible
Input and output are both modifiable
![Page 13: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/13.jpg)
Inferring rules
• Accept the changes
Validate the changes The rule is automatically inferred
The user can modify the rule and constants
![Page 14: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/14.jpg)
Code is interactive
• Changing constants shows the effects in the game
Colors Position
Numbers
![Page 15: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/15.jpg)
Game state before rule
Game state after rule
How infer rules?
Game state before rule
Game state after rule
Game state before
Game state before
Game state after
Game state after
Rule inference(synthesis)
![Page 16: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/16.jpg)
Templates inferring rules• Generalizing from input/output examples:
If block.x ≠ block.prev_x
« block.x = block.prev_x + {block.x - block.prev_x}
|| block.x = {block.x}
|| block.x = 2*obj.x – obj2.x //for some obj, obj2
….»
Resolve the ambiguity by either providing a second example (implicit), or selecting the desired line of code (explicit).
![Page 17: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/17.jpg)
Template parameters
•Objects• Iterate through all, find which ones can explain
the demonstration (alignment, result, etc.)
• Iterate through pairs of objects (mirror, binary operations, etc.)
•Constants(position, color, velocity, angle, text)• Approximate comparison.
• Grid fit for angles and positions.
![Page 18: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/18.jpg)
Accepting new examples
• Fibonacci through examples:
Fibonacci 1, 1, 2 Fibonacci 1, 2, 3
Fibonacci 2, 3, 5 Fibonacci 3, 5, 8
![Page 19: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/19.jpg)
Syracuse sequence
• Clock as a ball
• Demonstrate n/2, n*3, n*3+1
• Test on n%2 to copy either n/2 or 3n+1
• Demonstrate appending number to “seq:”
![Page 20: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/20.jpg)
Primes listing
• 2 balls• One to increment the test, the other to increment the
quotient
• Demonstrate remainder with (11, 3) => 2
• Output if quotient greater than half
• Stop ifremainder=0
![Page 21: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/21.jpg)
Minsky Machine
• Clock as a ball transferring the PC to read memory.
• Memory on a counter• A rule-per-integer-value increases or decreases registers
and set up new conditional program counters
• Integers testing if registers are zero• Override program counter
![Page 22: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/22.jpg)
Available on-line
lara.epfl.ch/w/pong
play.google.com/store/apps/details?id=ch.epfl.lara.synthesis.kingpong
New version is coming soon
![Page 23: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/23.jpg)
Upcoming version of Pong Designer
• Better engine and interface
• CategoriesFor b in blocks:
if ball collides b:b.visible = false
• Behaviors using constraints
X = Choose(x right ≤ border.left)
![Page 24: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/24.jpg)
Existing approaches• Accessible game programming
• Scratch• Construct 2• Kodu• GameMaker
• Interactive programming environments• Khan Academy 2012• Kojo• Bret Victor, Inventing on Principle• TouchDevelop
• Learning from input-output examples• Automating String processing (Gulwani, 2012)• Marquise (Myers et al., 1993)• Behavioral Programming (Harel et al. 2012)
![Page 25: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/25.jpg)
Conclusion
• Aim to bring game development to end users
• On-the-fly incremental rule demonstration
• Automatic rule inference
• Touch-based interface
• Access to history
• Visualization and modification of everything
• Freely available working implementation on Android
lara.epfl.ch/w/pong
![Page 26: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/26.jpg)
![Page 27: Game Programming by Demonstration](https://reader034.vdocument.in/reader034/viewer/2022052606/586b743b1a28ab816d8b7b0d/html5/thumbnails/27.jpg)
Questions?