Implementing Gravity into Machi

Sprited DevSprited Dev
4 min read

Day 2 on Machi project.

Yesterday was mostly just initializing the codebase and see what can be done, and “booting things up“ and seeing things on the screen. Today, we will get philosophical and try to gain some inspiration from different sources.

One of the source I’m using is the first chapter of book of Genesis (NIV edition).

1 In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters.

And God said, “Let there be light,” and there was light. God saw that the light was good, and he separated the light from the darkness. God called the light “day,” and the darkness he called “night.” And there was evening, and there was morning—the first day.

There are lots to unpack here, but first of all there were some concepts introduced here:

  • Heavens

  • Earth

  • Waters

  • Spirit of God

  • Light

  • Darkness

  • Day

  • Night

Without getting too much into the weeds, at fifty thousand yard view, these core concepts were introduced before animate beings were introduced on the earth.

So, taking inspirations from this, I’m think we should probably do something similar where we introduce these concepts early on before we introduce animate entities.

And wearing physicist hat a little, there are two noteworthy things introduced in these early verses.

  1. Gravity: For the earth to form and also for the water to gather together.

  2. Intermolecular Forces: For the water to stick together.

  3. Photons: Introduction of light means introduction of photons and its physics.

How do we introduce similar concepts to Machi project? Let’s tackle one by one

Gravity is like invisible strings that connect everything together. If you introduce 2 particles in the world, they are linked and they somehow “tell“ bidirectionally that the other exist and then they move towards each other.

This model is actually quite problematic because if you expand it out to multiple particles, you get a very complicated mesh.

An alternate model of this force of attraction is something reminiscent of quantum entanglement. In this mode, each particles have only randomly picked one entanglement partners which it is entangled together. Then they attract each other, as highlighted in blue arrows.

For simulating the world, this model works perfectly because at each time step, each particle will just attract one other particle so simulation will be O(n). However, they are not really gravity because these particle pairs will not gather towards an epicenter, and just gather towards the independent middle points for each pairs.

To make all of them congregate towards the center, we can introduce short-ranged inter-particle forces (shown as red arrows).

The red arrows are like chemical bonds. They only work when the particles are close together. They “lock in” with each other to form a ball of particles. In this mode, these balls still attract each other at scale by the entanglement partners attracting each other.

How do we implement this inside Machi project? Going to utilize my brain power to fullest here.

Say there is N particles in an array particles number[] where the number is going to represent its randomly assigned entanglement partner.

Then, there will be M “entities” which are collections of randomly selected particles according to its mass number m_j.

And when the simulation loop runs, we will simulate the attraction between the entanglement partners, and hope that at scale this will effectively simulate the gravity.

What does it mean for the Machi project? This probably does not mean anything to Machi project as Gravity can be more easily simulated by applying force to every object equally. The forces between entities are nominal so they don’t even need to be simulated. But one thing I like about this model is that there is some notion of entanglement and that each entities have is uniquely assigned set of IDs that compose them. That is, even if we don’t simulate it, there is a internal representation and configuration that are totally unique to each of the entities. That I think we can still integrate into the project.

Why this matters? In the physical world, things seems to behave pretty normally, however under the hood there is magic happening everywhere. Just a simple chemical bond is a thing of magic and electrons flowing is another. Quantum mechanics are not noticed but regardless happening under the hood. So, yeah, we still want to model it after what we know.

0
Subscribe to my newsletter

Read articles from Sprited Dev directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sprited Dev
Sprited Dev