No, that wouldn't work because the pathfinding algorithm would look around the red pieces. So as long as there is a path of white space between the start and finish, the game cannot be won.
Example:
Code: Select all
[B][0][0][0][R]
[0][b][0][0][0]
[0][0][b][0][0]
[r][r][0][b][0]
[R][r][0][0][B]
This would cause a victory for red, because it would cause there to be no possible path between R and R. Even though there isn't a complete line between R and R.
Also, this would not cause a victory for blue, because even though there is a complete line from B to B, the pathfinder can still follow the empty spaces around it, and complete a path.
The working solution would be to consider all blank spaces as collidable, and then consider each placed piece to be non-collidable.
This case also makes me think I should make a modification to my zStar library so it takes the collidables table as an argument, rather than storing it in the library. Because in this case, red and blue would each have their own separate collidables tables.
EDIT: @Roland_Yonaba thanks for linking to Jumper. I was looking for a pathfinding library before I wrote zStar, but couldn't find one that met my needs. If I had found Jumper, I may not have written zStar. (Assuming it runs as fast as zStar that is.)