8 Puzzle

1. Intro

Give a 3-by-3 grid with 8 square blocks and 1 blank.
Rearrange the block to make it in order, using as few moves as possible.

Return the result of sequence. Like this below:

1
2
3
4
5
   1  3        1     3        1  2  3        1  2  3        1  2  3
4 2 5 => 4 2 5 => 4 5 => 4 5 => 4 5 6
7 8 6 7 8 6 7 8 6 7 8 6 7 8

initial 1 left 2 up 5 left goal

The best-first search is that from initial broad to the goal, we do our each step at the best, or small cost move.

2.1 Search node

First, we need to define our start and goal. We use a terminology called

  • 本文作者: Wafer Li
  • 本文链接: https://wafer.li/Algorithm/8 Puzzle/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
0%