001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024:
025: #include <stdio.h>
026: #include <fstream.h>
027:
028: #include "Puzzle.h"
029: #include "Piece.h"
030: #include "Solver.h"
031: #include "InventorWriter.h"
032:
033:
034:
035: #ifdef DEBUG_BIN
036:
037: void dumpPieces(Piece *pieces[])
038: {
039: ofstream iv_out;
040: iv_out.open("pieces.iv");
041:
042: iv_out << InventorWriter::header;
043:
044: for(int i=0; i<NUM_PCS; i++) {
045: iv_out << InventorWriter::indent;
046: iv_out << InventorWriter::beginGroup;
047:
048: iv_out << InventorWriter::indent;
049: iv_out << InventorWriter::indent;
050:
051: InventorWriter::writeTranslation(iv_out, 0.0,
052: i%3 * 5 * InventorWriter::baseUnit,
053: i/3 * 5 * InventorWriter::baseUnit);
054:
055:
056: (pieces[i])->writePieceAsIV(iv_out, 2, i);
057: iv_out << InventorWriter::indent;
058: iv_out << InventorWriter::endGroup;
059: }
060:
061: iv_out << InventorWriter::footer;
062: iv_out.close();
063:
064: }
065:
066:
067: void dumpRotatedPieces(Piece *pieces[])
068: {
069: ofstream iv_out;
070: char filename[128];
071:
072: for(int i=0; i<NUM_PCS; i++) {
073: sprintf(filename, "rotatedPieces-%02d.iv", i);
074: iv_out.open(filename);
075:
076: iv_out << InventorWriter::header;
077:
078: (pieces[i])->writeRotatedPiecesAsIV(iv_out, 1, i);
079:
080: iv_out << InventorWriter::footer;
081: iv_out.close();
082: }
083:
084: }
085:
086: void dumpPiecePositions(Piece *pieces[])
087: {
088: ofstream iv_out;
089: char filename[128];
090:
091:
092: int i=0;{
093: sprintf(filename, "piecePositions-%02d.iv", i);
094: iv_out.open(filename);
095:
096: iv_out << InventorWriter::header;
097:
098: (pieces[i])->writePiecePositionsAsIV(iv_out, 1, i);
099:
100: iv_out << InventorWriter::footer;
101: iv_out.close();
102: }
103:
104: }
105:
106: #endif
107:
108:
109: int main(int argc, char **argv)
110: {
111: Piece *pieces[NUM_PCS+1];
112:
113: pieces[0] = new Piece(0, Puzzle::getPieces()[0].bbox,
114: Puzzle::getPieces()[0].positions, true);
115: for(int i=1; i<NUM_PCS; i++)
116: pieces[i] = new Piece(i, Puzzle::getPieces()[i].bbox,
117: Puzzle::getPieces()[i].positions);
118:
119:
120:
121:
122: pieces[NUM_PCS] = new Piece(NUM_PCS-1, Puzzle::getPieces()[NUM_PCS-1].bbox,
123: Puzzle::getPieces()[NUM_PCS-1].positions, false, true);
124:
125: #ifdef DEBUG_BIN
126: dumpPieces(pieces);
127: dumpRotatedPieces(pieces);
128: dumpPiecePositions(pieces);
129: #endif
130:
131: if(argc>1 && *argv[1] == 'c') {
132: pieces[0]->dumpPositionInfo();
133:
134: cout << "int positionIndex[NUM_PCS+1][NUM_LO_BITS] = {" << endl;
135: for(int i=0; i<NUM_PCS+1; i++)
136: pieces[i]->dumpOuccupanceIndexInfo();
137: cout << "};" << endl;
138:
139: cout << "long long positions[NUM_PCS+1][NUM_LO_BITS][24] = {" << endl;
140: for(int i=0; i<NUM_PCS+1; i++)
141: pieces[i]->dumpOuccupanceInfo();
142: cout << "};" << endl;
143:
144:
145: cout << "int positionIndex32[NUM_PCS+1][NUM_HI_BITS] = {" << endl;
146: for(int i=0; i<NUM_PCS+1; i++)
147: pieces[i]->dumpOuccupanceIndexInfo(true);
148: cout << "};" << endl;
149:
150: cout << "int positions32[NUM_PCS+1][NUM_HI_BITS][24] = {" << endl;
151: for(int i=0; i<NUM_PCS+1; i++)
152: pieces[i]->dumpOuccupanceInfo(true);
153: cout << "};" << endl;
154:
155:
156:
157:
158: cout << "int altPositionIndex[NUM_PCS+1][NUM_LO_BITS] = {" << endl;
159: for(int i=0; i<NUM_PCS+1; i++)
160: pieces[i]->dumpOuccupanceIndexInfo();
161: cout << "};" << endl;
162:
163: cout << "long long altPositions[NUM_PCS+1][NUM_LO_BITS][24] = {" << endl;
164: for(int i=0; i<NUM_PCS+1; i++)
165: pieces[i]->dumpOuccupanceInfo();
166: cout << "};" << endl;
167:
168:
169: cout << "int altPositionIndex32[NUM_PCS+1][NUM_HI_BITS] = {" << endl;
170: for(int i=0; i<NUM_PCS+1; i++)
171: pieces[i]->dumpOuccupanceIndexInfo(true);
172: cout << "};" << endl;
173:
174: cout << "int altPositions32[NUM_PCS+1][NUM_HI_BITS][24] = {" << endl;
175: for(int i=0; i<NUM_PCS+1; i++)
176: pieces[i]->dumpOuccupanceInfo(true);
177: cout << "};" << endl;
178:
179:
180: return 0;
181: }
182:
183: for(int i=0; i<NUM_PCS; i++)
184: cout << "piece " << i << ": "
185: << pieces[i]->getNumPositions() << " possible Positions" << endl;
186:
187: Solver *solver = new Solver(pieces);
188:
189: solver->solve();
190:
191: }