void AI::allPossibleMoves(boardState* nodeOrig, possibleMovesStruct* possibleMoves, int playerid){ vector<fakePiece> piecesOnBoard; findPiecesOnBoard(nodeOrig, piecesOnBoard); // Creates a vector of all pieces on the board with their file rank type and owner if (piecesOnBoard.size() >= 1){ for (int pos = 0; pos < piecesOnBoard.size(); pos++){ bool myPiece = false; bool skip = false; fakePiece piecetoMove; //Check if creating a new possibleMovesStruct and checking it's size returns 0 while (!myPiece && !skip){ if (pos < piecesOnBoard.size()){ piecetoMove = piecesOnBoard[pos]; } else{ if (possibleMoves->availiableMoves.size() == 0){ return; } else if (pos >= possibleMoves->availiableMoves.size()){ skip = true; return; } } if (piecetoMove.owner() == playerid){ myPiece = true; } else{ skip = true; } } if (!skip){ int typeofPiece = piecetoMove.type(); std::pair<int, int>* position = new std::pair<int, int>; position->first = piecetoMove.file(); position->second = piecetoMove.rank(); switch (piecetoMove.type()) { case 'K': moveKing(possibleMoves, position, playerid, nodeOrig); break; case 'Q': moveQueen(possibleMoves, position, playerid, nodeOrig); break; case 'B': moveBishop(possibleMoves, position, playerid, nodeOrig); break; case 'N': moveKnight(possibleMoves, position, playerid, nodeOrig); break; case 'R': moveRook(possibleMoves, position, playerid, nodeOrig); break; case 'P': movePawn(possibleMoves, position, playerid, nodeOrig); break; default: break; } delete position; } } } return; }
int menacedPiecesSingleType(Board * actualBoard, int pieceColor, int pieceType){ int piecesPosition[8], menacedValue; //Select the proper took color according to pieceColor BitMap piecesBitmap=0; if(pieceColor==BLACK) { piecesBitmap=actualBoard->blackPieces[pieceType]; } else { piecesBitmap=actualBoard->whitePieces[pieceType]; } int ppSuccess=getPiecePosition(&piecesBitmap,pieceType,piecesPosition); //Check if a table is empty return 0: cannot menace anyone! if(ppSuccess == NO_PIECES_IN_BOARD) { return 0; } if ( ppSuccess != SUCCESS ) { //logChess(WARN, "The piece position could not be retrieved."); } //for each position in the table let's calculate the menaced pieces int i; for(i=0; i<8; i++) { if((piecesPosition[i] == -9) ||( piecesPosition[i] ==- 1)) { break;//exit from the for cycle if there are no extra movement to search } else { int col = piecesPosition[i] % 8; int row = (piecesPosition[i] / 8); BitMap aux_board = 0x8000000000000000; aux_board >>= piecesPosition[i]; int generalCounter=0; Board tempBoard; memcpy(&tempBoard,actualBoard, sizeof(Board)); switch (pieceType) { case King: moveKing(&aux_board, col, row, &generalCounter, &tempBoard); break; case Queens: moveQueen(&aux_board, col, row, &generalCounter, &tempBoard); break; case Rooks: moveRook(&aux_board, col, row, &generalCounter, &tempBoard); break; case Bishops: moveBishop(&aux_board, col, row, &generalCounter, &tempBoard); break; case Knights: moveKnight(&aux_board, col, row, &generalCounter, &tempBoard); break; case Pawns: movePawn(&aux_board, col, row, &generalCounter, &tempBoard); break; default: logChess(WARN, "Incorrect piece type."); break; } int j; for(j=0; j<MAX_NUM_MOVES; j++) { if((tempBoard.boardState[j].killedTypePiece > -1) && (tempBoard.boardState[j].killedTypePiece < 6)) { menacedValue+=menacedHeuristicValue[tempBoard.boardState[j].killedTypePiece]; } else break; } } } return menacedValue; }
int findMoves(char pieceID,int currentPosition[2],char board[12][12],int moveList[1000][6]) { //Returns which piece is occupying a given square and all the possible moves for that piece switch(pieceID) { case 'o': break; case 'x': break; case 'P': printf("This is a white pawn, and these are it's possible moves: \n"); movePawn(currentPosition,board,moveList); break; case 'p': printf("This is a black pawn and these are it's possible moves: \n"); movePawn(currentPosition,board,moveList); break; case 'R': printf("This is a white rook and these are it's possible moves: \n"); moveRook(currentPosition,board,moveList); break; case 'r': printf("This is a black rook and these are it's possible moves: \n"); moveRook(currentPosition,board,moveList); break; case 'N': printf("This is a white knight and these are it's possible moves: \n"); moveKnight(currentPosition,board); break; case 'n': printf("This is a black knight and these are it's possible moves: \n"); moveKnight(currentPosition,board); break; case 'B': printf("This is a white bishop and these are it's possible moves: \n"); moveBishop(currentPosition,board,moveList); break; case 'b': printf("This is a black bishop and these are it's possible moves: \n"); moveBishop(currentPosition,board,moveList); break; case 'Q': printf("This is a white queen and these are it's possible moves: \n"); moveQueen(currentPosition,board); break; case 'q': printf("This is a black queen and these are it's possible moves: \n"); moveQueen(currentPosition,board); break; case 'A': printf("This is a white king and these are it's possible moves: \n"); moveKing(currentPosition,board); break; case 'a': printf("This is a black king and these are it's possible moves: \n"); moveKing(currentPosition,board); break; } return pieceID; }