Detection of a perfect point to start Flood fill: The Failed Solution
So once I was done with the flood fill implementation, there was a big challenge coming, which I thought would be easy, but surprisingly it was not. The challenge is to find a perfect point (A point that is inside the boundary drawn by the player trail) to start Flood Fill Algo.
Initially, I thought to use the ray-casting technique to find the perfect point, where I had to cast a ray toward a direction and I had to find the count of trail boundary cells it intersects. If the count is an odd number then the point is inside else if the count is even then the cell is outside of the trail boundary where I had to consider the inside point as a perfect point. I thought this would work fine, but later on, I found many cases where it failed.
Some examples of failure:
Example 1:-
Here you can see I am trying to do ray-casting from a cell(13, 7), where got 2 different outputs and these are as follows.
OP1: The Ray1 which is directed towards the left direction has 8 intersect trail cells, which tells that the ray is outside the boundary.
OP2: The Ray2 which is directed towards the right direction has 3 intersect trail cells, which tells that the ray is inside the boundary.
As you see I found 2 different outputs one is telling cell(13, 7) is inside and the other one is telling outside, but if you see the yellow-colored trail boundary of the player, you can notice the cell is already inside the boundary. This is the point where the logic using ray-cast failed.
Note: L(Left), R(Right), D(Down), and U(Up) are the current directions of the player at the particular cell, these are colored as yellow as they are part of the trail cells. 2 for filled cells and green for filled cells color. MB is for Map Boundary. Left white-colored cells are unfilled cells with their coordinates displayed.
Example 2:-
Even if I found a proper logic using ray-cast, there is another problem that may occur and the problem is the amount of load on the Server due to a huge number of ray-casts going on at the same time, which is a deal breaker issue. This is the reason why I stopped the implementation of this approach.
Now it is time to know the solution which took me a good amount of time to research and implement.
Can you guess the solution? , Do think about the solution before going to check the solution DevLog.
Solution DevLog Link: DevLog: detection-of-a-perfect-point-to-start-flood-fill-the-working-solution
Grid Ninja
Player expand territory and eliminate opponent. Player with big territory wins.
Status | In development |
Author | Goutamraj |
Genre | Strategy |
Tags | Indie, Multiplayer, Ninja, Pixel Art, Top-Down, Two Player, Unity |
Languages | English |
More posts
- AWS EC2 Dedicated Server deployment13 days ago
- Detection of a perfect point to start Flood fill: The Working SolutionOct 06, 2024
- Fill Player Territory (Using Flood Fill)Oct 01, 2024
- Player State Machine / State Pattern:Sep 30, 2024
- The Player Controller and Input SystemSep 28, 2024
- EnvironmentSep 25, 2024
Leave a comment
Log in with itch.io to leave a comment.