int valueForPiecesPosition(BitMap * piecesPosition, int pieceType, int pieceColor, int phase){ if ( piecesPosition == NULL ) { logChess(FATAL, "The position is null."); return ERROR_NULL_POSITION; } int retValue=0; int piecesPositionFound [8]; int result=getPiecePosition(piecesPosition, pieceType, piecesPositionFound); if(result ==SUCCESS)//if not return SUCCESS the table is empty { int i; for(i=0; i < 8; i++) { if(piecesPositionFound[i] == -1 || piecesPositionFound[i] == -9) break;//exit from the loop if there's not more piece of these type int position=getRelativePosition(piecesPositionFound[i],pieceColor); retValue+=getValueForPosition(position,pieceType, phase);//here we sum every value of position for every piece } } return retValue; }
int make_mesage_to_server(BitMap* start, BitMap* end,char* msg_player){ /* * Generating the message to send to the server */ int positionStart[8]; int positionEnd[8]; int success1 = getPiecePosition(start,0,positionStart); int success2 = getPiecePosition(end,0,positionEnd); if((success1 || success2) != SUCCESS) { printf("ERROR make simple movement\n"); return ERROR_FIND_POSITION; } if((positionStart[0] || positionEnd[0]) != -9) { char * from= index_messagge[positionStart[0]]; char * doblePoint=":"; char * to=index_messagge[positionEnd[0]]; printf("From : %d, To: %d\n", positionStart[0],positionEnd[0]); strncat(msg_player,from,3); strncat(msg_player,doblePoint,1); strncat(msg_player,to,3); printf("SEND Message player: %s\n",msg_player); } else { strcpy(msg_player,"x-x:x-x"); printf("ERROR make simple movement, SEND Message player: %s\n",msg_player); return ERROR_GENERATING_MESSAGE; } return SUCCESS; }
void drawPiece(int x, int y, int thePiece, int pRot) { color_t pColor; int newX, newY; getPiecePosition( x, y, &newX, &newY ); for (int i = 0; i < PIECE_BLOCKS; i++){ for (int j = 0; j < PIECE_BLOCKS; j++){ int cTest = getBlockType(thePiece, pRot, j, i); if (cTest == 1) pColor = color_from_name("orange"); else if (cTest == 2) pColor = color_from_name("blue"); if (cTest != 0){ terminal_color(pColor); terminal_put(newX + i, newY + j, 0x2588); } } } }
int white_jake_mate(Board* actualBoard, BitMap* king_position_oponent, BitMap* mov_position_king_oponent,BitMap* mov_my_pieces){ int i=0; //king_position_oponent *king_position_oponent=actualBoard->blackPieces[King]; //______mov_position_king_oponent_________ int position[8]; int col = -1, row = -1; int generalCounter=0; Board b_aux; memcpy(&b_aux,actualBoard,sizeof(Board)); BitMap aux_bitmap = 0x8000000000000000; getPiecePosition(&(b_aux.blackPieces[King]), King, position); if ( position[0] != -9 ) { col = position[0] % 8; row = position[0] / 8; aux_bitmap >>= position[0]; moveKing(&aux_bitmap, col, row, &generalCounter, &b_aux); }
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; }