本文整理汇总了C++中Direction::i方法的典型用法代码示例。如果您正苦于以下问题:C++ Direction::i方法的具体用法?C++ Direction::i怎么用?C++ Direction::i使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction::i方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculateClickablePieces
/** For the given board which current player is determined by 'current', calculate all pieces that are clickable.
Main rules are :
- pieces can take backwards.
- it is mandatory to play the piece that can take the maximum number of adversary pieces (can be 0).
- if there are more than one piece or the movement has several possibilities leading to this maximum number, a choice is given to the player.
- during a taking process, the player has to go through all the intermediate cell. **/
void BoardController::calculateClickablePieces(int** table, bool current) {
int maxRafle = 0;
int targetPiece = current ? BLACK_PAWN : WHITE_PAWN;
int currentPiece = current ? WHITE_PAWN : BLACK_PAWN;
int currentOtherPiece = current ? WHITE_QUEEN : BLACK_QUEEN;
QList<QPoint> possibleList;
clickablePieces = new QMap<QPoint, QList<QList<QPoint> > >();
for (int i = 0; i < MAX_COL; i++) {
for (int j = 0; j < MAX_ROW; j++) {
int rafle = 0;
if (table[i][j] == currentPiece) {
rafle = findPawnCapture(i, j, table, targetPiece); //combien de pions peut prendre ce pion.
} else if (table[i][j] == currentOtherPiece) {
rafle = findQueenCapture(i, j, Direction::UNDEFINED, table, targetPiece); //combien de pions peut prendre cette dame.
}
if (table[i][j] == currentPiece || table[i][j] == currentOtherPiece) {
if (rafle > maxRafle) { //si un pion peut prendre plus de pion qu'un autre, l'autre est oublié et seul lui compte.
possibleList.clear();
maxRafle = rafle;
possibleList << QPoint(i, j);
} else if (rafle == maxRafle) { //si un pion peut prendre autant de pion qu'un autre (dont 0), on l'ajoute à la liste des possibles.
possibleList << QPoint(i, j);
}
}
}
}
//pour tous les pions possibles, il faut calculer les coordonnées des mouvements respectifs.
foreach (QPoint point, possibleList) {
QList<QList<QPoint> > coord;
if (maxRafle > 0) { //les mouvements sont des rafles, appel des méthodes spécifiques aux pions et dames pour les coordonnées.
if (table[point.x()][point.y()] == currentPiece) {
coordMaxPawnCapture(point.x(), point.y(), table, coord, 0, maxRafle, targetPiece);
} else {
coordMaxQueenCapture(point.x(), point.y(), Direction::UNDEFINED, table, coord, 0, maxRafle, targetPiece);
}
clickablePieces->insert(point, coord);
} else { //les mouvement sont des déplacements simples.
if (table[point.x()][point.y()] == currentPiece) { //pion : acceptable = en jeu et une des deux cases voisines vide
int deltaY = current ? -1 : 1;
for (int i = -1; i <= 1; i += 2) {
if (inBounds(point.x() + i, point.y() + deltaY) && table[point.x() + i][point.y() + deltaY] == NONE) {
QList<QPoint> list;
list << QPoint(point.x() + i, point.y() + deltaY);
coord << list;
}
}
} else { //dame : acceptable = en jeu et toutes les cases des différents diagonales vides
QList<Direction> dirList = Direction::values();
for (int p = 0; p < dirList.size(); p++) {
int l = 1;
Direction dir = dirList[p];
QList<QPoint> list;
while (inBounds(point.x() + l*dir.i(), point.y() + l*dir.j()) && table[point.x() + l*dir.i()][point.y() + l*dir.j()] == NONE) {
list << QPoint(point.x() + l*dir.i(), point.y() + l*dir.j());
l++;
}
if(!list.isEmpty()) {
list.prepend(QPoint(-2, -2));
coord << list;
}
}
}
if (!coord.isEmpty()) {
clickablePieces->insert(point, coord);
}
}
}