int main(int argc, char *argv[]) { const char *pcHost; int nPort; if(argc < 2) { pcHost = kDefaultServerName; } else { pcHost = argv[1]; } if(argc < 3) { nPort = kDefaultServerPort; } else { nPort = atoi(argv[2]); } cout << "Host: " << pcHost << endl; cout << "Port: " << nPort << endl; BZRC MyTeam = BZRC(pcHost, nPort, false); if(!MyTeam.GetStatus()) { cout << "Can't connect to BZRC server." << endl; while(!_kbhit()); exit(1); } // Calling agent code world_init(&MyTeam); bool exit = false; while(!exit) { robot_pre_update(); exit = !robot_update(); robot_post_update(); } MyTeam.Close(); cout << "Press any key to continue"; while(!_kbhit()); return 0; }
int main(int argc, char *argv[]) { const char *pcHost; int nPort; std::srand(std::time(0)); nextTurnSeconds = 0; nextTurnMillis = 0; nextShotSeconds = 0; nextShotMillis = 0; nextTurn = STRAIGHT; if(argc < 2) { pcHost = kDefaultServerName; } else { pcHost = argv[1]; } if(argc < 3) { nPort = kDefaultServerPort; } else { nPort = atoi(argv[2]); } BZRC MyTeam = BZRC(pcHost, nPort, false); if(!MyTeam.GetStatus()) { cout << "Can't connect to BZRC server." << endl; exit(1); } // Calling agent code world_init(&MyTeam); // Update loop while (true) { robot_pre_update(&MyTeam); robot_update(&MyTeam); robot_post_update(&MyTeam); usleep(50); } MyTeam.Close(); free(&MyTeam); return 0; }
int main(int argc, char *argv[]) { const char *pcHost; int nPort; if(argc < 2) { pcHost = kDefaultServerName; } else { pcHost = argv[1]; } if(argc < 3) { nPort = kDefaultServerPort; } else { nPort = atoi(argv[2]); } BZRC MyTeam = BZRC(pcHost, nPort, false); if(!MyTeam.GetStatus()) { cout << "Can't connect to BZRC server." << endl; exit(1); } // Calling agent code world_init(&MyTeam); dumb_agent(MyTeam); /* for(int i=1; i>0; i++) { //robot_pre_update(); //robot_update(); //robot_post_update(); //Sleep(50); MyTeam.speed(1,1.0); MyTeam.shoot(2); } */ MyTeam.Close(); //free(&MyTeam); return 0; }
void dumb_agent(BZRC MyTeam) { for(int i=1; i>0; i++) { MyTeam.speed(1,1.0); MyTeam.speed(2,1.0); MyTeam.shoot(1); MyTeam.shoot(2); sleep(5); MyTeam.speed(1,0); MyTeam.speed(2,0); MyTeam.angvel(1, 1); MyTeam.angvel(2, 1); sleep(3); MyTeam.angvel(1, 0); MyTeam.angvel(2, 0); MyTeam.shoot(1); MyTeam.shoot(1); } }
int main(int argc, char *argv[]) { const char *pcHost = "127.0.0.1"; int portpurple = 0; int portgreen = 0; int portblue = 0; int portred = 0; int option; while ((option = getopt(argc,argv,"s:p:g:b:r:")) != -1) { switch (option) { case 'p': portpurple = atoi(optarg); break; case 'g': portgreen = atoi(optarg); break; case 'b': portblue = atoi(optarg); break; case 'r': portred = atoi(optarg); break; case 's': pcHost = optarg; break; default: // // cout << "client [-s IP address] [-c port], where c is the first char of the color" << endl; exit(EXIT_FAILURE); } } BZRC* blue = NULL; BZRC* red = NULL; BZRC* purple = NULL; BZRC* green = NULL; if(portred) red = new BZRC(pcHost, portred, false); if(portpurple) purple = new BZRC(pcHost, portpurple, false); if(portblue) blue = new BZRC(pcHost, portblue, false); if(portgreen) green = new BZRC(pcHost, portgreen, false); green->speed(0,0.2); double sleepAmount = .5; RandomAgent random(0, blue, 5); random.move(); KalmanAgent kalmanGreen(0, purple, sleepAmount, 0, "green"); KalmanAgent kalmanBlue(0, purple, sleepAmount, 0, "blue"); KalmanAgent kalmanRed(0, purple, sleepAmount, 0, "red"); ofstream greenFile; ofstream redFile; ofstream blueFile; ofstream trackedFile; greenFile.open ("values-green.dat"); redFile.open ("values-red.dat"); blueFile.open ("values-blue.dat"); trackedFile.open("values.dat"); bool shoot = true; time_t currentTime; time_t prevTime; time(&prevTime); KalmanAgent trackedAgent = kalmanGreen; for (int i = 0; i < 3; i++) { //while (true){ bool stopped = false; purple->speed(0,0); random.move(); // greenFile << kalmanGreen.update(sleepAmount); // blueFile << kalmanBlue.update(sleepAmount); // redFile << kalmanRed.update(sleepAmount); trackedAgent.update(sleepAmount); Node n = trackedAgent.getPos(); // // cout << "enemy tank: " << n.x << " " << n.y << endl; // // cout << "angle to enemy: " << changeInAngle(purple,n) << endl; //while (abs(changeInAngle(purple,n)) > .005){ for (int i = 0; i < 15; ++i) { if (shoot) usleep(10000);//sleepAmount); else usleep(sleepAmount * 1000000); time(¤tTime); /* get current time; same as: timer = time(NULL) */ double seconds = difftime(currentTime,prevTime); prevTime = currentTime; random.move(); trackedAgent.update(seconds); // greenFile << kalmanGreen.update(seconds); // blueFile << kalmanBlue.update(seconds); // redFile << kalmanRed.update(seconds); if (shoot){ Node n = trackedAgent.getPos(); double a = changeInAngle(purple,n); purple->angvel(0, a*3); } n = trackedAgent.getPos(); } purple->angvel(0,0); stopped = false; if (shoot) { double shootTime = 5; trackedAgent.predict(shootTime+8); Node futurePos = trackedAgent.getPos(); // // cout << "predicted shot location: " << futurePos.x << ", " << futurePos.y << endl; time(¤tTime); /* get current time; same as: timer = time(NULL) */ while (abs(changeInAngle(purple,futurePos)) > .005){ usleep(10000);//sleepAmount); double a = changeInAngle(purple,futurePos); purple->angvel(0, a*3); } purple->angvel(0,0); time(&prevTime); double seconds = difftime(currentTime,prevTime); double timeleft = shootTime - seconds - getBulletTime(purple, futurePos); if (timeleft > 0) sleep(timeleft); // // cout << "timeleft: " << timeleft << endl; purple->shoot(0); sleep(getBulletTime(purple, futurePos)); vector<tank_t> tanks; green->get_mytanks(tanks); // // cout << "actual position (noisy): " << tanks[0].pos[0] << ", " << tanks[0].pos[1] << endl; trackedAgent.reset(); } else { break; } } for (int i = 0; i < 10; i++){ usleep(sleepAmount * 1000000); // cout << trackedAgent.predict(i*sleepAmount); // greenFile << kalmanGreen.predict(i*(sleepAmount)); // blueFile << kalmanBlue.predict(i*(sleepAmount)); // redFile << kalmanRed.predict(i*(sleepAmount)); } greenFile.close(); redFile.close(); blueFile.close(); if(purple) delete purple; if(red) delete red; if(blue) delete blue; if(green) delete green; return 0; }