Ejemplo n.º 1
0
BALL aiHunter(int targetcoin)
{
	vector posprev;
	vector mostfitpos;
	vector mostfitvel;
	vector distance;
	float maxfitness = 0;
	float fitness = 0;
	BALL b;
	bzero(&b,sizeof(BALL));
	b.pos.z =0;
	BALL target[4];
	int i;
	char foundOne = 0;
	ghostBall(target,targetcoin,coins,pocket);
	char goneOneWay =0;
	while(1)
	{
		for(i= 0;i<4;i++)	
		{
			b.pos.x = coins[0].pos.x;
			b.pos.y = coins[0].pos.y;
			if(target[i].pos.x == 9999 && target[i].pos.y == 9999)
			{
				continue;
			}
			b.vel = velToGhost(target[i],b.pos);
			if(modValue(b.vel) > VEL_MAX)
			{
				//printf("GOING BEYOND GAME VEL");
			}
			if(b.vel.x == 0 && b.vel.y == 0)
			{
				continue;
			}
			distance = subVector(coins[targetcoin].pos,coins[0].pos);
			fitness = dotProduct(distance,b.vel);///(modValue(distance)*modValue(b.vel));
			fitness = fitness/(modValue(distance)*modValue(b.vel)*modValue(b.vel));
			if(fitness < 0)
			{
				fitness = -1*fitness;
			}
			if(fitness > maxfitness)
			{
				maxfitness = fitness;
				foundOne = 1;
				mostfitpos.x = b.pos.x;
				mostfitpos.y = b.pos.y;
				mostfitvel.x = b.vel.x;
				mostfitvel.y = b.vel.y;
			}
		}
		posprev.x = coins[0].pos.x;
		posprev.y = coins[0].pos.y;
		if(goneOneWay == 0)
		{
			//printf("BEEN HERE AT LEAST THAT MANY TIMES\n");
			handleKeypress('l',1,1);
		}
		if(goneOneWay == 1)
		{
			//printf("BEEN HERE AT LEAST THAT HOW MANY TIMES\n");
			handleKeypress('j',1,1);
		}
		if(posprev.x == coins[0].pos.x && posprev.y == coins[0].pos.y)
		{
			if(goneOneWay == 0)
			{
				goneOneWay =1;
			}
			else
			{
				break;
			}
		}
	}
	if(foundOne == 1)
	{
		//printf("MOST FIT POS : %f %f \n",mostfitpos.x,mostfitpos.y);
		b.pos = mostfitpos;
		b.vel = mostfitvel;
	}
	return b;
}
Ejemplo n.º 2
0
/****************************************************************************
REMARKS:
Does a simple overlay buffer static video capture test. The overlay will
show what is coming in via the video capture engine.
****************************************************************************/
static int staticTest(
    GA_videoFuncs *video,
    GA_videoCaptureFuncs *capture,
    GA_captureInputTypes input,
    GA_captureStandardTypes standard,
    GA_VideoCaptureInf *captureInfo)
{
    int             key,x,y,width = DEF_WIDTH,height = DEF_HEIGHT;
    int             centerX, centerY;
    ibool           done = false,freezeInput = false,newFreezeInput = false;
    GA_captureBuf   *captureBuf = NULL;
    GA_buf          *primaryVideo = NULL;
    int             outputHead = init.GetActiveHead();
    char            str[80];

    /* Draw background for video overlay */
    SetActivePage(0);
    ClearPage(0);
    moire(defcolor);
    if (maxX >= 479)
        gmoveto(80,80);
    else
        gmoveto(8,40);
    gprintf("Video capture static test");  y += 16;
    displaymodeInfo();
    gprintf("Press any key to continue");
    if (EVT_getch() == 0x1B)
        return 0x1B;

    /* Use larger overlay window for higher resolutions */
    if (modeInfo.XResolution >= 1280) {
        width *= 2;
        height *= 2;
        }
    else if (modeInfo.XResolution <= DEF_WIDTH) {
        width /= 2;
        height /= 2;
        }

    /* Allocate the source video buffer */
    if ((captureBuf = capture->AllocCaptureBuffer(width,height,captureInfo->VideoFormat,1)) == NULL) {
        displayError("Unable to allocate video capture buffer!");
        return 0x1B;
        }
    primaryVideo = captureBuf->VideoBuffers;
    centerX = (maxX - primaryVideo->Width)/2;
    centerY = (maxY - primaryVideo->Height)/2;

    /* Set up for single buffer video overlay */
    SetActiveBuffer(primaryVideo);
    ClearVideoBuffer(primaryVideo);

    /* Set the video output window */
    x = centerX;
    y = centerY;
    if (!video->SetVideoOutput(0,outputHead,primaryVideo,
            0,0,primaryVideo->Width,primaryVideo->Height,
            x,y,primaryVideo->Width,primaryVideo->Height,0)) {
        displayError("Unable to set video output window!");
        return 0x1B;
        }

    /* Set up the video capture and start it */
    capture->SetVideoInput(captureBuf,input,standard,0,false);
    capture->StartLiveVideo(captureBuf);

    /* Now loop around and display the video capture */
    sprintf(str,"%d x %d %d bit %s overlay",primaryVideo->Width,primaryVideo->Height,
        primaryVideo->BitsPerPixel,displayFormat(primaryVideo->Format));
    if (width < DEF_WIDTH)
        WriteText(8,60,displayFormat(primaryVideo->Format),defcolor);
    else
        WriteText(8,80,str,defcolor);
    while (!done) {
        if (handleKeypress(&key,&newFreezeInput))
            break;
        if (freezeInput != newFreezeInput) {
            freezeInput = newFreezeInput;
            if (freezeInput)
                capture->FreezeLiveVideo(captureBuf,gaCaptureFieldAny);
            else
                capture->StartLiveVideo(captureBuf);
            }
        }
    SetActivePage(0);
    video->DisableVideoOutput(0);
    capture->FreeCaptureBuffer(captureBuf);
    return key;
}
Ejemplo n.º 3
0
void TerminalEmulator::keyPressed(int key, const QString &text)
{
    handleKeypress(key, text);
    update();
}