diff --git a/config/settings.ini b/config/settings.ini index 9bc3f3c..7b59cef 100644 --- a/config/settings.ini +++ b/config/settings.ini @@ -3,12 +3,12 @@ [Game] Mode=Real;Simulation; [Team] -Color =Yellow;Blue; +Color =Blue;Yellow; Side =Left;Right; [Field] Size = Double;Single; [Transmitter] -SerialPort = /dev/ttyUSB1 +SerialPort = /dev/ttyUSB0 [VisionConfig] UsingCameras = 7;CAMERA_NONE = 0, CAMERA_0 = 1, CAMERA_1 = 2, CAMERA_2 = 3, CAMERA_3 = 4, CAMERA_BOTH_L = 5,CAMERA_BOTH_R = 6,CAMERA_ALL = 7 diff --git a/src/ai/mapsearchnode.cpp b/src/ai/mapsearchnode.cpp index 9c87661..9d64cdc 100644 --- a/src/ai/mapsearchnode.cpp +++ b/src/ai/mapsearchnode.cpp @@ -147,7 +147,7 @@ QList MapSearchNode::getObsCircle() { QList result; - double b_rad = ROBOT_RADIUS + 2*BALL_RADIUS; + double b_rad = ROBOT_RADIUS + 2*BALL_RADIUS;//20 double r_rad = ROBOT_RADIUS * 2; diff --git a/src/ai/play/playgameon.cpp b/src/ai/play/playgameon.cpp index e573966..e4c181c 100644 --- a/src/ai/play/playgameon.cpp +++ b/src/ai/play/playgameon.cpp @@ -445,7 +445,7 @@ void PlayGameOn::coach() } tGolie->setIdlePosition(goaliePos); - + wm->debug_pos.append(goaliePos.loc);//test game_status = wm->kn->gameStatus(game_status); int ballOwner = findBallOwner(); diff --git a/src/ai/play/playstop.cpp b/src/ai/play/playstop.cpp index af9b77c..9b94580 100644 --- a/src/ai/play/playstop.cpp +++ b/src/ai/play/playstop.cpp @@ -3,14 +3,14 @@ PlayStop::PlayStop(WorldModel *worldmodel, QObject *parent) : Play("PlayStop", worldmodel, parent) { - tGolie=new TacticGoalie(wm); - - tDefenderLeft=new TacticDefender(wm); - tDefenderRight=new TacticDefender(wm); - - tStopMid=new TacticStop(wm); - tStopLeft=new TacticStop(wm); - tStopRight=new TacticStop(wm); + tGoalie = new TacticGoalie(wm); + tDefenderLeft = new TacticDefender(wm); + tDefenderRight = new TacticDefender(wm); + tStopMid = new TacticStop(wm); + tStopLeft = new TacticStop(wm); + tStopRight = new TacticStop(wm); + tAttackerLeft = new TacticAttacker(wm); + tAttackerRight = new TacticAttacker(wm); leftChecker = 0; rightChecker = 0; @@ -27,63 +27,38 @@ int PlayStop::enterCondition() // return 20000; } -bool PlayStop::collisionwithDefenders(Vector2D center, Vector2D left, Vector2D right) -{ - if( ((center-wm->ourRobot[tDefenderLeft->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - || - ((left-wm->ourRobot[tDefenderLeft->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - || - ((right-wm->ourRobot[tDefenderLeft->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - || - ((center-wm->ourRobot[tDefenderRight->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - || - ((left-wm->ourRobot[tDefenderRight->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - || - ((right-wm->ourRobot[tDefenderRight->getID()].pos.loc).length() < 2*ROBOT_RADIUS) - ) - return true; - - return false; -} - -bool PlayStop::oneOfDefendersIsInPenalty(Vector2D leftPos, Vector2D midPos, Vector2D rightPos) -{ - if( wm->kn->IsInsideGolieArea(leftPos) || wm->kn->IsInsideGolieArea(midPos) || wm->kn->IsInsideGolieArea(rightPos)) - return true; - - return false; -} - void PlayStop::initRole() { - QList activeAgents=wm->kn->ActiveAgents(); - activeAgents.removeOne(wm->ref_goalie_our); + QList actives = wm->kn->ActiveAgents(); + actives.removeOne(wm->ref_goalie_our); wm->ourRobot[wm->ref_goalie_our].Role = AgentRole::Golie; - switch (activeAgents.length()) { + switch (actives.length()) { case 1: - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; break; case 2: - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderRight; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; break; case 3: - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderRight; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderLeft; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; break; case 4: - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderRight; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderLeft; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerLeft; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; break; case 5: - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderRight; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::DefenderLeft; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerMid; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerLeft; - wm->ourRobot[activeAgents.takeFirst()].Role = AgentRole::AttackerRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerRight; + break; + default: break; } } @@ -94,7 +69,7 @@ void PlayStop::setTactics(int index) switch (wm->ourRobot[index].Role) { case AgentRole::Golie: - tactics[index] = tGolie; + tactics[index] = tGoalie; break; case AgentRole::DefenderLeft: tactics[index] = tDefenderLeft; @@ -181,117 +156,113 @@ void PlayStop::setPositions() rightChecker = 0; } - tGolie->setIdlePosition(goaliePos); + tGoalie->setIdlePosition(goaliePos); - if(wm->kn->IsInsideGolieArea(wm->ball.pos.loc) ) - { - tStopLeft->setStopPosition(Vector2D(Field::MinX/2.0,Field::ourGoalPost_L.y+200)); - tStopRight->setStopPosition(Vector2D(Field::MinX/2.0,Field::ourGoalPost_R.y-200)); - tStopMid->setStopPosition(Vector2D(Field::MinX/2.0,Field::ourGoalCenter.y)); - } - else if( wm->kn->IsInsideNearArea(wm->ball.pos.loc) ) + if (wm->kn->IsInsideGolieArea(wm->ball.pos.loc)) { - Vector2D candidateL_1, candidateL_2, mainL; - - Circle2D cir_l(Field::defenceLineLinear_L,Field::goalCircle_R+ROBOT_RADIUS); - Line2D thirty_l(Field::defenceLineLinear_L,AngleDeg(30)); - cir_l.intersection(thirty_l,&candidateL_1,&candidateL_2); - if( wm->kn->IsInsideField(candidateL_1) && !wm->kn->IsInsideGolieArea(candidateL_1) ) - mainL = candidateL_1; - else - mainL = candidateL_2; - - tStopLeft->setStopPosition(Vector2D(mainL.x,sign(wm->ball.pos.loc.y)*mainL.y)); - tStopMid->setStopPosition(Vector2D(Field::MinX+300,-sign(wm->ball.pos.loc.y)*1400)); - tStopRight->setStopPosition(Vector2D(mainL.x,-sign(wm->ball.pos.loc.y)*mainL.y)); + tStopMid->setStopPosition({Field::ourGoalCenter.x + 2250, 0}); + tStopLeft->setStopPosition({Field::ourGoalCenter.x + 2250, 1250}); + tStopRight->setStopPosition({Field::ourGoalCenter.x + 2250, -1250}); } - else + else if (wm->ball.pos.loc.x < Field::ourGoalCenter.x + (Field::MaxX * 2) / 3) { - Vector2D finalPos,notImportant,leftPos,rightPos; - - Circle2D robotCircle(wm->ball.pos.loc,ALLOW_NEAR_BALL_RANGE); - Segment2D line2Goal(wm->ball.pos.loc,Field::ourGoalCenter); - robotCircle.intersection(line2Goal,&finalPos,¬Important); - - Circle2D secondCircle(finalPos,(2.5)*ROBOT_RADIUS); - robotCircle.intersection(secondCircle,&leftPos,&rightPos); - - if( !wm->kn->IsInsideField(leftPos) ) + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + + Circle2D goalieCir (Field::ourGoalCenter, 1300); + Line2D linetest (Field::ourGoalCenter, wm->ball.pos.loc); + if (wm->kn->IsInsideGolieArea(fdot)) { - leftPos = finalPos; - finalPos = rightPos; - - Vector2D leftPos2,rightPos2; - Circle2D secondCircle(finalPos,(2.5)*ROBOT_RADIUS); - robotCircle.intersection(secondCircle,&leftPos2,&rightPos2); - - if( leftPos.dist(leftPos2) < leftPos.dist(rightPos2) ) - rightPos = rightPos2; - else - rightPos = leftPos2; - + goalieCir.intersection(linetest, &fdot, &sdot); + if (fdot.x < sdot.x) + fdot = sdot; } - else if( !wm->kn->IsInsideField(rightPos) ) - { - rightPos = finalPos; - finalPos = leftPos; - Vector2D leftPos2,rightPos2; - Circle2D secondCircle(finalPos,(2.5)*ROBOT_RADIUS); - robotCircle.intersection(secondCircle,&leftPos2,&rightPos2); + tStopMid->setStopPosition(fdot); - if( rightPos.dist(leftPos2) < rightPos.dist(rightPos2) ) - leftPos = rightPos2; - else - leftPos = leftPos2; - } + tactics[tStopLeft->getID()] = tAttackerLeft; + tactics[tStopRight->getID()] = tAttackerRight; - if( collisionwithDefenders(finalPos,leftPos,rightPos) || oneOfDefendersIsInPenalty(leftPos,finalPos,rightPos) ) + Marking def; + def.setWorldModel(wm); //?? + bool isMatched; + QList opp = wm->kn->ActiveOppAgents(); + QList our; + our.append(tAttackerLeft->getID()); + our.append(tAttackerRight->getID()); + QList m2m = def.findMarking(our , opp, isMatched); + if (isMatched) { - if( wm->kn->IsInsideRect(wm->ball.pos.loc,Vector2D(Field::MinX,Field::MaxY),Vector2D(0,0.25*Field::MaxY)) - || - wm->kn->IsInsideRect(wm->ball.pos.loc,Vector2D(Field::MinX,0.25*Field::MinY),Vector2D(0,Field::MinY)) ) + for (int i = 0; i < m2m.size(); i++) { - Vector2D candidateL_1, candidateL_2, mainL; - - Circle2D cir_l(Field::defenceLineLinear_L,Field::goalCircle_R+ROBOT_RADIUS); - Line2D thirty_l(Field::defenceLineLinear_L,AngleDeg(30)); - cir_l.intersection(thirty_l,&candidateL_1,&candidateL_2); - if( wm->kn->IsInsideField(candidateL_1) && !wm->kn->IsInsideGolieArea(candidateL_1) ) - mainL = candidateL_1; - else - mainL = candidateL_2; - - tStopLeft->setStopPosition(Vector2D(mainL.x,sign(wm->ball.pos.loc.y)*mainL.y)); - tStopMid->setStopPosition(Vector2D(Field::ourPenaltySpot.x+200,Field::ourPenaltySpot.y)); - tStopRight->setStopPosition(Vector2D(mainL.x,-sign(wm->ball.pos.loc.y)*mainL.y)); - } - else - { - //tStopLeft->setStopPosition(Vector2D(wm->ourRobot[tDefenderLeft->getID()].pos.loc.x - // , wm->ourRobot[tDefenderLeft->getID()].pos.loc.y+5*ROBOT_RADIUS)); - finalPos = Vector2D(wm->ourRobot[tDefenderLeft->getID()].pos.loc.x, - 0.5*(wm->ourRobot[tDefenderLeft->getID()].pos.loc.y+wm->ourRobot[tDefenderRight->getID()].pos.loc.y) - ); - tStopLeft->setStopPosition(Vector2D(finalPos.x,finalPos.y+4.5*ROBOT_RADIUS)); - tStopMid->setStopPosition(Vector2D(finalPos.x,finalPos.y-6.5*ROBOT_RADIUS)); - tStopRight->setStopPosition(Vector2D(finalPos.x,finalPos.y-4.5*ROBOT_RADIUS)); + wm->ourRobot[m2m.at(i).ourI].Status = AgentStatus::BlockingRobot; + + switch (wm->ourRobot[m2m.at(i).ourI].Role) { + case AgentRole::DefenderLeft: + tDefenderLeft->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::DefenderRight: + tDefenderRight->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::AttackerLeft: + tAttackerLeft->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::AttackerRight: + tAttackerRight->setPlayerToKeep(m2m.at(i).oppI); + break; + default: + break; + } } } - else - { - tStopLeft->setStopPosition(leftPos); - tStopMid->setStopPosition(finalPos); - tStopRight->setStopPosition(rightPos); - } + } + else if (wm->ball.pos.loc.x < Field::ourGoalCenter.x + (Field::MaxX * 2)* 2 / 3) + { + Vector2D fPosAttMid, fPosAttLeft, fPosAttRight, sec; + double slope, degree, deltaa; + slope = (wm->ball.pos.loc.y - Field::ourGoalCenter.y) / (wm->ball.pos.loc.x - Field::ourGoalCenter.x); + degree = atan(slope); + deltaa = 2 * asin( ROBOT_RADIUS / ALLOW_NEAR_BALL_RANGE ); + AngleDeg deg(degree * 57.32), delta(deltaa * 57.32); + AngleDeg leftAttDeg, rightAttDeg; + leftAttDeg = operator -(deg, delta); + rightAttDeg = operator +(deg, delta); + Line2D leftAttLine(wm->ball.pos.loc, leftAttDeg.degree() - 1.5); + Line2D rightAttLine(wm->ball.pos.loc, rightAttDeg.degree() + 1.5); + Circle2D cir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + cir.intersection(leftAttLine, &fPosAttLeft, &sec); + if (sec.x < fPosAttLeft.x) + fPosAttLeft = sec; + cir.intersection(rightAttLine, &fPosAttRight, &sec); + if (sec.x < fPosAttRight.x) + fPosAttRight = sec; + + tStopLeft->setStopPosition(fPosAttLeft); + tStopRight->setStopPosition(fPosAttRight); + + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + tStopMid->setStopPosition(fdot); + } + else if (Field::ourGoalCenter.x + (Field::MaxX * 2)* 2 / 3 < wm->ball.pos.loc.x) + { + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + tStopMid->setStopPosition(fdot); + + tStopLeft->setStopPosition({wm->ball.pos.loc.x - 2250, 1250}); + tStopRight->setStopPosition({wm->ball.pos.loc.x - 2250, -1250}); } } void PlayStop::execute() { - wm->passPoints.clear(); - wm->debug_pos.clear(); - QList activeAgents=wm->kn->ActiveAgents(); for(int i=0;isetpos( Vector2D(1000,1000) ); + tactics[1] = tTest1; + tTest2->setpos( Vector2D(1500,1000) ); + tactics[2] = tTest2; + tTest3->setpos( Vector2D(2000,1000) ); + tactics[3] = tTest3; + */ + + /* + Segment2D line (Field::ourGoalCenter , wm->ball.pos.loc); + Circle2D cir (wm->ball.pos.loc , 500); + Vector2D first, second; + cir.intersection(line, &first, &second); + + tTest1->setpos(first); + tactics[1] = tTest1; + */ + + /* + Segment2D line (Field::ourGoalCenter , wm->oppRobot[1].pos.loc); + Circle2D cir (wm->oppRobot[1].pos.loc , 500); + Vector2D first, second; + cir.intersection(line, &first, &second); + + tTest1->setpos(first); + tactics[1] = tTest1; + */ + + /* + double minDTB = 50000; + int minDTBid; + for (int i = 0; i < 5; i++) + { + Segment2D dToBall (wm->oppRobot[i+1].pos.loc, wm->ball.pos.loc); + if (dToBall.length() < minDTB) + { + minDTB = dToBall.length(); + minDTBid = i+1; + } + } + double minD = 50000; + int minDid; + for (int i = 0; i < 3; i++) + { + Segment2D dToLoc (wm->ourRobot[i+1].pos.loc, wm->oppRobot[minDTBid].pos.loc); + if (dToLoc.length() < minD) + { + minD = dToLoc.length(); + minDid = i+1; + } + } + + tTest1->setidtest(minDTBid); + tactics[minDid] = tTest1; + + double dOpp[5][5]; + for (int i = 0; i < 5; i++) + for (int j = 0; j < 5; j++) + { + Segment2D seg (wm->oppRobot[i+1].pos.loc, wm->oppRobot[j+1].pos.loc); + dOpp[i][j] = seg.length(); + } + int n[2][2] = {0, 0, 0, 0}; + double minDis = 50000; + for (int i = 0; i < 5; i++) + for (int j = 0; j < 5; j++) + if ( i+1 != minDTBid && j+1 !=minDTBid && i != j ) + if (dOpp[i][j] < minDis) + { + minDis = dOpp[i][j]; + n[0][0] = i + 1; + n[0][1] = j + 1; + } + for (int i = 1; i <= 5; i++) + if (i != minDTBid && i != n[0][0] && i != n[0][1]) + n[1][0] = i; + n[1][1] = 15 - (minDTBid + n[0][0] + n[0][1] + n[1][0]); + + std::cout << minDTBid << std::endl; + std::cout << n[0][0] << "::" << n[0][1] << std::endl + << n[1][0] << "::" << n[1][1] << std::endl; + + int a[2]; + for (int i = 0; i < 2; i++) + { + Segment2D seg0 (Field::ourGoalCenter, wm->oppRobot[ n[i][0] ].pos.loc); + Segment2D seg1 (Field::ourGoalCenter, wm->oppRobot[ n[i][1] ].pos.loc); + if (seg0.length() < seg1.length()) + a[i] = n[i][0]; + else + a[i] = n[i][1]; + } + + int b[2]; + for (int i = 1; i <= 3; i++) + if (i != minDid) + b[0] = i; + b[1] = 6 - (minDid + b[0]); + + Segment2D seg2 (wm->ourRobot[ b[0] ].pos.loc, wm->oppRobot[ a[0] ].pos.loc); + Segment2D seg3 (wm->ourRobot[ b[1] ].pos.loc, wm->oppRobot[ a[0] ].pos.loc); + if (seg2.length() < seg3.length()) + { + tTest2->setidtest(a[0]); + tactics[b[0]] = tTest2; + tTest3->setidtest(a[1]); + tactics[b[1]] = tTest3; + } + else + { + tTest2->setidtest(a[0]); + tactics[b[1]] = tTest2; + tTest3->setidtest(a[1]); + tactics[b[0]] = tTest3; + } + + */ + + /* + //Project 1 + + Vector2D dot; + Segment2D seg(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + //std::cout << seg.length() << std::endl; + + Line2D line1(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + Line2D line2(Field::ourGoalCenter, Field::ourGoalPost_R); + dot = line1.intersection(line2); + + if ( seg.length() < 5 || abs(dot.y - Field::ourGoalCenter.y) > abs(Field::ourGoalPost_L.y - Field::ourGoalCenter.y) ) + { + dot = Field::ourGoalCenter; + } + + tTest1->setpos(dot); + tactics[0] = tTest1; + + //Step2 + + double slope1[2], slope2[2]; + Vector2D dot1 = Field::ourGoalCenter, dot2 = Field::ourGoalCenter; + dot1.y += ROBOT_RADIUS; + slope1[0] = (wm->ball.pos.loc.y - dot1.y) / (wm->ball.pos.loc.x - dot1.x); + slope2[0] = (wm->ball.pos.loc.y - Field::ourGoalPost_L.y) / (wm->ball.pos.loc.x - Field::ourGoalPost_L.x); + dot2.y -= ROBOT_RADIUS; + slope1[1] = (wm->ball.pos.loc.y - Field::ourGoalPost_R.y) / (wm->ball.pos.loc.x - Field::ourGoalPost_R.x); + slope2[1] = (wm->ball.pos.loc.y - dot2.y) / (wm->ball.pos.loc.x - dot2.x); + + for (int i = 0; i < 2; i++) + { + + + //AngleDeg deg1, deg2; + //deg1.atan_deg(slope1); + //deg2.atan_deg(slope2); + + double degree1 = atan(slope1[i]); + double degree2 = atan(slope2[i]); + AngleDeg deg1(degree1), deg2(degree2); + + AngleDeg bis, delta; + //bis.bisect(deg1, deg2); //?? + bis = operator +(deg1, deg2); + bis.operator /=(2); + delta = operator -(deg1, deg2); + delta.operator /=(2); + //delta = bis.operator -=(deg2); //?? + + Line2D linebis(wm->ball.pos.loc, bis.degree() * 57.32); + //linebis = angle_bisector(wm->ball.pos.loc, deg1, deg2); //?? + Vector2D IS = linebis.intersection(line2); + Segment2D seg1(wm->ball.pos.loc, IS); + + std::cout << deg1.degree() * 57.32 << ":::::" << deg2.degree() * 57.32 << ":::::" + << delta.degree() * 57.32 << ":::::" << bis.degree() * 57.32 << std::endl; + + //double d = ROBOT_RADIUS / abs( delta.sin() ); //?? + double d = ROBOT_RADIUS / sin(delta.degree()); + Circle2D cir1 (wm->ball.pos.loc, d); + Vector2D fdot, sdot; + cir1.intersection(seg1, &fdot, &sdot); + + Circle2D ourDCircle (Field::ourGoalCenter, 1300); + if (wm->kn->IsInsideGolieArea(wm->ball.pos.loc)) + fdot = {Field::ourGoalCenter.x + 1200, pow(-1, i) * 90}; + else if ( (fdot.x == NULL && fdot.y == NULL) || (wm->kn->IsInsideGolieArea(fdot)) ) + ourDCircle.intersection(seg1, &fdot, &sdot); + + std::cout << fdot.x << "::" << fdot.y << std::endl; + + if (i == 0) + { + tTest2->setpos(fdot); + tactics[1] = tTest2; + } + if (i == 1) + { + tTest3->setpos(fdot); + tactics[2] = tTest3; + } + } + + + //step 3 + + Segment2D segtest (wm->ourRobot[1].pos.loc, wm->ourRobot[2].pos.loc); + Vector2D dottest = segtest.intersection(line1); + + if ( (seg.length() > 5) && (dottest.x != NULL && dottest.y != NULL) ) + { + tTest2->setpos(dottest); + tactics[1] = tTest2; + tTest3->setpos(dottest); + tactics[2] = tTest3; + } + */ + + //Project 2 + + //tTest1->setidtest(5); + //tTest1->setpos(wm->ourRobot[5].pos.loc); + //tactics[4] = tTest1; + + + /* + if ( (wm->ball.pos.loc - wm->ourRobot[5].pos.loc).length() < 1500 ) + { + tTest1->setidtest(1); + tTest1->setpos(Field::oppGoalCenter); + tactics[5] = tTest1; + tTest2->setidtest(0); + tTest2->setpos({0,0}); + tactics[4] = tTest2; + } + else + { + tTest2->setidtest(1); + tTest2->setpos(wm->ourRobot[5].pos.loc); + tactics[4] = tTest2; + + + double a = atan(wm->ball.vel.loc.y /wm->ball.vel.loc.x); + Line2D line1(wm->ball.pos.loc, a); + Line2D line2(wm->ourRobot[5].pos.loc, {0,wm->ourRobot[5].pos.loc.y}); + + Vector2D dot; + + if ( abs(wm->ball.vel.loc.y) > 0.5 ) + { + dot = line1.intersection(line2); + tTest1->setidtest(0); + tTest1->setpos(dot); + tactics[5] = tTest1; + } + std::cout << abs(wm->ball.vel.loc.y) << std::endl; + + } + */ + + + /* + //if ( (wm->ball.pos.loc - wm->ourRobot[5].pos.loc).length() < 2000 ) + if (wm->ball.pos.loc.x > 700) + { + tTest1->setidtest(1); + tTest1->setpos(wm->ourRobot[4].pos.loc); + tactics[5] = tTest1; + //tTest2->setidtest(0); + //tTest2->setpos({-2000,0}); + //tactics[4] = tTest2; + } + else if (wm->ball.vel.loc.x < -0.5) + { + tTest1->setidtest(0); + tTest1->setpos({2000,0}); + tactics[5] = tTest1; + } + else if (wm->ball.vel.loc.x > 0.5) + { + Vector2D dot; + Segment2D seg(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + + Line2D line1(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + Line2D line2({2000,-100}, {2000,100}); + dot = line1.intersection(line2); + + if ( seg.length() < 5 ) + { + dot = {2000,0}; + } + + tTest1->setidtest(0); + tTest1->setpos(dot); + tactics[5] = tTest1; + } + //else + //if ( (wm->ball.pos.loc - wm->ourRobot[4].pos.loc).length() < 2000 ) + if (wm->ball.pos.loc.x < -700) + { + //tTest1->setidtest(0); + //tTest1->setpos({2000,0}); + //tactics[5] = tTest1; + tTest2->setidtest(1); + tTest2->setpos(wm->ourRobot[5].pos.loc); + tactics[4] = tTest2; + } + else if (wm->ball.vel.loc.x > 0.5) + { + tTest2->setidtest(0); + tTest2->setpos({-2000,0}); + tactics[4] = tTest2; + } + else if (wm->ball.vel.loc.x < -0.5) + { + Vector2D dot; + Segment2D seg(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + + Line2D line1(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + Line2D line2({-2000,-100}, {-2000,100}); + dot = line1.intersection(line2); + + if ( seg.length() < 5 ) + { + dot = {-2000,0}; + } + + tTest2->setidtest(0); + tTest2->setpos(dot); + tactics[4] = tTest2; + } + + std::cout << wm->ball.vel.loc.x << std::endl; + + */ + + //................................................................................... +/* + QList actives = wm->kn->ActiveAgents(); + actives.removeOne(wm->ref_goalie_our); + wm->ourRobot[wm->ref_goalie_our].Role = AgentRole::Golie; + switch (actives.length()) { + case 1: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + break; + case 2: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + break; + case 3: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + break; + case 4: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + break; + case 5: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerRight; + break; + default: + break; + } + + Vector2D dot; + Segment2D seg(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + + Line2D line1(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + Line2D line2(Field::ourGoalCenter, Field::ourGoalPost_R); + dot = line1.intersection(line2); + + if ( seg.length() < 5 || abs(dot.y - Field::ourGoalCenter.y) > abs(Field::ourGoalPost_L.y - Field::ourGoalCenter.y) ) + { + dot = Field::ourGoalCenter; + } + + double slope1[2], slope2[2]; + Vector2D dot1 = Field::ourGoalCenter, dot2 = Field::ourGoalCenter; + dot1.y += ROBOT_RADIUS; + slope1[0] = (wm->ball.pos.loc.y - dot1.y) / (wm->ball.pos.loc.x - dot1.x); + slope2[0] = (wm->ball.pos.loc.y - Field::ourGoalPost_L.y) / (wm->ball.pos.loc.x - Field::ourGoalPost_L.x); + dot2.y -= ROBOT_RADIUS; + slope1[1] = (wm->ball.pos.loc.y - Field::ourGoalPost_R.y) / (wm->ball.pos.loc.x - Field::ourGoalPost_R.x); + slope2[1] = (wm->ball.pos.loc.y - dot2.y) / (wm->ball.pos.loc.x - dot2.x); + + Vector2D fdotDefLeft, fdotDefRight; + for (int i = 0; i < 2; i++) + { + double degree1 = atan(slope1[i]); + double degree2 = atan(slope2[i]); + AngleDeg deg1(degree1), deg2(degree2); + + AngleDeg bis, delta; + bis = operator +(deg1, deg2); + bis.operator /=(2); + delta = operator -(deg1, deg2); + delta.operator /=(2); + + Line2D linebis(wm->ball.pos.loc, bis.degree() * 57.32); + Vector2D IS = linebis.intersection(line2); + Segment2D seg1(wm->ball.pos.loc, IS); + + double d = ROBOT_RADIUS / sin(delta.degree()); + Circle2D cir1 (wm->ball.pos.loc, d); + Vector2D fdot, sdot; + cir1.intersection(seg1, &fdot, &sdot); + + Circle2D ourDCircle (Field::ourGoalCenter, 1300); + if (wm->kn->IsInsideGolieArea(wm->ball.pos.loc)) + fdot = {Field::ourGoalCenter.x + 1200, pow(-1, i) * 90}; + else if ( (fdot.x == NULL && fdot.y == NULL) || (wm->kn->IsInsideGolieArea(fdot)) ) + ourDCircle.intersection(seg1, &fdot, &sdot); + + if (i == 0) + { + //tTest2->setpos(fdot); + //tactics[1] = tTest2; + fdotDefLeft = fdot; + } + if (i == 1) + { + //tTest3->setpos(fdot); + //tactics[2] = tTest3; + fdotDefRight = fdot; + } + } + + Vector2D fdotAttMid, fdotAttLeft, fdotAttRight; + Vector2D se; + Circle2D cir (wm->ball.pos.loc, 500); + Segment2D segA1 (Field::ourGoalCenter, wm->ball.pos.loc); + Segment2D segA2 (Field::ourGoalPost_L, wm->ball.pos.loc); + Segment2D segA3 (Field::ourGoalPost_R, wm->ball.pos.loc); + cir.intersection(segA1, &fdotAttMid, &se); + cir.intersection(segA2, &fdotAttLeft, &se); + cir.intersection(segA3, &fdotAttRight, &se); + + QList activeRobots = wm->kn->ActiveAgents(); + for (int i = 0; i < wm->kn->ActiveAgents().length(); i++) + { + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::Golie) + { + tTest1->setpos(dot); + tactics[activeRobots.at(i)] = tTest1; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::DefenderLeft) + { + tTest2->setpos(fdotDefLeft); + tactics[activeRobots.at(i)] = tTest2; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::DefenderRight) + { + tTest3->setpos(fdotDefRight); + tactics[activeRobots.at(i)] = tTest3; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerMid) + { + tTest4->setpos(fdotAttMid); + tactics[activeRobots.at(i)] = tTest4; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerLeft) + { + tTest5->setpos(fdotAttLeft); + tactics[activeRobots.at(i)] = tTest5; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerRight) + { + tTest6->setpos(fdotAttRight); + tactics[activeRobots.at(i)] = tTest6; + } + } + + //tactics[wm->ref_goalie_our] = tTest1; + //qDebug() << "Hello world"; +*/ + + //-------------------------------------------------------------------------------------------------------------------- + //play Stop version 1 +/* + QList actives = wm->kn->ActiveAgents(); + actives.removeOne(wm->ref_goalie_our); + wm->ourRobot[wm->ref_goalie_our].Role = AgentRole::Golie; + switch (actives.length()) { + case 1: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + break; + case 2: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + break; + case 3: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + break; + case 4: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + break; + case 5: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerRight; + break; + default: + break; + } + + Vector2D dot; + Segment2D seg(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + + Line2D line1(wm->ball.pos.loc, wm->ball.pos_predicted.loc); + Line2D line2(Field::ourGoalCenter, Field::ourGoalPost_R); + dot = line1.intersection(line2); + + if ( seg.length() < 5 || abs(dot.y - Field::ourGoalCenter.y) > abs(Field::ourGoalPost_L.y - Field::ourGoalCenter.y) ) + { + dot = Field::ourGoalCenter; + } + + Vector2D fPosAttLeft, fPosAttRight, sec; + Vector2D fPosAttMid, fPosDefLeft, fPosDefRight; + + if ( wm->kn->IsInsideGolieArea(wm->ball.pos.loc) ) + { + fPosAttLeft = {Field::ourGoalCenter.x + 2800, 1000}; + fPosAttRight = {Field::ourGoalCenter.x + 2800, -1000}; + + Line2D midAttLine (Field::ourGoalCenter, AngleDeg(0)); + Line2D leftDefLine (Field::ourGoalCenter, AngleDeg(45)); + Line2D rightDefLine (Field::ourGoalCenter, AngleDeg(-45)); + Circle2D cir1 (Field::ourGoalCenter, 1300); + cir1.intersection(midAttLine, &fPosAttMid, &sec); + if (sec.x > fPosAttMid.x) + fPosAttMid = sec; + cir1.intersection(leftDefLine, &fPosDefLeft, &sec); + if (sec.x > fPosDefLeft.x) + fPosDefLeft = sec; + cir1.intersection(rightDefLine, &fPosDefRight, &sec); + if (sec.x > fPosDefRight.x) + fPosDefRight = sec; + } + else if (wm->ball.pos.loc.x > Field::ourGoalCenter.x + 1300) + { + double slope, degree, deltaa; + slope = (wm->ball.pos.loc.y - Field::ourGoalCenter.y) / (wm->ball.pos.loc.x - Field::ourGoalCenter.x); + degree = atan(slope); + deltaa = asin( ROBOT_RADIUS / (500 + ROBOT_RADIUS) ); + AngleDeg deg(degree * 57.32), delta(deltaa * 57.32); + AngleDeg leftAttDeg, rightAttDeg; + leftAttDeg = operator -(deg, delta); + rightAttDeg = operator +(deg, delta); + Line2D leftAttLine(wm->ball.pos.loc, leftAttDeg.degree() - 1.5); + Line2D rightAttLine(wm->ball.pos.loc, rightAttDeg.degree() + 1.5); + Circle2D cir(wm->ball.pos.loc, 500); + cir.intersection(leftAttLine, &fPosAttLeft, &sec); + if (sec.x < fPosAttLeft.x) + fPosAttLeft = sec; + cir.intersection(rightAttLine, &fPosAttRight, &sec); + if (sec.x < fPosAttRight.x) + fPosAttRight = sec; + + Line2D midAttLine (Field::ourGoalCenter, AngleDeg(0)); + Line2D leftDefLine (Field::ourGoalCenter, AngleDeg(45)); + Line2D rightDefLine (Field::ourGoalCenter, AngleDeg(-45)); + Circle2D cir1 (Field::ourGoalCenter, 1300); + cir1.intersection(midAttLine, &fPosAttMid, &sec); + if (sec.x > fPosAttMid.x) + fPosAttMid = sec; + cir1.intersection(leftDefLine, &fPosDefLeft, &sec); + if (sec.x > fPosDefLeft.x) + fPosDefLeft = sec; + cir1.intersection(rightDefLine, &fPosDefRight, &sec); + if (sec.x > fPosDefRight.x) + fPosDefRight = sec; + + } + else + { + if (wm->ball.pos.loc.y > 0) + { + double slope, degree, deltaa; + slope = (wm->ball.pos.loc.y - Field::ourGoalCenter.y) / (wm->ball.pos.loc.x - Field::ourGoalCenter.x); + degree = atan(slope); + deltaa = asin( ROBOT_RADIUS / (500 + ROBOT_RADIUS) ); + AngleDeg deg(degree * 57.32), delta(deltaa * 57.32); + AngleDeg leftAttDeg, rightAttDeg; + leftAttDeg = operator +(deg, delta); + rightAttDeg = operator +(deg, delta); + Line2D leftAttLine(wm->ball.pos.loc, deg.degree()); + Circle2D cir(wm->ball.pos.loc, 500); + cir.intersection(leftAttLine, &fPosAttLeft, &sec); + if (sec.y < fPosAttLeft.y) + fPosAttLeft = sec; + + Line2D rightAttLine(Field::ourGoalCenter, AngleDeg(18)); + Line2D midAttLine (Field::ourGoalCenter, AngleDeg(-18)); + Line2D leftDefLine (Field::ourGoalCenter, AngleDeg(54)); + Line2D rightDefLine (Field::ourGoalCenter, AngleDeg(-54)); + Circle2D cir1 (Field::ourGoalCenter, 1300); + cir1.intersection(rightAttLine, &fPosAttRight, &sec); + if (sec.x > fPosAttRight.x) + fPosAttRight = sec; + cir1.intersection(midAttLine, &fPosAttMid, &sec); + if (sec.x > fPosAttMid.x) + fPosAttMid = sec; + cir1.intersection(leftDefLine, &fPosDefLeft, &sec); + if (sec.x > fPosDefLeft.x) + fPosDefLeft = sec; + cir1.intersection(rightDefLine, &fPosDefRight, &sec); + if (sec.x > fPosDefRight.x) + fPosDefRight = sec; + } + else + { + double slope, degree, deltaa; + slope = (wm->ball.pos.loc.y - Field::ourGoalCenter.y) / (wm->ball.pos.loc.x - Field::ourGoalCenter.x); + degree = atan(slope); + deltaa = asin( ROBOT_RADIUS / (500 + ROBOT_RADIUS) ); + AngleDeg deg(degree * 57.32), delta(deltaa * 57.32); + AngleDeg leftAttDeg, rightAttDeg; + leftAttDeg = operator -(deg, delta); + rightAttDeg = operator -(deg, delta); + Line2D rightAttLine(wm->ball.pos.loc, deg.degree()); + Circle2D cir(wm->ball.pos.loc, 500); + cir.intersection(rightAttLine, &fPosAttRight, &sec); + if (sec.y > fPosAttRight.y) + fPosAttRight = sec; + + Line2D leftAttLine(Field::ourGoalCenter, AngleDeg(-18)); + Line2D midAttLine (Field::ourGoalCenter, AngleDeg(18)); + Line2D leftDefLine (Field::ourGoalCenter, AngleDeg(54)); + Line2D rightDefLine (Field::ourGoalCenter, AngleDeg(-54)); + Circle2D cir1 (Field::ourGoalCenter, 1300); + cir1.intersection(leftAttLine, &fPosAttLeft, &sec); + if (sec.x > fPosAttLeft.x) + fPosAttLeft = sec; + cir1.intersection(midAttLine, &fPosAttMid, &sec); + if (sec.x > fPosAttMid.x) + fPosAttMid = sec; + cir1.intersection(leftDefLine, &fPosDefLeft, &sec); + if (sec.x > fPosDefLeft.x) + fPosDefLeft = sec; + cir1.intersection(rightDefLine, &fPosDefRight, &sec); + if (sec.x > fPosDefRight.x) + fPosDefRight = sec; + } + } + + + QList activeRobots = wm->kn->ActiveAgents(); + for (int i = 0; i < wm->kn->ActiveAgents().length(); i++) + { + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::Golie) + { + tTest1->setpos(dot); + tactics[activeRobots.at(i)] = tTest1; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::DefenderLeft) + { + tTest2->setpos(fPosDefLeft); + tactics[activeRobots.at(i)] = tTest2; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::DefenderRight) + { + tTest3->setpos(fPosDefRight); + tactics[activeRobots.at(i)] = tTest3; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerMid) + { + tTest4->setpos(fPosAttMid); + tactics[activeRobots.at(i)] = tTest4; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerLeft) + { + tTest5->setpos(fPosAttLeft); + tactics[activeRobots.at(i)] = tTest5; + } + if (wm->ourRobot[activeRobots.at(i)].Role == AgentRole::AttackerRight) + { + tTest6->setpos(fPosAttRight); + tactics[activeRobots.at(i)] = tTest6; + } + } +*/ + //-------------------------------------------------------------------------------------------------------------------- + //play Stop version 2 +/* + QList actives = wm->kn->ActiveAgents(); + actives.removeOne(wm->ref_goalie_our); + wm->ourRobot[wm->ref_goalie_our].Role = AgentRole::Golie; + switch (actives.length()) { + case 1: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + break; + case 2: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + break; + case 3: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + break; + case 4: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + break; + case 5: + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::DefenderRight; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerMid; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerLeft; + wm->ourRobot[actives.takeFirst()].Role = AgentRole::AttackerRight; + break; + default: + break; + } + + QList activeRobots = wm->kn->ActiveAgents(); + + for (int i = 0; i < activeRobots.size(); i++) + wm->ourRobot[activeRobots.at(i)].Status = AgentStatus::Idle; + + for (int i = 0; i < activeRobots.size(); i++) + { + int index = activeRobots.at(i); + + switch (wm->ourRobot[index].Role) { + case AgentRole::Golie: + tactics[index] = tGoalie; + break; + case AgentRole::DefenderLeft: + tactics[index] = tDefenderLeft; + tDefenderLeft->resetBooleans(); //?? + break; + case AgentRole::DefenderRight: + tactics[index] = tDefenderRight; + tDefenderRight->resetBooleans(); //?? + break; + case AgentRole::AttackerMid: + tactics[index] = tStopMid; + break; + case AgentRole::AttackerLeft: + tactics[index] = tStopLeft; + break; + case AgentRole::AttackerRight: + tactics[index] = tStopRight; + break; + default: + break; + } + } + + Position leftDefPos,rightDefPos,goaliePos; + int leftID = -1, rightID = -1 , midID = -1; + bool leftNav, rightNav; + + if( wm->ourRobot[previousLeftID].Role != AgentRole::DefenderLeft ) + previousLeftID = -1; + + if( wm->ourRobot[previousRightID].Role != AgentRole::DefenderRight ) + previousRightID = -1; + + if( (wm->ourRobot[tDefenderLeft->getID()].Role == AgentRole::DefenderLeft) && (leftChecker < PresenceCounter) ) + { + leftID = tDefenderLeft->getID(); + this->previousLeftID = tDefenderLeft->getID();; + } + + if( wm->ourRobot[tDefenderRight->getID()].Role == AgentRole::DefenderRight && (rightChecker < PresenceCounter) ) + { + rightID = tDefenderRight->getID(); + this->previousRightID = tDefenderRight->getID();; + } + + if( leftChecker > PresenceCounter || leftID == -1 ) + midID = rightID; + + if( rightChecker > PresenceCounter || rightID == -1) + midID = leftID; + + zonePositions(leftID,rightID,midID,goaliePos,leftDefPos,leftNav,rightDefPos,rightNav); + + tDefenderLeft->setIdlePosition(leftDefPos); + tDefenderLeft->setUseNav(leftNav); + tDefenderRight->setIdlePosition(rightDefPos); + tDefenderRight->setUseNav(rightNav); + + if( leftID != -1) + { + if( (wm->ourRobot[leftID].Status != AgentStatus::FollowingBall ) && (wm->ourRobot[leftID].pos.loc - leftDefPos.loc).length() > 250 ) + leftChecker++; + else + leftChecker = 0; + } + else + { + if( !haltedRobotIsInField(previousLeftID) ) + leftChecker = 0; + } + + if( rightID != -1) + { + if( (wm->ourRobot[rightID].Status != AgentStatus::FollowingBall ) && (wm->ourRobot[rightID].pos.loc - rightDefPos.loc).length() > 250 ) + rightChecker++; + else + rightChecker = 0; + } + else + { + if( !haltedRobotIsInField(previousRightID) ) + rightChecker = 0; + } + + tGoalie->setIdlePosition(goaliePos); + + if (wm->kn->IsInsideGolieArea(wm->ball.pos.loc)) + { + tStopMid->setStopPosition({Field::ourGoalCenter.x + 2250, 0}); + tStopLeft->setStopPosition({Field::ourGoalCenter.x + 2250, 1250}); + tStopRight->setStopPosition({Field::ourGoalCenter.x + 2250, -1250}); + } + else if (wm->ball.pos.loc.x < Field::ourGoalCenter.x + (Field::MaxX * 2) / 3) + { + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + + Circle2D goalieCir (Field::ourGoalCenter, 1300); + Line2D linetest (Field::ourGoalCenter, wm->ball.pos.loc); + if (wm->kn->IsInsideGolieArea(fdot)) + { + goalieCir.intersection(linetest, &fdot, &sdot); + if (fdot.x < sdot.x) + fdot = sdot; + } + + tStopMid->setStopPosition(fdot); + + tactics[tStopLeft->getID()] = tAttackerLeft; + tactics[tStopRight->getID()] = tAttackerRight; + + Marking def; + def.setWorldModel(wm); //?? + bool isMatched; + QList opp = wm->kn->ActiveOppAgents(); + QList our; + our.append(tAttackerLeft->getID()); + our.append(tAttackerRight->getID()); + QList m2m = def.findMarking(our , opp, isMatched); + if (isMatched) + { + for (int i = 0; i < m2m.size(); i++) + { + wm->ourRobot[m2m.at(i).ourI].Status = AgentStatus::BlockingRobot; + + switch (wm->ourRobot[m2m.at(i).ourI].Role) { + case AgentRole::DefenderLeft: + tDefenderLeft->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::DefenderRight: + tDefenderRight->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::AttackerLeft: + tAttackerLeft->setPlayerToKeep(m2m.at(i).oppI); + break; + case AgentRole::AttackerRight: + tAttackerRight->setPlayerToKeep(m2m.at(i).oppI); + break; + default: + break; + } + } + } + } + else if (wm->ball.pos.loc.x < Field::ourGoalCenter.x + (Field::MaxX * 2)* 2 / 3) + { + Vector2D fPosAttMid, fPosAttLeft, fPosAttRight, sec; + double slope, degree, deltaa; + slope = (wm->ball.pos.loc.y - Field::ourGoalCenter.y) / (wm->ball.pos.loc.x - Field::ourGoalCenter.x); + degree = atan(slope); + deltaa = 2 * asin( ROBOT_RADIUS / ALLOW_NEAR_BALL_RANGE ); + AngleDeg deg(degree * 57.32), delta(deltaa * 57.32); + AngleDeg leftAttDeg, rightAttDeg; + leftAttDeg = operator -(deg, delta); + rightAttDeg = operator +(deg, delta); + Line2D leftAttLine(wm->ball.pos.loc, leftAttDeg.degree() - 1.5); + Line2D rightAttLine(wm->ball.pos.loc, rightAttDeg.degree() + 1.5); + Circle2D cir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + cir.intersection(leftAttLine, &fPosAttLeft, &sec); + if (sec.x < fPosAttLeft.x) + fPosAttLeft = sec; + cir.intersection(rightAttLine, &fPosAttRight, &sec); + if (sec.x < fPosAttRight.x) + fPosAttRight = sec; + + tStopLeft->setStopPosition(fPosAttLeft); + tStopRight->setStopPosition(fPosAttRight); + + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + tStopMid->setStopPosition(fdot); + } + else if (Field::ourGoalCenter.x + (Field::MaxX * 2)* 2 / 3 < wm->ball.pos.loc.x) + { + Segment2D seg(Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D ballcir(wm->ball.pos.loc, ALLOW_NEAR_BALL_RANGE); + Vector2D fdot, sdot; + ballcir.intersection(seg, &fdot, &sdot); + tStopMid->setStopPosition(fdot); + + tStopLeft->setStopPosition({wm->ball.pos.loc.x - 2250, 1250}); + tStopRight->setStopPosition({wm->ball.pos.loc.x - 2250, -1250}); + } +*/ + + if (c == -1) + { + tTest1->setpos( Vector2D(-1500, 250) ); + tactics[2] = tTest1; + tTest2->setpos( Vector2D(-1750, 250) ); + tactics[3] = tTest2; + tTest3->setpos( Vector2D(-2000, 250) ); + tactics[4] = tTest3; +// tTest4->setpos( Vector2D(-1250, 250) ); +// tactics[3] = tTest4; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-1500, 250)).length() < 80 + && (wm->ourRobot[3].pos.loc - Vector2D(-1750, 250)).length() < 80 + && (wm->ourRobot[4].pos.loc - Vector2D(-2000, 250)).length() < 80 + //&& (wm->ourRobot[3].pos.loc - Vector2D(-1250, 250)).length() < 80 + ) + { + c = 0; + cout << "bbbbb"; + } + + if (c == 0 && t == 0) + { + tTest1->setpos( Vector2D(-1250, 250) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-1250, 250)).length() < 80 && t == 0) + c = 1; + + if (c == 1 && t == 0) + { + tTest1->setpos( Vector2D(-1250, 1750) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-1250, 1750)).length() < 80 && t == 0) + c = 2; + + if (c == 2 && t == 0) + { + tTest1->setpos( Vector2D(-3250, 1750) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 0) + c = 3; + + if (c == 3 && t == 0) + { + tTest1->setpos( Vector2D(-3250, 1750) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 0) + c = 4; + + if (c == 4 && t == 0) + { + tTest1->setpos( Vector2D(-3250, -1750) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-3250, -1750)).length() < 80 && t == 0) + c = 5; + + if (c == 5 && t == 0) + { + tTest1->setpos( Vector2D(-1250, -1750) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-1250, -1750)).length() < 80 && t == 0) + c = 6; + + if (c == 6 && t == 0) + { + tTest1->setpos( Vector2D(-1250, -250) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-1250, -250)).length() < 80 && t == 0) + c = 7; + + if (c == 7 && t == 0) + { + tTest1->setpos( Vector2D(-2250, -250) ); + tactics[2] = tTest1; + } + if ( (wm->ourRobot[2].pos.loc - Vector2D(-2250, -250)).length() < 80 && t == 0) + { + c = 8; + t = 1; + } +// + if (c == 8 && t == 1) + { + tTest2->setpos( Vector2D(-1250, 250) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-1250, 250)).length() < 80 && t == 1) + c = 9; + + if (c == 9 && t == 1) + { + tTest2->setpos( Vector2D(-1250, 1750) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-1250, 1750)).length() < 80 && t == 1) + c = 10; + + if (c == 10 && t == 1) + { + tTest2->setpos( Vector2D(-3250, 1750) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 1) + c = 11; + + if (c == 11 && t == 1) + { + tTest2->setpos( Vector2D(-3250, 1750) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 1) + c = 12; + + if (c == 12 && t == 1) + { + tTest2->setpos( Vector2D(-3250, -1750) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-3250, -1750)).length() < 80 && t == 1) + c = 13; + + if (c == 13 && t == 1) + { + tTest2->setpos( Vector2D(-1250, -1750) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-1250, -1750)).length() < 80 && t == 1) + c = 14; + + if (c == 14 && t == 1) + { + tTest2->setpos( Vector2D(-1250, -250) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-1250, -250)).length() < 80 && t == 1) + c = 15; + + if (c == 15 && t == 1) + { + tTest2->setpos( Vector2D(-2000, -250) ); + tactics[3] = tTest2; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-2000, -250)).length() < 80 && t == 1 ) + { + c = 16; + t = 2; + } +// + if (c == 16 && t == 2) + { + tTest3->setpos( Vector2D(-1250, 250) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-1250, 250)).length() < 80 && t == 2) + c = 17; + + if (c == 17 && t == 2) + { + tTest3->setpos( Vector2D(-1250, 1750) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-1250, 1750)).length() < 80 && t == 2) + c = 18; + + if (c == 18 && t == 2) + { + tTest3->setpos( Vector2D(-3250, 1750) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 2) + c = 19; + + if (c == 19 && t == 2) + { + tTest3->setpos( Vector2D(-3250, 1750) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-3250, 1750)).length() < 80 && t == 2) + c = 20; + + if (c == 20 && t == 2) + { + tTest3->setpos( Vector2D(-3250, -1750) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-3250, -1750)).length() < 80 && t == 2) + c = 21; + + if (c == 21 && t == 2) + { + tTest3->setpos( Vector2D(-1250, -1750) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-1250, -1750)).length() < 80 && t == 2) + c = 22; + + if (c == 22 && t == 2) + { + tTest3->setpos( Vector2D(-1250, -250) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-1250, -250)).length() < 80 && t == 2) + c = 23; + + if (c == 23 && t == 2) + { + tTest3->setpos( Vector2D(-1750, -250) ); + tactics[4] = tTest3; + } + if ( (wm->ourRobot[4].pos.loc - Vector2D(-1750, -250)).length() < 80 && t == 2) + { + c = 24; + t = 3; + } +// +/* + if (c == 24 && t == 3) + { + tTest4->setpos( Vector2D(-250, 250) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-250, 250)).length() < 50 && t == 3) + c = 25; + + if (c == 25 && t == 3) + { + tTest4->setpos( Vector2D(-250, 2750) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-250, 2750)).length() < 50 && t == 3) + c = 26; + + if (c == 26 && t == 3) + { + tTest4->setpos( Vector2D(-4250, 2750) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-4250, 2750)).length() < 50 && t == 3) + c = 27; + + if (c == 27 && t == 3) + { + tTest4->setpos( Vector2D(-4250, 2750) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-4250, 2750)).length() < 50 && t == 3) + c = 28; + + if (c == 28 && t == 3) + { + tTest4->setpos( Vector2D(-4250, -2750) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-4250, -2750)).length() < 50 && t == 3) + c = 29; + + if (c == 29 && t == 3) + { + tTest4->setpos( Vector2D(-250, -2750) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-250, -2750)).length() < 50 && t == 3) + c = 30; + + if (c == 30 && t == 3) + { + tTest4->setpos( Vector2D(-250, -250) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-250, -250)).length() < 50 && t == 3) + c = 31; + + if (c == 31 && t == 3) + { + tTest4->setpos( Vector2D(-500, -250) ); + tactics[3] = tTest4; + } + if ( (wm->ourRobot[3].pos.loc - Vector2D(-500, -250)).length() < 50 && t == 3) + c = 32; +*/ + cout << c << endl; + + //tTest1->setpos( Vector2D (-1000, 0) ); + //tactics[2] = tTest1; - tactics[0] = test; - tactics[1] = test; - tactics[2] = test; + //tTest1->setpos( Vector2D(-1000, 0) ); + //tactics[0] = tTest1; } diff --git a/src/ai/play/playtest.h b/src/ai/play/playtest.h index 106b915..0735fd7 100644 --- a/src/ai/play/playtest.h +++ b/src/ai/play/playtest.h @@ -12,11 +12,24 @@ class PlayTest : public Play virtual void initRole(); virtual int enterCondition(); - //////////////////////////// private: - int flag=0; - TacticTest *test; - TacticTest2 *test2; - /////////////////////////// + TacticTest *tTest1; + TacticTest *tTest2; + TacticTest *tTest3; + TacticTest *tTest4; + TacticTest *tTest5; + TacticTest *tTest6; + + TacticGoalie *tGoalie; + TacticDefender *tDefenderLeft; + TacticDefender *tDefenderRight; + TacticStop *tStopMid; + TacticStop *tStopLeft; + TacticStop *tStopRight; + TacticAttacker *tAttackerLeft; + TacticAttacker *tAttackerRight; + + int c = -1; + int t = 0; }; #endif // PLAYTEST_H diff --git a/src/ai/play/playtest2.cpp b/src/ai/play/playtest2.cpp index 0c70527..7b8b61a 100644 --- a/src/ai/play/playtest2.cpp +++ b/src/ai/play/playtest2.cpp @@ -3,11 +3,7 @@ PlayTest2::PlayTest2(WorldModel *worldmodel, QObject *parent) : Play("PlayTest2", worldmodel, parent) { - // Goaler. - tGolie = new TacticGoalie(wm); - tTF = new TacticTestFriction(wm); - thalt = new TacticHalt(wm); - tTest = new TacticTest(wm); + tTest1 = new TacticTest2(wm); } int PlayTest2::enterCondition() @@ -15,15 +11,262 @@ int PlayTest2::enterCondition() return 0; } +int PlayTest2::Parabola_intersection(Vector2D site1, Vector2D site2, double l, Vector2D *v1, Vector2D *v2) +{ + double a1, b1, c1; + double a2, b2, c2; + double a, b, c; + double delta; + + a1 = 0.5 / (site1.y - l); + b1 = site1.x / (l - site1.y); + c1 = ( 0.5 * (site1.y + l) ) + ( 0.5 * site1.x * site1.x / (site1.y -l) ); + //cout << a1 << "||" << b1 << "||" << c1 << endl; + + a2 = 0.5 / (site2.y - l); + b2 = site2.x / (l - site2.y); + c2 = ( 0.5 * (site2.y + l) ) + ( 0.5 * site2.x * site2.x / (site2.y -l) ); + //cout << a2 << "||" << b2 << "||" << c2 << endl; + + a = a1 - a2; + b = b1 - b2; + c = c1 - c2; + //cout << a << "||" << b << "||" << c << endl; + + delta = b * b - 4 * a * c; + + if (a == 0) + { + if (b == 0) + return 0; + else + { + v1->x = (-1) * c / b; + v1->y = a1 * v1->x * v1->x + b1 * v1->x + c1; + + return 1; + } + } + else + { + if (delta > 0) + { + v1->x = ( (-1) * b - sqrt(delta) ) / (2 * a); + v1->y = a1 * v1->x * v1->x + b1 * v1->x + c1; + v2->x = ( (-1) * b + sqrt(delta) ) / (2 * a); + v2->y = a1 * v2->x * v2->x + b1 * v2->x + c1; + + return 2; + } + else if (delta == 0) + { + v1->x = ((-1) * b) / (2 * a); + v1->y = a1 * v1->x * v1->x + b1 * v1->x + c1; + + return 1; + } + else + return 0; + } +} + void PlayTest2::initRole() { } + void PlayTest2::execute() { -// tactics[wm->ref_goalie_our] = tGolie; - tactics[3] = tTest; - qDebug()<<"Ball Speed is "<ball.vel.loc.length(); + + //QList order; + Vector2D t[3][2]; + + QList activeopp = wm->kn->ActiveOppAgents(); + + int s = 1; + + for (int i = 0; i < activeopp.size() - 1; i++) + for (int j = 0; j < activeopp.size() - 1; j++) + if (wm->oppRobot[ activeopp.at(j) ].pos.loc.x > wm->oppRobot[ activeopp.at(j+1) ].pos.loc.x) + activeopp.move(j, j + 1); + + for (double l = 3000; l >= -6000; l = l - 0.5) + { + QList order; + + for (int i = 0; i < activeopp.size() ; i++) + if (wm->oppRobot[ activeopp.at(i) ].pos.loc.y > l) + order.append( activeopp.at(i) ); + +//G + +/* + if (l == -1200) + { + Parabola_intersection(wm->oppRobot[ order.at(0) ].pos.loc, wm->oppRobot[ order.at(2) ].pos.loc, l, + &t[0][0], &t[0][1]); + Parabola_intersection(wm->oppRobot[ order.at(0) ].pos.loc, wm->oppRobot[ order.at(1) ].pos.loc, l, + &t[1][0], &t[1][1]); + Parabola_intersection(wm->oppRobot[ order.at(1) ].pos.loc, wm->oppRobot[ order.at(2) ].pos.loc, l, + &t[2][0], &t[2][1]); + + cout << "t[0][0].x = " << t[0][0].x << "||" << "t[0][0].y = " << t[0][0].y << endl; + cout << "t[0][1].x = " << t[0][1].x << "||" << "t[0][1].y = " << t[0][1].y << endl; + cout << "t[1][0].x = " << t[1][0].x << "||" << "t[1][0].y = " << t[1][0].y << endl; + cout << "t[1][1].x = " << t[1][1].x << "||" << "t[1][1].y = " << t[1][1].y << endl; + cout << "t[2][0].x = " << t[2][0].x << "||" << "t[2][0].y = " << t[2][0].y << endl; + cout << "t[2][1].x = " << t[2][1].x << "||" << "t[2][1].y = " << t[2][1].y << endl; + + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3 && k!=j; k++) + for (int m = 0; m < 2; m++) + { + if ( t[j][m].dist(t[k][0]) < 100 && t[j][m].x != 0 && t[j][m].y != 0) + { + wm->debug_pos.append(t[j][m]); + cout << t[j][m].x << "**" << t[j][m].y << endl; + cout << l << endl; + } + if ( t[j][m].dist(t[k][1]) < 100 && t[j][m].x != 0 && t[j][m].y != 0) + { + wm->debug_pos.append(t[j][m]); + cout << t[j][m].x << "**" << t[j][m].y << endl; + cout << l << endl; + } + } + } +*/ + + + + if (order.size() > 2) + { +/* + for (int i = 0; i < order.size() - 2; i++) + { + Parabola_intersection(wm->oppRobot[ order.at(i) ].pos.loc, wm->oppRobot[ order.at(i+2) ].pos.loc, l, + &t[0][0], &t[0][1]); + Parabola_intersection(wm->oppRobot[ order.at(i) ].pos.loc, wm->oppRobot[ order.at(i+1) ].pos.loc, l, + &t[1][0], &t[1][1]); + Parabola_intersection(wm->oppRobot[ order.at(i+1) ].pos.loc, wm->oppRobot[ order.at(i+2) ].pos.loc, l, + &t[2][0], &t[2][1]); +*/ + for (int a = 0; a < order.size()-2; a++) + for (int b = a+1; b < order.size()-1; b++) + for (int c = b+1; c < order.size(); c++) + { + Parabola_intersection(wm->oppRobot[ order.at(a) ].pos.loc, wm->oppRobot[ order.at(b) ].pos.loc, l, + &t[0][0], &t[0][1]); + Parabola_intersection(wm->oppRobot[ order.at(b) ].pos.loc, wm->oppRobot[ order.at(c) ].pos.loc, l, + &t[1][0], &t[1][1]); + Parabola_intersection(wm->oppRobot[ order.at(a) ].pos.loc, wm->oppRobot[ order.at(c) ].pos.loc, l, + &t[2][0], &t[2][1]); +/* + for (int j = 0; j < 3; j++) + for (int k = 0; k < 2; k++) + wm->debug_pos.append(t[j][k]); +*/ + + for (int j = 0; j < 3; j++) + for (int k = 0; k < 3 && k!=j; k++) + for (int m = 0; m < 2; m++) + { + if ( t[j][m].dist(t[k][0]) < 8 && t[j][m].x != 0 && t[j][m].y != 0) + { + s = 1; + for (int i = 0; i < order.size(); i++) + if ( i != a && i != b && i != c) + if ( t[j][m].dist(wm->oppRobot[ order.at(i) ].pos.loc) < t[j][m].dist(wm->oppRobot[ order.at(a) ].pos.loc)) + s = 0; + if (s == 1) + wm->debug_pos.append(t[j][m]); + //cout << t[j][m].x << "**" << t[j][m].y << endl; + //cout << l << endl; + } + if ( t[j][m].dist(t[k][1]) < 8 && t[j][m].x != 0 && t[j][m].y != 0) + { + s = 1; + for (int i = 0; i < order.size(); i++) + if ( i != a && i != b && i != c) + if ( t[j][m].dist(wm->oppRobot[ order.at(i) ].pos.loc) < t[j][m].dist(wm->oppRobot[ order.at(a) ].pos.loc)) + s = 0; + if (s == 1) + wm->debug_pos.append(t[j][m]); + //cout << t[j][m].x << "**" << t[j][m].y << endl; + //cout << l << endl; + } + } + + } + } + +//10 --> 49 +//5 --> 24 +//2 --> 10 +//1 --> 4 line --> 10 dot +//0.5 --> 2 line --> 6 --> 4 +//0.2 --> 1 --> 1 + + } + + //wm->debug_pos.clear(); + +/* + Vector2D first, second; + double a1, b1, c1; + double l = -1450; + + Vector2D site1 = wm->oppRobot[1].pos.loc; + a1 = 0.5 / (site1.y - l); + b1 = site1.x / (l - site1.y); + c1 = ( 0.5 * (site1.y + l) ) + ( 0.5 * site1.x * site1.x / (site1.y -l) ); + for (int x = -4500; x <= 4500; x++) + { + first.x = x; + first.y = a1 * x * x + b1 * x + c1; + wm->debug_pos.append(first); + } + + site1 = wm->oppRobot[4].pos.loc; + a1 = 0.5 / (site1.y - l); + b1 = site1.x / (l - site1.y); + c1 = ( 0.5 * (site1.y + l) ) + ( 0.5 * site1.x * site1.x / (site1.y -l) ); + for (int x = -4500; x <= 4500; x++) + { + first.x = x; + first.y = a1 * x * x + b1 * x + c1; + wm->debug_pos.append(first); + } + + site1 = wm->oppRobot[5].pos.loc; + a1 = 0.5 / (site1.y - l); + b1 = site1.x / (l - site1.y); + c1 = ( 0.5 * (site1.y + l) ) + ( 0.5 * site1.x * site1.x / (site1.y -l) ); + for (int x = -4500; x <= 4500; x++) + { + first.x = x; + first.y = a1 * x * x + b1 * x + c1; + wm->debug_pos.append(first); + } + + Vector2D lp; + lp.y = l; + for (int x = -4500; x <= 4500; x++) + { + lp.x = x; + wm->debug_pos.append(lp); + } +*/ + + /* + Vector2D a = {-1000,1000}, b = {0,1000}, c, d; + double l = 0; + Parabola_intersection(a, b, l, &c, &d); + cout << "c.x:" << c.x << "||||" << "c.y:" << c.y << endl; + cout << "d.x:" << d.x << "||||" << "d.y:" << d.y << endl; + */ + + //tactics[2] = tTest1; } diff --git a/src/ai/play/playtest2.h b/src/ai/play/playtest2.h index 1a5d002..10775a2 100644 --- a/src/ai/play/playtest2.h +++ b/src/ai/play/playtest2.h @@ -3,6 +3,7 @@ #include "play.h" #include "QDebug" +#include class PlayTest2 : public Play { @@ -10,16 +11,15 @@ class PlayTest2 : public Play public: explicit PlayTest2(WorldModel *worldmodel, QObject *parent = 0); virtual void execute(); - //virtual Tactic* getTactic(int id); + virtual void initRole(); virtual int enterCondition(); + //virtual Tactic* getTactic(int id); + + int Parabola_intersection (Vector2D, Vector2D, double, Vector2D *, Vector2D *); private: - TacticGoalie* tGolie; - TacticTestFriction* tTF; - TacticHalt* thalt; - TacticTest* tTest; + TacticTest2 *tTest1; - virtual void initRole(); }; #endif // PLAYTEST2_H diff --git a/src/ai/tactic/tactictest.cpp b/src/ai/tactic/tactictest.cpp index 1420b6f..e9aa47a 100644 --- a/src/ai/tactic/tactictest.cpp +++ b/src/ai/tactic/tactictest.cpp @@ -2,16 +2,189 @@ TacticTest::TacticTest(WorldModel *worldmodel, QObject *parent) : Tactic("TacticTest", worldmodel, parent) { - sTest = new SkillKick(wm); + } + RobotCommand TacticTest::getCommand() { RobotCommand rc; if(!wm->ourRobot[id].isValid) return rc; - sTest->execute(rc); + /* + rc.fin_pos.loc = Vector2D(1300,100); + rc.maxSpeed = 2; + rc.useNav = true; + */ + + /* + if ( id == 3 ) + { + Vector2D di = wm->ball.pos.loc - wm->ourRobot[3].pos.loc; + double diss = sqrt( di.x * di.x + di.y * di.y ); + rc.fin_pos.loc = wm->ourRobot[3].pos.loc + (di / diss) * (diss - 500); + } + + if ( id == 4 ) + { + Vector2D di = wm->ball.pos.loc - wm->ourRobot[4].pos.loc; + double diss = sqrt( di.x * di.x + di.y * di.y ); + rc.fin_pos.loc = wm->ourRobot[4].pos.loc + (di / diss) * (diss - 500); + } + + if ( id == 5 ) + { + Vector2D di = wm->ball.pos.loc - wm->ourRobot[5].pos.loc; + double diss = sqrt( di.x * di.x + di.y * di.y ); + rc.fin_pos.loc = wm->ourRobot[5].pos.loc + (di / diss) * (diss - 500); + } + */ + + /* + rc.fin_pos.loc = fpos; + rc.maxSpeed = 2; + rc.useNav = true; + */ + + /* + Segment2D line (Field::ourGoalCenter, wm->oppRobot[idtest].pos.loc); + Circle2D cir (wm->oppRobot[idtest].pos.loc, 500); + Vector2D first, second; + cir.intersection(line, &first, &second); + fpos = first; + rc.fin_pos.loc = fpos; + rc.maxSpeed = 2; + rc.useNav = true; + */ + + /* + rc.fin_pos.loc = fpos; + rc.maxSpeed = 2; + rc.useNav = true; + */ + + /* + if (idtest == 0) + { + rc.fin_pos.loc = fpos; + rc.maxSpeed = 2; + rc.useNav = true; + + double t = atan( (wm->ball.pos.loc.y - wm->ourRobot[id].pos.loc.y) / (wm->ball.pos.loc.x - wm->ourRobot[id].pos.loc.x) ); + if (wm->ball.pos.loc.x - wm->ourRobot[id].pos.loc.x < 0) + if (wm->ball.pos.loc.y - wm->ourRobot[id].pos.loc.y > 0) + t += 3.1415; + else + t -= 3.1415; + rc.fin_pos.dir = t; + } + + if (idtest == 1) + { + Line2D line (wm->ball.pos.loc, fpos); + Circle2D cir (wm->ball.pos.loc, ROBOT_RADIUS + 5); + Vector2D first, second, dot; + cir.intersection(line, &first, &second); + if ((first - fpos).length() < (second - fpos).length()) + dot = second; + else + dot = first; + + double t = atan( (fpos.y - wm->ball.pos.loc.y) / (fpos.x - wm->ball.pos.loc.x) ); + if (fpos.x - wm->ball.pos.loc.x < 0) + if (fpos.y - wm->ball.pos.loc.y > 0) + t += 3.1415; + else + t -= 3.1415; + + rc.fin_pos.loc = dot; + rc.maxSpeed = 2; + rc.useNav = true; + rc.fin_pos.dir = t; + + if (abs(wm->ourRobot[id].pos.dir - t) < 0.2) + rc.kickspeedx = 4; + + //std::cout << wm->ourRobot[id].pos.dir << ":::" << t << std::endl; + } + */ + //................................. + //Vector2D v(-1000,0); + rc.fin_pos.loc = fpos; + //rc.fin_pos.dir = (wm->ball.pos.loc - fpos).dir().radian(); + rc.maxSpeed = 2; + rc.useNav = true; + + + /* + if (wm->gs == STATE_Stop) + { + Segment2D line (Field::ourGoalCenter, wm->ball.pos.loc); + Circle2D cir (wm->ball.pos.loc, 500); + Vector2D first, second; + cir.intersection(line, &first, &second); + fpos = first; + rc.fin_pos.loc = fpos; + rc.maxSpeed = 2; + rc.useNav = true; + } + + if (wm->cmgs.theirFreeKick()) + { + qDebug()<<"oppFreeKick"; + rc.fin_pos.loc = Field::ourGoalCenter; + rc.maxSpeed = 2; + rc.useNav = true; + } + + if (wm->gs == STATE_Halt) + { + rc.fin_pos.loc = wm->ourRobot[id].pos.loc; + rc.maxSpeed = 2; + rc.useNav = true; + } + + if (wm->cmgs.ourFreeKick()) + { + qDebug()<<"ourFreeKick"; + Vector2D fposTest = Field::oppGoalCenter; + Line2D line (wm->ball.pos.loc, fposTest); + Circle2D cir (wm->ball.pos.loc, ROBOT_RADIUS + 5); + Vector2D first, second, dot; + cir.intersection(line, &first, &second); + if ((first - fposTest).length() < (second - fposTest).length()) + dot = second; + else + dot = first; + + double t = atan( (fposTest.y - wm->ball.pos.loc.y) / (fposTest.x - wm->ball.pos.loc.x) ); + if (fposTest.x - wm->ball.pos.loc.x < 0) + if (fposTest.y - wm->ball.pos.loc.y > 0) + t += 3.1415; + else + t -= 3.1415; + + rc.fin_pos.loc = dot; + rc.maxSpeed = 2; + rc.useNav = true; + rc.fin_pos.dir = t; + + if (abs(wm->ourRobot[id].pos.dir - t) < 0.2) + rc.kickspeedx = 4; + + } + */ return rc; } + +void TacticTest::setpos(Vector2D pos) +{ + fpos = pos; +} + +void TacticTest::setidtest(int idt) +{ + idtest = idt; +} diff --git a/src/ai/tactic/tactictest.h b/src/ai/tactic/tactictest.h index 3b2f8cb..ca14ad8 100644 --- a/src/ai/tactic/tactictest.h +++ b/src/ai/tactic/tactictest.h @@ -9,9 +9,14 @@ class TacticTest : public Tactic explicit TacticTest(WorldModel *worldmodel, QObject *parent = 0); virtual RobotCommand getCommand(); + void setpos ( Vector2D pos); + + void setidtest (int idt); + private: - Skill *sTest; + Vector2D fpos; + int idtest; }; -#endif // TACTICTEST_H +#endif // diff --git a/src/ai/tactic/tactictest2.cpp b/src/ai/tactic/tactictest2.cpp index 40fcffd..7477788 100644 --- a/src/ai/tactic/tactictest2.cpp +++ b/src/ai/tactic/tactictest2.cpp @@ -8,5 +8,9 @@ RobotCommand TacticTest2::getCommand() RobotCommand rc; if(!wm->ourRobot[id].isValid) return rc; + rc.fin_pos.loc = Vector2D(1300,100); + rc.maxSpeed = 2; + rc.useNav = true; + return rc; } diff --git a/src/ai/tactic/tactictest2.h b/src/ai/tactic/tactictest2.h index a60e6b9..74b491a 100644 --- a/src/ai/tactic/tactictest2.h +++ b/src/ai/tactic/tactictest2.h @@ -11,5 +11,7 @@ class TacticTest2: public Tactic explicit TacticTest2(WorldModel *worldmodel, QObject *parent = 0); virtual RobotCommand getCommand(); +private: + }; #endif // TACTICTEST2_H diff --git a/src/kn2cssl_new.pro.user.18 b/src/kn2cssl_new.pro.user.18 new file mode 100644 index 0000000..e193252 --- /dev/null +++ b/src/kn2cssl_new.pro.user.18 @@ -0,0 +1,271 @@ + + + + + + EnvironmentId + {a58473ed-b6ed-4db1-a972-6f88c31ab903} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.5.0 GCC 64bit + Desktop Qt 5.5.0 GCC 64bit + qt.55.gcc_64_kit + 0 + 0 + 0 + + /home/sadra/Desktop/kn2cPrograms/build-kn2cssl_new-Desktop_Qt_5_5_0_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -j4 -l4 + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/sadra/Desktop/kn2cPrograms/build-kn2cssl_new-Desktop_Qt_5_5_0_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + kn2cssl_new + + Qt4ProjectManager.Qt4RunConfiguration:/home/sadra/Desktop/kn2cPrograms/src/kn2cssl_new.pro + + kn2cssl_new.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/src/kn2cssl_new.pro.user.a58473e b/src/kn2cssl_new.pro.user.a58473e new file mode 100644 index 0000000..83c4924 --- /dev/null +++ b/src/kn2cssl_new.pro.user.a58473e @@ -0,0 +1,260 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.2.1 GCC 64bit + Desktop Qt 5.2.1 GCC 64bit + qt.521.gcc_64.essentials_kit + 0 + 0 + 0 + + /home/sadra/Desktop/kn2cPrograms/build-kn2cssl_new-Desktop_Qt_5_2_1_GCC_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -j4 -l4 + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/sadra/Desktop/kn2cPrograms/build-kn2cssl_new-Desktop_Qt_5_2_1_GCC_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + kn2cssl_new + + Qt4ProjectManager.Qt4RunConfiguration:/home/sadra/Desktop/kn2cPrograms/src/kn2cssl_new.pro + + kn2cssl_new.pro + false + false + + 3768 + true + false + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {a58473ed-b6ed-4db1-a972-6f88c31ab903} + + + ProjectExplorer.Project.Updater.FileVersion + 15 + + diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui index d0c4f03..13bd469 100644 --- a/src/ui/mainwindow.ui +++ b/src/ui/mainwindow.ui @@ -802,6 +802,9 @@ A* Nodes + + true + @@ -820,6 +823,9 @@ Debug Points + + true + diff --git a/src/ui/renderarea.cpp b/src/ui/renderarea.cpp index 9d35aa6..a7409c9 100644 --- a/src/ui/renderarea.cpp +++ b/src/ui/renderarea.cpp @@ -254,7 +254,8 @@ void RenderArea::paintEvent(QPaintEvent *) QPoint point(_sc->wm->debug_pos.at(i).x/WORLD_SCALE, -_sc->wm->debug_pos.at(i).y/WORLD_SCALE); painter.setPen(QColor::fromRgb(255,0,0)); painter.setBrush(*brush_debug); - painter.drawEllipse(point,BALL_R,BALL_R); + //painter.drawEllipse(point,BALL_R,BALL_R); + painter.drawEllipse(point,1,1); } } else if(_sc->wm->debug_type == 2)