00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __SOLVETHREAD_H__
00022 #define __SOLVETHREAD_H__
00023
00024 #include "assembler.h"
00025 #include "disassembler.h"
00026 #include "bt_assert.h"
00027 #include "thread.h"
00028
00029 #include <time.h>
00030
00031 class problem_c;
00032
00033
00034
00035
00036
00037 class solveThread_c : public assembler_cb, public thread_c {
00038
00039 public:
00040
00041 enum {
00042 ACT_PREPARATION,
00043 ACT_REDUCE,
00044 ACT_ASSEMBLING,
00045 ACT_DISASSEMBLING,
00046 ACT_PAUSING,
00047 ACT_FINISHED,
00048 ACT_ERROR,
00049 ACT_WAIT_TO_STOP
00050 };
00051
00052 private:
00053
00054 unsigned int action;
00055
00056 public:
00057
00058 unsigned int currentAction(void) { return action; }
00059
00060
00061 unsigned int currentActionParameter(void);
00062
00063 private:
00064
00065 assembler_c::errState errState;
00066 int errParam;
00067
00068 public:
00069
00070 assembler_c::errState getErrorState(void) {
00071 bt_assert(action == ACT_ERROR);
00072 return errState;
00073 }
00074 int getErrorParam(void) {
00075 bt_assert(action == ACT_ERROR);
00076 return errParam;
00077 }
00078
00079 private:
00080
00081 time_t startTime;
00082
00083 public:
00084
00085
00086 unsigned long getTime(void) { return time(0) - startTime; }
00087
00088 private:
00089
00090 problem_c * puzzle;
00091 int parameters;
00092
00093 public:
00094
00095 static const int PAR_REDUCE = 0x01;
00096 static const int PAR_KEEP_MIRROR = 0x02;
00097 static const int PAR_KEEP_ROTATIONS = 0x04;
00098 static const int PAR_DROP_DISASSEMBLIES = 0x08;
00099 static const int PAR_DISASSM = 0x10;
00100 static const int PAR_JUST_COUNT = 0x20;
00101 static const int PAR_COMPLETE_ROTATIONS = 0x40;
00102
00103
00104 solveThread_c(problem_c * puz, int par);
00105 const problem_c * getProblem(void) const { return puzzle; }
00106
00107 private:
00108
00109 int sortMethod;
00110
00111 public:
00112
00113 enum {
00114 SRT_UNSORT,
00115 SRT_COMPLETE_MOVES,
00116 SRT_LEVEL
00117 };
00118
00119 void setSortMethod(int sort) { sortMethod = sort; }
00120
00121 private:
00122
00123
00124 unsigned int solutionLimit;
00125
00126
00127 unsigned int solutionDrop;
00128
00129
00130
00131
00132 unsigned int dropMultiplicator;
00133
00134 public:
00135
00136 void setSolutionLimits(unsigned int limit, unsigned int drop = 1) {
00137 solutionLimit = limit;
00138 solutionDrop = drop;
00139 }
00140
00141 private:
00142
00143 assert_exception ae;
00144
00145 public:
00146
00147 const assert_exception & getAssertException(void) {
00148 return ae;
00149 }
00150
00151 private:
00152
00153
00154 bool stopPressed;
00155 bool return_after_prep;
00156
00157
00158
00159
00160 disassembler_c * disassm;
00161 assembler_c * assm;
00162
00163
00164
00165
00166
00167 public:
00168
00169
00170
00171 virtual ~solveThread_c(void);
00172
00173 private:
00174
00175
00176 bool assembly(assembly_c* a);
00177
00178 public:
00179
00180
00181
00182 bool start(bool stop_after_prep = false);
00183
00184
00185 void stop(void);
00186
00187 bool stopped(void) const {
00188 return ((action == ACT_PAUSING) ||
00189 (action == ACT_FINISHED) ||
00190 (action == ACT_ERROR)
00191 );
00192 }
00193
00194 void run(void);
00195
00196 private:
00197
00198
00199 solveThread_c(const solveThread_c&);
00200 void operator=(const solveThread_c&);
00201 };
00202
00203 #endif