Java Reference
In-Depth Information
wait for all the results by creating an
Executor
specific to the traversal and using
shut-
Listing 8.12. Waiting for Results to be Calculated in Parallel.
8.5.1. Example: A Puzzle Framework
An appealing application of this technique is solving puzzles that involve finding a sequence
of transformations from some initial state to reach a goal state, such as the familiar “sliding
We define a “puzzle” as a combination of an initial position, a goal position, and a set of rules
that determine valid moves. The rule set has two parts: computing the list of legal moves
from a given position and computing the result of applying a move to a position.
Puzzle
in
for a position and a move. From this interface, we can write a simple sequential solver that
searches the puzzle space until a solution is found or the puzzle space is exhausted.
Listing 8.13. Abstraction for Puzzles Like the “Sliding Blocks Puzzle”.