I’m planning to work on a project that involves pieces moving around a checkered board, the board will be in concentric, circles however.
The pieces that will move around the board will be able to move across many squares in their turns.
I’m trying to figure out the best way to setup this up so that a player can select a location on the board to move to and then the script will move the piece along the quickest route to the target avoiding any obstacles or other pieces.
I’m new to unity so I’m asking for some help with this.
My first idea would be that maybe each tile would have a gameobject, then before each tile move the script would locate all the gameobjects in adjacent tiles, take their position and compare it to the target to figure out which tile is closer. Then move to that tile provided its vacant.
Is this a possible/efficient method to approaching this?
I’ve thought a little more about how I might be able to do this.
Something along the lines of:
Destination selected by mouse click.
Is Destination tile occupied? → Yes = Invalid move.
No → ConstructRoute.
If route to destination can’t be made then invalid move.
If route is found but Moves > PieceMoveLimit then invalid move.
Else MovePiece (moving the piece along the found route).
What I’m stuck with is the best way to apply ConstructRoute. I figured that simply taking the location of all adjacent tiles then finding which is closest to the destination before moving would be a good method, avoiding tiles that are occupied. However the issue with this I realised is that the routine needs to know the position of the occupied in advance or it would proceed along the quickest route, then skirt around any blockades that it hits as it hits them which would make for really inefficient turns. Also I’m not sure what would happen if the piece is entirely blocked and how it would detect this.