# Building a 3D Rock Paper Scissors Battle Simulation in Python

--

It’s a classic game of rock-paper-scissors that everyone loves (I assume). But what about a giant R-P-S battle between a bunch of automated bots? That’s exactly what we see here in this very entertaining simulation.

Basically you have some 2D space with a bunch of random rocks, papers, and scissors. If the rock catches a scissor, the scissor turns into a rock. If the paper catches the rock, that rock turns into paper. I think you get the idea, right? Anyway, it’s fairly entertaining to watch.

But do you know what’s more fun than watching? Building. Yes, I want to make my own version of this game in python (technically, I’m going to use Web VPython). Oh, and I’m going to let the bots move in 3D not just 2D.

**Interaction Physics**

I don’t really know how to make bots that chase stuff — but I do know how to use physics. So, here’s my plan. I’m going to have a bunch of objects and then calculate the forces on each object. The force on a rock will be such that it is attracted to scissors but repelled by the paper. I can then add up all the forces on each object and use that to model the motion. When two different objects (like a rock and a paper) get close enough, then they will battle and change the identity of the loser.

Let’s start with a very simple case — a rock (which I will represent as a yellow sphere) and a scissor (magenta). I can calculate the vector from one object to the other and then calculate the following two forces:

Just for notation, a subscript RS means rock-scissor so that F_RS is the force the rock exerts on the scissor and r_RS is the vector from the rock to the scissor. Notice that these two forces are the same — so the scissor will get pushed away from the rock with the same force that the rock is pulled to the scissor. If they have the…