void Maguro::run() { while (true) { switch (this->currentState) { case MaguroAction::INIT: this->moveBack(20); break; case MaguroAction::ESCAPE: moveUp ? this->moveAhead(20) : this->moveBack(20); break; case MaguroAction::FIRING: if (this->currentTimestamp() - this->lastKnownPositionTimestamp < 5.0f) { this->shotTo(this->angleBetweenGunHeadingDirectionAndWorldPosition(lastKnownPosition)); } else { this->currentState = MaguroAction::AIMING; } break; case MaguroAction::AIMING: RWSize size = this->arenaDimensions(); RWVec pos = RWVec(size.width, size.height); RWVec pos2 = RWVec(size.width, 0.0f); float angle = this->angleBetweenGunHeadingDirectionAndWorldPosition(pos) + shotCount * 2.0f; shotTo(angle); shotCount = angle > angleBetweenGunHeadingDirectionAndWorldPosition(pos2) ? 0 : shotCount + 1; break; } } }
void FoeReaper4000RobotCpp::hitWallWithSideAndAngle(RobotWallHitSide::RobotWallHitSide side, float hitAngle) { this->cancelActiveAction(); RWSize areaSize = arenaDimensions(); switch (side) { case RobotWallHitSide::FRONT: { float x = generateRandomNumber(areaSize.width/4,areaSize.width/4*3); float y = 0.0f; int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y)); randomWalk(angle,angle,150,200); } break; case RobotWallHitSide::REAR: { float x = generateRandomNumber(areaSize.width/4,areaSize.width/4*3); float y = areaSize.height; int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y)); randomWalk(angle,angle,150,200); } break; case RobotWallHitSide::LEFT: { float x = 0.0; float y = generateRandomNumber(areaSize.height/4, areaSize.height/4*3); int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y)); randomWalk(angle,angle,150,200); } break; case RobotWallHitSide::RIGHT: { float x = areaSize.width; float y = generateRandomNumber(areaSize.height/4, areaSize.height/4*3); int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y)); randomWalk(angle,angle,150,200); } break; case RobotWallHitSide::NONE: break; } }
// move the gun base on the scan //if not move to the side which has more space void FoeReaper4000RobotCpp::optimizeGunPosition() { //TODO: check if scanner find the enemy if (keepStay) { shootToPos(lastEnemyPos); return; } RWVec robotPos = position(); RWSize areaSize = arenaDimensions(); float x,y; if (robotPos.x > (areaSize.width - robotPos.x)) { x = generateRandomNumber(0.0f, robotPos.x); } else { x = generateRandomNumber(robotPos.x, areaSize.width); } if (robotPos.y > (areaSize.height - robotPos.y)) { y = generateRandomNumber(0.0f, robotPos.y); } else { y = generateRandomNumber(robotPos.y, areaSize.height); } shootToPos(RWVec(x, y)); }
void LiveRobotCpp::performNextFirstMove() { switch (this->actionIndex % 4) { case 0: { RWVec currentPosition = this->position(); RWSize arenaSize = this->arenaDimensions(); if (currentPosition.y < arenaSize.height / 2.0f) { if (currentPosition.x < arenaSize.width / 2.0f) { // bottom left this->turnRobotLeft(90); } else { // bottom right this->turnRobotRight(90); } } else { if (currentPosition.x < arenaSize.width / 2.0f) { // top left this->turnRobotRight(90); } else { // top right this->turnRobotLeft(90); } } } break; case 1: { RWVec currentPosition = this->position(); RWSize arenaSize = this->arenaDimensions(); float bodyLength = this->robotBoundingBox().size.width; if (currentPosition.y < arenaSize.height / 2.0f) { this->moveBack(currentPosition.y - bodyLength); } else { this->moveBack((arenaSize.height - (currentPosition.y + bodyLength))); } } break; case 2: { RWSize arenaSize = this->arenaDimensions(); float angle = this->angleBetweenGunHeadingDirectionAndWorldPosition(RWVec(arenaSize.width / 2.0f, arenaSize.height / 2.0f)); if (angle < 0.0f) { this->turnGunLeft(fabsf(angle)); } else { this->turnGunRight(fabsf(angle)); } } break; case 3: this->shoot(); this->setCurrentState(LiveRobotCppAction::WAITING); break; } this->actionIndex++; }