I'm making a game which uses a 10x20 matrix to store the position of the objects.
I have a castle object, represented by a number in a matrix. It is randomly deployed in some cell of the matrix. I also have a wall object, represented by a different number, which the user will deploy into the matrix by clicking on cells. The idea is to surround the castle.
Basically it'll look like this:
0 0 0 0 0 0 0
0 1 1 1 1 1 0
0 1 0 0 2 1 0
0 1 1 0 0 1 0
0 0 1 0 0 1 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
(2 is the castle, and 1 is the wall.)
How can I tell if the castle is surrounded by walls?
DFS
orBFS
algorithm easily and check If you reach the border of your matrix or not. \$\endgroup\$