SlideShare a Scribd company logo
Game of eight chips
Ло Вэйчжи
Luo Weizhi
CONTENTS
0
1
Task introduction
Heuristic function analysis
Algorithm design
UML interpretation
0
2
0
3
0
4
0
5
Performance Evaluation & Test Cases
0
6
Conclusion
Task introduction
0
1
Task introduction
The puzzle "The Game of Eight Chips" is a heuristic search task. Chips will be
moved in order (right, left, up, down) to adjacent spaces. The goal is to reach the final
state with ordered chips.
Feasible heuristic function:
1.The heuristic function H1 characterizes number of chips shifted from optimal final state. For the state
(a) heuristic function H1=8.
2.The heuristic function H2 characterizes sum of distances between current (a) and target (b) chip
positions. For the state (a) heuristic function H2=3+1+2+2+2+3+3+2=18.
Heuristic function analysis
0
2
Heuristic function analysis
The requirement of the task is to implement a path shortest path search using the A* algorithm.The
A* algorithm is a heuristic graph search algorithm characterized by the definition of the valuation
function.
f(n) = g(n) + h(n)
The heuristic function f(n) is the key function used to evaluate nodes in the A* algorithm and
consists of two parts: g(n) and h(n).
g(n): this is the distance from the starting node to node n at actual cost. It reflects the cost of
reaching the current node n. For example, in an octet problem, it could be the number of steps
required to reach the current state from the initial state.
h(n): this is the estimated cost of traveling from node n to the goal node. This is a heuristic estimate
of the cost required to reach the goal node from the current node n to the goal node. In the octet
problem, this can be the estimated number of steps from the current state to the goal state, computed
by the heuristics H1, H2.
Algorithm design
0
3
Judgment of solutions
Conclusion of the eight-digit problem with and without solutions:
A state is represented in one-dimensional form by finding the sum of the inverse order of all the digits
except 0. That is, If a larger number precedes a smaller number, the two numbers are said to form an
inverse order, and the total number of inverses in an arrangement is called the number of inverses in that
arrangement.
Two states are mutually reachable if their inverse order parity is the same, otherwise they are not
mutually reachable.
Examples from the task,such as:
For the initial state, the one-dimensional array becomes: 724596831, Sum of inverses = 1 + 1 + 1 +
2 + 1 + 6 + 8 = 20(even).
For the final state, the one-dimensional array becomes: 912345678, Sum of inverses = 1 + 1 + 1 +
1+ 1 + 1+ 1 + 1 = 8(even).
So these two states are interchangeable.
Heuristic function H1
Heuristic is the number of misplaced digits.
f(n) = g(n) + h(n)
g(n) represents the depth
h(n) represents the total number of absent arrays
The following figure shows the specific operation of the heuristic strategy H1: the numbers circled
in red indicate the order of expansion.
Heuristic function H1
Heuristic function H2
Heuristic is the Manhattan distance.
f(n) = g(n) + h(n)
h(n) denotes the Manhattan distance. Using the Manhattan distance as heuristic information, it is the
sum of the distances required for misplaced digits to reach the target state compared to the current
state and the target state. For example the initial state in the example: h(n) = 3+1+2+2+2+3+3+2 =
18.The specific operation is the same, except that the value calculated for each h(n) is different.
Data Structure
In fact, in the BFS search algorithm, if the nodes in the Open table (queue) can be sorted
using the valuation function f(n) = g(n) + h(n) at each step of the search, then the search
algorithm is Algorithm A*.
The A* algorithm needs to maintain two data structures: the OPEN set and the CLOSED
set.The OPEN set and the COLED set of this implementation are realized using Map.The OPEN
set contains all the nodes to be detected that have been searched. In the initial state, the OPEN set
contains only one element: the start node.The CLOSED set contains the detected nodes. The
initial state CLOSED set is empty. Each node also contains a pointer to the parent node to
determine the tracking relationship.
Main loop
1.Each time an optimal node n (i.e., the node
with the smallest F-value) is taken from the
OPEN set to be tested.
2.If the OPEN table is empty, the search fails
and the program exits.
3.Remove node n from the OPEN set and add it
to the CLOSED set.
4.If n is the target node, the search succeeds and
the program exits.
Main loop
5. Otherwise try to add all neighbor nodes n of node n:
 Neighbor node in CLOSED set means it has already
been detected, then no need to add it again.
 Neighboring nodes are again in the OPEN set:
 If the recalculated G-value is smaller than the G-
