Skip to content

hjcba/bing-puzzle-solve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation


README

中文说明

这是一个使用 A* 算法解决 8 拼图问题的 Python 实现。

功能特点

  • 使用 A 搜索算法* 寻找最优解。
  • 启发函数采用 曼哈顿距离
  • 支持输出每一步的操作及状态变化。

如何运行

  1. 安装依赖:无额外依赖,确保已安装 Python(3.x)。
  2. 执行脚本:
    python solvepuzzle.py

自定义初始状态

修改 start_state 变量以设置不同的初始拼图状态。例如:

start_state = "87153642_"  # 初始状态

输出示例

程序会输出从初始状态到目标状态的移动步骤,并展示每次操作后的拼图状态。

目标状态

默认目标状态为:

123
456
78_

English Description

This is a Python implementation of solving the 8-puzzle problem using the A* algorithm.

Features

  • Uses the A* search algorithm to find the optimal solution.
  • The heuristic function uses Manhattan distance.
  • Supports outputting each move and puzzle state change.

How to Run

  1. Install dependencies: No additional dependencies are needed, ensure you have Python (3.x) installed.
  2. Run the script:
    python solvepuzzle.py

Customize Initial State

Modify the start_state variable to set a different initial puzzle configuration. For example:

start_state = "87153642_"  # Initial state

Example Output

The program will output the steps from the initial state to the goal state, along with the puzzle state after each move.

Goal State

The default goal state is:

123
456
78_

您可以将上述内容保存为 README.md 文件,以便项目维护和文档说明。

About

一个使用A*算法解决八数码问题的Python实现

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages