diff --git a/patsolve/abstract_fc_solve_solver.h b/patsolve/abstract_fc_solve_solver.h index 74bf04c..13dc21a 100644 --- a/patsolve/abstract_fc_solve_solver.h +++ b/patsolve/abstract_fc_solve_solver.h @@ -1,52 +1,52 @@ /* * Copyright (C) 2006-2009 Stephan Kulow * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef ABSTRACT_FC_SOLVE_SOLVER_H #define ABSTRACT_FC_SOLVE_SOLVER_H #include "patsolve.h" struct FcSolveSolver : public Solver<12> { public: FcSolveSolver(); virtual ~FcSolveSolver(); - virtual int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE = 0; - virtual bool isWon() Q_DECL_OVERRIDE; - virtual void make_move(MOVE *m) Q_DECL_OVERRIDE; - virtual void undo_move(MOVE *m) Q_DECL_OVERRIDE; - virtual int getOuts() Q_DECL_OVERRIDE; - virtual unsigned int getClusterNumber() Q_DECL_OVERRIDE; - virtual void translate_layout() Q_DECL_OVERRIDE = 0; - virtual void unpack_cluster( unsigned int k ) Q_DECL_OVERRIDE; - virtual MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE = 0; - virtual SolverInterface::ExitStatus patsolve( int _max_positions = -1) Q_DECL_OVERRIDE; + int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE = 0; + bool isWon() Q_DECL_OVERRIDE; + void make_move(MOVE *m) Q_DECL_OVERRIDE; + void undo_move(MOVE *m) Q_DECL_OVERRIDE; + int getOuts() Q_DECL_OVERRIDE; + unsigned int getClusterNumber() Q_DECL_OVERRIDE; + void translate_layout() Q_DECL_OVERRIDE = 0; + void unpack_cluster( unsigned int k ) Q_DECL_OVERRIDE; + MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE = 0; + SolverInterface::ExitStatus patsolve( int _max_positions = -1) Q_DECL_OVERRIDE; virtual void setFcSolverGameParams() = 0; - virtual void print_layout() Q_DECL_OVERRIDE; + void print_layout() Q_DECL_OVERRIDE; virtual int get_cmd_line_arg_count() = 0; virtual const char * * get_cmd_line_args() = 0; /* Names of the cards. The ordering is defined in pat.h. */ void * solver_instance; int solver_ret; // More than enough space for two decks. char board_as_string[4 * 13 * 2 * 4 * 3]; }; #endif // ABSTRACT_FC_SOLVE_SOLVER_H diff --git a/patsolve/freecellsolver.h b/patsolve/freecellsolver.h index c39c61d..08e05c5 100644 --- a/patsolve/freecellsolver.h +++ b/patsolve/freecellsolver.h @@ -1,71 +1,71 @@ /* * Copyright (C) 1998-2002 Tom Holroyd * Copyright (C) 2006-2009 Stephan Kulow * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef FREECELLSOLVER_H #define FREECELLSOLVER_H #include "abstract_fc_solve_solver.h" constexpr auto Nwpiles = 8; constexpr auto Ntpiles = 4; class Freecell; class FreecellSolver : public FcSolveSolver { public: explicit FreecellSolver(const Freecell *dealer); int good_automove(int o, int r); - virtual int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; + int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; #if 0 bool isWon() Q_DECL_OVERRIDE; void make_move(MOVE *m) Q_DECL_OVERRIDE; void undo_move(MOVE *m) Q_DECL_OVERRIDE; void prioritize(MOVE *mp0, int n) Q_DECL_OVERRIDE; int getOuts() Q_DECL_OVERRIDE; unsigned int getClusterNumber() Q_DECL_OVERRIDE; void translate_layout() Q_DECL_OVERRIDE; void unpack_cluster( unsigned int k ) Q_DECL_OVERRIDE; MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE; #endif - virtual void translate_layout() Q_DECL_OVERRIDE; + void translate_layout() Q_DECL_OVERRIDE; #if 0 virtual void unpack_cluster( unsigned int k ); #endif - virtual MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE; - virtual void setFcSolverGameParams() Q_DECL_OVERRIDE; - virtual int get_cmd_line_arg_count() Q_DECL_OVERRIDE; - virtual const char * * get_cmd_line_args() Q_DECL_OVERRIDE; + MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE; + void setFcSolverGameParams() Q_DECL_OVERRIDE; + int get_cmd_line_arg_count() Q_DECL_OVERRIDE; + const char * * get_cmd_line_args() Q_DECL_OVERRIDE; #if 0 virtual void print_layout(); int Nwpiles; /* the numbers we're actually using */ int Ntpiles; /* Names of the cards. The ordering is defined in pat.h. */ card_t Osuit[4]; static int Xparam[]; #endif card_t O[4]; /* output piles store only the rank or NONE */ const Freecell *deal; }; #endif // FREECELLSOLVER_H diff --git a/patsolve/patsolve.h b/patsolve/patsolve.h index e9ee7b7..554efff 100644 --- a/patsolve/patsolve.h +++ b/patsolve/patsolve.h @@ -1,160 +1,160 @@ /* * Copyright (C) 1998-2002 Tom Holroyd * Copyright (C) 2006-2009 Stephan Kulow * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef PATSOLVE_H #define PATSOLVE_H #include "solverinterface.h" #include "../hint.h" #include "memory.h" #include "KCardPile" #include #include #include #include #include /* A card is represented as ( down << 6 ) + (suit << 4) + rank. */ typedef quint8 card_t; struct POSITION { POSITION *queue; /* next position in the queue */ POSITION *parent; /* point back up the move stack */ TREE *node; /* compact position rep.'s tree node */ MOVE move; /* move that got us here from the parent */ quint32 cluster; /* the cluster this node is in */ short depth; /* number of moves so far */ quint8 nchild; /* number of child nodes left */ }; class MemoryManager; template class Solver : public SolverInterface { public: Solver(); virtual ~Solver(); - virtual ExitStatus patsolve( int max_positions = -1) Q_DECL_OVERRIDE; + ExitStatus patsolve( int max_positions = -1) Q_DECL_OVERRIDE; bool recursive(POSITION *pos = nullptr); - virtual void translate_layout() Q_DECL_OVERRIDE = 0; - virtual MoveHint translateMove(const MOVE &m ) Q_DECL_OVERRIDE = 0; + void translate_layout() Q_DECL_OVERRIDE = 0; + MoveHint translateMove(const MOVE &m ) Q_DECL_OVERRIDE = 0; void stopExecution() final Q_DECL_OVERRIDE; QList firstMoves() const final Q_DECL_OVERRIDE; QList winMoves() const final Q_DECL_OVERRIDE; protected: MOVE *get_moves(int *nmoves); bool solve(POSITION *parent); void doit(); void win(POSITION *pos); virtual int get_possible_moves(int *a, int *numout) = 0; int translateSuit( int s ); void queue_position(POSITION *pos, int pri); void free_position(POSITION *pos, int); POSITION *dequeue_position(); void hashpile(int w); POSITION *new_position(POSITION *parent, MOVE *m); TREE *pack_position(void); void unpack_position(POSITION *pos); void init_buckets(void); int get_pilenum(int w); MemoryManager::inscode insert(unsigned int *cluster, int d, TREE **node); void free_buckets(void); void printcard(card_t card, FILE *outfile); int translate_pile(const KCardPile *pile, card_t *w, int size); virtual void print_layout(); void pilesort(void); void hash_layout( void ); virtual void make_move(MOVE *m) = 0; virtual void undo_move(MOVE *m) = 0; virtual void prioritize(MOVE *mp0, int n); virtual bool isWon() = 0; virtual int getOuts() = 0; virtual unsigned int getClusterNumber() { return 0; } virtual void unpack_cluster( unsigned int ) {} void init(); void free(); /* Work arrays. */ std::array W; /* the workspace */ std::array Wp; /* point to the top card of each work pile */ std::array Wlen; /* the number of cards in each pile */ /* Every different pile has a hash and a unique id. */ std::array Whash; std::array Wpilenum = {}; // = {} for zero initialization /* Position freelist. */ POSITION *Freepos = nullptr; static constexpr auto MAXMOVES = 64; /* > max # moves from any position */ MOVE Possible[MAXMOVES]; std::unique_ptr mm; ExitStatus Status; /* win, lose, or fail */ static constexpr auto NQUEUES = 127; POSITION *Qhead[NQUEUES]; /* separate queue for each priority */ int Maxq; unsigned long Total_generated, Total_positions; qreal depth_sum; POSITION *Stack = nullptr; QMap recu_pos; int max_positions; protected: QList m_firstMoves; QList m_winMoves; std::atomic_bool m_shouldEnd; }; /* Misc. */ constexpr card_t PS_DIAMOND = 0x00; /* red */ constexpr card_t PS_CLUB = 0x10; /* black */ constexpr card_t PS_HEART = 0x20; /* red */ constexpr card_t PS_SPADE = 0x30; /* black */ constexpr card_t PS_BLACK = 0x10; constexpr card_t PS_COLOR = 0x10; /* black if set */ constexpr card_t PS_SUIT = 0x30; /* mask both suit bits */ constexpr card_t NONE = 0; constexpr card_t PS_ACE = 1; constexpr card_t PS_KING = 13; constexpr card_t RANK(card_t card) {return card & 0xF;} constexpr card_t SUIT(card_t card) {return (card >> 4 ) & 3;} constexpr card_t COLOR(card_t card) {return card & PS_COLOR;} constexpr card_t DOWN(card_t card) {return (card) & ( 1 << 7 );} #endif // PATSOLVE_H diff --git a/patsolve/simonsolver.h b/patsolve/simonsolver.h index b0892d7..f3e1d64 100644 --- a/patsolve/simonsolver.h +++ b/patsolve/simonsolver.h @@ -1,55 +1,55 @@ /* * Copyright (C) 2006-2009 Stephan Kulow * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef SIMONSOLVER_H #define SIMONSOLVER_H #include "abstract_fc_solve_solver.h" #include "simon.h" class Simon; class SimonSolver : public FcSolveSolver { public: explicit SimonSolver(const Simon *dealer); int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; #if 0 bool isWon() Q_DECL_OVERRIDE; void make_move(MOVE *m) Q_DECL_OVERRIDE; void undo_move(MOVE *m) Q_DECL_OVERRIDE; int getOuts() Q_DECL_OVERRIDE; unsigned int getClusterNumber() Q_DECL_OVERRIDE; #endif - virtual void translate_layout() Q_DECL_OVERRIDE; - virtual MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE; + void translate_layout() Q_DECL_OVERRIDE; + MoveHint translateMove(const MOVE &m) Q_DECL_OVERRIDE; #if 0 void unpack_cluster( unsigned int k ) Q_DECL_OVERRIDE; void print_layout() Q_DECL_OVERRIDE; #endif - virtual void setFcSolverGameParams() Q_DECL_OVERRIDE; + void setFcSolverGameParams() Q_DECL_OVERRIDE; - virtual int get_cmd_line_arg_count() Q_DECL_OVERRIDE; - virtual const char * * get_cmd_line_args() Q_DECL_OVERRIDE; + int get_cmd_line_arg_count() Q_DECL_OVERRIDE; + const char * * get_cmd_line_args() Q_DECL_OVERRIDE; #if 0 /* Names of the cards. The ordering is defined in pat.h. */ int O[4]; #endif const Simon *deal; }; #endif // SIMONSOLVER_H