void Shoot::pointSelector()
{
    Point thisPoint;

    float lineValue;
    float highestValue = 0;
    float i;
    float dis2Point = 9999;

    if (whichGoal == 'o')
    {
        thisPoint.x = pWorldData->oppPole1.getX();
    }
    if (whichGoal == 't')
    {
        thisPoint.x = pWorldData->ourPole1.getX();
    }

    selectedPoint = (0,0);

    reachPoints();

    //this is for checking that there is actually a selected points :
    if (firstReachablePoint.getX() == 0 && lastReachablePoint.getX() == 0)
    {
        selectedPoint.x = 0;
        selectedPoint.y = 0;
        can_i_shoot = false;
    }
    else
    {
        for (i = firstReachablePoint.getY(); i >= lastReachablePoint.getY(); i -= 3)
        {
            thisPoint.y = i;

            lineValue = getLineValue(ballPos, thisPoint);
             
            if (lineValue == 100 && ballPos.getDistance(thisPoint) < dis2Point)
            {
                selectedPoint = thisPoint;
                dis2Point = ballPos.getDistance(thisPoint);
                highestValue = 100;
            }
            if (lineValue > highestValue)
            {
                highestValue = lineValue;
                selectedPoint = thisPoint;
            }
        }
    }
    if (selectedPoint == (0 ,0))
        can_i_shoot = false ;
    else if (getLineValue(ballPos, selectedPoint) == 0)
        can_i_shoot = false;
    else
        can_i_shoot = true;
}
float Shoot::shootLastValue()
{
    if (can_i_shoot == 1)
        return getLineValue(ballPos, selectedPoint);
    else
        return 0;
}
Beispiel #3
0
float Pass::passLastValue()
{
    if (bestTeammate != -1)
    {
        return getLineValue(ballPos, pWorldData->basedCenter(pWorldData->teammate(bestTeammate)));
    }
    else
    {
        return 0;
    }
}
int main() {
    init(0);
    int count = 0;
    int proportional_signal = 1;
    while (count < 2000) {
        proportional_signal = getLineValue();
    if (proportional_signal < 0) {

		
		rightMotor = (50 - (proportional_signal / (160)) * 175); 
		leftSpeed = (50 + (proportional_signal / (160)) * 175);
	}

	else if (proportional_signal > 0) { 

		
		rightMotor = (50 - (proportional_signal / (160)) * 175);
		leftMotor = (50 + (proportional_signal / (160)) * 175); 
	}

	else {

	
		leftMotor = -80;
		rightMotor = -80;
	}
        		
		printf("%d\n", leftMotor);
		printf("%d\n", rightMotor);

		set_motor(1, leftMotor);
		set_motor(2, rightMotor);
        count++;
    }
    return 0;
}
Beispiel #5
0
void Pass::bestTeammateSelector()
{
    float maxValue = 0;
    //float zaribNextStep = 1;
    float zaribLineValue = 1;
    float thisValue;
    //163 = kick dist with power 1 and 35 = teammate kickable radius
    float passReachableDist = 163.927 + 35;
    float safeValue = 100;
    float maxDistFromGoal = 0;

    vector <int> tmms = pWorldData->mr_found_teammates();

    Point thisTeammate;
    Point ourGoal;

    ourGoal.x = pWorldData->ourPole1.getX();
    ourGoal.y = (pWorldData->ourPole1.getY() + pWorldData->ourPole2.getY()) / 2;

    bestTeammate = -1;

    for (int i = 0; i < tmms.size(); i++)
    {
        if (tmms[i] != callerUid)
        {
            thisTeammate = pWorldData->tmmPositions[i];

            if (ballPos.getDistance(thisTeammate) > passReachableDist)
            {
                thisValue = 0;
            }
            else
            {
                thisValue = zaribLineValue * getLineValue(ballPos, thisTeammate);

                if (thisValue == safeValue * zaribLineValue && ourGoal.getDistance(thisTeammate) > maxDistFromGoal)
                {
                    bestTeammate = tmms[i];
                    maxValue = thisValue;
                    maxDistFromGoal = ourGoal.getDistance(thisTeammate);
                }

                else if (thisValue > maxValue && getLineValue(ballPos, thisTeammate) != 0)
                {
                    maxValue = thisValue;
                    bestTeammate = tmms[i];
                }
            }
        }
    }

    //if we call the pass for another uid it won't check myID (for passing) so we have to do it by ourself
    if (callerUid != pWorldData->my_id())
    {
        thisTeammate.x = pWorldData->me(true).getX();
        thisTeammate.y = pWorldData->me(true).getY();
        if (ballPos.getDistance(thisTeammate) > passReachableDist)
        {
            thisValue = 0;
        }
        else
        {
            thisValue = zaribLineValue * getLineValue(ballPos, thisTeammate);

            if (thisValue == safeValue * zaribLineValue && ourGoal.getDistance(thisTeammate) > maxDistFromGoal)
            {
                bestTeammate = pWorldData->my_id();
                maxDistFromGoal = ourGoal.getDistance(thisTeammate);
            }

            else if (thisValue > maxValue && getLineValue(ballPos, thisTeammate) != 0)
            {
                maxValue = thisValue;
                bestTeammate = pWorldData->my_id();
            }
        }
    }
}