void ghost::update_pos(pm &pac) { if(reset) {x=defx;y=defy;} int i, offset=0, flag, d[4]={1,1,1,1}, min; static short di=0; di++; if(di==4) di=0; // randomize(); if(this==&pinky) offset= 20; else if(this==&inky) offset= -20; xspeed=yspeed=0; if(doa && mode!=2) doa--; if(doa) { tx=defx; ty=defy; if(x==tx && y==ty) doa--; } else if(mode==0) { tx=pac.getposx()+offset; ty=pac.getposy()+offset; } else if(mode==1) { if(this==&blinky) tx=ty=700; if(this==&pinky) {tx=20;ty=460;} else if(this==&inky) {tx=620;ty=20;} } else if(mode==2) { tx=SCREEN_W-pac.getposx()+offset; ty=SCREEN_H-pac.getposy()+offset; } for(i=0;i<=r;i++) { if(getpixel(x-r-1,y+i)==9 || getpixel(x-r-1,y-i)==9) d[0]=0; if(getpixel(x+i,y-r-1)==9 || getpixel(x-i,y-r-1)==9) d[1]=0; if(getpixel(x+r+1,y+i)==9 || getpixel(x+r+1,y-i)==9) d[2]=0; if(getpixel(x+i,y+r+1)==9 || getpixel(x-i,y+r+1)==9) d[3]=0; } if(dir==LEFT) d[2]=0; else if(dir==UP) d[3]=0; else if(dir==RIGHT) d[0]=0; else if(dir==DOWN) d[1]=0; if(d[0]+d[1]+d[2]+d[3]==1) { if(d[0]) dir=LEFT; else if(d[1]) dir=UP; else if(d[2]) dir=RIGHT; else if(d[3]) dir=DOWN; } if(d[0]+d[1]+d[2]+d[3]>1) { // if(this==&clyde) d[random(4)]=0; if(this==&clyde) d[di]=0; if(d[0]) d[0]=dist(x-5,y,tx,ty); if(d[1]) d[1]=dist(x,y-5,tx,ty); if(d[2]) d[2]=dist(x+5,y,tx,ty); if(d[3]) d[3]=dist(x,y+5,tx,ty); min=mindist(d); switch(min) { case 0:dir=LEFT;break; case 1:dir=UP;break; case 2:dir=RIGHT;break; case 3:dir=DOWN;break; } } switch(dir) { case LEFT :xspeed=-GM_SPEED;break; case UP :yspeed=-GM_SPEED;break; case RIGHT :xspeed=GM_SPEED;break; case DOWN :yspeed=GM_SPEED;break; } x+=xspeed; y+=yspeed; if(dist(x,y,pac.getposx(),pac.getposy())<15) { if(mode==2 && !doa) { doa=1; setcolor(3); settextstyle(0,HORIZ_DIR,1); outtextxy(x,y,"200"); score+=200; delay(200); } else if(mode!=2)quit++; } if(x==-GM_SPEED && dir==LEFT) x=SCREEN_W; //values > 640 ! allowed?! else if(x==SCREEN_W-10 && dir==RIGHT) x=-10; }
void distfun(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[], T classDummy) { int status; mwSize numCoords,numPoints; char metric[4]; T *x,*d,*arg,scalarArg; /* get the metric */ status = mxGetString(prhs[1],metric,4); /* create a pointer to the input matrix y */ x = (T*)mxGetData(prhs[0]); /* get the dimensions of the matrix input y */ numCoords = mxGetM(prhs[0]); numPoints = mxGetN(prhs[0]); /* get extra arg */ if (nrhs>2 && !mxIsEmpty(prhs[2])) { if (mxGetNumberOfElements(prhs[2]) == 1) { /*scalar case */ scalarArg = (T)mxGetScalar(prhs[2]); } else if (mxGetClassID(prhs[2]) == mxGetClassID(prhs[0])) { arg = (T*)mxGetData(prhs[2]); } else { mexErrMsgIdAndTxt("stats:pdistmex:MixedInputTypes", "Additional input arguments must be the same class as X."); } } /* make sure that the distance matrix can be created, then create it. doing * this in double remains exact except in the cases where we error out anyway. */ double numDists = ((double)numPoints * (double)(numPoints-1)) / 2; if (numDists >= (double)MWSIZE_MAX) { mexErrMsgIdAndTxt("stats:pdistmex:OutputTooLarge", "Distance matrix has more elements than the maximum allowed size in MATLAB."); } plhs[0] = mxCreateNumericMatrix(1, (mwSize)numDists, mxGetClassID(prhs[0]), mxREAL); /* create a pointer to a copy of the output matrix */ d = (T*)mxGetData(plhs[0]); /* call the appropriate distance subroutine */ if (strcmp(metric,"euc") == 0) eucdist(x,numPoints,numCoords,d); else if(strcmp(metric,"seu") == 0) seudist(x,numPoints,numCoords,arg,d); else if(strcmp(metric,"cit") == 0) citdist(x,numPoints,numCoords,d); else if(strcmp(metric,"min") == 0) mindist(x,numPoints,numCoords,scalarArg,d); else if(strcmp(metric,"cos") == 0) coscordist(x,numPoints,numCoords,d); else if(strcmp(metric,"cor") == 0) coscordist(x,numPoints,numCoords,d); else if(strcmp(metric,"spe") == 0) coscordist(x,numPoints,numCoords,d); else if(strcmp(metric,"ham") == 0) hamdist(x,numPoints,numCoords,d); else if(strcmp(metric,"jac") == 0) jacdist(x,numPoints,numCoords,d); else if(strcmp(metric,"che") == 0) chedist(x,numPoints,numCoords,d); else if(strcmp(metric,"mah") == 0) mahdist(x,numPoints,numCoords,arg,d); }