Here is a test of Artificial Intelligence informed and uninformed search algorithms.
We have a 3×3 grid where B means BLACK KNIGHT and W is WHITE KNIGHT of chess.
+---+---+---+ +---+---+---+ | W | | W | | B | | B | +---+---+---+ +---+---+---+ | | | | ----> | | | | +---+---+---+ +---+---+---+ | B | | B | | W | | W | +---+---+---+ +---+---+---+B and W can “L” move exactly like knights chess pieces.
What is the best search algorithm to put black ones into current white ones squares and white ones into current black ones square?
- A STAR
- BFS
- DFS
- HILL CLIMBING
I’m really confused and I don’t know the correct choice.
2
Answers
A* should be the appropriate algorithm for this problem. As a target-heuristic, u could use the no. of moves required to reach the target destination assuming the board is empty, which is always <= the actual amount of moves required.
An important aspect is that the number of possible positions is rather small :
A consequence is that whatever which the algorithm is selected, you have to pay attention not to go through the same node several times , i.e. through the same position. Traditionally, chess programmes use hash tables when analyzing positions with a low number of pieces. Here, taking into account the small number of possible positions, it is possible to select a perfect hashing, i.e. with no collusion.
Concerning the algorithms:
I have therefore implemented the BFS in C++. The result is provided about instantaneously.
The 16 half-moves are given hereafter:
And the programme: