glm::vec3 Quadtree::calcRelativePoints2D(int x, int y, int screenWidth, int screenHeight) { float w = screenWidth / 2; float h = screenHeight / 2; float newX = (x - w) / w; float newY = (h - y) / h; glm::vec3 newCord(newX, newY, 0.0f); return newCord; }
boardSquare ohPlayer::nextMove() { static char directs[8][3] = { {'N'}, {'N', 'E'}, {'E'}, {'S', 'E'}, {'S'}, {'S', 'W'}, {'W'}, {'N', 'W'} }; int checkStreak=0; if (streak_length>boardSize) { //well *something* is wrong here... streak_length=0; } //char direct[2]="NW"; boardSquare bs; bool checkError=0; int x,y; int *ptr; int *ptr2; //int newxy[2]; //ptr=newxy; bool flagvar=1; char newdirect[2]; int timing_var=0; //This var will keep going up as we look for a new spot. //if it exceeds 20, assume we'll go over the time limit, and jump out. printf("direction: %s\n",direction); //Simple idea is find a possible streak, go there. while (flagvar) { checkError=0; printf("starting while loop.\n"); timing_var++; if (timing_var%20==0) { //jump out! Abort! Abort! Run out of time! while (table[bs.xx][bs.yy]!=blank) { bs.xx = rand()%boardSize; bs.yy = rand()%boardSize; } flagvar=0; break; } if (streak_length==0) { //Pick a random location. No streak as of right now. while (table[bs.xx][bs.yy]!=blank) { bs.xx = rand()%boardSize; bs.yy = rand()%boardSize; } for (int i=0; i<8; i++) { checkStreak = this->CheckDir(directs[i],bs.xx,bs.yy,0); printf("checkStreak returned: %d\n",checkStreak); if (checkStreak) { //Found something. Throw it into direction. strcpy(direction, directs[i]); //ptr=newxy; ptr=newCord(direction,bs.xx,bs.yy,checkStreak); streak_length+=checkStreak; xstreak=bs.xx; ystreak=bs.yy; bs.xx=ptr[0]; bs.yy=ptr[1]; checkError=this->ErrorCheck(bs.xx,bs.yy); if (checkError) { //well SOMETHING went wrong; streak_length=0; xstreak=-1; ystreak=-2; strcpy(direction,"NO"); flagvar=1; break; } else { flagvar=0; break; } } } } else { //We're on a streak. Go! ptr2=streakCord(direction,xstreak,ystreak,streak_length); // x=xstreak+streak_length; // y=ystreak+streak_length; x=ptr2[0]; y=ptr2[1]; printf("on streak, x: %d, y: %d, length: %d\n",x,y,streak_length); checkStreak = this->CheckDir(direction,x,y,streak_length); printf("On streak, CheckDir returned %d\n",checkStreak); if (checkStreak) { //keep going on your streak! //printf("(1) streak newx: %d, newy: %d\n",newxy[0],newxy[1]); ptr=newCord(direction,x,y,checkStreak); //printf("(2) streak newx: %d, newy: %d\n",newxy[0],newxy[1]); streak_length+=checkStreak; bs.xx=ptr[0]; bs.yy=ptr[1]; checkError=this->ErrorCheck(bs.xx,bs.yy); if (checkError) { //well SOMETHING went wrong; streak_length=0; xstreak=-1; ystreak=-2; strcpy(direction,"NO"); flagvar=1; } else { flagvar=0; break; } } else { //Try another random location, try to find a new streak. streak_length=0; xstreak=-1; ystreak=-1; strcpy(direction,"NO"); } } } table[bs.xx][bs.yy]=oh; return bs; }