value saved by the neighboring node, then the G-
value amount F-value of this neighboring node needs
to be updated, as well as the parent node.
 Otherwise, no operation is done.
 Otherwise, add this neighbor node to the OPEN set,
set its parent node to n, and set its G value and F
value.

UML interpretation
0
4
UML1: Diagram of precedents
Users can choose the calculation algorithm, and after using the corresponding algorithm
to calculate, they can view the results of the algorithm and get the path to the final state.
The user can control the movement of the queen. Before controlling the movement of the
queen, the user needs to input or generate the starting state or ending state of the queen.
UML2: Diagram of activity
Enter the starting state and ending state,
and the misunderstanding ends directly.
If you have a solution, select the
corresponding algorithm and click the
corresponding button to calculate.
View the path to the final state and
control the movement of the queen.
UML3: Class diagram
Algorithm.java--algorithm file, is
a tool class that implements all
algorithms. Of course, I also added
the DFS and BFS algorithms for
performance comparison.
State.java---node class, stores
the nine-square grid sequence,
real cost, real cost + heuristic
cost of each state.
GUI.java--entry file
GUI file
CalThread.java--for
multi-threaded
calculations
LimitedTextField.java
--limit the input of
TextField.
UML3: Class diagram
UML4: Diagram of interactions
The user needs to input or randomly
generate an initial state or state, then
submit the initial state and final state to
the corresponding algorithm and then
call the corresponding algorithm. After
the Algorithm calculation is completed,
the corresponding calculation result is
returned.
UML5: Diagram of states
At the beginning, the
program waits for input or
generates the initial state and
final state. If there is no
solution to the two, it ends
directly.
If there is a solution, select
the corresponding algorithm
and perform the calculation.
According to the calculation
results, control the movement
of the queen.
UML6: Diagram of components
The LimitedField component and the
CalThread component are inserted into the
GUI. The Algorithm component is called in
the CalThread component.
The smallest unit of calculation in the
Algorithm component is the State
component.
Performance Evaluation & Test Cases
0
5
Performance Evaluation Metrics & Test Cases
Performance Evaluation:
 Consumption time (ms)
 Comparison times
 Path length
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Conclusion
0
6
Conclusion
 DFS is not necessarily faster than BFS, and vice versa.
 DFS may not necessarily find the shortest path.
 BFS can definitely find the shortest path if the search depth is not limited.
The choice of heuristic function h(n) in the A* algorithm is crucial. h*(n) represents the
actual minimum cost from node n to the target node.
h(n) < h*(n), in this case, there are many points to search, the search range is large,
and the efficiency is low. But the optimal solution can be obtained.
h(n)=h*(n), the search efficiency is the highest at this time.
h(n)>h*(n), the number of search points is small, the search range is small, and the
efficiency is high, but the optimal solution cannot be guaranteed.

More Related Content

PPTX
heuristic technique.pptx...............................
DOCX
UNIT-1.docx Design and Analysis of Algorithm
PPTX
A-star Algorithm in artificial intelligence.pptx
PDF
Cs6402 design and analysis of algorithms may june 2016 answer key
DOC
ALGORITHMS - SHORT NOTES
PDF
PPTX
Week 2 Rational Function, Equation and Inequality -Autosaved-.pptx
PPT
algorithms-1 master in computer application
heuristic technique.pptx...............................
UNIT-1.docx Design and Analysis of Algorithm
A-star Algorithm in artificial intelligence.pptx
Cs6402 design and analysis of algorithms may june 2016 answer key
ALGORITHMS - SHORT NOTES
Week 2 Rational Function, Equation and Inequality -Autosaved-.pptx
algorithms-1 master in computer application

Similar to Implementing an 8-chip game based on the A algorithm.pptx (20)

