00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __ASSEMBLER_1_H__
00022 #define __ASSEMBLER_1_H__
00023
00024 #include "assembler.h"
00025
00026 #include <vector>
00027 #include <set>
00028 #include <stack>
00029
00030 class problem_c;
00031 class gridType_c;
00032 class mirrorInfo_c;
00033
00047 class assembler_1_c : public assembler_c {
00048
00049 protected:
00050
00051 const problem_c * puzzle;
00052
00053 private:
00054
00055
00056
00057
00058
00059
00060
00061 std::vector<unsigned int> left;
00062 std::vector<unsigned int> right;
00063 std::vector<unsigned int> up;
00064 std::vector<unsigned int> down;
00065 std::vector<unsigned int> colCount;
00066 std::vector<unsigned int> weight;
00067 std::vector<unsigned int> min;
00068 std::vector<unsigned int> max;
00069
00070
00071
00072
00073
00074 std::vector<unsigned int> holeColumns;
00075 unsigned int holes;
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 void solution(void);
00086
00087
00088 bool abbort;
00089
00090
00091 bool running;
00092
00093 std::vector<unsigned int> rows;
00094 std::vector<unsigned int> finished_a;
00095 std::vector<unsigned int> finished_b;
00096 std::vector<unsigned int> hidden_rows;
00097
00098
00099 std::vector<unsigned int>task_stack;
00100 std::vector<unsigned int>next_row_stack;
00101 std::vector<unsigned int>column_stack;
00102
00103 unsigned int headerNodes;
00104
00105 bool open_column_conditions_fulfillable(void);
00106 int find_best_unclosed_column(void);
00107 void cover_column_only(int col);
00108 void uncover_column_only(int col);
00109 void cover_column_rows(int col);
00110 void uncover_column_rows(int col);
00111 void hiderow(int r);
00112 void unhiderow(int r);
00113 void hiderows(unsigned int r);
00114 void unhiderows(void);
00115 bool column_condition_fulfilled(int col);
00116 bool column_condition_fulfillable(int col);
00117
00118 void iterative(void);
00119 void remove_row(register unsigned int r);
00120 void remove_column(register unsigned int c);
00121 unsigned int clumpify(void);
00122
00123
00128 bool canPlace(const voxel_c * piece, int x, int y, int z) const;
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 int prepare(bool hasRange, unsigned int rangeMin, unsigned int rangeMax);
00139
00140
00141 errState errorsState;
00142 int errorsParam;
00143
00144
00145 unsigned int piecenumber;
00146
00147
00148 assembler_cb * asm_bc;
00149
00150
00151
00152
00153 class piecePosition {
00154
00155 public:
00156
00157 int x, y, z;
00158 unsigned char transformation;
00159 unsigned int row;
00160 unsigned int piece;
00161
00162 piecePosition(unsigned int pc_, int x_, int y_, int z_, unsigned char transformation_, unsigned int row_) : x(x_), y(y_), z(z_),
00163 transformation(transformation_), row(row_), piece(pc_) {}
00164 };
00165 std::vector<piecePosition> piecePositions;
00166
00167
00168
00169 bool avoidTransformedAssemblies;
00170 unsigned int avoidTransformedPivot;
00171 mirrorInfo_c * avoidTransformedMirror;
00172
00174 bool complete;
00175
00176
00177
00178 bool debug;
00179 int debug_loops;
00180
00181 unsigned long iterations;
00182
00183 protected:
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 void GenerateFirstRow(unsigned int res_filled);
00196
00197
00198
00199
00200
00201
00202
00203
00204 int AddPieceNode(unsigned int piece, unsigned int rot, unsigned int x, unsigned int y, unsigned int z);
00205
00206
00207
00208 void AddRangeNode(unsigned int col, unsigned int piecenode, unsigned int weight);
00209
00210
00211
00212
00213
00214
00215 void getPieceInformation(unsigned int node, unsigned int * piece, unsigned char *tran, int *x, int *y, int *z) const;
00216
00217
00218
00219
00220
00221 void AddVoxelNode(unsigned int col, unsigned int piecenode);
00222
00223
00224 unsigned int getRight(int pos) { return right[pos]; }
00225 unsigned int getColCount(int pos) { return colCount[pos]; }
00226
00227
00228
00229
00230
00231 assembler_cb * getCallback(void) { return asm_bc; }
00232
00233 unsigned int getPiecenumber(void) { return piecenumber; }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245 void checkForTransformedAssemblies(unsigned int pivot, mirrorInfo_c * mir);
00246
00247 unsigned int reducePiece;
00248
00249 public:
00250
00251 assembler_1_c(void);
00252 ~assembler_1_c(void);
00253
00254
00255 errState createMatrix(const problem_c * puz, bool keepMirror, bool keepRotations, bool complete);
00256 void assemble(assembler_cb * callback);
00257 int getErrorsParam(void) { return errorsParam; }
00258 virtual float getFinished(void) const;
00259 virtual void stop(void) { abbort = true; }
00260 virtual bool stopped(void) const { return !running; }
00261 virtual errState setPosition(const char * string, const char * version);
00262 virtual void save(xmlWriter_c & xml) const;
00263 virtual void reduce(void);
00264 virtual unsigned int getReducePiece(void) const { return reducePiece; }
00265 void debug_step(unsigned long num = 1);
00266 assembly_c * getAssembly(void);
00267
00268 static bool canHandle(const problem_c * p);
00269
00270
00271 bool getPiecePlacementSupported(void) const { return true; }
00272 unsigned int getPiecePlacement(unsigned int node, int delta, unsigned int piece, unsigned char *tran, int *x, int *y, int *z) const;
00273 unsigned int getPiecePlacementCount(unsigned int piece) const;
00274 unsigned long getIterations(void) { return iterations; }
00275
00276 private:
00277
00278
00279 assembler_1_c(const assembler_1_c&);
00280 void operator=(const assembler_1_c&);
00281 };
00282
00283 #endif