MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // Brush QBrush backgroundBrush(Qt::cyan, Qt::Dense6Pattern); // Scene and View scene = new QGraphicsScene(this); view = new myView(scene); view->setParent(this); view->setBackgroundBrush(backgroundBrush); view->display = new GUI; view->display->scene = scene; view->display->setPos(view->gameManager.board.currentPos); ui->layout->addWidget(view); view->show(); // Label Font QFont f( "Helvetica Neue", 16); ui->strengthLabel->setFont(f); ui->toPlayLabel->setFont(f); updateToPlayLabel(); // Search Thread search = new searchThread(); search->view = view; connect(view, SIGNAL(moveSearch()), this, SLOT(moveSearch())); connect(view, SIGNAL(updateToPlayLabel()), this, SLOT(updateToPlayLabel())); connect(search, SIGNAL(finished()), this, SLOT(finishSearch())); searchLeftTimer = new QTimer(this); searchLeftTimer->setInterval(1000); connect(searchLeftTimer, SIGNAL(timeout()), this, SLOT(updateSearchLeft()) ); // New Game Pop Up newGamePU = new newGamePopUp(this); connect(newGamePU, SIGNAL(colorChosen(int)), this, SLOT(getColorChoice(int))); view->ready = 1; }
void MainWindow::on_MoveButton_clicked() { if (!view->ready) return; moveSearch(); }
void CamControl::search(HeadMotor &hm) { if(!hm.ismoving_motor()) moveSearch(hm, 65,65); }
void xboardLoop(Position *pos) { int version = 1; int player = 2; //don't make moves setbuf(stdout, NULL); while (1) { char *line; char *word; line = readLine(); word = strtok(line, " "); if (strcmp(word, "xboard") == 0) { ; //no action required } else if (strcmp(word, "protover") == 0) { int i; word = strtok(NULL, " "); version = atol(word); for (i = 0; i < n_features; ++i) { if (features[i].s_value) { printf("feature %s=\"%s\"\n", features[i].name, features[i].s_value); } else { printf("feature %s=%d\n", features[i].name, features[i].i_value); } } printf("feature done=1\n"); } else if (strcmp(word, "accepted") == 0) { int i; word = strtok(NULL, " "); for (i = 0; i < n_features; ++i) { if (strcmp(word, features[i].name) == 0) { features[i].accepted = 1; } } } else if (strcmp(word, "rejected") == 0) { int i; word = strtok(NULL, " "); for (i = 0; i < n_features; ++i) { if (strcmp(word, features[i].name) == 0) { features[i].accepted = 0; } } } else if (strcmp(word, "new") == 0) { initPosition(pos); player = 1; } else if (strcmp(word, "variant") == 0) { //uh oh, variants not supported yet exit(1); } else if (strcmp(word, "quit") == 0) { exit(0); } else if (strcmp(word, "random") == 0) { ;//not supported, nop for the time being } else if (strcmp(word, "force") == 0) { player = 2; //no player } else if (strcmp(word, "go") == 0) { player = pos->ply % 2; } else if (strcmp(word, "playother") == 0) { player = 1 - (pos->ply % 2); } else if (strcmp(word, "level") == 0) { //TODO: add time controls ; } else if (strcmp(word, "st") == 0) { ; } else if (strcmp(word, "sd") == 0) { //TODO: set depth ; } else { int move; move = fromAlg(pos, word); if (move < -1) { printf("Illegal move: %s\n", word); } else if (move > 0) { makeMove(pos, move); } } if (player == pos->ply % 2) { char moveStr[21]; int move, score; move = moveSearch(pos, SEARCH_DEPTH, &score); toAlg(pos, move, moveStr); makeMove(pos, move); printf("move %s\n", moveStr); } } }
//Refer findBall.mm in Dropbox/ for flowchart //TODO: prev_ballx is compared with 320. Replace it by image-width/2 if possible, also same thing in rest of code //TODO: there are constant 4 passes for finding ball. Replace by default variable possibly? BallReturns CamControl::findBall(FeatureDetection &fd, HeadMotor &hm) // new findball function { if(fd.ballFound()==true) // function to return ball coordinates if found { prev_img_flag=1; // flag to check whether prev img has ball in it or not. to be used ltr. prev_ballx=fd.ballX(); prev_bally=fd.ballY(); float ballx_center=fd.ballX()-(IMAGE_WIDTH/2); float bally_center=fd.ballY()-(IMAGE_HEIGHT/2); if(inCentreRect(fd.ballX(), fd.ballY(), CENTRE_RECT_X1, CENTRE_RECT_Y1, CENTRE_RECT_X2, CENTRE_RECT_Y2)) // function which checks whether ball in centre or not { //ball is found and it is in centre pass_counter=0; prev_img_flag = 0; return BALLFOUND; //distance and angle stored in ball.r and ball.theta } else // if ball not in centre { switch(moveToPoint(fd.ballX(), fd.ballY(), hm)) /*function which controls motor movements and Returns 0 on success. -2: can't move along x, -4: unable to read, -10: turn left, -20: turn right*/ { case 0: case -2: case -4: return BALLFINDING; case -10: return TURNLEFT; case -20: return TURNRIGHT; } } } else // if ball not found { if(prev_img_flag==1)// if ball in prev img then w'll move motors accordingly... { prev_img_flag=0; if(prev_ballx>(IMAGE_WIDTH/2))//for turning right { state_of_motion = 0; } else//for turning left { state_of_motion = 1; } moveSearch(hm, 30, 70); } else// ball not in prev. img either.... { if(!hm.ismoving_motor(18))//if motor is not moving { moveSearch(hm, 30, 70); pass_counter++; if(pass_counter>1) { pass_counter=0; return TURNRIGHT; } } //hm.read_motor(thetaX, thetaY); } return BALLFINDING; } }