PBeFS
Parallel Best-First Search
Loading...
Searching...
No Matches
NQueens Class Reference

the n-queens problem, with at most 32 queens More...

#include <PBeFS/astar/NQueens.h>

Classes

struct  Board
 a board: the queens placed and the row of each of them More...

Public Types

using state_type = Board
 a board
using cost_type = int
 the cost type

Public Member Functions

 NQueens (int n)
 constructor of the problem with \( n \) queens, \( 1 \leq n \leq 32 \)
Board initial_state (void) const noexcept
bool is_goal (const Board &s) const noexcept
std::uint64_t hash (const Board &s) const noexcept
int heuristic (const Board &s) const noexcept
template<class F>
void for_each_successor (const Board &s, int h, F &&f) const
 calls f( t , 1 , h - 1 ) for each row of the column \( k \) free of attacks
std::size_t num_features (void) const noexcept
 the number of features: one per pair ( column , row )
template<class F>
void for_each_feature (const Board &s, F &&f) const
 calls f( c n + r ) for the queen of each column \( c < k \), in the row \( r \)
int size (void) const noexcept
 the size of the board

Detailed Description

the n-queens problem, with at most 32 queens

A queen is added in the leftmost empty column, in a row where no queen already on the board attacks it; a state is the number \( k \) of the queens on the board and the row of the queen of each column \( c < k \), the other rows being 0, with \( n \leq 32 \). Each queen costs 1, and the heuristic, the number of the empty columns, is exact on the states that lead to a solution: every state has \( f = n \), and A* with the ties broken in favour of the larger g behaves as a depth-first search.

The feature \( c n + r \) of Zobrist hashing is the queen of the column \( c \) in the row \( r \), for \( c < k \); the states do not fit a 64-bit word for \( n > 12 \), and the Domain gives no perfect hash.

Member Typedef Documentation

◆ cost_type

using cost_type = int

the cost type

◆ state_type

using state_type = Board

a board

Constructor & Destructor Documentation

◆ NQueens()

NQueens ( int n)
inlineexplicit

constructor of the problem with \( n \) queens, \( 1 \leq n \leq 32 \)

Member Function Documentation

◆ for_each_feature()

template<class F>
void for_each_feature ( const Board & s,
F && f ) const
inline

calls f( c n + r ) for the queen of each column \( c < k \), in the row \( r \)

◆ for_each_successor()

template<class F>
void for_each_successor ( const Board & s,
int h,
F && f ) const
inline

calls f( t , 1 , h - 1 ) for each row of the column \( k \) free of attacks

◆ hash()

std::uint64_t hash ( const Board & s) const
inlinenodiscardnoexcept

◆ heuristic()

int heuristic ( const Board & s) const
inlinenodiscardnoexcept

◆ initial_state()

Board initial_state ( void ) const
inlinenodiscardnoexcept

◆ is_goal()

bool is_goal ( const Board & s) const
inlinenodiscardnoexcept

◆ num_features()

std::size_t num_features ( void ) const
inlinenodiscardnoexcept

the number of features: one per pair ( column , row )

◆ size()

int size ( void ) const
inlinenodiscardnoexcept

the size of the board


The documentation for this class was generated from the following file: