int choosePiece(state_t st, point_t p){ char player; int i; if(st->player == A) player = 'A'; else player = 'B'; while(1){ printBoard(st); printf("TURN %c : choose your piece: (ex. enter XY to chooce piece at (X, Y))\n", player); printf("you can move:"); for(i = 0; i < st->activePiece; i++) printf("(%d, %d), ", st->piece[i]->p.x, st->piece[i]->p.y); printf("\n"); choosePoint(p); if(st->bd[p->x][p->y] != st->player){ printf("the piece on (%d, %d) is not yours\n", p->x, p->y); continue; } for(i = 0; i < st->activePiece; i++){ if((st->piece[i]->p.x==p->x)&& (st->piece[i]->p.y==p->y)) break; } if(i == st->activePiece){//選んだ駒が動かせないやつだった printf("you can't move the piece on (%d, %d)\n", p->x, p->y); continue; } st->pieceToMove = st->piece[i]; break;//ここまで来たら駒の選択は終了 } return 0;//終了 }
int HeuristicPacker::bottomLeft(int width, int height, vector<Item>& items) { #ifdef BOTTOMLEFT_LOG cout << "Starting BottomLeft algorithm (" << items.size() << "):" << endl; #endif sortItems(items.begin(), items.end()); #ifdef BOTTOMLEFT_LOG cout << "Sorted Input List (" << items.size() << "):" << endl; for (size_t i = 0; i < items.size(); i++) { cout << items[i] << endl; } #endif int iteration = 0, bestSol = INF; do { #ifdef BOTTOMLEFT_COST_LOG cout << "starting iteration (" << iteration << ")" << endl; cout << "bestSol: " << bestSol << endl; #endif int currentSol = 0; vector<Point> contourPoints; Point p; vector<Item> packed; for (size_t i = 0; i < items.size(); i++) { #ifdef BOTTOMLEFT_LOG cout << "Trying to pack: " << items[i] << endl; #endif getContourPoints(width, height, items[i], packed, contourPoints); #ifdef BOTTOM_LEFT_LOG cout << "Contourpoints:" << endl; for (size_t i = 0; i < contourPoints.size(); i++) cout << contourPoints[i] << endl; #endif if (choosePoint(contourPoints, packed, items[i], p)) { #ifdef BOTTOMLEFT_LOG cout << "Selected Point: " << p << endl; #endif pack(items[i], packed, p, currentSol); } else { #ifdef BOTTOMLEFT_LOG cout << "No valid points." << endl; #endif currentSol = INF; break; } } #ifdef BOTTOMLEFT_COST_BEST if (currentSol != INF) { cout << "(" << currentSol << ")" << endl; } else { cout << "." << endl; } #endif bestSol = min(bestSol, currentSol); randomlySwap(items); if (bestSol <= height) break; } while ((++iteration) < this->_nIter); #ifdef BOTTOMLEFT_COST_LOG cout << endl << "Best solution Found:" << bestSol << endl; #endif return bestSol; }