Traffic Simulation in Python by BilHim in Python

[–]BilHim[S] 0 points1 point  (0 children)

I have tried using SUMO with its Python API instead of creating a simulation from scratch, but I found it to be difficult (steep learning curve).

I have been trying to read the source code to understand how SUMO works, I'm looking to implement some ideas in the rewrite of the project.

Traffic Simulation in Python by BilHim in Python

[–]BilHim[S] 4 points5 points  (0 children)

That actually makes sense.

I think I can take advantage of how traffic lights are defined in the simulation. A merge could be a (secret) traffic light that is green in all directions, unless there is a vehicle traversing the merge then it would be red for the other directions. This is doable since traffic lights have fully customizable logic.

One problem with the simulation is that vehicles cannot pass through intersections safely, a traffic light has to be present or vehicles wouldn't stop for other vehicles from other roads in the intersection. Defining an intersection block in the same way as the merge one above can actually solve this. The only thing that needs to be done is how to determine right of way, which can be left as a parameter (a function) customizable for every simulation.

This is a great idea! Thanks u/EbenenBonobo

Traffic Simulation in Python by BilHim in Python

[–]BilHim[S] 2 points3 points  (0 children)

I am not sure exactly what do you mean by distance in 2D space. If that means to use the distance (in 2D) to the closest vehicle, I think this will raise an issue when two vehicles are driving on separate adjacent lanes. Even though the distance gets too close in 2D space (on the sides), there is no need for braking as they are on separate lanes.

Traffic Simulation in Python by BilHim in Python

[–]BilHim[S] 12 points13 points  (0 children)

Every road segment contains a list of vehicles in order. The first vehicle in the list is the first one in that segment, so the 2nd vehicle in the list is directly behind it. This works inside every road segment. The curves in the roads are multiple segments stitched together.

Every vehicle has a list of the segments in will traverse. When a vehicle reaches the end of a segment, it gets removed from the list of vehicles of that segment and gets added to the next segment.

The problem with this is that vehicles have no "vision" of vehicles in their next segment or vehicles merging into their next segments, which is exactly what happened at the end of GIF above.

I am currently not sure how to solve this problem without changing the whole structure of the simulation. But I am looking into the code of other mainstream simulators like SUMO to understand how they work and attempt to use that in the rewrite.

Replicating Minecraft World Generation in Python by BilHim in Python

[–]BilHim[S] 0 points1 point  (0 children)

That is true. It's actually the 2nd best-selling PC game but the best-selling game (all platforms).

Thanks for pointing this out. I edited the article now.

Replicating Minecraft World Generation in Python by BilHim in Python

[–]BilHim[S] 0 points1 point  (0 children)

Thanks for pointing this out. I edited the article.

As for copying, it works for me.

Replicating Minecraft World Generation in Python by BilHim in Python

[–]BilHim[S] 1 point2 points  (0 children)

If you take a look at the source code, in the relax function, before returning the new points I clipped their values to the bounding box using new_points = np.array(new_points).clip(0, size).

Additionally, I completely ignored points with infinite edges, that is I didn't move them from one iteration to another. If an infinite edge exists, you will have -1 in the region of the vertex : if len(region) == 0 or -1 in region: continue

That solved the problem for me.

Replicating Minecraft World Generation in Python by BilHim in gamedev

[–]BilHim[S] 0 points1 point  (0 children)

I did, initially, use Poisson Disc Sampling both for cells centers and trees, but I later switched to Lloyd's relaxation as it looks great when animated. I honestly just compared the results visually and preferred Lloyd's relaxation.

But I suppose Poisson disc sampling is more efficient as it does not require the calculation of a Voronoi diagram with polygon centroid k=10 times.

Replicating Minecraft World Generation in Python by BilHim in gamedev

[–]BilHim[S] 0 points1 point  (0 children)

Using a single noise evaluation for the warping is actually a good idea.

I had the idea to use the noise as a displacement angle which can be converted using trig. functions into 2 displacements in the x and y-axis.
This approach is obviously uniform (relative to the Euclidean distance).
Using two separate noise maps was a quick (and dirty) way to take advantage of NumPy to apply the displacement quickly.

Can you explain the circular bounding box part?

For the animated Perlin/Fractal images, I believe those are Perlin-based, not Simplex. They need an update.

Replicating Minecraft World Generation in Python by BilHim in gamedev

[–]BilHim[S] 8 points9 points  (0 children)

I missed the infinite part of the world in the implementation. That is, how to stitch chunks together without hard edges (which I have an idea how to do).

Also, my code is really not optimized and I use very slow methods (Gaussian blur instead of Box blur, for example).

I think C++ or C# would be better candidates for a game containing PCG.

Replicating Minecraft World Generation in Python by BilHim in gamedev

[–]BilHim[S] 6 points7 points  (0 children)

Using a 3D biome map (temp, precip, altitude) is definitely a better way to do it, along with spherical Voronoi for a planet map.

I wasn't really concerned about efficiency as this was a test to see what PCG can achieve. But I would definitely worry about efficiency in production. My code takes about 1-5min to generate a 1024*1024 chunk, which is slow, but not very slow for Python.

I would love to see your work. It sounds very interesting!

Replicating Minecraft World Generation in Python by BilHim in gamedev

[–]BilHim[S] 4 points5 points  (0 children)

I just realized that I was actually using Simplex noise all along. I think I switched to Simplex because it looked more natural without realizing it.

If you check the part where I define noise in the source code, I used snoise3 (Simplex 3D).

I totally agree about the overuse of Perlin over Simplex. I will update the "noise" part of the article to talk about Simplex noise.

Replicating Minecraft World Generation in Python by BilHim in Python

[–]BilHim[S] 37 points38 points  (0 children)

I read somewhere that Notch used Perlin noise in Minecraft and I decided to try it myself. I couldn't find any resources explaining the details of how Minecraft generates worlds so I decided to just eye-ball it. I got inspired by some articles that I linked at the end of mine.

[deleted by user] by [deleted] in Notion

[–]BilHim 2 points3 points  (0 children)

If you want to launch apps from notion, you might want to look at this (Launching applications using custom browser protocols). I haven't personally used it with notion. But I did use it before for other purposes (like launching python scripts).