19#ifndef __PBeFS_SequenceScore
20 #define __PBeFS_SequenceScore
53template<
int W ,
int H >
71 : f_base( start , goal ) , v_goal( goal ) {
72 for(
int c = 0 ; c <
cells ; ++c )
73 v_goal_cell[ goal[ c ] ] = c;
74 if constexpr( ( W == 3 ) && ( H == 3 ) ) {
75 const int ring[ 8 ] = { 0 , 1 , 2 , 5 , 8 , 7 , 6 , 3 };
76 for(
int k = 0 ; k < 8 ; ++k )
77 v_next[ ring[ k ] ] = ring[ ( k + 1 ) % 8 ];
81 for(
int c = 0 ; c <
cells - 1 ; ++c )
83 v_next[
cells - 1 ] = -1;
87 for(
int t = 1 ; t <
cells ; ++t ) {
88 const int c = v_goal_cell[ t ];
91 n = ( W == 3 ) && ( H == 3 ) ? 0 : 1;
92 v_follower[ t ] = goal[ n ];
97 return( f_base.initial_state() );
101 return( f_base.is_goal( s ) );
105 return( f_base.hash( s ) );
111 const int centre = ( W == 3 ) && ( H == 3 ) ? 4 : 0;
112 int m = 0 , sc =
Base::tile( s , centre ) != v_goal[ centre ] ? 1 : 0;
113 for(
int c = 0 ; c <
cells ; ++c ) {
117 const int g = v_goal_cell[ t ];
118 m += std::abs( g % W - c % W ) + std::abs( g / W - c / W );
119 if( ( v_next[ c ] >= 0 ) &&
120 (
Base::tile( s , v_next[ c ] ) != v_follower[ t ] ) )
123 return( m + W * sc );
135 [[nodiscard]]
const Base &
base(
void )
const noexcept {
return( f_base ); }
143 int v_goal_cell[
cells ] = {};
144 int v_next[
cells ] = {};
145 int v_follower[
cells ] = {};
Header file for the class template SlidingTile, which implements the Domain concept [see Domain....
state_type initial_state(void) const noexcept
Definition SequenceScore.h:96
std::uint64_t hash(state_type s) const noexcept
Definition SequenceScore.h:104
static constexpr int cells
the cells
Definition SequenceScore.h:65
cost_type heuristic(state_type s) const noexcept
M + W S.
Definition SequenceScore.h:110
bool is_goal(state_type s) const noexcept
Definition SequenceScore.h:100
typename Base::cost_type cost_type
the cost type
Definition SequenceScore.h:62
const Base & base(void) const noexcept
the underlying puzzle
Definition SequenceScore.h:135
SequenceScore(const board_type &start, const board_type &goal=Base::korf_goal())
constructor, taking the start and the goal boards
Definition SequenceScore.h:69
void for_each_successor(state_type s, cost_type, F &&f) const
Definition SequenceScore.h:127
typename Base::board_type board_type
a board
Definition SequenceScore.h:63
typename Base::state_type state_type
a packed board
Definition SequenceScore.h:61
SlidingTile< W, H > Base
the puzzle
Definition SequenceScore.h:60
the sliding-tile puzzle on a board of at most 25 cells
Definition SlidingTile.h:170
std::conditional_t< cells<=16, std::uint64_t, Word128 > state_type
a packed board
Definition SlidingTile.h:187
static constexpr int cells
the number of cells
Definition SlidingTile.h:180
static board_type korf_goal(void)
the goal of Korf (1985): the blank in the first cell, then 1 , 2 , ...
Definition SlidingTile.h:196
std::array< std::uint8_t, cells > board_type
a board
Definition SlidingTile.h:190
int cost_type
the cost type
Definition SlidingTile.h:189
static int tile(state_type s, int c) noexcept
the tile in the cell c of s
Definition SlidingTile.h:456
namespace for the Parallel Best-First Search library
Definition AStar.h:83