Exemple #1
0
/*
* Get all possible moves for the given square.
* If the square is illegal or vacant, empty list is returned.
* Otherwise we query the square to find out which player occupies the square, and returns the possible moves for that
* player's piece.
* Input:
*		board ~ The game board.
*		x, y ~ The position on board to search for moves.
*/
LinkedList* getMovesForSquare(char board[BOARD_SIZE][BOARD_SIZE], int x, int y)
{
	LinkedList* possibleMoves = createList(deleteMove);  // <-- This list contains the results of moves available.
														 // Note we change this list in the following service functions.
	if (g_memError)
		return NULL;

	if (!isSquareOnBoard(x, y) || isSquareVacant(board, x, y))
		return possibleMoves;

	bool isMovesForBlackPlayer = isSquareOccupiedByBlackPlayer(board, x, y);

	Position kingPos = getKingPosition(board, isMovesForBlackPlayer); // Position of current player's king
	Position startPos;
	startPos.x = x;
	startPos.y = y;
	getPieceMove(board, possibleMoves, isMovesForBlackPlayer, &startPos, &kingPos);

	if (g_memError)
	{
		deleteList(possibleMoves);
		return NULL;
	}

	return possibleMoves;
}
Exemple #2
0
/* 
 * Iterates the board and returns a list of moves the player can make with each piece
 * Input:
 *		board ~ The game board.
 *		isMovesForBlackPlayer ~ True if the function returns moves for the black player.
 *							    False if the function returns moves for the white player.
 */
LinkedList* getMoves(char board[BOARD_SIZE][BOARD_SIZE], bool isMovesForBlackPlayer)
{
	LinkedList* possibleMoves = createList(deleteMove);  // <-- This list contains the results of moves available.
													     // Note we change this list in the following service functions.
	if (g_memError)
		return NULL;

	Position kingPos = getKingPosition(board, isMovesForBlackPlayer); // Position of current player's king

	int i, j; // i = row, j = column

	for (i = 0; i < BOARD_SIZE; i++)
	{
		for (j = 0; j < BOARD_SIZE; j++)
		{
			Position startPos;
			startPos.x = i;
			startPos.y = j;
			getPieceMove(board, possibleMoves, isMovesForBlackPlayer, &startPos, &kingPos);

			if (g_memError)
			{
				deleteList(possibleMoves);
				return NULL;
			}
		}
	}

	return possibleMoves;
}
PIECE Mind::getMove(int *movePositions){
    PIECE piesa;
    int ok=0,da=0;
  
    fprintf(debug_file,"se incerca generare arbore\n");
 
   // Tools::printBitBoard(joc.currentBoard.board[joc.colorEngine][1]);
  


Tools::printBitBoard(joc.currentBoard.getAllBoard());
    //fprintf(debug_file,"se cauta piesa potrivita\n");
    
  do{
      piesa=getPiece();

      if(ok>200 &&da==0)
      {piesa=getDesperateMove(movePositions);
      da=1;
      return piesa;
      }
      else
	  if (ok>205)
	      return NO_PIECE;

      ok++;
      //fprintf(debug_file,"incercari %d %d\n",ok,piesa);
      


      if(piesa!=NO_PIECE)
          piesa=getPieceMove(piesa,movePositions);


  }while(piesa==NO_PIECE);

    
    //salvam pozitiile obtinute
   

    return piesa;
}