Ejemplo n.º 1
0
void loop(){
    DEBUG(("%d", api.getTime()));
    
    api.getMyZRState(me);
	api.getOtherZRState(other);
	
	aboveOtherPos[0] = other[0];
	aboveOtherPos[1] = other[1];
	
	if (game.getMemoryFilled() != 2 /*&& game.getEnergy() >= 3*/) {
	    mathVecSubtract(vecBtwnSph, other, me, 3);
	    mathVecNormalize(vecBtwnSph, 3);
	    api.setAttitudeTarget(vecBtwnSph);
	}
	
    if ((game.getEnergy() > 3) && (game.getPicPoints() > 0) && canTakePic()) {
        game.takePic();
    }
    
    if (game.getMemoryFilled() == 2) {
        api.setAttitudeTarget(earth);
        
        if (matrixEqual(me+6, earth) && game.getEnergy() >= 3) {
            game.uploadPics();
        }
    }
    
    state = setState();
    
    if (game.getNumMirrorsHeld() > 0) game.useMirror();
    
	//bunch of states
    switch (state) {
        case 0://Get items
            DEBUG(("State 0"));
            
            if (!(sphColor)) {
                if (game.hasItem(8) == -1) {
                    moveFast(mir2);
                }
                else if (game.hasItem(4) == -1) {
                    if (game.getEnergy() > 3) moveFast(score2);
                    else api.setPositionTarget(me);
                }
            }
            
            else {
                if (game.hasItem(7) == -1) {
                    moveFast(mir1);
                }
                else if (game.hasItem(5) == -1) {
                    if (game.getEnergy() > 3) moveFast(score3);
                    else api.setPositionTarget(me);
                }
            }
            
            //Not worth it to get the other mirror
            /*else if (game.hasItem(7) == -1 && !(sphColor)) {
                moveFast(mir1);
            }
            else if (game.hasItem(8) && sphColor) {
                moveFast(mir2);
            }*/
            
            //Bottom score a waste of energy?
            /*else if (game.hasItem(3) == -1) {
                if (game.getEnergy() > 3) moveFast(score1);
                else api.setPositionTarget(me);
            }*/
            
            //Top score object
            /*else if (game.hasItem(6) == -1) {
                if (game.getEnergy() > 3) moveFast(score4);
                else api.setPositionTarget(me);
            }*/
        break;
        
        case 1://Stay at top
            DEBUG(("State 1"));
            
            if (dist(me, other) > 0.5) {
                api.setPositionTarget(aboveOtherPos);
            }
            else {
                api.setPositionTarget(me);
            }
        break;
        
        case 2://Spam upload
            DEBUG(("State 2"));
            
            if (game.getMemoryFilled() != 0 && game.getEnergy() > 2) game.uploadPics();
        break;
        
        /*case 3://Try to ram
            DEBUG(("Case 3"));
            
            moveFast(otherPos);
            
        break;*/
    }
}
Ejemplo n.º 2
0
void loop(){
    api.getMyZRState(zrstate);
    if (api.getTime()%60 == 2 && api.getTime() > 60) {
        target[0] = -0.6;
        target[1] = 0;
        target[2] = 0;
        state = 2;
    }
    if (state == 0) {
        if (canTakePic(POI,zrstate,0.8,0.42,0.31,ID)) {
            game.takePic(ID);
            target[0] = 2.5*POI[0];
            target[1] = 2.5*POI[1];
            target[2] = 2.5*POI[2];
            state = 1;
        }
        else {
            api.setPositionTarget(target);
            api.setAttitudeTarget(angle);
        }
    }
    
    if (state == 1) {
       if (canTakePic(POI,zrstate,0.4,0.53,0.42,ID)) {
            game.takePic(ID);
            target[0] = -0.6;
            target[1] = 0;
            target[2] = 0;
            state = 2;
        }
        else {
            api.setPositionTarget(target);
            api.setAttitudeTarget(angle);
        } 
    }
    
    if (state == 2) {
        if (mathVecMagnitude(zrstate,3) > 0.53) {
            game.uploadPic();
            state = 3;
        }
        api.setPositionTarget(target);
    }
    
    if (state == 3) {
        game.takePic(ID);
        if (api.getTime()%60 < 30) {
            getPOI();
            target[0] = 1.8*POI[0];
            target[1] = 1.8*POI[1];
            target[2] = 1.8*POI[2];
            state = 0;
            api.setAttitudeTarget(angle);
        }
        api.setPositionTarget(target);
        if (game.getNextFlare() == 2) {
            game.turnOff();
            game.turnOn();
        }
    }
}
Ejemplo n.º 3
0
void loop(){
	//This function is called once per second.  Use it to control the satellite.
	
	DEBUG(("%d", api.getTime()));
	
	api.getMyZRState(me);
	api.getOtherZRState(other);
	
	myPos[0] = me[0];
	myPos[1] = me[1];
	myPos[2] = me[2];
	
	otherPos[0] = other[0];
	otherPos[1] = other[1];
	otherPos[2] = other[2];
	
	//Finds the dark/gray bounds
	darkGray[0] = 0.0f;
	darkGray[1] = game.getDarkGreyBoundary() - 0.2f;
	darkGray[2] = 0.0f;
	
	//For finding the correct attitude to point to opponent
	mathVecSubtract(vecBtwnSph, otherPos, myPos, 3);
	mathVecNormalize(vecBtwnSph, 3);
	api.setAttitudeTarget(vecBtwnSph);
	
	if (canTakePic() && (game.getEnergy() > 3))
	        game.takePic();
	if (game.getMemoryFilled() == 2)
	        game.uploadPics();
	
	//This has high energy comsumption
	//if (canTakePic() && (game.getEnergy() > 3))
	//        game.takePic();
	//if (game.getMemoryFilled() != 0)
	//        game.uploadPics();
	
	//Gets mirror
	if (counter == 0) {
	    if (sphColor == 0) {
	        if (dist(myPos, mir1) > 0.01f)
	            api.setPositionTarget(mir1);
	        else {
	            counter++;
	        }
	    }
	    else {
	        if (dist(myPos, mir2) > 0.01f)
	            api.setPositionTarget(mir2);
	        else {
	            counter++;
	        }
	    }
	}
	
	//Gets energy
	if (counter == 1) {
	    if (dist(myPos, en4) > 0.01f) {
	        api.setPositionTarget(en4);
	    }
	    else {
	        counter++;
	    }
	}
	
	//Gets score
	else if (counter == 2) {
	    if (game.posInDark(myPos) && myPos[1] < 0) {
	            api.setPositionTarget(en4);
	    }
	    else {
	        if (dist (myPos, score3) > 0.01f) {
	            api.setPositionTarget(score3);
	        }
	        else {
	            counter++;
	        }
	    }
	}
	
	//Light should be on, so activate mirror and get other score item
	else if (counter == 3) {
	    if (game.posInLight(myPos)) {
	        game.useMirror();
	    }
	    
	    if (dist(myPos, score1) > 0.01f)
	        api.setPositionTarget(score1);
	    else
	        counter++;
	}
	
	//Mirror time runs out, so recede back to same side
	else if (counter == 4) {
	    if (sphColor == 0) {
	        if (dist(myPos, tempBlue) > 0.01f)
	            api.setPositionTarget(tempBlue);
	        else
	            counter++;
	    }
	    else {
	        if (dist(myPos, tempRed) > 0.01f)
	            api.setPositionTarget(tempRed);
	        else
	            counter++;
	    }
	}
	
	//Stay in place and take pics
	else if (counter == 5) {
	    if (sphColor == 0) {
	        api.setPositionTarget(tempBlue);
	    }
	    else {
	        api.setPositionTarget(tempRed);
	    }
	}
	
	
}
void loop(){
    api.getMyZRState(zrstate);
    
    if (api.getTime()%60 < 1 && api.getTime() > 20) {
        target[0] = 3*POI[0];
        target[1] = 3*POI[1];
        target[2] = 3*POI[2];
        POIS[0] = 1;
        POIS[1] = 1;
        POIS[2] = 1;
        state = 2;
    }
    
    if (state == 0) {
        if (canTakePic(POI,zrstate,0.8,0.42,0.31,ID)) {
            game.takePic(ID);
            if (game.getNextFlare() < 17 && game.getNextFlare() > -1) {
                target[0] = 4*POI[0];
                target[1] = 4*POI[1];
                target[2] = 4*POI[2];
                state = 2;
            }
            else {
                target[0] = 2.5*POI[0];
                target[1] = 2.5*POI[1];
                target[2] = 2.5*POI[2];
                state = 1;
            }
        }
        else {
            moveTo(target);
            api.setAttitudeTarget(angle);
        }
    }
    
    if (state == 1) {
       if (canTakePic(POI,zrstate,0.4,0.53,0.42,ID)) {
            game.takePic(ID);
            POIS[ID] = 0;
            target[0] = 3*POI[0];
            target[1] = 3*POI[1];
            target[2] = 3*POI[2];
            state = 2;
        }
        else {
            moveTo(target);
            api.setAttitudeTarget(angle);
        } 
    }
    
    if (state == 2) {
        if (mathVecMagnitude(zrstate,3) > 0.53) {
            game.uploadPic();
            target[0] = 2.9*POI[0];
            target[1] = 2.9*POI[1];
            target[2] = 2.9*POI[2];
            state = 3;
        }
        moveTo(target);
    }
    
    if (state == 3) {
        game.takePic(ID);
        if (api.getTime()%60 < 40) {
            ID = getClosestPOI(POI,POI0,POI1,POI2, POIS, zrstate);
            getPOI(POI,ID);
            float tmp[3];
            mathVecSubtract(tmp,zrstate,POI,3);
            if (mathVecMagnitude(tmp,3) <= 0.65) {
                target[0] = 1.8*POI[0];
                target[1] = 1.8*POI[1];
                target[2] = 1.8*POI[2];
                state = 0;
                api.setAttitudeTarget(angle);
            }
        }
        api.setPositionTarget(target);
        if (game.getNextFlare() == 2) {
            game.turnOff();
            game.turnOn();
        }
    }
}