Exemplo n.º 1
0
void rand_pawn(struct position MyPosition)
{
	int randomDir;
	randomDir=randomdir();
	
	switch (randomDir)
	{
		case 0:
			move_pawn(bglobal, MyPosition.colonne-1, MyPosition.ligne);
		break;
		case 2:
			move_pawn(bglobal, MyPosition.colonne+1, MyPosition.ligne);
		break;
		case 3:
			if (MyPosition.imPlayer=1)
			move_pawn(bglobal, MyPosition.colonne, MyPosition.ligne+1);
			else if (MyPosition.imPlayer=0)
				move_pawn(bglobal, MyPosition.colonne, MyPosition.ligne-1);
		break;
		case 1:
			if (MyPosition.imPlayer=1)
				move_pawn(bglobal, MyPosition.colonne, MyPosition.ligne-1);
			else if (MyPosition.imPlayer=0)
				move_pawn(bglobal, MyPosition.colonne, MyPosition.ligne+1);
		break;
		}
}
Exemplo n.º 2
0
static int
find_move(char *board)
{
    char *piece;
    int x, y;

    if ((piece = strpbrk(board, "prnbqk")) == NULL)
        return EXIT_FAILURE;

    get_coords(board, piece, &x, &y);

    switch(*piece) {
    case 'p':
        move_pawn(board, x, y);
        break;
    case 'r':
        move_rook(board, x, y);
        break;
    case 'n':
        move_knight(board, x, y);
        break;
    case 'b':
        move_bishop(board, x, y);
        break;
    case 'q':
        move_queen(board, x, y);
        break;
    case 'k':
        move_king(board, x, y);
        break;
    default:
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}