Games for Science!

Interactive psychology experiments in Python with Panda3D

Jessica Hamrick (@jhamrick)
jhamrick@berkeley.edu
http://www.jesshamrick.com/
Peter Battaglia
pbatt@mit.edu
http://web.mit.edu/~pbatt/www/

The rise of games

Angry Birds games had so far been played a total of 200,000 years, with 300 million minutes of playing time daily.

-- TNW Blog, May 2012 (emphasis added)

300 million minutes = 5 million hours = 208,000 days = 570 years

... per day!

What if we could leverage the popularity of games to do science?

Fun games for interesting science!

  1. The question
  2. The hypothesis
  3. The experiments

How do people reason about the world?

How do people reason about the world?

How do people reason about the world?

How do people reason about the world?

How do people reason about the world?

How do people reason about the world?

Outline

  1. The question: How do people reason about the physical world?
  2. The hypothesis
  3. The experiments

Brain as a computer

Computational cognitive science
software (i.e., mind)

Computational neuroscience
hardware (i.e., brain)

Computer models of behavior

Physics games

“The physics engine in your head”

Approximate
simulations are not exact

Probabilistic
simulations have some randomness

Why approximate and probabilistic?

Why a physics engine?

Effective
Simulations are sufficiently realistic

Efficient
Created to run in realtime

General-purpose
Applies to many situations

Outline

  1. The question: How do people reason about the physical world?
  2. The hypothesis: "The physics engine in your head"
  3. The experiments

Ok, so how do we test this?

We use video game tools as our theories, and in our experiments.

  • Create a computational model using video game physics (e.g., Bullet)
  • Generate stimuli using a 3D modeling program (e.g., Blender)
  • Run experiments using a video game framework (e.g., Panda3D)
  • (All open source, and all with Python bindings!)
  • Perform data analysis using other Python tools: NumPy, SciPy, pandas, IPython, matplotlib, etc.

More information about the research

I am just going to focus on the experiments, but if you're interested in the research, check out these links:

Demo: “Which direction?”

Demo: “Which direction?”

How does it work?

  1. Create graphics models to depict the objects
  2. Display the models with a rendering engine
  3. Add physical dynamics with a physics engine
  4. Link graphics and physics together

We'll go through a conceptual overview of these steps. If you want to learn how to actually code it, you can find the code here:
https://github.com/jhamrick/pycon-2014-talk/blob/master/demos/tutorial.py

Panda3D also has a great "Hello, world!" tutorial here:
https://www.panda3d.org/manual/index.php/A_Panda3D_Hello_World_Tutorial

Step 1: Create a graphics model

3D objects are typically created in a modeling program like Blender (which is Python scriptable!)

Step 2: Set up graphics

Panda3D is a C++ game library with Python bindings

Step 2a: Set up the scene graph

Step 2b: Load the model

Step 2c: Add it to the scene graph

Step 2: The result

Step 3: Set up physics

  • Bullet is a mature C++ physics engine. Panda3d includes bindings to it, and it can be controlled through Python.
  • To simulate physics, you need a BulletWorld
    • Keeps track of all the physics objects
    • Computes new positions
    • Handles collisions
  • Physics objects consist of a shape (collisions) and a body (dynamics)

Step 3a: Create the physics world

Step 3b: Create collision geometry

Step 3c: Create a physical body

Step 3d: Add it to the physical world

Step 3: The result

Step 4: Link graphics and physics

Step 4a: Add the body to the scene graph

Step 4b: Link physics and graphics

Step 4: The result

Demo: “Glue blocks together to make the tower stable”

Demo: “Glue blocks together to make the tower stable”

Demo: “Bump the table”

Demo: “Angry blocks 3D”

Demo: “Angry blocks 3D”

Conclusion

  • Question: How do people reason about the physical world?
  • Hypothesis: "The physics engine in your head"
  • Tools: Blender, Panda3D, and Bullet

Looking forward...

Angry Birds games had so far been played a total of 200,000 years, with 300 million minutes of playing time daily.

-- TNW Blog, May 2012 (emphasis added)

Think how much we could learn if people participated in psychology experiments at that scale!

With engaging and interactive physics experiments, it doesn't seem impossible.

Thanks!

  • People
    • Josh Tenenbaum
    • Tom Griffiths
    • Computational Cognitive Science Lab @ MIT
    • Computational Cognitive Science Lab @ Berkeley
  • Tools
    • Python
    • Panda3D, Blender, and Bullet
    • IPython, NumPy, and the rest of the SciPy stack
    • Slides created with IPython notebook and reveal.js

Links

IPython Notebook