Am looking for a solution (algorithm) to check if an object in a neighbor tile can be connected (i.e transfer power). Best example I could come up with to make this more clear, is pipes.
I am using a fixed 1 x 1 grid size. So only one object can occupy that space. I do not store where objects are in the world, as there could be a lot of them placed down by the player.
Let's say you can place down 4 different types of pipe connectors. Straight, Right angle, Cross, and T. These can all be rotated by 90 degrees each rotation on the Y (up) axis.
Like in this example I put together quickly:
In that case above, they all connect correctly, but how do I check that when a pipe is placed down in its final position, it is a valid connection?
So in this image, the Straight pipe is not connected correctly to the T pipe to the right or the Straight pipe above it. So in a pipe example that might be transferring power, the Straight pipe would not be powered.
If it helps because it's Unity. I added the directions (I tested by drawing a ray to the direction that it can connect).
Spent some time playing with the "pipe" prototype a bit more.
Each pipe has 4 booleans. Forward, Back, Left, Right. These indicate which side the pipe can be connected too. So for example, a straight pipe that hasn't been rotated can connect left and right. If the straight pipe gets rotated, then forward and back becomes true, and left and right become false. This is applied to all pipe types.
When placing a pipe down, a raycast is done in all 4 directions to see if there is another pipe nearby. So I have access to the neighbor pipes to see which side they can be connected on. My problem now, is the logic to do the check.
Note: The 4 raycasts are a one time deal. It's just to check the neighbors on placement.