PPT
analysis of algorithms and asymptotic complexity
PDF
Daa chapter 1
PPTX
DAA-Module-5.pptx
PPTX
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
PPTX
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
PPTX
Discrete_Mathematics 6 algorithm complexity.pptx
PDF
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
PPTX
Simplex algorithm
PDF
Analysis and Design of Algorithms notes
PPTX
Unit ii algorithm
PPT
introduction to algorithm for beginneer1
PPTX
Analysis Framework, Asymptotic Notations
PPT
lecture 1
PDF
State-Space Realizations Using Control Canonical Form and Simulation Diagram
PDF
Heuristic search for AI CSE EVE dsfdsf sdfdsfsdf sdfdsfdsfsd sdfsdfds
PDF
Matlab Sample Assignment Solution
PPTX
Simplex Algorithm
PDF
L1803016468
PPT
Insersion & Bubble Sort in Algoritm
PDF
frozen_lake_rl_report.pdf
analysis of algorithms and asymptotic complexity
Daa chapter 1
DAA-Module-5.pptx
Module-1.pptxbdjdhcdbejdjhdbchchchchchjcjcjc
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
Discrete_Mathematics 6 algorithm complexity.pptx
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
Simplex algorithm
Analysis and Design of Algorithms notes
Unit ii algorithm
introduction to algorithm for beginneer1
Analysis Framework, Asymptotic Notations
lecture 1
State-Space Realizations Using Control Canonical Form and Simulation Diagram
Heuristic search for AI CSE EVE dsfdsf sdfdsfsdf sdfdsfdsfsd sdfsdfds
Matlab Sample Assignment Solution
Simplex Algorithm
L1803016468
Insersion & Bubble Sort in Algoritm
frozen_lake_rl_report.pdf
Ad

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Essential Infomation Tech presentation.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Nekopoi APK 2025 free lastest update
PDF
Digital Strategies for Manufacturing Companies
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
top salesforce developer skills in 2025.pdf
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How to Migrate SBCGlobal Email to Yahoo Easily
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PTS Company Brochure 2025 (1).pdf.......
Essential Infomation Tech presentation.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Reimagine Home Health with the Power of Agentic AI​
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Nekopoi APK 2025 free lastest update
Digital Strategies for Manufacturing Companies
Understanding Forklifts - TECH EHS Solution
Upgrade and Innovation Strategies for SAP ERP Customers
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administraation Chapter 3
top salesforce developer skills in 2025.pdf
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Design an Analysis of Algorithms I-SECS-1021-03
How to Choose the Right IT Partner for Your Business in Malaysia
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Ad

Implementing an 8-chip game based on the A algorithm.pptx

  • 1. Game of eight chips Ло Вэйчжи Luo Weizhi
  • 2. CONTENTS 0 1 Task introduction Heuristic function analysis Algorithm design UML interpretation 0 2 0 3 0 4 0 5 Performance Evaluation & Test Cases 0 6 Conclusion
  • 4. Task introduction The puzzle "The Game of Eight Chips" is a heuristic search task. Chips will be moved in order (right, left, up, down) to adjacent spaces. The goal is to reach the final state with ordered chips. Feasible heuristic function: 1.The heuristic function H1 characterizes number of chips shifted from optimal final state. For the state (a) heuristic function H1=8. 2.The heuristic function H2 characterizes sum of distances between current (a) and target (b) chip positions. For the state (a) heuristic function H2=3+1+2+2+2+3+3+2=18.
  • 6. Heuristic function analysis The requirement of the task is to implement a path shortest path search using the A* algorithm.The A* algorithm is a heuristic graph search algorithm characterized by the definition of the valuation function. f(n) = g(n) + h(n) The heuristic function f(n) is the key function used to evaluate nodes in the A* algorithm and consists of two parts: g(n) and h(n). g(n): this is the distance from the starting node to node n at actual cost. It reflects the cost of reaching the current node n. For example, in an octet problem, it could be the number of steps required to reach the current state from the initial state. h(n): this is the estimated cost of traveling from node n to the goal node. This is a heuristic estimate of the cost required to reach the goal node from the current node n to the goal node. In the octet problem, this can be the estimated number of steps from the current state to the goal state, computed by the heuristics H1, H2.
  • 8. Judgment of solutions Conclusion of the eight-digit problem with and without solutions: A state is represented in one-dimensional form by finding the sum of the inverse order of all the digits except 0. That is, If a larger number precedes a smaller number, the two numbers are said to form an inverse order, and the total number of inverses in an arrangement is called the number of inverses in that arrangement. Two states are mutually reachable if their inverse order parity is the same, otherwise they are not mutually reachable. Examples from the task,such as: For the initial state, the one-dimensional array becomes: 724596831, Sum of inverses = 1 + 1 + 1 + 2 + 1 + 6 + 8 = 20(even). For the final state, the one-dimensional array becomes: 912345678, Sum of inverses = 1 + 1 + 1 + 1+ 1 + 1+ 1 + 1 = 8(even). So these two states are interchangeable.
  • 9. Heuristic function H1 Heuristic is the number of misplaced digits. f(n) = g(n) + h(n) g(n) represents the depth h(n) represents the total number of absent arrays The following figure shows the specific operation of the heuristic strategy H1: the numbers circled in red indicate the order of expansion.
  • 11. Heuristic function H2 Heuristic is the Manhattan distance. f(n) = g(n) + h(n) h(n) denotes the Manhattan distance. Using the Manhattan distance as heuristic information, it is the sum of the distances required for misplaced digits to reach the target state compared to the current state and the target state. For example the initial state in the example: h(n) = 3+1+2+2+2+3+3+2 = 18.The specific operation is the same, except that the value calculated for each h(n) is different.
  • 12. Data Structure In fact, in the BFS search algorithm, if the nodes in the Open table (queue) can be sorted using the valuation function f(n) = g(n) + h(n) at each step of the search, then the search algorithm is Algorithm A*. The A* algorithm needs to maintain two data structures: the OPEN set and the CLOSED set.The OPEN set and the COLED set of this implementation are realized using Map.The OPEN set contains all the nodes to be detected that have been searched. In the initial state, the OPEN set contains only one element: the start node.The CLOSED set contains the detected nodes. The initial state CLOSED set is empty. Each node also contains a pointer to the parent node to determine the tracking relationship.
  • 13. Main loop 1.Each time an optimal node n (i.e., the node with the smallest F-value) is taken from the OPEN set to be tested. 2.If the OPEN table is empty, the search fails and the program exits. 3.Remove node n from the OPEN set and add it to the CLOSED set. 4.If n is the target node, the search succeeds and the program exits.
  • 14. Main loop 5. Otherwise try to add all neighbor nodes n of node n:  Neighbor node in CLOSED set means it has already been detected, then no need to add it again.  Neighboring nodes are again in the OPEN set:  If the recalculated G-value is smaller than the G- value saved by the neighboring node, then the G- value amount F-value of this neighboring node needs to be updated, as well as the parent node.  Otherwise, no operation is done.  Otherwise, add this neighbor node to the OPEN set, set its parent node to n, and set its G value and F value. 
  • 16. UML1: Diagram of precedents Users can choose the calculation algorithm, and after using the corresponding algorithm to calculate, they can view the results of the algorithm and get the path to the final state. The user can control the movement of the queen. Before controlling the movement of the queen, the user needs to input or generate the starting state or ending state of the queen.
  • 17. UML2: Diagram of activity Enter the starting state and ending state, and the misunderstanding ends directly. If you have a solution, select the corresponding algorithm and click the corresponding button to calculate. View the path to the final state and control the movement of the queen.
  • 18. UML3: Class diagram Algorithm.java--algorithm file, is a tool class that implements all algorithms. Of course, I also added the DFS and BFS algorithms for performance comparison. State.java---node class, stores the nine-square grid sequence, real cost, real cost + heuristic cost of each state.
  • 20. UML4: Diagram of interactions The user needs to input or randomly generate an initial state or state, then submit the initial state and final state to the corresponding algorithm and then call the corresponding algorithm. After the Algorithm calculation is completed, the corresponding calculation result is returned.
  • 21. UML5: Diagram of states At the beginning, the program waits for input or generates the initial state and final state. If there is no solution to the two, it ends directly. If there is a solution, select the corresponding algorithm and perform the calculation. According to the calculation results, control the movement of the queen.
  • 22. UML6: Diagram of components The LimitedField component and the CalThread component are inserted into the GUI. The Algorithm component is called in the CalThread component. The smallest unit of calculation in the Algorithm component is the State component.
  • 23. Performance Evaluation & Test Cases 0 5
  • 24. Performance Evaluation Metrics & Test Cases Performance Evaluation:  Consumption time (ms)  Comparison times  Path length
  • 30. Conclusion  DFS is not necessarily faster than BFS, and vice versa.  DFS may not necessarily find the shortest path.  BFS can definitely find the shortest path if the search depth is not limited. The choice of heuristic function h(n) in the A* algorithm is crucial. h*(n) represents the actual minimum cost from node n to the target node. h(n) < h*(n), in this case, there are many points to search, the search range is large, and the efficiency is low. But the optimal solution can be obtained. h(n)=h*(n), the search efficiency is the highest at this time. h(n)>h*(n), the number of search points is small, the search range is small, and the efficiency is high, but the optimal solution cannot be guaranteed.