├── .gitignore ├── .gitmodules ├── CMake └── FindZeroMQ.cmake ├── CMakeLists.txt ├── Data ├── ballFilterFast.txt ├── ballFilterSlow.txt ├── config.toml ├── config_schema.json └── strategy.ims ├── README.md ├── Source ├── Common │ ├── ControlBlock.h │ ├── GameSetting.h │ ├── MATHS_REGRESSION_PARABOLIC.cpp │ ├── MATHS_REGRESSION_PARABOLIC.h │ ├── MedianFilter.h │ ├── PID_Controller.cpp │ ├── PID_Controller.h │ ├── Random.cpp │ ├── Random.h │ ├── Vector.cpp │ ├── Vector.h │ ├── common_colors.cpp │ ├── common_colors.h │ ├── config │ │ ├── config.cpp │ │ └── config.h │ ├── debug │ │ ├── debug.cpp │ │ └── debug.h │ ├── distance.cpp │ ├── distance.h │ ├── kbhit.cpp │ ├── kbhit.h │ ├── linear.cpp │ ├── linear.h │ ├── logging │ │ ├── logging.cpp │ │ └── logging.h │ ├── net_log.cpp │ ├── net_log.h │ ├── network │ │ ├── udp_client.cpp │ │ ├── udp_client.h │ │ ├── udp_server.cpp │ │ └── udp_server.h │ ├── parameter.cpp │ ├── parameter.h │ ├── poly_find.cpp │ ├── poly_find.h │ ├── services.h │ ├── setting.h │ ├── timer.cpp │ └── timer.h ├── Network │ ├── PracticalSocket.cpp │ ├── PracticalSocket.h │ └── Protobuf │ │ ├── Imm_wrapper.proto │ │ ├── data_plot.proto │ │ ├── grSim_Commands.proto │ │ ├── grSim_Packet.proto │ │ ├── grSim_Replacement.proto │ │ ├── messages_robocup_ssl_detection.proto │ │ ├── messages_robocup_ssl_geometry.proto │ │ ├── messages_robocup_ssl_geometry_legacy.proto │ │ ├── messages_robocup_ssl_wrapper.proto │ │ ├── messages_robocup_ssl_wrapper_legacy.proto │ │ ├── referee2018.proto │ │ ├── strategy.proto │ │ ├── text_log.proto │ │ └── visual_log.proto ├── Reality │ ├── Plotter │ │ ├── plotter.cpp │ │ └── plotter.h │ ├── Referee_2018 │ │ ├── NewReferee.cpp │ │ ├── NewReferee.h │ │ ├── commands.h │ │ ├── commands2018.h │ │ ├── commandsOLD.h │ │ └── game_state.h │ ├── Sender │ │ ├── Protocol │ │ │ ├── data_lite.h │ │ │ ├── defines.h │ │ │ ├── half.c │ │ │ ├── half.h │ │ │ ├── reader.c │ │ │ ├── reader.h │ │ │ ├── writer.c │ │ │ └── writer.h │ │ ├── Sender.cpp │ │ └── Sender.h │ ├── Vision │ │ ├── Kalman │ │ │ ├── FilteredObject.cpp │ │ │ └── FilteredObject.h │ │ ├── Vision.cpp │ │ ├── Vision.h │ │ ├── VisionBall.cpp │ │ ├── VisionComminucation.cpp │ │ ├── VisionParam.cpp │ │ ├── VisionRobot.cpp │ │ └── visionPrediction.cpp │ ├── WorldState.cpp │ └── WorldState.h ├── Soccer │ ├── ai09 │ │ ├── CalcIsDefending.cpp │ │ ├── DefGhuz.cpp │ │ ├── DefHi.cpp │ │ ├── FreeAngle.cpp │ │ ├── GK.cpp │ │ ├── Geom.cpp │ │ ├── Geom.h │ │ ├── Mark2Goal.cpp │ │ ├── NormalPlay.cpp │ │ ├── OneDef.cpp │ │ ├── OneTouchDetector.h │ │ ├── OutOfField.cpp │ │ ├── Robot.cpp │ │ ├── Robot.h │ │ ├── RobotCheck.cpp │ │ ├── ShootOut.cpp │ │ ├── TwoDef.cpp │ │ ├── VelocityProfile.h │ │ ├── ai09.cpp │ │ ├── ai09.h │ │ ├── ai09_process.cpp │ │ ├── attackFuckingAngle.cpp │ │ ├── backPass.cpp │ │ ├── ballIsGoaling.cpp │ │ ├── ballTrajectory.cpp │ │ ├── calculate_mark_cost.cpp │ │ ├── calculate_opp_threat.cpp │ │ ├── calculate_swicth_to_attacker_score.cpp │ │ ├── circle_ball.cpp │ │ ├── cmuAngle.cpp │ │ ├── cmu_goto_point.cpp │ │ ├── cmu_goto_point.h │ │ ├── data_flow.cpp │ │ ├── data_flow.h │ │ ├── def_2018.cpp │ │ ├── defenceWall.cpp │ │ ├── dribblr.cpp │ │ ├── dss │ │ │ ├── Dss.cpp │ │ │ ├── Dss.h │ │ │ ├── Parabolic.cpp │ │ │ ├── Parabolic.h │ │ │ ├── Trajectory.cpp │ │ │ └── Trajectory.h │ │ ├── errt │ │ │ ├── errt.cpp │ │ │ ├── errt.h │ │ │ ├── obstacle.cpp │ │ │ ├── obstacle.h │ │ │ ├── obstacle_circle.cpp │ │ │ ├── obstacle_map.cpp │ │ │ ├── obstacle_new.h │ │ │ ├── obstacle_rectangle.cpp │ │ │ ├── tree.cpp │ │ │ └── tree.h │ │ ├── errt_setObs.cpp │ │ ├── evaluate.cpp │ │ ├── findCruncherOpp.cpp │ │ ├── findGusheRobot.cpp │ │ ├── findJeloOpps.cpp │ │ ├── findKickerOpp.cpp │ │ ├── gkHi.cpp │ │ ├── gkHi_Simple.cpp │ │ ├── gk_ghuz.cpp │ │ ├── goalBlocked.cpp │ │ ├── halt.cpp │ │ ├── helpers.cpp │ │ ├── helpers.h │ │ ├── intercept_ball.cpp │ │ ├── internalFinalize.cpp │ │ ├── internalProcessData.cpp │ │ ├── manageAttRoles.cpp │ │ ├── mark.cpp │ │ ├── mark2ball.cpp │ │ ├── markManager.cpp │ │ ├── motionPlan.cpp │ │ ├── navigation.cpp │ │ ├── nearestAsshole.cpp │ │ ├── one_touch_score.cpp │ │ ├── pass.cpp │ │ ├── pass_gool.cpp │ │ ├── pass_omghi.cpp │ │ ├── penalty.cpp │ │ ├── placeBall.cpp │ │ ├── planner.h │ │ ├── play_book.cpp │ │ ├── plays │ │ │ ├── NewNormalPlay.cpp │ │ │ ├── NormalPlayAtt.cpp │ │ │ ├── NormalPlayDef.cpp │ │ │ ├── corner_simple_chip.cpp │ │ │ ├── corner_simple_pass.cpp │ │ │ ├── corner_switch_pass.cpp │ │ │ ├── corner_their_def_ajor.cpp │ │ │ ├── corner_their_def_karkas.cpp │ │ │ ├── corner_their_global.cpp │ │ │ ├── corner_their_marker_ajor.cpp │ │ │ ├── corner_their_marker_karkas.cpp │ │ │ ├── corner_their_mrl.cpp │ │ │ ├── corner_their_skuba.cpp │ │ │ ├── far_penalty_shoot.cpp │ │ │ ├── kickoff_their_back_def.cpp │ │ │ ├── kickoff_their_one_wall.cpp │ │ │ ├── kickoff_us_chip.cpp │ │ │ ├── kickoff_us_farar.cpp │ │ │ ├── kickoff_us_pass.cpp │ │ │ ├── kickoff_us_zamini.cpp │ │ │ ├── penalty_their_gool.cpp │ │ │ ├── penalty_their_simple.cpp │ │ │ ├── penalty_us_ghuz.cpp │ │ │ ├── stop.cpp │ │ │ ├── stop_def.cpp │ │ │ ├── strategy_maker.cpp │ │ │ ├── tech_challenge.cpp │ │ │ ├── tech_circle.cpp │ │ │ ├── tech_cmu.cpp │ │ │ ├── tech_khers.cpp │ │ │ ├── tech_khers_def.cpp │ │ │ ├── tech_mexico.cpp │ │ │ ├── tech_motion_ann.cpp │ │ │ ├── throwin_chip_shoot.cpp │ │ │ ├── throwin_their_khafan.cpp │ │ │ ├── throwin_tu_omgh.cpp │ │ │ └── throwin_us_outgir.cpp │ │ ├── recievePass.cpp │ │ ├── strategyWeight.cpp │ │ ├── test.cpp │ │ ├── their_place_ball.cpp │ │ ├── trapezoid.cpp │ │ └── trapezoid.h │ ├── aiBase.cpp │ └── aiBase.h ├── grsim_fwd.cpp ├── grsim_fwd.h ├── main.cpp └── pch.h └── vcpkg.json /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore thumbnails created by windows 3 | Thumbs.db 4 | #Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.cache 20 | *.ilk 21 | *.log 22 | [Bb]in 23 | *.lib 24 | *.sbr 25 | obj/ 26 | [Rr]elease*/ 27 | _ReSharper*/ 28 | [Tt]est[Rr]esult* 29 | *.opensdf 30 | *.sdf 31 | build/ 32 | ._* 33 | .DS_Store 34 | .idea 35 | Projects 36 | Source/Reality/Vision/Protobuf/*.pb.h 37 | Source/Reality/Vision/Protobuf/*.pb.cc 38 | Source/Reality/Vision/Protobuf/*.java 39 | 3rdparty 40 | cmake-build-debug 41 | #Ignore the generated protobuf files 42 | **/Protobuf/*.pb.cc 43 | **/Protobuf/*.pb.h 44 | 45 | 46 | out 47 | log 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vcpkg"] 2 | path = vcpkg 3 | url = git@github.com:microsoft/vcpkg.git 4 | -------------------------------------------------------------------------------- /Data/ballFilterFast.txt: -------------------------------------------------------------------------------- 1 | -0.206088 0.001880 2 | -37.601656 0.169928 3 | 0.229689 -37.099475 4 | 1.000000 0.000000 5 | 0.000000 1.000000 6 | 0.887195 49.804294 7 | 0.112805 -49.804294 8 | -------------------------------------------------------------------------------- /Data/ballFilterSlow.txt: -------------------------------------------------------------------------------- 1 | 0.213300 0.009390 2 | -18.779746 0.807168 3 | 0.551861 8.349313 4 | 1.000000 0.000000 5 | 0.000000 1.000000 6 | 0.436608 11.569924 7 | 0.563392 -11.569924 8 | -------------------------------------------------------------------------------- /Data/strategy.ims: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immortals-Robotics/Software/9fc9a8e7ab17d58bef099812a2b90677cfe5ec86/Data/strategy.ims -------------------------------------------------------------------------------- /Source/Common/ControlBlock.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 5/29/18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_CONTROLBLOCK_H 6 | #define IMMORTALSSSL_CONTROLBLOCK_H 7 | 8 | #include 9 | #include "deque" 10 | 11 | class median{ 12 | private: 13 | std::deque buff; 14 | int len; 15 | 16 | public: 17 | 18 | median(int _len):len(_len) {} 19 | 20 | void add_data(float num){ 21 | buff.push_back(num); 22 | if(buff.size()>len){ 23 | buff.pop_front(); 24 | } 25 | } 26 | 27 | float get_output(){ 28 | std::deque temp(buff); 29 | std::sort(temp.begin(), temp.end(), 30 | [](float const &a, float const &b) { 31 | return a < b; 32 | } 33 | ); 34 | int buff_size; 35 | if((buff_size = temp.size()) > 0) 36 | return temp.at(buff_size/2); 37 | else { 38 | std::cout<<"median: ERROR the buff is empty!!!"<< std::endl; 39 | return 0.0; 40 | } 41 | } 42 | 43 | void print_all(){ 44 | std::deque temp(buff); 45 | std::sort(temp.begin(), temp.end(), 46 | [](float const &a, float const &b) { 47 | return a < b; 48 | } 49 | ); 50 | for(std::deque::iterator it = temp.begin();it!=temp.end();it++) { 51 | 52 | std::cout<<*it<<"_"; 53 | 54 | } 55 | std::cout<< std::endl; 56 | for(int i=0;i 3 | #include 4 | 5 | template 6 | class MedianFilter 7 | { 8 | std::vector data; 9 | std::vector temp; 10 | bool index; 11 | int size; 12 | 13 | public: 14 | MedianFilter( int _size = 10 ) 15 | { 16 | index = false; 17 | size = _size; 18 | } 19 | 20 | void AddData ( T in ) 21 | { 22 | if ( index == 0 ) 23 | { 24 | for ( int i = 0 ; i < size ; i ++ ) 25 | data.push_back(in); 26 | index = true; 27 | } 28 | else 29 | { 30 | data.push_back(in); 31 | data.erase(data.begin()); 32 | } 33 | } 34 | 35 | T GetCurrent ( void ) 36 | { 37 | temp = data; 38 | std::sort ( temp.begin() , temp.end() ); 39 | if ( size%2 == 0 ) 40 | return ( temp.at(temp.size()/2) + temp.at(1+temp.size()/2) ) / 2; 41 | return temp.at(temp.size()/2); 42 | } 43 | 44 | void reset ( void ) 45 | { 46 | data.clear(); 47 | index = false; 48 | } 49 | }; -------------------------------------------------------------------------------- /Source/Common/PID_Controller.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by server on 2/13/18. 3 | // 4 | 5 | #include "PID_Controller.h" 6 | 7 | PID_Controller::PID_Controller(double iGain, double pGain, double dGain, double iMax, double iMin) : 8 | iGain(iGain),pGain(pGain),dGain(dGain),iMax(iMax),iMin(iMin),iState(0.0) { 9 | 10 | } 11 | 12 | double PID_Controller::calcPI(double error) { 13 | double pTerm = pGain * error; 14 | double iTerm; 15 | 16 | double iState = iState + error; 17 | 18 | if(iState>iMax) 19 | iState=iMax; 20 | if(iState(min, max); 15 | } 16 | 17 | Random::~Random() 18 | { 19 | delete rnd_device; 20 | delete rnd_engine; 21 | delete rnd_dist; 22 | } 23 | 24 | float Random::get() const 25 | { 26 | return (*rnd_dist)(*rnd_engine); 27 | } 28 | -------------------------------------------------------------------------------- /Source/Common/Random.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Random 5 | { 6 | private: 7 | std::random_device *rnd_device; 8 | std::mt19937 *rnd_engine; 9 | std::uniform_real_distribution *rnd_dist; 10 | 11 | float min; 12 | float max; 13 | public: 14 | Random(); 15 | Random(float _min, float _max); 16 | ~Random(void); 17 | 18 | float get(void) const; 19 | }; 20 | -------------------------------------------------------------------------------- /Source/Common/Vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct TVec2 4 | { 5 | float X; 6 | float Y; 7 | }; 8 | 9 | struct TVec3 10 | { 11 | float X; 12 | float Y; 13 | float Z; 14 | }; 15 | 16 | TVec2 Vec2 ( float X , float Y ); 17 | TVec2 Vec2 ( float a = 0.0f ); 18 | TVec3 Vec3 ( float X , float Y , float Z ); 19 | TVec3 Vec3 ( float a = 0.0f ); 20 | 21 | TVec2 operator + ( const TVec2 & a , const TVec2 & b ); 22 | TVec2 operator - ( const TVec2 & a , const TVec2 & b ); 23 | TVec2 operator * ( const TVec2 & a , const TVec2 & b ); 24 | TVec2 operator / ( const TVec2 & a , const TVec2 & b ); 25 | TVec2 operator * ( const TVec2 & a , const float b ); 26 | TVec2 operator / ( const TVec2 & a , const float b ); 27 | TVec2 operator += ( TVec2 & a , const TVec2 & b ); 28 | TVec2 operator -= ( TVec2 & a , const TVec2 & b ); 29 | TVec2 operator *= ( TVec2 & a , const TVec2 & b ); 30 | TVec2 operator /= ( TVec2 & a , const TVec2 & b ); 31 | TVec2 operator *= ( TVec2 & a , const float b ); 32 | TVec2 operator /= ( TVec2 & a , const float b ); 33 | 34 | TVec3 operator + ( const TVec3 & a , const TVec3 & b ); 35 | TVec3 operator - ( const TVec3 & a , const TVec3 & b ); 36 | TVec3 operator * ( const TVec3 & a , const TVec3 & b ); 37 | TVec3 operator / ( const TVec3 & a , const TVec3 & b ); 38 | TVec3 operator * ( const TVec3 & a , const float b ); 39 | TVec3 operator / ( const TVec3 & a , const float b ); 40 | TVec3 operator += ( TVec3 & a , const TVec3 & b ); 41 | TVec3 operator -= ( TVec3 & a , const TVec3 & b ); 42 | TVec3 operator *= ( TVec3 & a , const TVec3 & b ); 43 | TVec3 operator /= ( TVec3 & a , const TVec3 & b ); 44 | TVec3 operator *= ( TVec3 & a , const float b ); 45 | TVec3 operator /= ( TVec3 & a , const float b ); 46 | 47 | TVec2 Normalize ( const TVec2& a ); 48 | TVec3 Normalize ( const TVec3& a ); 49 | 50 | float Magnitude ( const TVec2& a ); 51 | float Magnitude ( const TVec3& a ); 52 | 53 | 54 | float Dot ( const TVec2& a , const TVec2& b ); 55 | float Dot ( const TVec3& a , const TVec3& b ); 56 | 57 | TVec2 Rotate( const TVec2& v, const double a); -------------------------------------------------------------------------------- /Source/Common/common_colors.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum CommonColor{ 4 | Alice_Blue = 0, 5 | Antique_White , 6 | Aqua , 7 | Aquamarine , 8 | Azure , 9 | Beige , 10 | Bisque , 11 | Black , 12 | Blanched_Almond , 13 | Blue , 14 | Blue_Violet , 15 | Brown , 16 | Burlywood , 17 | Cadet_Blue , 18 | Chartreuse , 19 | Chocolate , 20 | Coral , 21 | Cornflower_Blue , 22 | Cornsilk , 23 | Cyan , 24 | Dark_Blue , 25 | Dark_Cyan , 26 | Dark_Goldenrod , 27 | Dark_Gray , 28 | Dark_Green , 29 | Dark_Khaki , 30 | Dark_Magenta , 31 | Dark_Olive_Green , 32 | Dark_Orange , 33 | Dark_Orchid , 34 | Dark_Red , 35 | Dark_Salmon , 36 | Dark_Sea_Green , 37 | Dark_Slate_Blue , 38 | Dark_Slate_Gray , 39 | Dark_Turquoise , 40 | Dark_Violet , 41 | Deep_Pink , 42 | Deep_Sky_Blue , 43 | Dim_Gray , 44 | Dodger_Blue , 45 | Firebrick , 46 | Floral_White , 47 | Forest_Green , 48 | Fuschia , 49 | Gainsboro , 50 | Ghost_White , 51 | Gold , 52 | Goldenrod , 53 | Gray , 54 | Green , 55 | Green_Yellow , 56 | Honeydew , 57 | Hot_Pink , 58 | Indian_Red , 59 | Ivory , 60 | Khaki , 61 | Lavender , 62 | Lavender_Blush , 63 | Lawn_Green , 64 | Lemon_Chiffon , 65 | Light_Blue , 66 | Light_Coral , 67 | Light_Cyan , 68 | Light_Goldenrod , 69 | Light_Goldenrod_Yellow , 70 | Light_Gray , 71 | Light_Green , 72 | Light_Pink , 73 | Light_Salmon , 74 | Light_Sea_Green , 75 | Light_Sky_Blue , 76 | Light_Slate_Blue , 77 | Light_Slate_Gray , 78 | Light_Steel_Blue , 79 | Light_Yellow , 80 | Lime , 81 | Lime_Green , 82 | Linen , 83 | Magenta , 84 | Maroon , 85 | Medium_Aquamarine , 86 | Medium_Blue , 87 | Medium_Orchid , 88 | Medium_Purple , 89 | Medium_Sea_Green , 90 | Medium_Slate_Blue , 91 | Medium_Spring_Green , 92 | Medium_Turquoise , 93 | Medium_Violet_Red , 94 | Midnight_Blue , 95 | Mint_Cream , 96 | Misty_Rose , 97 | Moccasin , 98 | Navajo_White , 99 | Navy , 100 | Old_Lace , 101 | Olive , 102 | Olive_Drab , 103 | Orange , 104 | Orange_Red , 105 | Orchid , 106 | Pale_Goldenrod , 107 | Pale_Green , 108 | Pale_Turquoise , 109 | Pale_Violet_Red , 110 | Papaya_Whip , 111 | Peach_Puff , 112 | Peru , 113 | Pink , 114 | Plum , 115 | Powder_Blue , 116 | Purple , 117 | Red , 118 | Rosy_Brown , 119 | Royal_Blue , 120 | Saddle_Brown , 121 | Salmon , 122 | Sandy_Brown , 123 | Sea_Green , 124 | Seashell , 125 | Sienna , 126 | Silver , 127 | Sky_Blue , 128 | Slate_Blue , 129 | Slate_Gray , 130 | Snow , 131 | Spring_Green , 132 | Steel_Blue , 133 | Tan , 134 | Teal , 135 | Thistle , 136 | Tomato , 137 | Turquoise , 138 | Violet , 139 | Violet_Red , 140 | Wheat , 141 | White , 142 | White_Smoke , 143 | Yellow , 144 | Yellow_Green 145 | }; 146 | 147 | const int CommonColorsNum = 141; 148 | 149 | extern float CommonColorVal[141][3]; -------------------------------------------------------------------------------- /Source/Common/config/config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | ConfigReader::ConfigReader(const std::string_view t_file_path) 4 | { 5 | const std::filesystem::path data_dir(DATA_DIR); 6 | const std::filesystem::path file(t_file_path); 7 | m_file_path = data_dir / file; 8 | 9 | load(); 10 | } 11 | 12 | void ConfigReader::load() 13 | { 14 | toml::parse_result config = toml::parse_file(m_file_path.string()); 15 | 16 | m_table = std::move(config).table(); 17 | } 18 | -------------------------------------------------------------------------------- /Source/Common/config/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class ConfigReader 4 | { 5 | public: 6 | explicit ConfigReader(std::string_view t_file_path); 7 | 8 | void load(); 9 | 10 | [[nodiscard]] auto getRoot() const 11 | { 12 | return static_cast>(m_table); 13 | } 14 | 15 | private: 16 | std::filesystem::path m_file_path; 17 | 18 | toml::table m_table; 19 | }; 20 | 21 | struct IConfig 22 | { 23 | protected: 24 | ~IConfig() = default; 25 | 26 | public: 27 | virtual void load(toml::node_view t_node) = 0; 28 | }; 29 | -------------------------------------------------------------------------------- /Source/Common/debug/debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../network/udp_server.h" 3 | 4 | #include "../Vector.h" 5 | 6 | struct Color 7 | { 8 | Color(const int t_r, const int t_g, const int t_b) 9 | : r(t_r), g(t_g), b(t_b) 10 | {} 11 | 12 | int r, g, b; 13 | }; 14 | 15 | class Debug 16 | { 17 | private: 18 | Debug(NetworkAddress t_address, bool t_enabled); 19 | ~Debug() = default; 20 | 21 | friend struct Services; 22 | 23 | public: 24 | Debug(const Debug &) = delete; 25 | Debug &operator=(const Debug &) = delete; 26 | 27 | void broadcast(); 28 | 29 | // Plotting 30 | void plotPoint(std::string_view t_func_name, double t_x, double t_y, std::string_view t_point_name = "") const; 31 | 32 | void drawPoint(TVec2 t_pos, std::string_view t_layer = "point_0", Color t_color = Color(255, 0, 0)) const; 33 | void drawLineSegment(TVec2 t_pos1, TVec2 t_pos2, std::string_view t_layer = "line_0", 34 | Color t_color = Color(0, 255, 0)) const; 35 | void drawRect(const TVec2& p, float w, float h, std::string_view t_layer = "rect_0", Color t_color = Color(0, 0, 255)) const; 36 | void drawCircle(const TVec2 ¢er, float r, std::string_view t_layer = "cir_0", 37 | Color t_color = Color(255, 255, 0)) const; 38 | void drawRobot(TVec2 t_pos, float t_angle, int t_id, std::string_view t_layer = "bot_0", 39 | Color t_color = Color(255, 255, 0)) const; 40 | 41 | // Text Logging 42 | void logMessage(std::string_view t_title, std::string_view t_text) const; 43 | void logMessage(std::string_view t_title, double t_num) const; 44 | 45 | protected: 46 | bool m_enabled; 47 | 48 | private: 49 | static inline Debug* m_instance; 50 | 51 | // UDP_connection 52 | NetworkAddress m_address; 53 | std::unique_ptr m_udp; 54 | 55 | std::unique_ptr m_wrapper; 56 | 57 | uint32_t m_last_sent_frame_id = 0; 58 | }; 59 | -------------------------------------------------------------------------------- /Source/Common/distance.cpp: -------------------------------------------------------------------------------- 1 | #include "distance.h" 2 | #include 3 | 4 | float dis_lut [610][410]; 5 | 6 | void calculate_dis_lut ( void ) 7 | { 8 | for ( int i = 0 ; i < 610 ; i ++ ) 9 | for ( int j = 0 ; j < 410 ; j ++ ) 10 | dis_lut[i][j] = sqrt((float)( i * i + j * j ) ); 11 | //int a; 12 | } 13 | 14 | float dx , dy , dz; 15 | 16 | float DIS ( const TVec3 a , const TVec3 b ) 17 | { 18 | dx = a.X - b.X; 19 | dy = a.Y - b.Y; 20 | dz = a.Z - b.Z; 21 | return sqrt ( ( dx ) * ( dx ) + 22 | ( dy ) * ( dy ) + 23 | ( dz ) * ( dz ) ); 24 | } 25 | 26 | float DIS ( const TVec2 a , const TVec2 b ) 27 | { 28 | dx = a.X - b.X; 29 | dy = a.Y - b.Y; 30 | return sqrt ( dx * dx + dy * dy ); 31 | } 32 | 33 | float DISPOW ( TVec2 a , const TVec2 b ) 34 | { 35 | dx = a.X - b.X; 36 | dy = a.Y - b.Y; 37 | return ( dx * dx + dy * dy ); 38 | } 39 | 40 | float DISM ( const TVec2 a , const TVec2 b ) 41 | { 42 | dx = fabs ( a.X - b.X ); 43 | dy = fabs ( a.Y - b.Y ); 44 | return dx + dy; 45 | } 46 | 47 | float DIS ( const float x1 , const float y1 , const float x2 , const float y2 ) 48 | { 49 | dx = x1 - x2; 50 | dy = y1 - y2; 51 | return sqrt ( dx * dx + dy * dy ); 52 | } 53 | 54 | float DISL ( const TVec2 a , const TVec2 b ) 55 | { 56 | return dis_lut[(int)fabs(a.X-b.X)][(int)fabs(a.Y-b.Y)]; 57 | } 58 | 59 | /*float DIS ( float & a , float & b ) 60 | { 61 | return sqrt ( a * a + b * b ); 62 | }*/ 63 | -------------------------------------------------------------------------------- /Source/Common/distance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Vector.h" 5 | 6 | void calculate_dis_lut ( void ); 7 | float DIS ( const TVec3 a , const TVec3 b ); 8 | float DIS ( const TVec2 a , const TVec2 b ); 9 | float DISPOW ( TVec2 a , const TVec2 b ); 10 | float DIS ( const float x1 , const float y1 , const float x2 , const float y2 ); 11 | float DISL ( const TVec2 a , const TVec2 b ); 12 | float DISM ( const TVec2 a , const TVec2 b ); 13 | //float DIS ( float a , float b ); 14 | -------------------------------------------------------------------------------- /Source/Common/kbhit.cpp: -------------------------------------------------------------------------------- 1 | #ifndef _WIN32 2 | 3 | #include "kbhit.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void changemode(int dir) 11 | { 12 | static struct termios oldt, newt; 13 | 14 | if ( dir == 1 ) 15 | { 16 | tcgetattr( STDIN_FILENO, &oldt); 17 | newt = oldt; 18 | newt.c_lflag &= ~( ICANON | ECHO ); 19 | tcsetattr( STDIN_FILENO, TCSANOW, &newt); 20 | } 21 | else 22 | tcsetattr( STDIN_FILENO, TCSANOW, &oldt); 23 | } 24 | 25 | int kbhit (void) 26 | { 27 | struct timeval tv; 28 | fd_set rdfs; 29 | 30 | tv.tv_sec = 0; 31 | tv.tv_usec = 0; 32 | 33 | FD_ZERO(&rdfs); 34 | FD_SET (STDIN_FILENO, &rdfs); 35 | 36 | select(STDIN_FILENO+1, &rdfs, NULL, NULL, &tv); 37 | return FD_ISSET(STDIN_FILENO, &rdfs); 38 | 39 | } 40 | 41 | #endif -------------------------------------------------------------------------------- /Source/Common/kbhit.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #include 5 | #else 6 | void changemode(int); 7 | int kbhit(void); 8 | #endif -------------------------------------------------------------------------------- /Source/Common/linear.cpp: -------------------------------------------------------------------------------- 1 | #include "linear.h" 2 | 3 | #include 4 | 5 | //! Given a set of points, this class calculates the linear regression parameters and evaluates the regression line at arbitrary abscissas. 6 | 7 | void Linear::calculate(int n, float *x, float *y) 8 | { 9 | 10 | // calculate the averages of arrays x and y 11 | double xa = 0, ya = 0; 12 | for (int i = 0; i < n; i++) { 13 | xa += x[i]; 14 | ya += y[i]; 15 | } 16 | xa /= n; 17 | ya /= n; 18 | 19 | // calculate auxiliary sums 20 | double xx = 0, yy = 0, xy = 0; 21 | for (int i = 0; i < n; i++) { 22 | double tmpx = x[i] - xa, tmpy = y[i] - ya; 23 | xx += tmpx * tmpx; 24 | yy += tmpy * tmpy; 25 | xy += tmpx * tmpy; 26 | } 27 | 28 | // calculate regression line parameters 29 | amoodi = false; 30 | xinter = 0; 31 | m_a = 0; 32 | m_b = 0; 33 | m_coeff = 0; 34 | // make sure slope is not infinite 35 | if ( xx < 0.01 ) 36 | { 37 | amoodi = true; 38 | xinter = xa; 39 | return; 40 | } 41 | 42 | m_b = xy / xx; 43 | if (fabs(m_b) > 50 ) { 44 | amoodi = true; 45 | xinter = xa; 46 | return; 47 | } 48 | m_a = ya - m_b * xa; 49 | m_coeff = (fabs(yy) == 0) ? 1 : xy / sqrt(xx * yy); 50 | 51 | } 52 | 53 | //! Evaluates the linear regression function at the given abscissa. 54 | 55 | float Linear::getValue(float x) 56 | { 57 | return m_a + m_b * x; 58 | } 59 | 60 | //! Returns the slope of the regression line 61 | 62 | float Linear::getSlope() 63 | { 64 | return m_b; 65 | } 66 | 67 | //! Returns the intercept on the Y axis of the regression line 68 | 69 | float Linear::getIntercept() 70 | { 71 | return m_a; 72 | } 73 | 74 | //! Returns the linear regression coefficient 75 | 76 | float Linear::getCoefficient() 77 | { 78 | return m_coeff; 79 | } 80 | 81 | bool Linear::isAmoodi() 82 | { 83 | return amoodi; 84 | } 85 | 86 | float Linear::getXIntercept() 87 | { 88 | return xinter; 89 | } 90 | 91 | float Linear::getDisToPoint ( TVec2 p ) 92 | { 93 | if ( amoodi ) 94 | return fabs(p.X-xinter); 95 | return fabs(m_b*p.X-p.Y+m_a)/sqrt(m_b*m_b+1.0); 96 | } 97 | 98 | void Linear::chapeKon ( void ) 99 | { 100 | m_a = -m_a / m_b; 101 | m_b = 1.0f / m_b; 102 | } 103 | 104 | //! A static function implementing the Linear Class for one off calculations 105 | 106 | float Linear_once(int n, float *x, float *y, float a ) 107 | { 108 | // This function is created to enable an Instant Calculator on CodeCogs. 109 | // You probably shouldn't be using this function otherwise. 110 | 111 | Linear A; 112 | A.calculate(n, x, y); 113 | return A.getValue(a); 114 | } -------------------------------------------------------------------------------- /Source/Common/linear.h: -------------------------------------------------------------------------------- 1 | // GNU General Public License Agreement 2 | // Copyright (C) 2004-2010 CodeCogs, Zyba Ltd, Broadwood, Holford, TA5 1DU, England. 3 | // 4 | // This program is free software; you can redistribute it and/or modify it under 5 | // the terms of the GNU General Public License as published by CodeCogs. 6 | // You must retain a copy of this licence in all copies. 7 | // 8 | // This program is distributed in the hope that it will be useful, but WITHOUT ANY 9 | // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10 | // PARTICULAR PURPOSE. See the GNU General Public License for more details. 11 | // --------------------------------------------------------------------------------- 12 | //! Calculates the linear regression parameters and evaluates the regression line at arbitrary abscissas 13 | 14 | #ifndef MATHS_REGRESSION_LINEAR_H 15 | #define MATHS_REGRESSION_LINEAR_H 16 | 17 | #include "Vector.h" 18 | //! Given a set of points, this class calculates the linear regression parameters and evaluates the regression line at arbitrary abscissas. 19 | 20 | class Linear 21 | { 22 | public: 23 | 24 | void calculate(int n, float *x, float *y); 25 | 26 | //! Evaluates the linear regression function at the given abscissa. 27 | float getValue(float x); 28 | 29 | //! Returns the slope of the regression line 30 | float getSlope(); 31 | 32 | //! Returns the intercept on the Y axis of the regression line 33 | float getIntercept(); 34 | 35 | //! Returns the linear regression coefficient 36 | float getCoefficient(); 37 | 38 | bool isAmoodi(); 39 | 40 | float getXIntercept(); 41 | 42 | float getDisToPoint ( TVec2 p ); 43 | 44 | void chapeKon ( void ); 45 | 46 | private: 47 | 48 | float m_a, m_b, m_coeff, xinter; 49 | bool amoodi; 50 | }; 51 | 52 | 53 | //! A static function implementing the Linear Class for one off calculations 54 | 55 | float Linear_once(int n, float *x, float *y, float a ); 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /Source/Common/logging/logging.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Logger 4 | { 5 | protected: 6 | Logger(); 7 | ~Logger() = default; 8 | 9 | friend struct Services; 10 | 11 | private: 12 | std::filesystem::path getNewLogFilePath() const; 13 | }; 14 | -------------------------------------------------------------------------------- /Source/Common/net_log.cpp: -------------------------------------------------------------------------------- 1 | #include "net_log.h" 2 | #include 3 | #include 4 | 5 | int NetLogger::sync() 6 | { 7 | // ensure NUL termination 8 | //overflow(0); 9 | //Send data 10 | std::string data = str(); 11 | printf("%s", data.c_str()); 12 | //data.insert(0, frame_id_str); 13 | //udpSock.sendTo(data.c_str(), data.length(), logger_ip, logger_port); 14 | // clear buffer 15 | str(std::string()); 16 | return std::stringbuf::sync(); 17 | } 18 | 19 | NetLogger::NetLogger ( const std::string _address , const short _port ) 20 | :logger_ip(_address),logger_port(_port),frame_id(0){} 21 | 22 | void NetLogger::SetFrameID ( unsigned int id ) 23 | { 24 | frame_id = id; 25 | //sprintf(frame_id_str, "%u\n", frame_id); 26 | } 27 | 28 | unsigned int NetLogger::GetFrameID ( void ) 29 | { 30 | return frame_id; 31 | } 32 | 33 | void NetLogger::Init() 34 | { 35 | SetFrameID(0); 36 | std::cout.rdbuf(this); 37 | } -------------------------------------------------------------------------------- /Source/Common/net_log.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../Network/PracticalSocket.h" 5 | 6 | class NetLogger : public std::stringbuf 7 | { 8 | protected: 9 | std::string logger_ip; 10 | short logger_port; 11 | UDPSocket udpSock; 12 | 13 | unsigned int frame_id; 14 | char frame_id_str[100]; 15 | 16 | virtual int sync(); 17 | 18 | public: 19 | NetLogger ( const std::string _address , const short _port ); 20 | 21 | void SetFrameID ( unsigned int id ); 22 | unsigned int GetFrameID ( void ); 23 | 24 | void Init(); 25 | }; -------------------------------------------------------------------------------- /Source/Common/network/udp_client.cpp: -------------------------------------------------------------------------------- 1 | #include "udp_client.h" 2 | 3 | UdpClient::UdpClient(const NetworkAddress &t_address) 4 | { 5 | m_context = std::make_unique(); 6 | m_socket = std::make_unique(*m_context); 7 | 8 | m_address = asio::ip::make_address(t_address.ip); 9 | m_listen_endpoint = asio::ip::udp::endpoint{asio::ip::udp::v4(), t_address.port}; 10 | 11 | m_socket->open(m_listen_endpoint.protocol()); 12 | m_socket->set_option(asio::ip::udp::socket::reuse_address(true)); 13 | m_socket->bind(m_listen_endpoint); 14 | 15 | if (m_address.is_multicast()) 16 | { 17 | m_socket->set_option(asio::ip::multicast::join_group(m_address)); 18 | } 19 | } 20 | 21 | bool UdpClient::receive(google::protobuf::MessageLite *const t_message) 22 | { 23 | const size_t received_size = m_socket->receive_from(asio::buffer(m_buffer), m_last_receive_endpoint); 24 | 25 | if (received_size > 0) 26 | { 27 | return t_message->ParseFromArray(m_buffer.data(), received_size); 28 | } 29 | 30 | return false; 31 | } 32 | 33 | std::span UdpClient::receiveRaw() 34 | { 35 | const size_t received_size = m_socket->receive_from(asio::buffer(m_buffer), m_last_receive_endpoint); 36 | 37 | if (received_size > 0) 38 | { 39 | return std::span(m_buffer.data(), received_size); 40 | } 41 | 42 | return {}; 43 | } 44 | -------------------------------------------------------------------------------- /Source/Common/network/udp_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../setting.h" 4 | 5 | class UdpClient 6 | { 7 | public: 8 | explicit UdpClient(const NetworkAddress &t_address); 9 | 10 | bool receive(google::protobuf::MessageLite *t_message); 11 | 12 | std::span receiveRaw(); 13 | 14 | [[nodiscard]] asio::ip::udp::endpoint getListenEndpoint() const 15 | { 16 | return m_listen_endpoint; 17 | } 18 | 19 | [[nodiscard]] asio::ip::udp::endpoint getLastReceiveEndpoint() const 20 | { 21 | return m_last_receive_endpoint; 22 | } 23 | 24 | [[nodiscard]] asio::ip::address getAddress() const 25 | { 26 | return m_address; 27 | } 28 | 29 | [[nodiscard]] bool isConnected() const 30 | { 31 | return m_socket->is_open(); 32 | } 33 | 34 | private: 35 | asio::ip::udp::endpoint m_listen_endpoint; 36 | asio::ip::address m_address; 37 | 38 | asio::ip::udp::endpoint m_last_receive_endpoint; 39 | 40 | std::unique_ptr m_context; 41 | std::unique_ptr m_socket; 42 | 43 | std::array m_buffer = {}; 44 | }; 45 | -------------------------------------------------------------------------------- /Source/Common/network/udp_server.cpp: -------------------------------------------------------------------------------- 1 | #include "udp_server.h" 2 | 3 | UdpServer::UdpServer() 4 | { 5 | m_context = std::make_unique(); 6 | 7 | m_socket = std::make_unique(*m_context, asio::ip::udp::v4()); 8 | } 9 | 10 | bool UdpServer::send(const google::protobuf::MessageLite &t_message, const NetworkAddress &t_address) 11 | { 12 | if (!t_message.SerializeToArray(m_buffer.data(), m_buffer.size())){ 13 | LOG_ERROR("Failed to serializeToArray (Maybe need to adjust Setting::kMaxUdpPacketSize)"); 14 | return false; 15 | } 16 | 17 | const size_t serialized_size = t_message.ByteSizeLong(); 18 | 19 | return send(serialized_size, t_address); 20 | } 21 | 22 | bool UdpServer::send(const size_t t_size, const NetworkAddress &t_address) 23 | { 24 | const asio::ip::address_v4 address = asio::ip::make_address_v4(t_address.ip); 25 | const asio::ip::udp::endpoint endpoint{address, t_address.port}; 26 | 27 | const size_t m_sent_size = m_socket->send_to(asio::buffer(m_buffer, t_size), endpoint); 28 | 29 | return m_sent_size == t_size; 30 | } 31 | -------------------------------------------------------------------------------- /Source/Common/network/udp_server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../setting.h" 4 | 5 | class UdpServer 6 | { 7 | public: 8 | UdpServer(); 9 | 10 | // Serializes the protobuf message to the internal buffer and sends it 11 | bool send(const google::protobuf::MessageLite &t_message, const NetworkAddress &t_address); 12 | 13 | // Sends the first t_size bytes of the internal buffer 14 | bool send(size_t t_size, const NetworkAddress &t_address); 15 | 16 | std::span getBuffer() 17 | { 18 | return m_buffer; 19 | } 20 | 21 | [[nodiscard]] asio::ip::udp::endpoint getListenEndpoint() const 22 | { 23 | return m_listen_endpoint; 24 | } 25 | 26 | private: 27 | asio::ip::udp::endpoint m_listen_endpoint; 28 | 29 | std::unique_ptr m_context; 30 | std::unique_ptr m_socket; 31 | 32 | std::array m_buffer = {}; 33 | }; 34 | -------------------------------------------------------------------------------- /Source/Common/parameter.cpp: -------------------------------------------------------------------------------- 1 | #include "parameter.h" 2 | 3 | void LoadParameters ( const std::string& add , ParameterBook& parameterBook ) 4 | { 5 | } 6 | 7 | void ParseParameters ( const std::string& data , ParameterBook& parameterBook ) 8 | { 9 | } -------------------------------------------------------------------------------- /Source/Common/parameter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Vector.h" 6 | 7 | struct DataNode 8 | { 9 | union { 10 | bool _bool ; 11 | short _short ; 12 | int _int ; 13 | float _float ; 14 | double _double ; 15 | TVec2 _TVec2 ; 16 | TVec3 _TVec3 ; 17 | char c[12] ; 18 | }; 19 | std::string _string ; 20 | }; 21 | 22 | typedef std::map ParameterSet; 23 | typedef std::map ParameterBook; 24 | 25 | void LoadParameters ( const std::string& add , ParameterBook& parameterBook ); 26 | void ParseParameters ( const std::string& data , ParameterBook& parameterBook ); -------------------------------------------------------------------------------- /Source/Common/poly_find.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 26/01/17. 3 | // 4 | 5 | #if 0 6 | 7 | #ifndef QTGRAPHICTEST_POLY_FIND_H 8 | #define QTGRAPHICTEST_POLY_FIND_H 9 | 10 | #include 11 | #include 12 | 13 | class poly_find { 14 | public: 15 | poly_find(int degree); 16 | ~poly_find(); 17 | void add_point(double pos_X, double pos_Y); 18 | void calculate(); 19 | void print_res(); 20 | void reset(); 21 | double give_X_by_Y(double _Y,double start); 22 | double give_Y_by_X(double _X); 23 | double give_derivedY_by_X(double _X); 24 | void set_result(double res[]); 25 | bool is_valid(); 26 | int give_data_count(); 27 | 28 | private: 29 | int deg; 30 | std::vector _X,_Y; 31 | int data_count; 32 | double* result; 33 | double* X; 34 | double* Y; 35 | 36 | }; 37 | 38 | 39 | #endif //QTGRAPHICTEST_POLY_FIND_H 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Source/Common/services.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "setting.h" 3 | #include "logging/logging.h" 4 | #include "debug/debug.h" 5 | 6 | struct Services 7 | { 8 | static void initialize() 9 | { 10 | const ConfigReader config("config.toml"); 11 | s_setting = new Setting(); 12 | s_setting->load(config.getRoot()); 13 | 14 | s_logger = new Logger(); 15 | 16 | s_debug = new Debug(s_setting->debug_address, s_setting->enable_debug); 17 | } 18 | 19 | static void shutdown() 20 | { 21 | delete s_debug; 22 | delete s_setting; 23 | delete s_logger; 24 | } 25 | 26 | static const Setting &setting() 27 | { 28 | return *s_setting; 29 | } 30 | 31 | static Debug& debug() 32 | { 33 | return *s_debug; 34 | } 35 | 36 | private: 37 | static inline Setting* s_setting; 38 | static inline Debug* s_debug; 39 | static inline Logger* s_logger; 40 | }; 41 | 42 | static const Setting &setting() 43 | { 44 | return Services::setting(); 45 | } 46 | 47 | static Debug& debug() 48 | { 49 | return Services::debug(); 50 | } 51 | -------------------------------------------------------------------------------- /Source/Common/timer.cpp: -------------------------------------------------------------------------------- 1 | /*======================================================================== 2 | Timer.h : Simple C++ wrapper for making interval timers 3 | ------------------------------------------------------------------------ 4 | Copyright (C) 1999-2002 James R. Bruce 5 | School of Computer Science, Carnegie Mellon University 6 | ------------------------------------------------------------------------ 7 | This software is distributed under the GNU General Public License, 8 | version 2. If you do not have a copy of this licence, visit 9 | www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 10 | Suite 330 Boston, MA 02111-1307 USA. This program is distributed 11 | in the hope that it will be useful, but WITHOUT ANY WARRANTY, 12 | including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | ========================================================================*/ 14 | 15 | #include "timer.h" 16 | 17 | using namespace std::chrono; 18 | 19 | void Timer::start() { tv1 = high_resolution_clock::now(); } 20 | void Timer::end() { tv2 = high_resolution_clock::now(); } 21 | 22 | double Timer::time() 23 | { 24 | end(); 25 | auto time_span = duration_cast>(tv2 - tv1); 26 | return time_span.count(); 27 | } 28 | 29 | double Timer::interval(){ 30 | double t; 31 | tv2 = high_resolution_clock::now(); 32 | t = time(); 33 | tv1 = tv2; 34 | return(t); 35 | } 36 | -------------------------------------------------------------------------------- /Source/Common/timer.h: -------------------------------------------------------------------------------- 1 | /*======================================================================== 2 | Timer.h : Simple C++ wrapper for making interval timers 3 | ------------------------------------------------------------------------ 4 | Copyright (C) 1999-2002 James R. Bruce 5 | School of Computer Science, Carnegie Mellon University 6 | ------------------------------------------------------------------------ 7 | This software is distributed under the GNU General Public License, 8 | version 2. If you do not have a copy of this licence, visit 9 | www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 10 | Suite 330 Boston, MA 02111-1307 USA. This program is distributed 11 | in the hope that it will be useful, but WITHOUT ANY WARRANTY, 12 | including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | ========================================================================*/ 14 | 15 | #pragma once 16 | #include 17 | 18 | class Timer{ 19 | std::chrono::high_resolution_clock::time_point tv1,tv2; 20 | public: 21 | void start(); 22 | void end(); 23 | double time(); 24 | double interval(); 25 | }; 26 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/Imm_wrapper.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | import "data_plot.proto"; 4 | import "visual_log.proto"; 5 | import "text_log.proto"; 6 | 7 | message Imm_DBG_wrapper { 8 | optional raw_points DBG_raw_points = 1; 9 | optional Debug_Draw DBG_draw = 2; 10 | optional Text_Message DBG_text = 3; 11 | required uint32 frame_id = 4; 12 | } 13 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/data_plot.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message point_2D { 4 | optional string name = 1; 5 | required float x = 2; 6 | required float y = 3; 7 | } 8 | 9 | message function_2D { 10 | optional string name = 1; 11 | repeated point_2D points = 2; 12 | } 13 | 14 | message function_wrapper { 15 | repeated function_2D funcArr = 1; 16 | } 17 | 18 | // This message gives all the points in one array, unseperatly 19 | message raw_points { 20 | repeated point_2D allPoints = 1; 21 | } 22 | 23 | message data_flow { 24 | optional string name = 1; 25 | repeated float y = 2; 26 | } 27 | 28 | message data_gram { 29 | repeated data_flow data_package = 1; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/grSim_Commands.proto: -------------------------------------------------------------------------------- 1 | message grSim_Robot_Command { 2 | required uint32 id = 1; 3 | required float kickspeedx = 2; 4 | required float kickspeedz = 3; 5 | required float veltangent = 4; 6 | required float velnormal = 5; 7 | required float velangular = 6; 8 | required bool spinner = 7; 9 | required bool wheelsspeed = 8; 10 | optional float wheel1 = 9; 11 | optional float wheel2 = 10; 12 | optional float wheel3 = 11; 13 | optional float wheel4 = 12; 14 | } 15 | 16 | message grSim_Commands { 17 | required double timestamp = 1; 18 | required bool isteamyellow = 2; 19 | repeated grSim_Robot_Command robot_commands = 3; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/grSim_Packet.proto: -------------------------------------------------------------------------------- 1 | import "grSim_Commands.proto"; 2 | import "grSim_Replacement.proto"; 3 | message grSim_Packet { 4 | optional grSim_Commands commands = 1; 5 | optional grSim_Replacement replacement = 2; 6 | } -------------------------------------------------------------------------------- /Source/Network/Protobuf/grSim_Replacement.proto: -------------------------------------------------------------------------------- 1 | message grSim_RobotReplacement { 2 | required double x=1; 3 | required double y=2; 4 | required double dir=3; 5 | required uint32 id=4; 6 | required bool yellowteam=5; 7 | optional bool turnon=6; 8 | } 9 | 10 | message grSim_BallReplacement { 11 | required double x=1; 12 | required double y=2; 13 | required double vx=3; 14 | required double vy=4; 15 | } 16 | 17 | message grSim_Replacement { 18 | optional grSim_BallReplacement ball = 1; 19 | repeated grSim_RobotReplacement robots = 2; 20 | } 21 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/messages_robocup_ssl_detection.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message SSL_DetectionBall { 4 | required float confidence = 1; 5 | optional uint32 area = 2; 6 | required float x = 3; 7 | required float y = 4; 8 | optional float z = 5; 9 | required float pixel_x = 6; 10 | required float pixel_y = 7; 11 | } 12 | 13 | message SSL_DetectionRobot { 14 | required float confidence = 1; 15 | optional uint32 robot_id = 2; 16 | required float x = 3; 17 | required float y = 4; 18 | optional float orientation = 5; 19 | required float pixel_x = 6; 20 | required float pixel_y = 7; 21 | optional float height = 8; 22 | } 23 | 24 | message SSL_DetectionFrame { 25 | required uint32 frame_number = 1; 26 | required double t_capture = 2; 27 | required double t_sent = 3; 28 | required uint32 camera_id = 4; 29 | repeated SSL_DetectionBall balls = 5; 30 | repeated SSL_DetectionRobot robots_yellow = 6; 31 | repeated SSL_DetectionRobot robots_blue = 7; 32 | } 33 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/messages_robocup_ssl_geometry.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | // A 2D float vector. 3 | message Vector2f { 4 | required float x = 1; 5 | required float y = 2; 6 | } 7 | 8 | // Represents a field marking as a line segment represented by a start point p1, 9 | // and end point p2, and a line thickness. The start and end points are along 10 | // the center of the line, so the thickness of the line extends by thickness / 2 11 | // on either side of the line. 12 | message SSL_FieldLineSegment { 13 | // Name of this field marking. 14 | required string name = 1; 15 | // Start point of the line segment. 16 | required Vector2f p1 = 2; 17 | // End point of the line segment. 18 | required Vector2f p2 = 3; 19 | // Thickness of the line segment. 20 | required float thickness = 4; 21 | } 22 | 23 | // Represents a field marking as a circular arc segment represented by center point, a 24 | // start angle, an end angle, and an arc thickness. 25 | message SSL_FieldCicularArc { 26 | // Name of this field marking. 27 | required string name = 1; 28 | // Center point of the circular arc. 29 | required Vector2f center = 2; 30 | // Radius of the arc. 31 | required float radius = 3; 32 | // Start angle in counter-clockwise order. 33 | required float a1 = 4; 34 | // End angle in counter-clockwise order. 35 | required float a2 = 5; 36 | // Thickness of the arc. 37 | required float thickness = 6; 38 | } 39 | 40 | message SSL_GeometryFieldSize { 41 | required int32 field_length = 1; 42 | required int32 field_width = 2; 43 | required int32 goal_width = 3; 44 | required int32 goal_depth = 4; 45 | required int32 boundary_width = 5; 46 | repeated SSL_FieldLineSegment field_lines = 6; 47 | repeated SSL_FieldCicularArc field_arcs = 7; 48 | } 49 | 50 | message SSL_GeometryCameraCalibration { 51 | required uint32 camera_id = 1; 52 | required float focal_length = 2; 53 | required float principal_point_x = 3; 54 | required float principal_point_y = 4; 55 | required float distortion = 5; 56 | required float q0 = 6; 57 | required float q1 = 7; 58 | required float q2 = 8; 59 | required float q3 = 9; 60 | required float tx = 10; 61 | required float ty = 11; 62 | required float tz = 12; 63 | optional float derived_camera_world_tx = 13; 64 | optional float derived_camera_world_ty = 14; 65 | optional float derived_camera_world_tz = 15; 66 | } 67 | 68 | message SSL_GeometryData { 69 | required SSL_GeometryFieldSize field = 1; 70 | repeated SSL_GeometryCameraCalibration calib = 2; 71 | } 72 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/messages_robocup_ssl_geometry_legacy.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "messages_robocup_ssl_geometry.proto"; 3 | package RoboCup2014Legacy.Geometry; 4 | 5 | message SSL_GeometryFieldSize { 6 | required int32 line_width = 1; 7 | required int32 field_length = 2; 8 | required int32 field_width = 3; 9 | required int32 boundary_width = 4; 10 | required int32 referee_width = 5; 11 | required int32 goal_width = 6; 12 | required int32 goal_depth = 7; 13 | required int32 goal_wall_width = 8; 14 | required int32 center_circle_radius = 9; 15 | required int32 defense_radius = 10; 16 | required int32 defense_stretch = 11; 17 | required int32 free_kick_from_defense_dist = 12; 18 | required int32 penalty_spot_from_field_line_dist = 13; 19 | required int32 penalty_line_from_spot_dist = 14; 20 | } 21 | 22 | // SSL_GeometryCameraCalibration is identical to the one defined in 23 | // messages_robocup_ssl_geometry.proto . 24 | 25 | message SSL_GeometryData { 26 | required SSL_GeometryFieldSize field = 1; 27 | repeated SSL_GeometryCameraCalibration calib = 2; 28 | } 29 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/messages_robocup_ssl_wrapper.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "messages_robocup_ssl_detection.proto"; 3 | import "messages_robocup_ssl_geometry.proto"; 4 | 5 | message SSL_WrapperPacket { 6 | optional SSL_DetectionFrame detection = 1; 7 | optional SSL_GeometryData geometry = 2; 8 | } 9 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/messages_robocup_ssl_wrapper_legacy.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | import "messages_robocup_ssl_detection.proto"; 3 | import "messages_robocup_ssl_geometry_legacy.proto"; 4 | 5 | package RoboCup2014Legacy.Wrapper; 6 | 7 | message SSL_WrapperPacket { 8 | optional SSL_DetectionFrame detection = 1; 9 | optional RoboCup2014Legacy.Geometry.SSL_GeometryData geometry = 2; 10 | } 11 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/strategy.proto: -------------------------------------------------------------------------------- 1 | message SyncPoint 2 | { 3 | required int32 robotID = 1; 4 | required int32 pointID = 2; 5 | 6 | } 7 | 8 | message SyncData 9 | { 10 | repeated SyncPoint point = 1; 11 | } 12 | 13 | message Waypoint 14 | { 15 | enum WayType { 16 | POS = 0; 17 | TIME = 1; 18 | } 19 | 20 | enum VelProfile { 21 | AROOM = 0; 22 | MAMOOLI = 1; 23 | KHARAKI = 2; 24 | } 25 | 26 | required WayType type = 1[default = POS]; 27 | required float x = 2; 28 | required float y = 3; 29 | required bool needRRT = 4[default = true]; 30 | required float speed = 5[default = 100.0]; 31 | required VelProfile profile = 6[default = MAMOOLI]; 32 | optional float tolerance = 7[default = 100.0]; 33 | optional float time = 8; 34 | } 35 | 36 | message Role 37 | { 38 | required int32 id = 1; 39 | optional string name = 2[default = "NAN"]; 40 | repeated Waypoint path = 3; 41 | required int32 afterlife = 4; 42 | } 43 | 44 | message Strategy 45 | { 46 | required string name = 1; 47 | repeated Role role = 2; 48 | repeated SyncData sync = 3; 49 | required float minX = 4; 50 | required float maxX = 5; 51 | required float minY = 6; 52 | required float maxY = 7; 53 | 54 | } 55 | 56 | message PlayBook 57 | { 58 | repeated Strategy strategy = 1; 59 | repeated float weight = 2; 60 | 61 | } -------------------------------------------------------------------------------- /Source/Network/Protobuf/text_log.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message Debug_Text { 4 | required string text = 1; 5 | required string title = 2; 6 | } 7 | 8 | message Text_Message { 9 | repeated Debug_Text log = 1; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Source/Network/Protobuf/visual_log.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | message color 4 | { 5 | required double r = 1; 6 | required double g = 2; 7 | required double b = 3; 8 | } 9 | 10 | message Debug_Point 11 | { 12 | required double x = 1; 13 | required double y = 2; 14 | required string layer = 3; 15 | optional int32 col_r = 4 [default = 0]; 16 | optional int32 col_g = 5 [default = 0]; 17 | optional int32 col_b = 6 [default = 0]; 18 | } 19 | 20 | message Debug_Line 21 | { 22 | required double x1 = 1; 23 | required double y1 = 2; 24 | required double x2 = 3; 25 | required double y2 = 4; 26 | required string layer = 5; 27 | optional int32 col_r = 6 [default = 0]; 28 | optional int32 col_g = 7 [default = 0]; 29 | optional int32 col_b = 8 [default = 0]; 30 | } 31 | 32 | message Debug_Rect 33 | { 34 | required double x1 = 1; 35 | required double y1 = 2; 36 | required double x2 = 3; 37 | required double y2 = 4; 38 | required string layer = 5; 39 | optional int32 col_r = 6 [default = 0]; 40 | optional int32 col_g = 7 [default = 0]; 41 | optional int32 col_b = 8 [default = 0]; 42 | } 43 | 44 | message Debug_Circle 45 | { 46 | required double x = 1; 47 | required double y = 2; 48 | required double r = 3; 49 | required string layer = 4; 50 | optional int32 col_r = 5 [default = 0]; 51 | optional int32 col_g = 6 [default = 0]; 52 | optional int32 col_b = 7 [default = 0]; 53 | } 54 | 55 | message Debug_Robot 56 | { 57 | required int32 id = 1; 58 | required double x = 2; 59 | required double y = 3; 60 | required double ang = 4; 61 | required string layer = 5; 62 | optional int32 col_r = 6 [default = 0]; 63 | optional int32 col_g = 7 [default = 0]; 64 | optional int32 col_b = 8 [default = 0]; 65 | } 66 | 67 | message Debug_Draw 68 | { 69 | repeated Debug_Point point = 1; 70 | repeated Debug_Line line = 2; 71 | repeated Debug_Rect rect = 3; 72 | repeated Debug_Circle circle = 4; 73 | repeated Debug_Robot robot = 5; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /Source/Reality/Plotter/plotter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 11/29/18. 3 | // 4 | #include 5 | #include "plotter.h" 6 | 7 | 8 | void plotter::BLUE_pushData(float data){ 9 | y_Blue -> add_y(data); 10 | } 11 | 12 | void plotter::RED_pushData(float data) { 13 | y_Red -> add_y(data); 14 | } 15 | 16 | void plotter::GREEN_pushData(float data) { 17 | y_Green -> add_y(data); 18 | } 19 | 20 | void plotter::send_data() { 21 | std::string* tempSTR = new std::string(); 22 | try { 23 | bufferStream.SerializeToString(tempSTR); 24 | commUDP.sendTo ( tempSTR->c_str() , tempSTR->length() , this->UDP_Address , this->port_Address ); 25 | std::cout<<"The DATA length was: "<length()<< std::endl; 26 | } catch (...) { 27 | std::cout << "ERROR: failed to send plot packets." << std::endl; 28 | } 29 | y_Blue -> Clear(); 30 | y_Red -> Clear(); 31 | y_Green -> Clear(); 32 | 33 | } 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Source/Reality/Plotter/plotter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 11/29/18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_PLOTTER_H 6 | #define IMMORTALSSSL_PLOTTER_H 7 | 8 | 9 | #include "../../Network/Protobuf/data_plot.pb.h" 10 | #include "../../Network/PracticalSocket.h" 11 | 12 | class plotter { 13 | public: 14 | data_gram bufferStream; 15 | data_flow* y_Blue; 16 | data_flow* y_Red; 17 | data_flow* y_Green; 18 | 19 | UDPSocket commUDP; 20 | std::string UDP_Address; 21 | short port_Address; 22 | 23 | plotter(const char *const ip, const short port_num){ 24 | UDP_Address = ip; 25 | port_Address = port_num; 26 | 27 | y_Blue = bufferStream.add_data_package(); 28 | y_Blue -> set_name("BLUE DATA"); 29 | 30 | y_Red = bufferStream.add_data_package(); 31 | y_Red -> set_name("RED DATA"); 32 | 33 | y_Green = bufferStream.add_data_package(); 34 | y_Green -> set_name("GREEN DATA"); 35 | } 36 | void BLUE_pushData(float data); 37 | void RED_pushData(float data); 38 | void GREEN_pushData(float data); 39 | 40 | void send_data(); 41 | }; 42 | 43 | 44 | #endif //IMMORTALSSSL_PLOTTER_H 45 | -------------------------------------------------------------------------------- /Source/Reality/Referee_2018/NewReferee.cpp: -------------------------------------------------------------------------------- 1 | #include "NewReferee.h" 2 | #include "../../Common/distance.h" 3 | 4 | NewReferee::NewReferee ( GameSetting* settings,WorldState* state ) 5 | { 6 | if(!settings){ 7 | std::cout<<"NewReferee: \"setting\" is NULL"<< std::endl; 8 | } 9 | if(!state){ 10 | std::cout<<"NewReferee: \"state\" is NULL"<< std::endl; 11 | } 12 | our_color = settings->our_color; 13 | command_CNT = -1; 14 | 15 | RefState = state->refereeState; 16 | ballData = &(state->ball); 17 | 18 | RefState->State->init(our_color); 19 | } 20 | 21 | bool NewReferee::connectToRefBox ( void ) 22 | { 23 | m_udp = std::make_unique(setting().referee_address); 24 | 25 | return isConnected(); 26 | } 27 | 28 | bool NewReferee::isConnected() 29 | { 30 | return m_udp != nullptr && m_udp->isConnected(); 31 | } 32 | 33 | void NewReferee::process () 34 | { 35 | if(pSSLRef.has_designated_position()){ 36 | // std::cout<<"HAS POSITION!!!!!"<placeBallTargetPosition = Vec2(pSSLRef.designated_position().x(),pSSLRef.designated_position().y()); 39 | } 40 | // else 41 | // std::cout<<"no new packet received"<Position; 47 | 48 | if (our_color == TEAM_BLUE) 49 | RefState->oppGK = pSSLRef.yellow().goalie(); 50 | else 51 | RefState->oppGK = pSSLRef.blue().goalie(); 52 | 53 | move_hys = 0;//TODO maybe it needs to be commented 54 | 55 | timer.start(); 56 | 57 | 58 | // std::cout << "command: " << pSSLRef.command() << std::endl; 59 | // std::cout << "command_CNT: " << pSSLRef.command_counter() << std::endl; 60 | } 61 | 62 | RefState->State->transition ( pSSLRef.command() , isKicked(ballData->Position) || timer.time() > 5 ); 63 | // if ( isKicked(ballData->Position) ) 64 | // std::cout << "kicked" << std::endl; 65 | 66 | } 67 | 68 | bool NewReferee::isKicked ( TVec2 ballPos ) 69 | { 70 | int requiredHys = 5; 71 | float requiredDis = 50.0f; 72 | if (RefState) { 73 | if (RefState->State->ourRestart()) { 74 | requiredHys = 5; 75 | requiredDis = 150.0f; 76 | } 77 | } 78 | // std::cout<<"the distance: "< requiredDis ) 80 | { 81 | move_hys ++; 82 | } 83 | if ( move_hys >= requiredHys ) 84 | { 85 | move_hys = 0; 86 | return true; 87 | } 88 | return false; 89 | } 90 | 91 | bool NewReferee::recieve ( void ) 92 | { 93 | if (!isConnected()) 94 | return false; 95 | 96 | if (m_udp->receive(&pSSLRef)) 97 | { 98 | return true; 99 | } 100 | 101 | return false; 102 | } -------------------------------------------------------------------------------- /Source/Reality/Referee_2018/NewReferee.h: -------------------------------------------------------------------------------- 1 | //Immortals referee module for RefBox 2018 2 | #include "../WorldState.h" 3 | #include "../../Network/Protobuf/referee2018.pb.h" 4 | #include "../../Common/GameSetting.h" 5 | #include "../../Common/network/udp_client.h" 6 | #include "../../Common/timer.h" 7 | 8 | class NewReferee 9 | { 10 | private: 11 | bool our_color; 12 | 13 | std::unique_ptr m_udp; 14 | 15 | RefereeState* RefState; 16 | BallState* ballData; 17 | 18 | TVec2 LastPlacedBall; 19 | int move_hys;//For isKicked 20 | 21 | Timer timer; 22 | 23 | int command_CNT; 24 | 25 | SSL_Referee pSSLRef; 26 | SSL_Referee_Stage playTimeStage; 27 | SSL_Referee_Command commandState; 28 | 29 | public: 30 | NewReferee ( GameSetting* settings,WorldState* State ); 31 | bool connectToRefBox ( void ); 32 | bool isConnected( void ); 33 | bool recieve ( void ); 34 | bool isKicked ( TVec2 ballPos ); 35 | void process ( void ); 36 | 37 | int oppGK; 38 | }; -------------------------------------------------------------------------------- /Source/Reality/Referee_2018/commands.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TITLE: Commands.h 3 | * 4 | * PURPOSE: This file contains the constants that define the various 5 | * serial commands the referee box can send to the operating 6 | * computers. 7 | * 8 | * WRITTEN BY: Brett Browning 9 | */ 10 | /* LICENSE: ========================================================================= 11 | RoboCup F180 Referee Box Source Code Release 12 | ------------------------------------------------------------------------- 13 | Copyright (C) 2003 RoboCup Federation 14 | ------------------------------------------------------------------------- 15 | This software is distributed under the GNU General Public License, 16 | version 2. If you do not have a copy of this licence, visit 17 | www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 18 | Suite 330 Boston, MA 02111-1307 USA. This program is distributed 19 | in the hope that it will be useful, but WITHOUT ANY WARRANTY, 20 | including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ------------------------------------------------------------------------- 22 | 23 | */ 24 | 25 | #ifndef __COMMANDS_H__ 26 | #define __COMMANDS_H__ 27 | 28 | /* Baud rate */ 29 | #define COMM_BAUD_RATE 9600 30 | 31 | // play commands 32 | #define COMM_STOP 'S' 33 | #define COMM_START 's' 34 | #define COMM_HALT 'H' 35 | #define COMM_READY ' ' 36 | 37 | // game flow commands 38 | #define COMM_FIRST_HALF '1' 39 | #define COMM_HALF_TIME 'h' 40 | #define COMM_SECOND_HALF '2' 41 | #define COMM_OVER_TIME1 'o' 42 | #define COMM_OVER_TIME2 'O' 43 | #define COMM_PENALTY_SHOOTOUT 'a' 44 | 45 | /* timeout commands */ 46 | #define COMM_TIMEOUT_YELLOW 't' 47 | #define COMM_TIMEOUT_BLUE 'T' 48 | #define COMM_TIMEOUT_END 'z' 49 | 50 | #define COMM_CANCEL 'c' 51 | 52 | // goal status 53 | #define COMM_GOAL_YELLOW 'g' 54 | #define COMM_GOAL_BLUE 'G' 55 | #define COMM_SUBGOAL_YELLOW 'd' 56 | #define COMM_SUBGOAL_BLUE 'D' 57 | 58 | // penalty signals 59 | #define COMM_YELLOWCARD_YELLOW 'y' 60 | #define COMM_YELLOWCARD_BLUE 'Y' 61 | 62 | #define COMM_REDCARD_YELLOW 'r' 63 | #define COMM_REDCARD_BLUE 'R' 64 | 65 | 66 | /* game flow commands */ 67 | #define COMM_RESTART 'n' 68 | 69 | #define COMM_KICKOFF_YELLOW 'k' 70 | #define COMM_KICKOFF_BLUE 'K' 71 | 72 | #define COMM_PENALTY_YELLOW 'p' 73 | #define COMM_PENALTY_BLUE 'P' 74 | 75 | #define COMM_DIRECT_YELLOW 'f' 76 | #define COMM_DIRECT_BLUE 'F' 77 | 78 | #define COMM_INDIRECT_YELLOW 'i' 79 | #define COMM_INDIRECT_BLUE 'I' 80 | 81 | 82 | // acceptable referee commands 83 | #define COMM_CMD_STRING "iIfFpPkKnrRyYdDgGcztTaoO2h1 HsS" 84 | 85 | #endif /* __COMMANDS_H__ */ 86 | 87 | -------------------------------------------------------------------------------- /Source/Reality/Referee_2018/commandsOLD.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TITLE: Commands.h 3 | * 4 | * PURPOSE: This file contains the constants that define the various 5 | * serial commands the referee box can send to the operating 6 | * computers. 7 | * 8 | * WRITTEN BY: Brett Browning 9 | */ 10 | /* LICENSE: ========================================================================= 11 | RoboCup F180 Referee Box Source Code Release 12 | ------------------------------------------------------------------------- 13 | Copyright (C) 2003 RoboCup Federation 14 | ------------------------------------------------------------------------- 15 | This software is distributed under the GNU General Public License, 16 | version 2. If you do not have a copy of this licence, visit 17 | www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 18 | Suite 330 Boston, MA 02111-1307 USA. This program is distributed 19 | in the hope that it will be useful, but WITHOUT ANY WARRANTY, 20 | including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ------------------------------------------------------------------------- 22 | 23 | */ 24 | 25 | #ifndef __COMMANDS_H__ 26 | #define __COMMANDS_H__ 27 | 28 | /* Baud rate */ 29 | #define COMM_BAUD_RATE 9600 30 | 31 | // play commands 32 | #define COMM_STOP 'S' 33 | #define COMM_START 's' 34 | #define COMM_HALT 'H' 35 | #define COMM_READY ' ' 36 | 37 | // game flow commands 38 | #define COMM_FIRST_HALF '1' 39 | #define COMM_HALF_TIME 'h' 40 | #define COMM_SECOND_HALF '2' 41 | #define COMM_OVER_TIME1 'o' 42 | #define COMM_OVER_TIME2 'O' 43 | #define COMM_PENALTY_SHOOTOUT 'a' 44 | 45 | /* timeout commands */ 46 | #define COMM_TIMEOUT_YELLOW 't' 47 | #define COMM_TIMEOUT_BLUE 'T' 48 | #define COMM_TIMEOUT_END 'z' 49 | 50 | #define COMM_CANCEL 'c' 51 | 52 | // goal status 53 | #define COMM_GOAL_YELLOW 'g' 54 | #define COMM_GOAL_BLUE 'G' 55 | #define COMM_SUBGOAL_YELLOW 'd' 56 | #define COMM_SUBGOAL_BLUE 'D' 57 | 58 | // penalty signals 59 | #define COMM_YELLOWCARD_YELLOW 'y' 60 | #define COMM_YELLOWCARD_BLUE 'Y' 61 | 62 | #define COMM_REDCARD_YELLOW 'r' 63 | #define COMM_REDCARD_BLUE 'R' 64 | 65 | 66 | /* game flow commands */ 67 | #define COMM_RESTART 'n' 68 | 69 | #define COMM_KICKOFF_YELLOW 'k' 70 | #define COMM_KICKOFF_BLUE 'K' 71 | 72 | #define COMM_PENALTY_YELLOW 'p' 73 | #define COMM_PENALTY_BLUE 'P' 74 | 75 | #define COMM_DIRECT_YELLOW 'f' 76 | #define COMM_DIRECT_BLUE 'F' 77 | 78 | #define COMM_INDIRECT_YELLOW 'i' 79 | #define COMM_INDIRECT_BLUE 'I' 80 | 81 | 82 | // acceptable referee commands 83 | #define COMM_CMD_STRING "iIfFpPkKnrRyYdDgGcztTaoO2h1 HsS" 84 | 85 | #endif /* __COMMANDS_H__ */ 86 | 87 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Protocol/defines.h: -------------------------------------------------------------------------------- 1 | #ifndef DEFINES_H 2 | #define DEFINES_H 3 | 4 | #define PAYLOAD_SIZE 32 5 | 6 | #define PROTO_VERSION_FIXED 0x1 7 | #define PROTO_VERSION_VAR 0x2 8 | #define TYPE_COMMAND 0x1 9 | #define TYPE_CONFIG 0x2 10 | #define TYPE_MATRIX 0x3 11 | #define TYPE_FEEDBACK 0x4 12 | #define TYPE_FEEDBACK_CUSTOM 0x5 13 | 14 | #define MESSAGE_HEADER(v,t) ((v << 4) | t) 15 | #define MESSAGE_VERSION(a) (a >> 4) 16 | #define MESSAGE_TYPE(a) (a & 0x0F) 17 | 18 | 19 | #define PARSE_RESULT_SUCCESS 0 20 | #define PARSE_RESULT_HEADER_CORRUPTED 1 21 | #define PARSE_RESULT_SIZE_MISMATCH 2 22 | 23 | #ifndef TRUE 24 | #define TRUE 1 25 | #endif 26 | 27 | #ifndef FALSE 28 | #define FALSE 0 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Protocol/half.h: -------------------------------------------------------------------------------- 1 | #ifndef HALF_H 2 | #define HALF_H 3 | #include 4 | 5 | union FLOAT_32 6 | { 7 | float f32; 8 | uint32_t u32; 9 | }; 10 | 11 | uint32_t half_to_float( uint16_t h ); 12 | uint16_t half_from_float( uint32_t f ); 13 | uint16_t half_add( uint16_t arg0, uint16_t arg1 ); 14 | uint16_t half_mul( uint16_t arg0, uint16_t arg1 ); 15 | 16 | static inline uint16_t 17 | half_sub( uint16_t ha, uint16_t hb ) 18 | { 19 | // (a-b) is the same as (a+(-b)) 20 | return half_add( ha, hb ^ 0x8000 ); 21 | } 22 | 23 | #endif /* HALF_H */ 24 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Protocol/reader.h: -------------------------------------------------------------------------------- 1 | #ifndef READER_H 2 | #define READER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #include "data_lite.h" 12 | 13 | void read_bytes(const uint8_t* const buffer, size_t* const pos, void* const data, const size_t count); 14 | 15 | void read_bits8(const uint8_t* const buffer, size_t* const pos, struct bits8_t* const data); 16 | 17 | void read_bits16(const uint8_t* const buffer, size_t* const pos, struct bits16_t* const data); 18 | 19 | void read_bits32(const uint8_t* const buffer, size_t* const pos, struct bits32_t* const data); 20 | 21 | void read_uint8(const uint8_t* const buffer, size_t* const pos, uint8_t* const data); 22 | 23 | void read_uint16(const uint8_t* const buffer, size_t* const pos, uint16_t* const data); 24 | 25 | void read_uint32(const uint8_t* const buffer, size_t* const pos, uint32_t* const data); 26 | 27 | void read_float_h(const uint8_t* const buffer, size_t* const pos, union FLOAT_32* const data); 28 | 29 | void read_float(const uint8_t* const buffer, size_t* const pos, union FLOAT_32* const data); 30 | 31 | void read_v2f(const uint8_t* const buffer, size_t* const pos, struct Vector2f_V2* const data); 32 | 33 | void read_v2f_h(const uint8_t* const buffer, size_t* const pos, struct Vector2f_V2* const data); 34 | 35 | void read_v3f(const uint8_t* const buffer, size_t* const pos, struct Vector3f* const data); 36 | 37 | void read_v3f_h(const uint8_t* const buffer, size_t* const pos, struct Vector3f* const data); 38 | 39 | void read_v4f(const uint8_t* const buffer, size_t* const pos, struct Vector4f* const data); 40 | 41 | void read_v4f_h(const uint8_t* const buffer, size_t* const pos, struct Vector4f* const data); 42 | 43 | uint8_t read_robot_command_fixed(const uint8_t* const buffer, const size_t size, struct RobotCommand* const data); 44 | 45 | uint8_t read_robot_command_fixed_V2(const uint8_t* const buffer, const size_t size, struct RobotCommand_V2* const data); 46 | 47 | uint8_t read_robot_config_fixed(const uint8_t* const buffer, const size_t size, struct RobotConfig* const data); 48 | 49 | uint8_t read_robot_matrix_fixed(const uint8_t* const buffer, const size_t size, struct RobotMatrix* const data); 50 | 51 | uint8_t read_robot_feedback_fixed(const uint8_t* const buffer, const size_t size, struct RobotFeedback* const data); 52 | 53 | uint8_t read_robot_feedback_custom_fixed(const uint8_t* const buffer, const size_t size, struct RobotFeedbackCustom* const data); 54 | 55 | void read_float_h_from_2x_buf(const uint8_t* const buffer, float* const float_out); 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Protocol/writer.h: -------------------------------------------------------------------------------- 1 | #ifndef WRITER_H 2 | #define WRITER_H 3 | 4 | #ifdef __cplusplus 5 | extern "C"{ 6 | #endif 7 | 8 | #include 9 | #include 10 | 11 | #include "data_lite.h" 12 | 13 | void write_bytes(uint8_t* const buffer, size_t* const pos, const void* const data, const size_t count); 14 | 15 | void write_bits8(uint8_t* const buffer, size_t* const pos, const struct bits8_t* const data); 16 | 17 | void write_bits16(uint8_t* const buffer, size_t* const pos, const struct bits16_t* const data); 18 | 19 | void write_bits32(uint8_t* const buffer, size_t* const pos, const struct bits32_t* const data); 20 | 21 | void write_uint8(uint8_t* const buffer, size_t* const pos, const uint8_t data); 22 | 23 | void write_uint16(uint8_t* const buffer, size_t* const pos, const uint16_t data); 24 | 25 | void write_uint32(uint8_t* const buffer, size_t* const pos, const uint32_t data); 26 | 27 | void write_float_h(uint8_t* const buffer, size_t* const pos, const union FLOAT_32 data); 28 | 29 | void write_float(uint8_t* const buffer, size_t* const pos, const union FLOAT_32 data); 30 | 31 | void write_v2f_h(uint8_t* const buffer, size_t* const pos, const struct Vector2f_V2* const data); 32 | 33 | void write_v2f(uint8_t* const buffer, size_t* const pos, const struct Vector2f_V2* const data); 34 | 35 | void write_v3f_h(uint8_t* const buffer, size_t* const pos, const struct Vector3f* const data); 36 | 37 | void write_v3f(uint8_t* const buffer, size_t* const pos, const struct Vector3f* const data); 38 | 39 | void write_v4f_h(uint8_t* const buffer, size_t* const pos, const struct Vector4f* const data); 40 | 41 | void write_v4f(uint8_t* const buffer, size_t* const pos, const struct Vector4f* const data); 42 | 43 | size_t write_robot_command_fixed(uint8_t* const buffer, const struct RobotCommand* const data); 44 | 45 | size_t write_robot_command_fixed_V2(uint8_t* const buffer, const struct RobotCommand_V2* const data); 46 | 47 | size_t write_robot_config_fixed(uint8_t* const buffer, const struct RobotConfig* const data); 48 | 49 | size_t write_robot_matrix_fixed(uint8_t* const buffer, const struct RobotMatrix* const data); 50 | 51 | size_t write_robot_feedback_fixed(uint8_t* const buffer, const struct RobotFeedback* const data); 52 | 53 | size_t write_robot_feedback_custom_fixed(uint8_t* const buffer, const struct RobotFeedbackCustom* const data); 54 | 55 | void write_uint16_in_buff(uint8_t* const buffer, const uint16_t data); 56 | 57 | void convert_float_to_2x_buff(uint8_t* const buffer, const float data); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Sender.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by server on 1/19/18. 3 | // 4 | 5 | #include "Sender.h" 6 | 7 | bool Sender::getCommand(Robot* bot) { 8 | 9 | auto buffer = commUDP->getBuffer(); 10 | 11 | if(bot->new_comm_ready) { 12 | for (int i = 0; i < bot->data[1]; i++) { 13 | buffer[i + buff_idx] = bot->data[i]; 14 | } 15 | buff_idx += bot->data[1]; 16 | bot->new_comm_ready = false; 17 | return true; 18 | } 19 | 20 | return false; 21 | } 22 | 23 | bool Sender::appendData(unsigned char* data,int length){ 24 | auto buffer = commUDP->getBuffer(); 25 | 26 | for (int i = 0; i < length; i++) { 27 | buffer[i + buff_idx] = data[i]; 28 | } 29 | buff_idx += length; 30 | return true; 31 | } 32 | 33 | bool Sender::sendAll() { 34 | if(startup > 0){ 35 | startup--; 36 | return false; 37 | } 38 | 39 | if (commUDP->send(buff_idx, NetworkAddress{ "224.5.92.5" , 60005 })) 40 | { 41 | buff_idx = 0; 42 | return true; 43 | } 44 | else 45 | { 46 | std::cout << "ERROR: failed to send robot packets." << std::endl; 47 | buff_idx = 0; 48 | return false; 49 | } 50 | 51 | buff_idx = 0; 52 | return true; 53 | } 54 | 55 | Sender::Sender() { 56 | commUDP = std::make_shared(); 57 | 58 | buff_idx = 0; 59 | auto buffer = commUDP->getBuffer(); 60 | for(int i=0;igetBuffer(); 68 | buffer[0 + buff_idx] = 25; 69 | buffer[1 + buff_idx] = 0x0A; 70 | buffer[2 + buff_idx] = 0x00; 71 | buffer[3 + buff_idx] = 0x00; 72 | buffer[4 + buff_idx] = 0x00; 73 | buffer[5 + buff_idx] = 0x00; 74 | buffer[6 + buff_idx] = 0x00; 75 | buffer[7 + buff_idx] = 0x00; 76 | buffer[8 + buff_idx] = 0x00; 77 | buffer[9 + buff_idx] = 0x00; 78 | buff_idx += 10; 79 | } 80 | -------------------------------------------------------------------------------- /Source/Reality/Sender/Sender.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Soccer/ai09/Robot.h" 4 | 5 | //Network 6 | #include "../../Common/network/udp_server.h" 7 | 8 | class Sender { 9 | private: 10 | std::shared_ptr commUDP; 11 | 12 | public: 13 | 14 | int buff_idx; 15 | int startup; 16 | 17 | bool getCommand(Robot* bot); 18 | bool appendData(unsigned char* data,int length); 19 | bool sendAll(); 20 | void append_demo_data(); 21 | 22 | Sender(); 23 | }; 24 | -------------------------------------------------------------------------------- /Source/Reality/Vision/Kalman/FilteredObject.h: -------------------------------------------------------------------------------- 1 | // FilteredObject.h: interface for the FilteredObject class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #if !defined FILTEREDOBJECT_H 6 | #define FILTEREDOBJECT_H 7 | 8 | /** 9 | * Class FilteredObject 10 | * This filtered object class gives the predicted position and velocity using Kalman Filter 11 | * @author Chee Yong Lee 12 | * Developed from Matlab Code filtDesign written by Raffaello D'Andrea. 13 | * The updating equation is as follows : 14 | * filtOut = Cimp*filtState + Dimp*posMeasure 15 | * filtState = Aimp*filtState + Bimp*posMeasure 16 | * 17 | * on loss of future information 18 | * filtState = inv(I-Aimp)Bimp + posMeasure, where we denote lossVec = inv(I-Aimp)Bimp 19 | * Date : June 2002 20 | **/ 21 | 22 | #if _MSC_VER > 1000 23 | #pragma once 24 | #endif // _MSC_VER > 1000 25 | 26 | class FilteredObject 27 | { 28 | public: 29 | /// Default constructor 30 | FilteredObject(); 31 | /// Constructor with intialization matrices fed in 32 | FilteredObject(float A[2][2], float B[2], float C[2][2], float D[2],float lossMat[2]); 33 | /// Constructor from a file 34 | void initialize(const char* filename1, const char* filename2); 35 | /// Default Destructor 36 | virtual ~FilteredObject(); 37 | /// Initialize the position whenever it is lost and refound. Use this for the first initial state too. 38 | void initializePos(float pos[2]); 39 | 40 | /** update the internal state using known vision data 41 | * @param z is the measured position. first component is for x axis, and second component is for y axis 42 | * @param filtOut is a pointer to whether the output position and velocity is output to 43 | * First component is the dimension, second component indicates whether it is position or velocity 44 | * @return filtered position and velocity in param filtOut 45 | **/ 46 | void updatePosition(float z[2], float filtOut[2][2]); 47 | 48 | private: 49 | 50 | /** FilterState : Internal representation for Kalman filter 51 | * The first component represent the dimension. 0 for x axis, 1 for y axis 52 | * The second component represents the current position and velocity component 53 | * This is a column vector 54 | **/ 55 | float filtState[2][2]; 56 | float filtStateP[2][2]; 57 | 58 | //./ filtered matrices that is determined by matlab 59 | float Aimp[2][2], Bimp[2], Cimp[2][2], Dimp[2], lossVec[2]; 60 | float CimpInv[2][2]; 61 | float AimpP[2][2], BimpP[2], CimpP[2][2], DimpP[2], lossVecP[2]; 62 | 63 | /// The number of time it has been used 64 | long usageCount; 65 | }; 66 | 67 | #endif // !defined FILTEREDOBJECT_H 68 | -------------------------------------------------------------------------------- /Source/Reality/Vision/Vision.cpp: -------------------------------------------------------------------------------- 1 | #include "Vision.h" 2 | 3 | #include "Kalman/FilteredObject.h" 4 | #include "../../Common/GameSetting.h" 5 | 6 | #include 7 | 8 | VisionModule::VisionModule(GameSetting* _settings,WorldState* _State) 9 | { 10 | playState = _State; 11 | 12 | if(_settings == NULL){ 13 | return; 14 | } 15 | //Initializing the settings: 16 | our_color = _settings->our_color; 17 | our_side = _settings->our_side; 18 | 19 | for ( int i = 0 ; i < Setting::kCamCount ; i ++ ) 20 | packet_recieved[i] = false; 21 | 22 | for ( int i = 0 ; i < BALL_BUFFER_FRAMES ; i ++ ) 23 | { 24 | ball_pos_buff[i] = Vec2(0.0,0.0); 25 | } 26 | 27 | lastRawBall.set_x ( 0.0f ); 28 | lastRawBall.set_y ( 0.0f ); 29 | 30 | std::string fast_filter_path(DATA_DIR); fast_filter_path.append("/ballFilterFast.txt"); 31 | std::string slow_filter_path(DATA_DIR); slow_filter_path.append("/ballFilterSlow.txt"); 32 | 33 | ball_kalman.initialize(fast_filter_path.c_str(), slow_filter_path.c_str()); 34 | 35 | for ( int i = 0 ; i < Setting::kMaxRobots; i++ ) 36 | { 37 | robot_kalman[0][i].initialize (fast_filter_path.c_str(), slow_filter_path.c_str()); 38 | robot_kalman[1][i].initialize (fast_filter_path.c_str(), slow_filter_path.c_str()); 39 | rawAngles[0][i] = 0.0f; 40 | rawAngles[1][i] = 0.0f; 41 | } 42 | 43 | ball_kalman.initialize(fast_filter_path.c_str(), slow_filter_path.c_str()); 44 | 45 | //Launching UDP Connections 46 | if(!connectToVisionServer()){ 47 | std::cout<<"Failed to connect to Vision UDP"<< std::endl; 48 | } 49 | 50 | } 51 | VisionModule::~VisionModule() 52 | { 53 | } 54 | 55 | void VisionModule::recieveAllCameras( void ) 56 | { 57 | if (!isConnected()) { 58 | std::cout << " Hey you! Put the LAN cable back in its socket, or ..." << std::endl; 59 | return; 60 | //connectToVisionServer ( setting -> UDP_Adress , setting -> LocalPort ); 61 | } 62 | 63 | bool cams_ready = false; 64 | while (!cams_ready) { 65 | cams_ready = true; 66 | for (int i = 0; i < Setting::kCamCount; i++) { 67 | bool new_cam_ready = packet_recieved[i] || (!setting().use_camera[i]); 68 | if (!new_cam_ready) { 69 | cams_ready = false; 70 | break; 71 | } 72 | } 73 | if (cams_ready) 74 | break; 75 | //std::cout << "bodo dg " << cams_ready << std::endl; 76 | recievePacket(); 77 | 78 | } 79 | } 80 | 81 | void VisionModule::ProcessVision() 82 | { 83 | ProcessBalls ( this->playState ); 84 | ProcessRobots ( this->playState ); 85 | ProcessParam ( this->playState ); 86 | 87 | 88 | for ( int i = 0 ; i < Setting::kCamCount ; i ++ ) 89 | packet_recieved[i] = false; 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /Source/Reality/Vision/VisionComminucation.cpp: -------------------------------------------------------------------------------- 1 | #include "Vision.h" 2 | 3 | bool VisionModule::connectToVisionServer ( void ) 4 | { 5 | m_visionUDP = std::make_unique(setting().vision_address); 6 | return isConnected(); 7 | } 8 | 9 | bool VisionModule::recievePacket ( void ) 10 | { 11 | if (!isConnected()) 12 | return false; 13 | 14 | if (m_visionUDP->receive(&packet)) 15 | { 16 | if (packet.has_detection()) 17 | { 18 | frame[packet.detection().camera_id()] = packet.detection(); 19 | packet_recieved[packet.detection().camera_id()] = true; 20 | } 21 | 22 | return true; 23 | } 24 | 25 | return false; 26 | } 27 | 28 | bool VisionModule::isConnected ( void ) 29 | { 30 | return m_visionUDP != nullptr && m_visionUDP->isConnected(); 31 | } 32 | -------------------------------------------------------------------------------- /Source/Reality/Vision/VisionParam.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 12/5/18. 3 | // 4 | 5 | #include "Vision.h" 6 | 7 | 8 | void VisionModule::ProcessParam( WorldState * state ) { 9 | double avg = 0; 10 | int count = 0; 11 | for ( int i = 0 ; i < Setting::kCamCount ; i ++ ) { 12 | if (setting().use_camera[i]) { 13 | avg += frame[i].t_capture(); 14 | count++; 15 | } 16 | } 17 | 18 | avg /= count; 19 | state->delta_t_capture = avg - state->t_capture; 20 | state->t_capture = avg; 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Source/Reality/Vision/visionPrediction.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Immortals-Robotics/Software/9fc9a8e7ab17d58bef099812a2b90677cfe5ec86/Source/Reality/Vision/visionPrediction.cpp -------------------------------------------------------------------------------- /Source/Reality/WorldState.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 10/23/18. 3 | // 4 | #include "WorldState.h" 5 | #include 6 | #include 7 | 8 | sample_tuple tmp_sample; 9 | 10 | double first_t = -1.0; 11 | 12 | void write_to_file(){ 13 | std::ofstream myfile; 14 | 15 | std::string sample_path(DATA_DIR); 16 | sample_path.append("/samples.txt"); 17 | 18 | myfile.open(sample_path, std::ios::app);//append 19 | 20 | myfile << tmp_sample.t << " " 21 | << tmp_sample.X << " " 22 | << tmp_sample.Y << " " 23 | << tmp_sample.VX_in << " " 24 | << tmp_sample.VY_in << " " 25 | << tmp_sample.VX_out << " " 26 | << tmp_sample.VY_out << std::endl; 27 | 28 | myfile.close(); 29 | } 30 | 31 | void get_sample_set1(double sample_t, float sample_X,float sample_Y){ 32 | if(first_t == -1.0){ 33 | first_t = sample_t; 34 | } 35 | tmp_sample.t = sample_t - first_t; 36 | tmp_sample.X = sample_X; 37 | tmp_sample.Y = sample_Y; 38 | std::cout <<"tmp_sample.t: "<< tmp_sample.t << std::endl; 39 | } 40 | 41 | void get_sample_set2(float sample_VX, float sample_VY){ 42 | tmp_sample.VX_out = sample_VX; 43 | tmp_sample.VY_out = sample_VY; 44 | // write_to_file(); 45 | } 46 | 47 | void get_sample_set3(float sample_VX, float sample_VY){ 48 | tmp_sample.VX_in = sample_VX; 49 | tmp_sample.VY_in = sample_VY; 50 | write_to_file(); 51 | } 52 | 53 | //----------------------------------- 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/CalcIsDefending.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::CalcIsDefending ( void ) 4 | { 5 | if (isDefending) { 6 | if (side*ball.Position.X<-200) { 7 | isDefending = false; 8 | } 9 | } 10 | else if (side*ball.Position.X>300) 11 | { 12 | isDefending = true; 13 | } 14 | 15 | if (timer.time()<2.0) { 16 | if (oppRestarted) { 17 | isDefending = true; 18 | } 19 | else { 20 | isDefending = false; 21 | } 22 | 23 | } 24 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/Mark2Goal.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::Mark2Goal(int robot_num, int opp, float dist) 4 | { 5 | const float opp_predict_t = 0.15; 6 | dist = min(1500, dist); 7 | 8 | TVec2 predictedOpp = Vec2(OppRobot[opp].Position.X + OppRobot[opp].velocity.x*opp_predict_t, OppRobot[opp].Position.Y + OppRobot[opp].velocity.y*opp_predict_t); 9 | TVec2 target = PointOnConnectingLine(predictedOpp, Vec2(side*field_width, 0), dist); 10 | 11 | OwnRobot[robot_num].face(ball.Position); 12 | ERRTSetObstacles(robot_num, 1, 1, 1, 1); 13 | ERRTNavigate2Point(robot_num, target, 0, 100, REF_playState->stop() ? &VELOCITY_PROFILE_AROOM : &VELOCITY_PROFILE_MAMOOLI); 14 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/OneDef.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | #include 3 | 4 | void ai09::OneDef ( int robot_num , TVec2 * defendTarget , bool stop ) 5 | { 6 | if ( !defendTarget ) 7 | defendTarget = &(ball.Position); 8 | 9 | ERRTSetObstacles ( robot_num , stop , true , true , false ); 10 | OwnRobot[robot_num].face ( Vec2 ( (*defendTarget).X , (*defendTarget).Y ) ); 11 | ERRTNavigate2Point ( robot_num , PointOnConnectingLine(Vec2(side*3025.0f,-200.0f*sgn((*defendTarget).Y+100.0f)),Vec2((*defendTarget).X,(*defendTarget).Y),1000.0f) ); 12 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/OneTouchDetector.h: -------------------------------------------------------------------------------- 1 | #include "Geom.h" 2 | #include "../../Common/distance.h" 3 | 4 | class OneTouchDetector 5 | { 6 | public: 7 | float field_w; 8 | float field_h; 9 | int hys; 10 | RobotState* rState; 11 | BallState* bState; 12 | int* side; 13 | 14 | float BAR; 15 | 16 | OneTouchDetector() 17 | { 18 | hys = 0; 19 | BAR = 89.0; 20 | } 21 | bool IsArriving ( float angleTol = 40 , float passAngleLimit = 80 ) 22 | { 23 | return IsArriving(Vec2(-(*side)*field_w,0),angleTol,passAngleLimit); 24 | } 25 | bool IsArriving ( const TVec2& target, float angleTol, float passAngleLimit ) 26 | { 27 | float ballDistBeforeStop = (bState->velocity.magnitude*bState->velocity.magnitude) / 500.0f; 28 | //ballDistBeforeStop += 100.0f; 29 | float angleWithTarget = AngleWith(rState->Position, target); 30 | if ( ( fabs ( NormalizeAngle ( bState->velocity.direction - AngleWith ( bState->Position , Vec2 ( rState->Position.X + BAR * cosDeg ( angleWithTarget ) , rState->Position.Y + BAR * sinDeg ( angleWithTarget ) ) ) ) ) < angleTol ) && 31 | ( fabs(NormalizeAngle(180+bState->velocity.direction-AngleWith(rState->Position, target))) < passAngleLimit ) && 32 | //( bState->velocity.magnitude > 50 ) ) 33 | ( DIS(rState->Position, bState->Position) < ballDistBeforeStop ) ) 34 | //&&(abs(ball.vel_angle-90)>0.01)&& 35 | //(abs(ball.vel_angle+90)>0.01)&& 36 | //(abs(ball.vel_angle-180)>0.01)&& 37 | //(abs(ball.vel_angle+180)>0.01)) 38 | { 39 | hys = 10; 40 | return true; 41 | } 42 | else if (( hys > 0 )&& ( bState->velocity.magnitude > 50 ))// &&(abs(ball.vel_angle-90)>0.01)&&(abs(ball.vel_angle+90)>0.01)&&(abs(ball.vel_angle-180)>0.01)&&(abs(ball.vel_angle+180)>0.01)) 43 | { 44 | hys --; 45 | return true; 46 | } 47 | 48 | else 49 | { 50 | hys = 0; 51 | return false; 52 | } 53 | } 54 | }; -------------------------------------------------------------------------------- /Source/Soccer/ai09/OutOfField.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 12/6/18. 3 | // 4 | 5 | #include "ai09.h" 6 | 7 | 8 | float ai09::outOfField(TVec2 point){ 9 | float THR = 0.0;//200.0; 10 | if(fabs(point.X) > field_width || fabs(point.Y) > field_height){ 11 | return true; 12 | } 13 | return false; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/Robot.h: -------------------------------------------------------------------------------- 1 | #include "helpers.h" 2 | #include "trapezoid.h" 3 | #include "VelocityProfile.h" 4 | #include 5 | #include 6 | #include "../../Common/timer.h" 7 | #include "../../Reality/Sender/Protocol/writer.h" 8 | 9 | #define PREDICT_CMDS 6 10 | 11 | #ifndef ROBOT_H 12 | #define ROBOT_H 13 | 14 | class Robot 15 | { 16 | Timer angleSendTimer; 17 | 18 | public : 19 | 20 | float field_w; 21 | float field_h; 22 | 23 | float shootMult = 1.0f; 24 | 25 | bool oldRobot; 26 | RobotState State; 27 | RobotState target; 28 | int shoot , chip , Break , dribbler; 29 | int Motor[4]; 30 | unsigned char data[32]; 31 | struct Vector2f_V2 velocity; 32 | union FLOAT_32 target_orientation; 33 | int serial_id,vision_id; 34 | bool control_mode; 35 | bool halted; 36 | bool new_comm_ready; 37 | 38 | TVec3 lastCMDs[11]; 39 | int CMDindex; 40 | 41 | TrapezoidPlanner trapezoid; 42 | 43 | int remainingPIDParams; 44 | float p , i , iMax , torque; 45 | 46 | Robot(void); 47 | 48 | void sendPID ( float _p , float _i , float _iMax , float _torque ); 49 | 50 | void set_serial_id(unsigned short s_id); 51 | 52 | void set_vision_id(unsigned short v_id); 53 | 54 | void set_control_mode(bool c_mode); 55 | 56 | float dis(float x1,float y1,float x2,float y2); 57 | 58 | void Shoot(int pow); 59 | 60 | void Chip(int pow); 61 | 62 | void Dribble(int pow); 63 | 64 | void face(TVec2 _target); 65 | 66 | TVec3 MotionPlan ( RobotState state , RobotState target , float speed , bool accurate , TVec3 * cmd , VelocityProfile * velocityProfile ); 67 | 68 | void Move(bool accurate , float speed , VelocityProfile * velocityProfile ); 69 | 70 | void MoveByMotion(TVec3 motion); 71 | 72 | TVec3 ComputeMotionCommand( bool accurate , float speed , VelocityProfile * velocityProfile ); 73 | 74 | TVec3 GetCurrentMotionCommand( void ) const; 75 | 76 | void makeSendingDataReady ( void ); 77 | 78 | }; 79 | 80 | #endif //ROBOT_H -------------------------------------------------------------------------------- /Source/Soccer/ai09/RobotCheck.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 6/8/18. 3 | // 4 | 5 | #include "ai09.h" 6 | 7 | void ai09::want_this_robot(int robot_num) { 8 | requiredRobots[robot_num]= true; 9 | } 10 | 11 | bool ai09::position_robots(bool avoid_GK, bool avoid_DEF){ 12 | // if(avoid_GK) 13 | // requiredRobots[avoid_GK] = true; 14 | // if(avoid_DEF) 15 | // requiredRobots[avoid_DEF] = true; 16 | 17 | 18 | for(int j=0;j -2500){ 10 | OwnRobot[attack].face(Vec2(-side*field_width,0)); 11 | ERRTSetObstacles(attack,0,1,0,1);//test 12 | ERRTNavigate2Point(attack, ball.Position, 1, 100, &VELOCITY_PROFILE_KHARAKI); 13 | OwnRobot[attack].Shoot(0); 14 | OwnRobot[attack].Chip(0); 15 | } else { 16 | TVec2 shootPoint; 17 | 18 | float shootDelta = (goal_width/2.0) - 50.0f; 19 | 20 | if ( randomParam < 0.5 ) 21 | { 22 | shootPoint = Vec2 ( -side*field_width,-shootDelta ); 23 | } 24 | else { 25 | shootPoint = Vec2 ( -side*field_width,shootDelta ); 26 | } 27 | 28 | VecPosition intPoint[2]; 29 | side = -side; 30 | int oppGK = findCruncherOpp(-1, -1,true); 31 | side = -side; 32 | std::cout << " GK e harif: " << oppGK << std::endl; 33 | if ( oppGK != -1 ) 34 | { 35 | Line shootLine = Line::makeLineFromTwoPoints ( VecPosition ( shootPoint.X,shootPoint.Y ) , VecPosition ( ball.Position.X,ball.Position.Y ) ); 36 | if (shootLine.getCircleIntersectionPoints(Circle(VecPosition(OppRobot[oppGK].Position.X,OppRobot[oppGK].Position.Y),130),intPoint,intPoint+1)>0) { 37 | shootPoint.Y = -shootPoint.Y; 38 | } 39 | } 40 | // penaltyAngle+=180; 41 | penaltyAngle = AngleWith ( shootPoint , ball.Position ); 42 | 43 | PenaltyUs(attack, NormalizeAngle( penaltyAngle), 28 );//TODO Fix this (it goes in the goal field) 44 | // PenaltyUs(attack,) 45 | } 46 | } 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/VelocityProfile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | struct VelocityProfile 4 | { 5 | TVec2 max_spd; 6 | TVec2 max_dec; 7 | TVec2 max_acc; 8 | float max_w_acc; 9 | float max_w_dec; 10 | }; -------------------------------------------------------------------------------- /Source/Soccer/ai09/attackFuckingAngle.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | bool ai09::attackFuckingAngle ( void ) 4 | { 5 | bool ans = false; 6 | 7 | static int attfuanHys = 0; 8 | 9 | int oppAttack = findKickerOpp(-1); 10 | if (oppAttack != -1) { 11 | float ownGoalAngle = AngleWith(Vec2(side*field_width, 0),ball.Position); 12 | float oppGoalAngle = AngleWith(ball.Position, Vec2(-side*field_height, 0)); 13 | 14 | if (fabs(NormalizeAngle(ownGoalAngle-oppGoalAngle)) > 80) { 15 | ans = true; 16 | } 17 | } 18 | 19 | if (ans) { 20 | attfuanHys = 30; 21 | return true; 22 | } 23 | 24 | 25 | if (attfuanHys > 0) { 26 | attfuanHys --; 27 | return true; 28 | } 29 | 30 | return false; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/backPass.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::backPass ( int robot_num , float target , float t ) 4 | { 5 | static TVec2 initBall; 6 | float dt = timer.time()-t; 7 | if ( dt < 0 ) 8 | { 9 | initBall = ball.Position; 10 | tech_circle(robot_num, 90 + side * 90 , 0, 0,true,1,0,1); 11 | } 12 | else if ( dt < 1 ) 13 | { 14 | tech_circle(robot_num, 180+target , 0, 0,true,1,0,1); 15 | } 16 | else if ( dt < 2 ) 17 | { 18 | tech_circle(robot_num, 180+target , 0,0,true,1,1,1); 19 | } 20 | else { 21 | //OwnRobot[robot_num].Dribble(15); 22 | OwnRobot[robot_num].target.Angle = target; 23 | Navigate2Point(robot_num, Vec2(initBall.X+cosDeg(target+210)*800, initBall.Y+sinDeg(target+210)*800),0,100,&VELOCITY_PROFILE_KHARAKI); 24 | } 25 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/ballIsGoaling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ai09.h" 3 | 4 | bool ai09::ballIsGoaling ( void ) 5 | { 6 | bool towardGoal = false; 7 | 8 | if ( ( side == -1 ) && ( fabs(ball.velocity.direction) > 90 ) ) 9 | towardGoal = true; 10 | if ( ( side == 1 ) && ( fabs(ball.velocity.direction) < 90 ) ) 11 | towardGoal = true; 12 | 13 | if (!towardGoal) 14 | return false; 15 | 16 | if ( ball.velocity.magnitude < 200 ) 17 | return false; 18 | 19 | Line ball_line = Line::makeLineFromPositionAndAngle ( VecPosition ( ball.Position.X , ball.Position.Y ) , ball.velocity.direction ); 20 | Line targetLine = Line::makeLineFromTwoPoints ( VecPosition ( side * field_width , -100 ) , VecPosition ( side * field_width , 100 ) ); 21 | VecPosition ballInter = ball_line.getIntersection(targetLine); 22 | 23 | debug().drawPoint(Vec2(ballInter.getX(), ballInter.getY())); 24 | 25 | if (fabs(ballInter.getY())<(goal_width / 2) + 100.0) 26 | return true; 27 | 28 | return false; 29 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/ballTrajectory.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::CalculateBallTrajectory ( void ) 4 | { 5 | if ( ball.velocity.magnitude == 0 ) 6 | return; 7 | 8 | if (ballHist.size()<5) { 9 | return; 10 | } 11 | 12 | static MedianFilter visionM; 13 | if ( ball.velocity.x == 0 ) 14 | visionM.AddData(100.0f); 15 | else 16 | visionM.AddData(fabs(ball.velocity.y/ball.velocity.x)); 17 | 18 | bool isVertical = visionM.GetCurrent() > 1.0f; 19 | 20 | std::vector ball_x; 21 | std::vector ball_y; 22 | MedianFilter dMedian(5); 23 | 24 | int i; 25 | for (i = ballHist.size()-1; i>=0; i--) { 26 | if (ball_x.size()>1) 27 | { 28 | float d; 29 | if (isVertical) { 30 | ballLine.calculate(ball_x.size(), &ball_y[0], &ball_x[0]); 31 | d = ballLine.getDisToPoint(Vec2(ballHist[i].Position.Y,ballHist[i].Position.X)); 32 | } 33 | else { 34 | ballLine.calculate(ball_x.size(), &ball_x[0], &ball_y[0]); 35 | d = ballLine.getDisToPoint(ballHist[i].Position); 36 | } 37 | 38 | dMedian.AddData(d); 39 | if ( ( dMedian.GetCurrent()> 50)&&(ballHist.size()-i>5)) { 40 | break; 41 | } 42 | } 43 | ball_x.push_back(ballHist[i].Position.X); 44 | ball_y.push_back(ballHist[i].Position.Y); 45 | } 46 | 47 | i++; 48 | 49 | if ( isVertical ) 50 | ballLine.chapeKon(); 51 | 52 | //ball_line.calculate(ball_x.size(), &ball_x[0], &ball_y[0]); 53 | if (ballLine.isAmoodi()) { 54 | AddDebugLine(Vec2(ballLine.getXIntercept(), -2000),Vec2(ballLine.getXIntercept(), 2000),Purple); 55 | } 56 | AddDebugLine(Vec2(ball.Position.X, ballLine.getValue(ball.Position.X)),Vec2(ballHist[i].Position.X, ballLine.getValue(ballHist[i].Position.X))); 57 | 58 | if (!ballLine.isAmoodi()) 59 | { 60 | Line new_line ( 1.0 , -ballLine.getSlope() , -ballLine.getIntercept() ); 61 | VecPosition ballN,lastN; 62 | ballN = new_line.getPointOnLineClosestTo(VecPosition(ball.Position.X,ball.Position.Y)); 63 | lastN = new_line.getPointOnLineClosestTo(VecPosition(ballHist[i].Position.X,ballHist[i].Position.Y)); 64 | AddDebugLine(Vec2(ballN.getX(),ballN.getY()),Vec2(lastN.getX(),lastN.getY()),isVertical?Yellow:Red); 65 | } 66 | 67 | for (i = max ( ballHist.size() - 60 , 0 ) ; i < ballHist.size(); i +=10) { 68 | //AddDebugCircle(ballHist[i].Position,10+10.0*(float(i)/float(ballHist.size())),Red); 69 | } 70 | 71 | //AddDebugCircle(Vec2(0, 0),1000,Blue); 72 | 73 | //AddDebugLine(ballHist.front().Position,ballHist.back().Position,Blue); 74 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/calculate_mark_cost.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | float ai09::calculateMarkCost(int robot_num, int opp) 4 | { 5 | if (OwnRobot[robot_num].State.seenState == CompletelyOut) 6 | return -1; 7 | if (OppRobot[opp].seenState == CompletelyOut) 8 | return -1; 9 | 10 | const float predict_t = 0.3f; 11 | auto predicted_pos_own = Vec2( 12 | OwnRobot[robot_num].State.Position.X + OwnRobot[robot_num].State.velocity.x*predict_t, 13 | OwnRobot[robot_num].State.Position.Y + OwnRobot[robot_num].State.velocity.y*predict_t); 14 | auto predicted_pos_opp = Vec2( 15 | OppRobot[opp].Position.X + OppRobot[opp].velocity.x*predict_t, 16 | OppRobot[opp].Position.Y + OppRobot[opp].velocity.y*predict_t); 17 | 18 | auto dis_pred = DIS(predicted_pos_own, predicted_pos_opp); 19 | bool already_marked = false; 20 | for (auto it = markMap.begin(); it != markMap.end(); ++it) { 21 | if (*it->first == robot_num) 22 | { 23 | already_marked = it->second == opp; 24 | break; 25 | } 26 | } 27 | 28 | float score_stay; 29 | if (!already_marked) 30 | score_stay = 0.0f; 31 | else 32 | { 33 | if (dis_pred < 500) 34 | score_stay = 1.0f; 35 | else 36 | score_stay = 1.0f - (dis_pred - 500.0f) / 1000.0f; 37 | } 38 | 39 | float cost_reach; 40 | if (dis_pred < 500) 41 | cost_reach = 0.0f; 42 | else 43 | cost_reach = (dis_pred - 500.0f) / 1000.0f; 44 | 45 | float cost_attack = robot_num == attack ? 1.0f : 0.0f; 46 | 47 | score_stay = min(1.0f, max(0.0f, score_stay)); 48 | cost_reach = min(1.0f, max(0.0f, cost_reach)); 49 | cost_attack = min(1.0f, max(0.0f, cost_attack)); 50 | 51 | auto cost = 1.0f - score_stay + cost_reach + cost_attack; 52 | 53 | return cost; 54 | } 55 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/calculate_opp_threat.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | float ai09::calculateOppThreat(int opp, bool restart) 4 | { 5 | if (OppRobot[opp].seenState == CompletelyOut) 6 | return -1; 7 | if (opp == oppGK) 8 | return -1; 9 | 10 | if ((DIS(OppRobot[opp].Position, ball.Position) < 400) && 11 | ((DIS(OwnRobot[attack].State.Position, ball.Position) < 400) || restart)) 12 | return -1; 13 | 14 | if (OppRobot[opp].Position.X*side < 1000 && fabs(OppRobot[opp].Position.X - ball.Position.X) > 6000) 15 | return -1; 16 | 17 | 18 | float oppDisToGoal = DIS(OppRobot[opp].Position, Vec2(side*field_width, 0)); 19 | 20 | TVec2 t2 = Vec2(field_width*side, goal_width / 2.0f); 21 | TVec2 t1 = Vec2(field_width*side, -goal_width / 2.0f); 22 | float t1Angel = atan2((t1.Y - OppRobot[opp].Position.Y), (t1.X - OppRobot[opp].Position.X)); 23 | float t2Angel = atan2((t2.Y - OppRobot[opp].Position.Y), (t2.X - OppRobot[opp].Position.X)); 24 | float oppOpenAngleToGoal = fabs(NormalizeAngle(t2Angel - t1Angel))*180.0f / 3.1415f; 25 | 26 | auto oppToBall = Normalize(ball.Position - OppRobot[opp].Position); 27 | auto oppToGoal = Normalize(Vec2(side*field_width, 0) - OppRobot[opp].Position); 28 | auto oneTouchDot = Dot(oppToBall, oppToGoal); 29 | 30 | auto ballToOppDis = DIS(ball.Position, OppRobot[opp].Position); 31 | 32 | float score_goal_dis; 33 | if (oppDisToGoal < 3000) 34 | score_goal_dis = 1.0f; 35 | else 36 | score_goal_dis = 1.0f - pow(max(0.0f, (oppDisToGoal - 3000.0f) / 3000.0f), 0.5f); 37 | 38 | float score_ball_dis; 39 | if (ballToOppDis < 1500) 40 | score_ball_dis = pow(ballToOppDis / 1500.0f, 2.0f); 41 | else if (ballToOppDis < 4000) 42 | score_ball_dis = 1.0f; 43 | else 44 | score_ball_dis = 1.0f - (ballToOppDis - 4000.0f) / 4000.0f; 45 | 46 | float score_open_angle = oppOpenAngleToGoal / 15.0f; 47 | 48 | float score_one_touch_angle; 49 | if (oneTouchDot > 0.7f) 50 | score_one_touch_angle = 1.0f - (oneTouchDot - 0.7f) / 0.3f; 51 | else if (oneTouchDot > 0.0f) 52 | score_one_touch_angle = 1.0f; 53 | else 54 | score_one_touch_angle = 0.0f; 55 | 56 | score_goal_dis = min(1.0f, max(0.0f, score_goal_dis)); 57 | score_ball_dis = min(1.0f, max(0.0f, score_ball_dis)); 58 | score_open_angle = min(1.0f, max(0.0f, score_open_angle)); 59 | score_one_touch_angle = min(1.0f, max(0.0f, score_one_touch_angle)); 60 | 61 | auto final_score_one_touch = score_one_touch_angle * min(score_ball_dis*score_goal_dis, score_open_angle); 62 | auto final_score_turn_shoot = min(score_ball_dis*score_goal_dis, score_open_angle); 63 | 64 | auto score = max(final_score_one_touch, final_score_turn_shoot); 65 | 66 | return score; 67 | } 68 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/calculate_swicth_to_attacker_score.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | float ai09::calculateSwicthToAttackerScore(int robot_num) 4 | { 5 | if (OwnRobot[robot_num].State.seenState == CompletelyOut) 6 | return -1; 7 | 8 | if (robot_num != mid1 && robot_num != mid2) 9 | return -1; 10 | 11 | if (!isDefending && oneTouchDetector[robot_num].IsArriving(45, 150)) 12 | return -1; 13 | 14 | float currAttBallDis = DIS(OwnRobot[attack].State.Position, ball.Position); 15 | 16 | if (OwnRobot[attack].State.seenState == CompletelyOut) 17 | currAttBallDis = 20000; 18 | 19 | auto marked_id = -1; 20 | for (auto it = markMap.begin(); it != markMap.end(); ++it) 21 | { 22 | if (*it->first == robot_num) 23 | { 24 | marked_id = it->second; 25 | break; 26 | } 27 | } 28 | 29 | if (isDefending && marked_id != -1) 30 | { 31 | auto opp = marked_id; 32 | if ( 33 | (DIS(OppRobot[opp].Position, ball.Position) < 400) && 34 | (DIS(OwnRobot[robot_num].State.Position, ball.Position) < 400) && 35 | (currAttBallDis > 600) && 36 | (ball.velocity.magnitude < 500)) { 37 | return 0; 38 | } 39 | else 40 | return -1; 41 | } 42 | 43 | auto disToBall = DIS(OwnRobot[robot_num].State.Position, ball.Position); 44 | if (disToBall > currAttBallDis - 500) 45 | return 0; 46 | 47 | auto dis_score = (currAttBallDis - disToBall - 500) / 1000.0f; 48 | dis_score = min(1.0f, max(0.0f, dis_score)); 49 | 50 | return dis_score; 51 | } 52 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/cmu_goto_point.h: -------------------------------------------------------------------------------- 1 | // tactic.cc 2 | // 3 | // Parent class for tactics. 4 | // 5 | // Created by: Michael Bowling (mhb@cs.cmu.edu) 6 | // 7 | /* LICENSE: 8 | ========================================================================= 9 | CMDragons'02 RoboCup F180 Source Code Release 10 | ------------------------------------------------------------------------- 11 | Copyright (C) 2002 Manuela Veloso, Brett Browning, Mike Bowling, 12 | James Bruce; {mmv, brettb, mhb, jbruce}@cs.cmu.edu 13 | School of Computer Science, Carnegie Mellon University 14 | ------------------------------------------------------------------------- 15 | This software is distributed under the GNU General Public License, 16 | version 2. If you do not have a copy of this licence, visit 17 | www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 18 | Suite 330 Boston, MA 02111-1307 USA. This program is distributed 19 | in the hope that it will be useful, but WITHOUT ANY WARRANTY, 20 | including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | ------------------------------------------------------------------------- */ 22 | 23 | #include "helpers.h" 24 | #include "Robot.h" 25 | #include "VelocityProfile.h" 26 | #include "../../Reality/WorldState.h" 27 | 28 | struct Trajectory 29 | { 30 | double vx, vy, va; 31 | 32 | double eta; 33 | 34 | Trajectory(){;} 35 | 36 | Trajectory(double _vx, double _vy, double _va, 37 | double _eta = 0.0) 38 | { 39 | vx = _vx; vy = _vy; va = _va; 40 | eta = _eta; 41 | } 42 | }; 43 | 44 | float motion_time_1d(float dx,float vel0,float vel1, 45 | float max_vel,float max_accel, 46 | float &t_accel,float &t_cruise,float &t_decel); 47 | 48 | double max_speed(float dx,float max_a); 49 | void compute_motion_1d(float x0, float v0, float v1, 50 | float a_max, float v_max, float a_factor, 51 | float &traj_accel, float &traj_time); 52 | 53 | void compute_motion_2d(TVec2 x0, TVec2 v0, TVec2 v1, 54 | float a_max, float v_max, float a_factor, 55 | TVec2 &traj_accel, float &time); 56 | 57 | float compute_stop(float v, float max_a); 58 | 59 | Trajectory goto_point(RobotState state, 60 | RobotState target, 61 | VelocityProfile *profile); 62 | // 1400.0, 2000.0, 12.0, 12.0 63 | // 1600.0, 3000.0, 18.0, 18.0 64 | 65 | // Normal 66 | const float diff_max_vx = 1200.0; // 1600.0; 67 | const float diff_max_avx = 2000.0; // 3000.0; 68 | const float diff_max_va = 14.0; // 18.0; 69 | const float diff_max_ava = 14.0; // 18.0; 70 | const float diff_accel_margin = 0.85; 71 | 72 | 73 | 74 | Trajectory goto_point_speed(int me, 75 | TVec2 target_pos,TVec2 target_vel, 76 | double target_angle); 77 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/data_flow.cpp: -------------------------------------------------------------------------------- 1 | #include "data_flow.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/data_flow.h: -------------------------------------------------------------------------------- 1 | #pragma once -------------------------------------------------------------------------------- /Source/Soccer/ai09/defenceWall.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::DefenceWall ( int robot_num , bool kickOff ) 4 | { 5 | float x = -side*ball.Position.X; 6 | x = max ( -3200.0f , min ( 3200.0f , x ) ); 7 | float tetta = -0.000003f*x*x + 0.0016f*x + 90.0f; 8 | if (kickOff) { 9 | tetta = 14.0f; 10 | } 11 | 12 | TVec2 target; 13 | 14 | //std::cout << " wall limit: " << tetta << std::endl; 15 | int index = findKickerOpp ( -1 ); 16 | if ( index == -1 ) 17 | { 18 | target = CircleAroundPoint(Vec2(ball.Position.X,ball.Position.Y),NormalizeAngle(AngleWith(ball.Position , Vec2(side*field_width,0))),730); 19 | } 20 | else 21 | { 22 | target = PointOnConnectingLine ( OppRobot[index].Position , ball.Position , 590+DIS ( ball.Position , OppRobot[index].Position ) ); 23 | } 24 | 25 | //std::cout << index << std::endl; 26 | 27 | float ballAngle = AngleWith(ball.Position, target); 28 | float firstLeg = AngleWith(ball.Position, Vec2(side*field_width, sgn(ball.Position.Y)*(350.0f))); 29 | float secLeg = firstLeg - tetta * sgn(ball.Position.Y)*side; 30 | 31 | //std::cout << " ball: " << ballAngle << " f: " << firstLeg << " s: " << secLeg << std::endl; 32 | 33 | bool isOut = fabs((fabs(NormalizeAngle(ballAngle-firstLeg))+fabs(NormalizeAngle(ballAngle-secLeg))) - tetta ) > 1.0f; 34 | 35 | if ( isOut ) 36 | { 37 | target = CircleAroundPoint(Vec2(ball.Position.X,ball.Position.Y),NormalizeAngle(AngleWith(ball.Position , Vec2(side*field_width,0))),730); 38 | } 39 | 40 | OwnRobot[robot_num].face ( ball.Position ); 41 | ERRTSetObstacles ( robot_num , true , true , true , false ); 42 | ERRTNavigate2Point ( robot_num , target ); 43 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/dribblr.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | #include 3 | 4 | void ai09::dribble ( int robot_num , TVec2 target ) 5 | { 6 | ERRTSetObstacles ( robot_num , false , true , true , false ); 7 | OwnRobot[robot_num].face ( ball.Position ); 8 | float appAng = AngleWith(OwnRobot[robot_num].State.Position, ball.Position); 9 | appAng /=1.3; 10 | TVec2 exte = Vec2(cosDeg(appAng)*(DIS(OwnRobot[robot_num].State.Position, ball.Position)+300.0f), sinDeg(appAng)*(DIS(OwnRobot[robot_num].State.Position, ball.Position)+300.0f)); 11 | exte += OwnRobot[robot_num].State.Position; 12 | // = PointOnConnectingLine(OwnRobot[robot_num].State.Position, ball.Position, DIS(OwnRobot[robot_num].State.Position, ball.Position)+3300.0f); 13 | ERRTNavigate2Point ( robot_num , exte , 0 , 70 ); 14 | OwnRobot[robot_num].Dribble(15); 15 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/dss/Dss.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 18.06.18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_DSS_H 6 | #define IMMORTALSSSL_DSS_H 7 | 8 | 9 | #include "../../../Reality/WorldState.h" 10 | #include "../Robot.h" 11 | #include "../../../Common/Random.h" 12 | 13 | class Dss 14 | { 15 | private: 16 | Random random; 17 | 18 | const float robot_r; 19 | const float cmd_dt; 20 | const float max_dec; 21 | const float max_dec_opp; 22 | 23 | const Robot *const own_robots; 24 | const RobotState *const opp_robots; 25 | 26 | TVec2 computed_motions[Setting::kMaxOnFieldTeamRobots]; 27 | 28 | TVec2 GetAccFromMotion(const int robot_num, const TVec2 &motion); 29 | TVec2 GetMotionFromAcc(const int robot_num, const TVec2 &acc); 30 | 31 | bool OwnRobotsHaveCollision(const RobotState &state_a, const TVec2 &cmd_a, 32 | const RobotState &state_b, const TVec2 &cmd_b) const; 33 | bool OppRobotsHaveCollision(const RobotState &state_own, const TVec2 &cmd_own, 34 | const RobotState &state_opp) const; 35 | bool RobotHasStaticCollision(const RobotState &state, const TVec2 &cmd) const; 36 | 37 | bool IsAccSafe(const int robot_num, const TVec2 &cmd); 38 | TVec2 GetRandomAcceleration(const TVec2 &v, const float a_mag) const; 39 | static float ComputeError(const TVec2 &target, const TVec2 & current); 40 | 41 | public: 42 | Dss(const Robot *const own_robots, 43 | const RobotState *const opp_robots, 44 | const float robot_r, const float cmd_dt, 45 | const float max_dec, const float max_dec_opp); 46 | 47 | void Reset( void ); 48 | 49 | TVec2 ComputeSafeMotion(const int robot_num, const TVec2 &motion); 50 | }; 51 | 52 | 53 | #endif //IMMORTALSSSL_DSS_H 54 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/dss/Parabolic.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 18.06.18. 3 | // 4 | 5 | #include "Parabolic.h" 6 | #include "../helpers.h" 7 | #include "../../../Common/distance.h" 8 | #include "../errt/obstacle.h" 9 | 10 | bool Parabolic::HaveOverlap(const Parabolic &a, const Parabolic &b, const float r) 11 | { 12 | const float t0 = min(a.t0, b.t0); 13 | const float t1 = min(a.t1, b.t1); 14 | 15 | if (t1 <= t0) 16 | { 17 | return false; 18 | } 19 | 20 | float check_t[6]; 21 | int check_t_count = 0; 22 | 23 | check_t[check_t_count++] = t0; 24 | check_t[check_t_count++] = t1; 25 | check_t[check_t_count++] = (t0 + t1) / 2.f; 26 | 27 | for (int t_idx = 0; t_idx < check_t_count; ++t_idx) 28 | { 29 | const float t = check_t[t_idx]; 30 | if (HasCollision(a, b, r, t)) 31 | { 32 | return true; 33 | } 34 | } 35 | 36 | return false; 37 | } 38 | 39 | bool Parabolic::HasStaticOverlap(const Parabolic &a) 40 | { 41 | const float t0 = a.t0; 42 | const float t1 = a.t1; 43 | 44 | if (t1 <= t0) 45 | { 46 | return false; 47 | } 48 | 49 | float check_t[6]; 50 | int check_t_count = 0; 51 | 52 | check_t[check_t_count++] = t0; 53 | check_t[check_t_count++] = t1; 54 | check_t[check_t_count++] = (t0 + t1) / 2.f; 55 | 56 | for (int t_idx = 0; t_idx < check_t_count; ++t_idx) 57 | { 58 | const float t = check_t[t_idx]; 59 | const TVec2 p = a.Evaluate(t); 60 | if (IsInObstacle(p)) 61 | { 62 | return true; 63 | } 64 | } 65 | 66 | return false; 67 | } 68 | 69 | bool Parabolic::HasCollision(const Parabolic &a, const Parabolic &b, const float r, const float t) 70 | { 71 | const float t0 = min(a.t0, b.t0); 72 | const float t1 = min(a.t1, b.t1); 73 | 74 | if (t1 <= t0 || 75 | t < t0 || 76 | t > t1) 77 | { 78 | return false; 79 | } 80 | 81 | const float dis = Distance(a, b, t); 82 | return dis <= r; 83 | } 84 | 85 | float Parabolic::Distance(const Parabolic &a, const Parabolic &b, const float t) 86 | { 87 | const TVec2 p_a = a.Evaluate(t); 88 | const TVec2 p_b = b.Evaluate(t); 89 | return DIS(p_a, p_b); 90 | } 91 | 92 | TVec2 Parabolic::Evaluate(const float t) const 93 | { 94 | if (Magnitude(a) < 1e-10 && Magnitude(v) < 1e-10) 95 | { 96 | return p; 97 | } 98 | 99 | const float dt = t - t0; 100 | const float x = p.X + (v.X * dt) + (a.X * (dt * dt * .5f)); 101 | const float y = p.Y + (v.Y * dt) + (a.Y * (dt * dt * .5f)); 102 | return Vec2(x, y); 103 | } 104 | 105 | TVec2 Parabolic::EvaluateDerivative(const float t) const 106 | { 107 | if (Magnitude(a) < 1e-10) 108 | { 109 | return v; 110 | } 111 | 112 | const float dt = t - t0; 113 | const float x = v.X + (a.X * dt); 114 | const float y = v.Y + (a.Y * dt); 115 | return Vec2(x, y); 116 | } 117 | 118 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/dss/Parabolic.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 18.06.18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_PARABOLIC_H 6 | #define IMMORTALSSSL_PARABOLIC_H 7 | 8 | #include "../../../Common/Vector.h" 9 | 10 | class Parabolic 11 | { 12 | private: 13 | static bool HasCollision(const Parabolic &a, const Parabolic &b, const float r, const float t); 14 | static float Distance(const Parabolic &a, const Parabolic &b, const float t); 15 | 16 | public: 17 | TVec2 a; 18 | TVec2 v; 19 | TVec2 p; 20 | 21 | float t0; 22 | float t1; 23 | 24 | static bool HaveOverlap(const Parabolic &a, const Parabolic &b, const float r); 25 | static bool HasStaticOverlap(const Parabolic &a); 26 | 27 | TVec2 Evaluate(const float t) const; 28 | TVec2 EvaluateDerivative(const float t) const; 29 | }; 30 | 31 | 32 | #endif //IMMORTALSSSL_PARABOLIC_H 33 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/dss/Trajectory.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 18.06.18. 3 | // 4 | 5 | #include "Trajectory.h" 6 | #include 7 | 8 | Trajectory Trajectory::MakeTrajectory(const RobotState &state, const TVec2 &a_acc, const float a_dec, const float a_dt) 9 | { 10 | Trajectory trajectory; 11 | 12 | const float t0 = 0.f; 13 | 14 | const TVec2 p0 = state.Position; 15 | const TVec2 v0 = Vec2(state.velocity.x, state.velocity.y); 16 | const TVec2 a0 = a_acc; 17 | 18 | const float t1 = t0 + a_dt; 19 | 20 | trajectory.acc.t0 = t0; 21 | trajectory.acc.t1 = t1; 22 | trajectory.acc.p = p0; 23 | trajectory.acc.v = v0; 24 | trajectory.acc.a = a0; 25 | 26 | const TVec2 p1 = trajectory.acc.Evaluate(t1); 27 | const TVec2 v1 = trajectory.acc.EvaluateDerivative(t1); 28 | const TVec2 a1 = Normalize(v1) * (- a_dec); 29 | 30 | const float dec_dt = Magnitude(v1) / a_dec; 31 | const float t2 = t1 + dec_dt; 32 | 33 | trajectory.dec.t0 = t1; 34 | trajectory.dec.t1 = t2; 35 | trajectory.dec.p = p1; 36 | trajectory.dec.v = v1; 37 | trajectory.dec.a = a1; 38 | 39 | const TVec2 p2 = trajectory.dec.Evaluate(t2); 40 | const TVec2 v2 = Vec2(0.f, 0.f); 41 | const TVec2 a2 = Vec2(0.f, 0.f); 42 | 43 | trajectory.stopped.t0 = t2; 44 | trajectory.stopped.t1 = FLT_MAX; 45 | trajectory.stopped.p = p2; 46 | trajectory.stopped.v = v2; 47 | trajectory.stopped.a = a2; 48 | 49 | return trajectory; 50 | } 51 | 52 | Trajectory Trajectory::MakeOpponentTrajectory(const RobotState &state, const float a_dec) 53 | { 54 | Trajectory trajectory; 55 | 56 | const float t0 = -1.f; 57 | 58 | const TVec2 p0 = state.Position; 59 | const TVec2 v0 = Vec2(state.velocity.x, state.velocity.y); 60 | const TVec2 a0 = Vec2(0.f, 0.f); 61 | 62 | const float t1 = 0.f; 63 | 64 | trajectory.acc.t0 = t0; 65 | trajectory.acc.t1 = t1; 66 | trajectory.acc.p = p0; 67 | trajectory.acc.v = v0; 68 | trajectory.acc.a = a0; 69 | 70 | const TVec2 p1 = p0; 71 | const TVec2 v1 = v0; 72 | const TVec2 a1 = Normalize(v1) * (- a_dec); 73 | 74 | const float dec_dt = Magnitude(v1) / a_dec; 75 | const float t2 = t1 + dec_dt; 76 | 77 | trajectory.dec.t0 = t1; 78 | trajectory.dec.t1 = t2; 79 | trajectory.dec.p = p1; 80 | trajectory.dec.v = v1; 81 | trajectory.dec.a = a1; 82 | 83 | const TVec2 p2 = trajectory.dec.Evaluate(t2); 84 | const TVec2 v2 = Vec2(0.f, 0.f); 85 | const TVec2 a2 = Vec2(0.f, 0.f); 86 | 87 | trajectory.stopped.t0 = t2; 88 | trajectory.stopped.t1 = FLT_MAX; 89 | trajectory.stopped.p = p2; 90 | trajectory.stopped.v = v2; 91 | trajectory.stopped.a = a2; 92 | 93 | return trajectory; 94 | } 95 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/dss/Trajectory.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 18.06.18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_TRAJECTORY_H 6 | #define IMMORTALSSSL_TRAJECTORY_H 7 | 8 | #include "Parabolic.h" 9 | #include "../../../Reality/WorldState.h" 10 | 11 | class Trajectory 12 | { 13 | public: 14 | Parabolic acc; 15 | Parabolic dec; 16 | Parabolic stopped; 17 | 18 | static Trajectory MakeTrajectory(const RobotState &state, const TVec2 &a_acc, const float a_dec, const float a_dt); 19 | static Trajectory MakeOpponentTrajectory(const RobotState &state, const float a_dec); 20 | }; 21 | 22 | 23 | #endif //IMMORTALSSSL_TRAJECTORY_H 24 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/errt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "tree.h" 4 | #include "obstacle.h" 5 | #include "../../../Common/Vector.h" 6 | #include 7 | #include "../../../Common/Random.h" 8 | 9 | class Planner 10 | { 11 | float step_size; 12 | TVec2 init_state , final_state; 13 | TVec2 waypoint[MAX_NODES]; 14 | unsigned int waypoints , cached_waypoints , cache_start; 15 | 16 | void reverse_waypoints ( void ); 17 | 18 | float field_width; 19 | float field_height; 20 | 21 | bool started_in_obs; 22 | 23 | Random random; 24 | 25 | public: 26 | 27 | float goal_target_prob; 28 | float waypoint_target_prob; 29 | float acceptable_dis; 30 | 31 | Planner ( void ); 32 | ~Planner(void); 33 | Tree tree; 34 | void set_field_params ( float _w , float _h ); 35 | void init ( TVec2 init , TVec2 final , float step ); 36 | TVec2 random_state ( void ); 37 | TVec2 nearest_free ( TVec2 state ); 38 | TVec2 nearest_free_prob ( TVec2 state ); 39 | 40 | TVec2 choose_target ( int * type = NULL ); 41 | Node * extend ( Node * s , TVec2 & target ); 42 | void SetWayPoints ( void ); 43 | TVec2 GetWayPoint ( unsigned int i ); 44 | unsigned int GetWayPointNum ( void ); 45 | bool IsReached ( void ); 46 | 47 | void optimize_tree ( void ); 48 | 49 | TVec2 Plan ( void ); 50 | }; 51 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/obstacle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /*bool obs_lut[605][405]; 4 | 5 | void clear_map ( void ) 6 | { 7 | for ( int i = 0 ; i < 605 ; i ++ ) 8 | for ( int j = 0 ; j < 405 ; j ++ ) 9 | { 10 | obs_lut[i][j] = false; 11 | } 12 | } 13 | 14 | bool IsInObstacle ( TVec2 p ) 15 | { 16 | return obs_lut[(int)p.X][(int)p.Y]; 17 | } 18 | 19 | bool collisionDetect ( TVec2 p1 , TVec2 p2 ) 20 | { 21 | float coss , sinn; 22 | coss = ( p2.X - p1.X ) / DIS ( p1 , p2 ); 23 | sinn = ( p2.Y - p1.Y ) / DIS ( p1 , p2 ); 24 | 25 | TVec2 current = p1; 26 | 27 | while ( DIS ( current , p2 ) > 9 ) 28 | { 29 | if ( IsInObstacle ( current ) ) 30 | return true; 31 | 32 | current.X += coss * 9; 33 | current.Y += sinn * 9; 34 | } 35 | 36 | return false; 37 | } 38 | 39 | void AddCircle ( int x , int y , int r ) 40 | { 41 | for ( int i = 0 ; i < 605 ; i ++ ) 42 | for ( int j = 0 ; j < 405 ; j ++ ) 43 | { 44 | //obs_lut[i][j] = false; 45 | if ( (i-x) * (i-x) + (j-y) * (j-y) < r * r ) obs_lut[i][j] = true; 46 | } 47 | }*/ 48 | 49 | #include "obstacle_new.h" 50 | #include "../../../Common/Vector.h" 51 | 52 | void clear_map ( void ); 53 | bool IsInObstacle ( TVec2 p ); 54 | bool collisionDetect ( TVec2 p1 , TVec2 p2 ); 55 | void AddCircle ( float x , float y , float r ); 56 | void AddRectangle ( float x , float y , float w , float h ); -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/obstacle_circle.cpp: -------------------------------------------------------------------------------- 1 | #include "obstacle_new.h" 2 | #include "../../../Common/distance.h" 3 | 4 | CircleObstacle::CircleObstacle ( float _x , float _y , float _r ) 5 | { 6 | x = _x; 7 | y = _y; 8 | r = _r; 9 | } 10 | 11 | bool CircleObstacle::IsInObstacle ( float _x , float _y ) 12 | { 13 | if ( ( _x > x + r ) || 14 | ( _x < x - r ) || 15 | ( _y > y + r ) || 16 | ( _y < y - r ) ) 17 | return false; 18 | 19 | if ( DIS ( x , y , _x , _y ) <= r ) 20 | return true; 21 | 22 | return false; 23 | } 24 | 25 | float CircleObstacle::NearestDistance ( float _x , float _y ) 26 | { 27 | return DIS ( x , y , _x , _y ) - r; 28 | } 29 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/obstacle_map.cpp: -------------------------------------------------------------------------------- 1 | #include "obstacle_new.h" 2 | #include 3 | 4 | #include 5 | 6 | ObsMap::ObsMap ( unsigned int _maxObs ) 7 | { 8 | obstacle = new BaseObstacle * [_maxObs]; 9 | 10 | obsNum = 0; 11 | maxObs = _maxObs; 12 | } 13 | 14 | void ObsMap::AddCircle ( float _x , float _y , float _r ) 15 | { 16 | if ( ( _r > 0 ) && ( obsNum < maxObs ) ) 17 | { 18 | obstacle[obsNum++] = new CircleObstacle ( _x , _y , _r ); 19 | } 20 | } 21 | void ObsMap::AddRectangle ( float _x , float _y , float _w , float _h ) 22 | { 23 | if ( obsNum < maxObs ) 24 | { 25 | obstacle[obsNum++] = new RectangleObstacle ( _x , _y , _w , _h ); 26 | } 27 | } 28 | 29 | void ObsMap::AddObstacle ( BaseObstacle * obs ) 30 | { 31 | if ( ( obs ) && ( obsNum < maxObs ) ) 32 | { 33 | obstacle[obsNum++] = obs; 34 | } 35 | } 36 | 37 | bool ObsMap::IsInObstacle ( float _x , float _y ) 38 | { 39 | for ( int i = 0 ; i < obsNum ; i ++ ) 40 | { 41 | if ( obstacle[i] -> IsInObstacle ( _x , _y ) ) 42 | return true; 43 | } 44 | if(fabs(_x) > 10000 || fabs(_y) > 10000)//If the values where getting to much (this fixes the errors for now... 45 | { 46 | return true; 47 | } 48 | return false; 49 | } 50 | 51 | float ObsMap::NearestDistance ( float _x , float _y ) 52 | { 53 | if ( obsNum == 0 ) 54 | return INT_MAX; 55 | float dis = obstacle[0] -> NearestDistance( _x , _y ); 56 | float tmp_dis; 57 | for ( int i = 0 ; i < obsNum ; i ++ ) 58 | { 59 | tmp_dis = obstacle[i] -> NearestDistance ( _x , _y ); 60 | if ( tmp_dis < dis ) 61 | dis = tmp_dis; 62 | if ( dis <= 0 ) 63 | return dis; 64 | } 65 | 66 | return dis; 67 | } 68 | 69 | void ObsMap::resetMap ( void ) 70 | { 71 | for ( int i = 0 ; i < obsNum ; i ++ ) 72 | { 73 | delete obstacle[i]; 74 | } 75 | 76 | free ( obstacle ); 77 | 78 | obstacle = new BaseObstacle * [maxObs]; 79 | 80 | obsNum = 0; 81 | } 82 | 83 | int ObsMap::getObsNum ( void ) 84 | { 85 | return obsNum; 86 | } 87 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/obstacle_new.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //#include "line.h" 3 | #include 4 | 5 | class BaseObstacle 6 | { 7 | public: 8 | virtual bool IsInObstacle ( float _x , float _y ) = 0; 9 | virtual float NearestDistance ( float _x , float _y ) = 0; 10 | }; 11 | 12 | class CircleObstacle : public BaseObstacle 13 | { 14 | private: 15 | float x , y; 16 | float r; 17 | 18 | public: 19 | CircleObstacle ( float _x , float _y , float _r ); 20 | bool IsInObstacle ( float _x , float _y ); 21 | float NearestDistance ( float _x , float _y ); 22 | }; 23 | 24 | class RectangleObstacle : public BaseObstacle 25 | { 26 | private: 27 | float x , y; 28 | float w , h; 29 | 30 | public: 31 | RectangleObstacle ( float _x , float _y , float _w , float _h ); 32 | bool IsInObstacle ( float _x , float _y ); 33 | float NearestDistance ( float _x , float _y ); 34 | }; 35 | 36 | class HalfPlaneObstacle : public BaseObstacle 37 | { 38 | private: 39 | float w , h; 40 | 41 | public: 42 | HalfPlaneObstacle ( float _x , float _y , float _w , float _h ); 43 | bool IsInObstacle ( float _x , float _y ); 44 | float NearestDistance ( float _x , float _y ); 45 | }; 46 | 47 | class ObsMap 48 | { 49 | private: 50 | unsigned int obsNum , maxObs; 51 | 52 | BaseObstacle ** obstacle; 53 | 54 | public: 55 | ObsMap ( unsigned int _maxObs ); 56 | 57 | void AddCircle ( float _x , float _y , float _r ); 58 | void AddRectangle ( float _x , float _y , float _w , float _h ); 59 | //void AddHalfPlane ( float _x , float _y , float _w , float _h ); 60 | void AddObstacle ( BaseObstacle * obs ); 61 | 62 | bool IsInObstacle ( float _x , float _y ); 63 | float NearestDistance ( float _x , float _y ); 64 | 65 | 66 | void resetMap ( void ); 67 | 68 | int getObsNum ( void ); 69 | }; 70 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/obstacle_rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "obstacle_new.h" 2 | #include "../helpers.h" 3 | #include "../../../Common/distance.h" 4 | 5 | RectangleObstacle::RectangleObstacle ( float _x , float _y , float _w , float _h ) 6 | { 7 | if (_w < 0) 8 | { 9 | x = _x + _w; 10 | w = -_w; 11 | } 12 | else 13 | { 14 | x = _x; 15 | w = _w; 16 | } 17 | 18 | if (_h < 0) 19 | { 20 | y = _y + _h; 21 | h = _h; 22 | } 23 | else 24 | { 25 | y = _y; 26 | h = _h; 27 | } 28 | } 29 | 30 | bool RectangleObstacle::IsInObstacle ( float _x , float _y ) 31 | { 32 | return (_x < x + w ) && 33 | ( _x > x ) && 34 | ( _y < y + h ) && 35 | ( _y > y ); 36 | 37 | } 38 | 39 | float RectangleObstacle::NearestDistance ( float _x , float _y ) 40 | { 41 | if ( IsInObstacle( _x , _y ) ) 42 | return -1.0f; 43 | 44 | if ( ( _x > x ) && ( _x < x + w ) ) 45 | { 46 | return min ( fabs ( _y - y ) , fabs ( _y - y - h ) ); 47 | } 48 | 49 | if ( ( _y > y ) && ( _y < y + h ) ) 50 | { 51 | return min ( fabs ( _x - x ) , fabs ( _x - x - w ) ); 52 | } 53 | 54 | if ( ( _x < x ) && ( _y < y ) ) 55 | { 56 | return DIS( _x , _y , x , y ); 57 | } 58 | 59 | if ( ( _x < x ) && ( _y > y + h ) ) 60 | { 61 | return DIS( _x , _y , x , y+h ); 62 | } 63 | 64 | if ( ( _x > x + w ) && ( _y < y ) ) 65 | { 66 | return DIS( _x , _y , x+w , y ); 67 | } 68 | 69 | if ( ( _x > x + w ) && ( _y > y + h ) ) 70 | { 71 | return DIS( _x , _y , x+w , y+h ); 72 | } 73 | 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/tree.cpp: -------------------------------------------------------------------------------- 1 | #include "tree.h" 2 | #include "../../../Common/distance.h" 3 | 4 | Tree::Tree ( void ) 5 | { 6 | reset ( ); 7 | } 8 | 9 | void Tree::reset ( void ) 10 | { 11 | nodes_num = 0; 12 | } 13 | 14 | Node * Tree::AddNode( TVec2 & s , Node *p ) 15 | { 16 | if ( nodes_num < MAX_NODES ) 17 | { 18 | node[nodes_num].state = s; 19 | node[nodes_num].parent = p; 20 | node[nodes_num].childs_num = 0; 21 | if ( p ) 22 | p->childs_num ++; 23 | nodes_num ++; 24 | } 25 | else 26 | { 27 | LOG_WARNING("Tree node limit of {} reached", MAX_NODES); 28 | } 29 | return &(node[nodes_num-1]); 30 | } 31 | 32 | Node * Tree::NearestNeighbour ( TVec2 & s ) 33 | { 34 | if ( nodes_num == 0 ) 35 | return NULL; 36 | if ( nodes_num == 1) 37 | return &node[0]; 38 | float d = DISM ( s , node[0].state ); 39 | float tmp_d = d; 40 | int ans = 0; 41 | for ( int i = 0 ; i < nodes_num ; i ++ ) 42 | { 43 | tmp_d = DISM ( s , node[i].state ); 44 | if ( tmp_d < d ) 45 | { 46 | ans = i; 47 | d = tmp_d; 48 | } 49 | } 50 | return &node[ans]; 51 | } 52 | 53 | unsigned int Tree::tree_size ( void ) 54 | { 55 | return nodes_num; 56 | } 57 | 58 | Node* Tree::GetNode ( unsigned int num ) 59 | { 60 | return &node[num]; 61 | } 62 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/errt/tree.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../../Common/Vector.h" 4 | #include 5 | 6 | struct Node 7 | { 8 | Node *parent; 9 | unsigned int childs_num; 10 | TVec2 state; 11 | }; 12 | 13 | #define MAX_NODES 1000 14 | 15 | class Tree 16 | { 17 | Node node[MAX_NODES]; 18 | 19 | unsigned int nodes_num; 20 | 21 | public: 22 | Tree ( void ); 23 | void reset ( void ); 24 | Node * AddNode ( TVec2 & s , Node* p ); 25 | Node * NearestNeighbour ( TVec2 & s ); 26 | unsigned int tree_size ( void ); 27 | Node* GetNode ( unsigned int num ); 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/findCruncherOpp.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | int ai09::findCruncherOpp ( int mask1 , int mask2 , bool acceptNearBall ) 4 | { 5 | float mdis = 7000; 6 | int index = -1; 7 | for ( int i = 0 ; i < Setting::kMaxRobots; i ++ ) 8 | { 9 | if ( ( i == mask1 ) || ( i == mask2 ) ) 10 | continue; 11 | if ( OppRobot[i].seenState == CompletelyOut ) 12 | continue; 13 | if ( ( fabs ( OppRobot[i].Position.X ) > field_width ) || 14 | ( fabs ( OppRobot[i].Position.Y ) > field_height ) ) 15 | continue; 16 | if ((!acceptNearBall)&&(( DIS ( ball.Position , OppRobot[i].Position ) < 500 ))) { 17 | continue; 18 | } 19 | if ( ( DIS ( Vec2 ( side*field_width , 0 ) , OppRobot[i].Position ) < mdis ) ) 20 | { 21 | mdis = DIS ( Vec2 ( side*field_width , 0 ) , OppRobot[i].Position ); 22 | index = i; 23 | } 24 | } 25 | return index; 26 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/findGusheRobot.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | bool ai09::isGooshe ( int id , bool sameSideAsBall ) 4 | { 5 | /*TVec2 search_center = Vec2(side*2900, -sgn(ball.Position.Y)*1900); 6 | if (sameSideAsBall) { 7 | search_center.Y = -search_center.Y; 8 | } 9 | 10 | if ( DIS(OppRobot[id].Position, search_center) < 1700 ) 11 | return true; 12 | 13 | return false;*/ 14 | 15 | int ballYsgn = sgn(ball.Position.Y); 16 | if ( !sameSideAsBall ) 17 | ballYsgn = - ballYsgn; 18 | 19 | if ( ( OppRobot[id].Position.X * side > 500 ) && ( ballYsgn * OppRobot[id].Position.Y > 1000 ) ) 20 | return true; 21 | return false; 22 | 23 | } 24 | 25 | int ai09::findGusheRobot ( int mask ) 26 | { 27 | float minDis = (field_width+field_height)*2.0; 28 | int ans = -1; 29 | for ( int i = 0 ; i < Setting::kMaxRobots; i ++ ) 30 | { 31 | if ( i == mask ) 32 | continue; 33 | if ( i == oppGK ) 34 | continue; 35 | if ( OppRobot[i].seenState == CompletelyOut ) 36 | continue; 37 | if ( ( fabs ( OppRobot[i].Position.X ) > field_width ) || 38 | ( fabs ( OppRobot[i].Position.Y ) > field_height ) ) 39 | continue; 40 | 41 | if ( isGooshe(i,0) ){ 42 | float newDis = DIS(OppRobot[i].Position, Vec2(side*field_width, 0)); 43 | if ( newDis < minDis ) 44 | { 45 | minDis = newDis; 46 | ans = i; 47 | } 48 | } 49 | } 50 | 51 | return ans; 52 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/findJeloOpps.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | int ai09::findJeloOpps ( float minX , int* ans , int mask1 , int mask2 , bool acceptNearBall , bool acceptGooshe ) 4 | { 5 | int index = 0; 6 | for ( int i = 0 ; i < Setting::kMaxRobots; i ++ ) 7 | { 8 | if ( i == oppGK ) 9 | continue; 10 | if ( i == mask1 || i == mask2 ) 11 | continue; 12 | if ( OppRobot[i].seenState == CompletelyOut ) 13 | continue; 14 | if ( ( fabs ( OppRobot[i].Position.X ) > field_width ) || 15 | ( fabs ( OppRobot[i].Position.Y ) > field_height ) ) 16 | continue; 17 | if ((!acceptNearBall)&&(( DIS ( ball.Position , OppRobot[i].Position ) < 500 ))) { 18 | continue; 19 | } 20 | if ((!acceptGooshe)&&(isGooshe(i,0))) 21 | continue; 22 | //if (isGooshe(i,1)) 23 | // continue; 24 | 25 | if ( OppRobot[i].Position.X*side > minX ) 26 | { 27 | ans[index] = i; 28 | index ++; 29 | } 30 | } 31 | 32 | for (int i = index; i< Setting::kMaxRobots; i++) { 33 | ans[i] = -1; 34 | } 35 | 36 | for ( int i = 0 ; i < index ; i ++ ) 37 | { 38 | if (isGooshe(ans[i], 1)) 39 | { 40 | std::swap(ans[i], ans[0]); 41 | break; 42 | } 43 | } 44 | 45 | return index; 46 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/findKickerOpp.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | int ai09::findKickerOpp ( int mask ) 4 | { 5 | float mdis = 500; 6 | int index = -1; 7 | for ( int i = 0 ; i < Setting::kMaxRobots; i ++ ) 8 | { 9 | if ( i == mask ) 10 | continue; 11 | if ( OppRobot[i].seenState == CompletelyOut ) 12 | continue; 13 | if ( DIS ( ball.Position , OppRobot[i].Position ) < mdis ) 14 | { 15 | mdis = DIS ( ball.Position , OppRobot[i].Position ); 16 | index = i; 17 | } 18 | } 19 | return index; 20 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/goalBlocked.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | bool ai09::goal_blocked ( TVec2 init_pos, float max_shoot_blocker_dis, float shoot_blocker_r ) 4 | { 5 | bool oppGoalOpen = true; 6 | 7 | Line ballGoalLine = Line::makeLineFromTwoPoints(VecPosition(-side * field_width,0),VecPosition(init_pos.X,init_pos.Y)); 8 | for (int i = 0; i < Setting::kMaxRobots; i ++) { 9 | if ( OppRobot[i].seenState == CompletelyOut ) 10 | continue; 11 | if ( ( fabs ( OppRobot[i].Position.X ) > field_width ) || 12 | ( fabs ( OppRobot[i].Position.Y ) > field_height ) ) 13 | continue; 14 | if (DIS(OppRobot[i].Position, init_pos)>max_shoot_blocker_dis) 15 | continue; 16 | 17 | if (ballGoalLine.getDistanceWithPoint(VecPosition(OppRobot[i].Position.X,OppRobot[i].Position.Y)) 3025 ) || 27 | ( fabs ( OwnRobot[i].State.Position.Y ) > 2025 ) ) 28 | continue; 29 | if (DIS(OwnRobot[i].State.Position, init_pos)>max_shoot_blocker_dis) 30 | continue; 31 | 32 | if (ballGoalLine.getDistanceWithPoint(VecPosition(OwnRobot[i].State.Position.X,OwnRobot[i].State.Position.Y)) 3 | 4 | float max(float a, float b) 5 | { 6 | return (a > b) ? a : b; 7 | } 8 | 9 | float min(float a, float b) 10 | { 11 | return (a < b) ? a : b; 12 | } 13 | 14 | int sgn(float num) 15 | { 16 | if (num > 0) return(1); 17 | else if (num < 0) return(-1); 18 | else return(0); 19 | } 20 | 21 | bool sgnBool(float num) 22 | { 23 | if (num >= 0) return(false); 24 | else return(true); 25 | } 26 | 27 | float Angle(TVec2 a){ 28 | float ans; 29 | ans=atan(a.Y/a.X); 30 | ans*=(float)180.0/(float)3.1415; 31 | if(a.X<0) 32 | ans+=180; 33 | while(ans>180) 34 | ans-=360; 35 | while(ans<-180) 36 | ans+=360; 37 | return ans; 38 | } 39 | 40 | float AngleWith(TVec2 a,TVec2 b){ 41 | float ans; 42 | ans=atan((b.Y-a.Y)/(b.X-a.X)); 43 | ans*=(float)180.0/(float)3.1415; 44 | if(b.X-a.X<0) 45 | ans+=180; 46 | while(ans>180) 47 | ans-=360; 48 | while(ans<-180) 49 | ans+=360; 50 | return ans; 51 | } 52 | 53 | float dis(float x1,float y1,float x2,float y2){ 54 | return sqrt(pow(x2-x1,2)+pow(y2-y1,2)); 55 | } 56 | 57 | float NormalizeAngle(float teta){ 58 | if(teta>180) 59 | teta-=360; 60 | if(teta<-180) 61 | teta+=360; 62 | return teta; 63 | } 64 | 65 | TVec2 PointOnConnectingLine(TVec2 FirstPoint,TVec2 SecondPoint,float distance){ 66 | float m = (SecondPoint.Y-FirstPoint.Y)/(SecondPoint.X-FirstPoint.X); 67 | TVec2 ans; 68 | if(SecondPoint.X-FirstPoint.X>0) 69 | ans.X = FirstPoint.X + distance/sqrt(pow(m,2)+1); 70 | else 71 | ans.X = FirstPoint.X - distance/sqrt(pow(m,2)+1); 72 | ans.Y = FirstPoint.Y + m*(ans.X-FirstPoint.X); 73 | return ans; 74 | } 75 | 76 | TVec2 CircleAroundPoint(TVec2 point,float angle,float radius){ 77 | angle = NormalizeAngle(angle) * 3.1415 / 180.0; 78 | TVec2 ans = Vec2(point.X + radius * cos(angle),point.Y + radius * sin(angle)); 79 | return ans; 80 | } 81 | 82 | float sq(float a) 83 | { 84 | return a * a; 85 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Common/Vector.h" 4 | //#include "WorldState.h" 5 | 6 | #ifndef max 7 | float max(float a, float b); 8 | #endif 9 | #ifndef min 10 | float min(float a, float b); 11 | #endif 12 | 13 | float sq(float a); 14 | 15 | /*#ifndef max 16 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 17 | #endif 18 | 19 | #ifndef min 20 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 21 | #endif*/ 22 | 23 | int sgn(float num); 24 | bool sgnBool(float num); 25 | 26 | float Angle(TVec2 a); 27 | 28 | float AngleWith(TVec2 a,TVec2 b); 29 | 30 | float dis(float x1,float y1,float x2,float y2); 31 | 32 | float NormalizeAngle(float teta); 33 | 34 | TVec2 PointOnConnectingLine(TVec2 FirstPoint,TVec2 SecondPoint,float distance); 35 | 36 | TVec2 CircleAroundPoint(TVec2 point,float angle,float radius); -------------------------------------------------------------------------------- /Source/Soccer/ai09/intercept_ball.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | enum ball_intercept_state { 4 | kVeryFar = 0, 5 | kFar, 6 | kNear, 7 | kKick 8 | }; 9 | 10 | void ai09::intercept_ball ( int robot_num , float angle , int shoot_pow , int chip_pow ) 11 | { 12 | static float last_change_t = 0.0f; 13 | static int hys_bank[4]={0,0,0,0}; 14 | static ball_intercept_state state = kVeryFar; 15 | 16 | const float very_far_ball_dis = 600.0f; 17 | const float far_ball_dis = 150.0f; 18 | const int far_to_near_hys = 5; 19 | float near_ball_dis = 140.0f; 20 | const float near_angle_tol = 4.0f; 21 | const int near_to_kick_hys = 3; 22 | const float shmit_coeff = 1.2f; 23 | 24 | if (state == kVeryFar) { 25 | 26 | float ball_intercept_t = calculateBallRobotReachTime(robot_num, &VELOCITY_PROFILE_MAMOOLI); 27 | TVec2 ball_reach_point = predictBallForwardAI(ball_intercept_t); 28 | 29 | if (DIS(OwnRobot[robot_num].State.Position, ball.Position) < very_far_ball_dis) { 30 | state = kFar; 31 | last_change_t = timer.time(); 32 | } 33 | } 34 | 35 | else if (state == kFar) { 36 | 37 | 38 | if (DIS(OwnRobot[robot_num].State.Position, ball.Position) < far_ball_dis) { 39 | hys_bank[0]++; 40 | } 41 | else { 42 | hys_bank[0]=0; 43 | } 44 | if (hys_bank[0] > far_to_near_hys ) { 45 | state = kNear; 46 | last_change_t = timer.time(); 47 | } 48 | else if (DIS(OwnRobot[robot_num].State.Position, ball.Position) > very_far_ball_dis * shmit_coeff) { 49 | state = kVeryFar; 50 | last_change_t = timer.time(); 51 | } 52 | } 53 | 54 | else if (state == kNear) { 55 | 56 | 57 | if (DIS(OwnRobot[robot_num].State.Position, ball.Position) > far_ball_dis*shmit_coeff) { 58 | state = kFar; 59 | last_change_t = timer.time(); 60 | } 61 | 62 | //if (fabs(deltaAngle) < near_angle_tol) { 63 | hys_bank[0]++; 64 | //} 65 | //else { 66 | // hys_bank[0]=0; 67 | //} 68 | 69 | if ((hys_bank[0]>near_to_kick_hys)&&((shoot_pow>0)||(chip_pow>0))) { 70 | state = kKick; 71 | last_change_t = timer.time(); 72 | } 73 | } 74 | 75 | else if (state == kKick) { 76 | 77 | if (DIS(OwnRobot[robot_num].State.Position, ball.Position) > near_ball_dis*shmit_coeff) { 78 | state = kFar; 79 | last_change_t = timer.time(); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/internalFinalize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ai09.h" 3 | 4 | void ai09::internalFinalize ( WorldState * worldState , GameSetting * setting ) 5 | { 6 | //bool saveKinoData = !OwnRobot[cmf].halted; 7 | 8 | for ( int i = 0 ; i < Setting::kMaxOnFieldTeamRobots ; i ++ ) 9 | OwnRobot[i].makeSendingDataReady ( ); 10 | 11 | 12 | for ( int i = 0 ; i < Setting::kMaxOnFieldTeamRobots ; i ++ ) 13 | { 14 | senderBase->getCommand(&OwnRobot[i]); 15 | OwnRobot[i].halted = false; 16 | } 17 | senderBase->append_demo_data(); 18 | 19 | 20 | for ( int i = 0 ; i < Setting::kMaxRobots ; i ++ ) 21 | { 22 | for ( int j = 0 ; j < 10 ; j ++ ) 23 | { 24 | worldState -> lastCMDS[i][j] = Vec3 ( 0.0f ); 25 | } 26 | } 27 | 28 | for ( int i = 0 ; i < Setting::kMaxOnFieldTeamRobots; i ++ ) 29 | { 30 | if ( OwnRobot[i].State.seenState == CompletelyOut ) 31 | continue; 32 | for ( int j = 0 ; j < 11 ; j ++ )//kheyli tof malie... 33 | { 34 | worldState -> lastCMDS[OwnRobot[i].State.vision_id][j] = OwnRobot[i].lastCMDs[j]; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/internalProcessData.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::internalProcessData ( WorldState * worldState , GameSetting * setting ) 4 | { 5 | this -> oppGK = worldState -> refereeState -> oppGK; 6 | 7 | this->ball = worldState -> ball; 8 | if ( ball.seenState != CompletelyOut ) 9 | this->ballHist.push_back(this->ball); 10 | if ( this->ballHist.size() > maxBallHist ) 11 | this->ballHist.pop_front(); 12 | //debugDraw = true; 13 | CalculateBallTrajectory(); 14 | debugDraw = false; 15 | 16 | for ( int i = 0 ; i < Setting::kMaxOnFieldTeamRobots ; i ++ ) 17 | { 18 | bool halt_this_robot_for_now = false; 19 | this->OwnRobot[i].State = worldState -> OwnRobot[OwnRobot[i].vision_id]; 20 | 21 | if ( !worldState ->refereeState -> State || worldState ->refereeState -> State->get() == GameState::GAME_OFF ) 22 | { 23 | if ( OwnRobot[i].State.OutForSubsitute ) 24 | { 25 | for ( int j = 0 ; j < Setting::kMaxRobots ; j ++ ) 26 | { 27 | if ( ( worldState -> OwnRobot[j].seenState == Seen ) && ( fabs(worldState->OwnRobot[j].Position.X)OwnRobot[j].Position.Y)OwnRobot[i].set_serial_id(OwnRobot[i].vision_id); 50 | //this->OwnRobot[i].oldRobot = true; 51 | //if ( ( i != gk ) && ( i != def1 ) ) 52 | //this->OwnRobot[i].oldRobot = false; 53 | 54 | this->OwnRobot[i].shoot = 0; 55 | this->OwnRobot[i].dribbler = 0; 56 | this->OwnRobot[i].shoot = 0; 57 | this->OwnRobot[i].chip = 0; 58 | this->OwnRobot[i].Break = 0; 59 | this->navigated[i] = false; 60 | 61 | //if ((OwnRobot[i].vision_id==7)||(OwnRobot[i].vision_id==4)||(OwnRobot[i].vision_id==0)) { 62 | // this->OwnRobot[i].oldRobot = true; 63 | //} 64 | //if (OwnRobot[i].vision_id==10) { 65 | // this->OwnRobot[i].oldRobot = true; 66 | //} 67 | //this->OwnRobot[def].oldRobot = true; 68 | //if(i==passgir) 69 | // this->OwnRobot[i].oldRobot = true; 70 | 71 | } 72 | //std::cout << std::endl; 73 | 74 | for ( int i = 0 ; i < Setting::kMaxRobots ; i ++ ) 75 | this->OppRobot[i] = worldState -> OppRobot[i]; 76 | 77 | this->OwnRobotNum = worldState -> ownRobots_num; 78 | this->OppRobotNum = worldState -> oppRobots_num; 79 | 80 | if ( setting -> our_side == RIGHT_SIDE ) 81 | this->side = 1; 82 | else 83 | this->side = -1; 84 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/manageAttRoles.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | static int attackerChangeHys = 0; 4 | 5 | void ai09::ManageAttRoles ( void ) 6 | { 7 | if (DIS(OwnRobot[attack].State.Position, ball.Position) > 600) //Check if the current attacker has lost the ball, before switching its role 8 | attackerChangeHys++; 9 | if (OwnRobot[attack].State.seenState == CompletelyOut) 10 | attackerChangeHys = 100; 11 | 12 | if (attackerChangeHys > 30) { 13 | int newAttack = attack; 14 | 15 | auto mid1_score = calculateSwicthToAttackerScore(mid1); 16 | auto mid2_score = calculateSwicthToAttackerScore(mid2); 17 | if (mid1_score > 0.1f && mid2_score > 0.1f) 18 | { 19 | if (mid1_score > mid2_score) 20 | newAttack = mid1; 21 | else 22 | newAttack = mid2; 23 | } 24 | else if (mid1_score > 0.1f) 25 | { 26 | newAttack = mid1; 27 | } 28 | else if (mid2_score > 0.1f) 29 | { 30 | newAttack = mid2; 31 | } 32 | 33 | if ( attack != newAttack ) 34 | { 35 | if (mid1 == newAttack) { 36 | mid1 = attack; 37 | } 38 | else if (mid2 == newAttack) { 39 | mid2 = attack; 40 | } 41 | 42 | attackerChangeHys = 0; 43 | attack = newAttack; 44 | } 45 | } 46 | 47 | if (OwnRobot[mid1].State.Position.Y 0 || oppToGoalDis < 2500) { 11 | Mark2Goal(robot_num, opp, dist); 12 | } 13 | else { 14 | if (oneTouchDetector[robot_num].IsArriving(20)) { 15 | WaitForPass(robot_num, false); 16 | } 17 | else 18 | { 19 | Mark2Ball(robot_num, opp, dist); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/mark2ball.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::Mark2Ball ( int robot_num , int opp , float dist ) 4 | { 5 | const float opp_predict_t = 0.15; 6 | dist = min(1500, dist); 7 | 8 | TVec2 predictedOpp = Vec2(OppRobot[opp].Position.X + OppRobot[opp].velocity.x*opp_predict_t, OppRobot[opp].Position.Y + OppRobot[opp].velocity.y*opp_predict_t); 9 | TVec2 target = PointOnConnectingLine(predictedOpp, ball.Position, dist); 10 | 11 | OwnRobot[robot_num].face(ball.Position); 12 | ERRTSetObstacles(robot_num, true, 1, 1, 1); 13 | ERRTNavigate2Point(robot_num, target, 0, 100, REF_playState->stop() ? &VELOCITY_PROFILE_AROOM : &VELOCITY_PROFILE_MAMOOLI); 14 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/navigation.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::Navigate2Point ( int robot_num , TVec2 dest , bool accurate , int speed , VelocityProfile * velocityProfile, bool use_dss ) 4 | { 5 | OwnRobot[robot_num].target.Position.X = dest.X; 6 | OwnRobot[robot_num].target.Position.Y = dest.Y; 7 | 8 | if ( velocityProfile == NULL ) 9 | velocityProfile = &this->VELOCITY_PROFILE_MAMOOLI; 10 | 11 | TVec3 motion_cmd = OwnRobot[robot_num].ComputeMotionCommand ( accurate , speed , velocityProfile ); 12 | 13 | if (use_dss) 14 | { 15 | const TVec2 safe_motion_cmd = dss->ComputeSafeMotion(robot_num, Vec2(motion_cmd.X, motion_cmd.Y)); 16 | motion_cmd.X = safe_motion_cmd.X; 17 | motion_cmd.Y = safe_motion_cmd.Y; 18 | } 19 | OwnRobot[robot_num].MoveByMotion(motion_cmd); 20 | 21 | // OwnRobot[robot_num].target.velocity.x = motion_cmd.X;//TODO #4 erase these three lines (It is used for plotting) 22 | // OwnRobot[robot_num].target.velocity.y = motion_cmd.Y;// 23 | // OwnRobot[robot_num].target.velocity.magnitude = sqrt(motion_cmd.X * motion_cmd.X + motion_cmd.Y * motion_cmd.Y);// 24 | 25 | navigated[robot_num] = true; 26 | } 27 | 28 | void ai09::ERRTNavigate2Point ( int robot_num , TVec2 dest , bool accurate , int speed , VelocityProfile * velocityProfile ) 29 | { 30 | //Navigate2Point(robot_num, dest,accurate,speed,velocityProfile); 31 | //return; 32 | if ( OwnRobot[robot_num].State.seenState == CompletelyOut ) 33 | Halt ( robot_num ); 34 | else 35 | { 36 | planner[robot_num].init ( OwnRobot[robot_num].State.Position , dest , 90.0f ); 37 | TVec2 wayp = planner[robot_num].Plan ( ); 38 | 39 | //if ( robot_num == 0 ) 40 | { 41 | /*for ( int i = 0 ; i < planner[robot_num].GetWayPointNum() - 1 ; i ++ ) 42 | { 43 | Debug_Line * newDbgLine = AIDebug.add_line(); 44 | newDbgLine -> set_x1(planner[robot_num].GetWayPoint(i).X); 45 | newDbgLine -> set_y1(planner[robot_num].GetWayPoint(i).Y); 46 | newDbgLine -> set_x2(planner[robot_num].GetWayPoint(i+1).X); 47 | newDbgLine -> set_y2(planner[robot_num].GetWayPoint(i+1).Y); 48 | }*/ 49 | 50 | } 51 | 52 | //if ( planner[robot_num].GetWayPointNum ( ) <= 2 ) 53 | Navigate2Point ( robot_num , wayp , accurate , speed , velocityProfile, true ); 54 | //else 55 | // Navigate2Point ( robot_num , wayp , false , speed , velocityProfile ); 56 | //Navigate2Point ( robot_num , dest , accurate , speed ); 57 | } 58 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/nearestAsshole.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | int ai09::findNearestAsshole ( TVec2 pos , int mask , bool acceptNearBall ) 4 | { 5 | float mdis = 7000; 6 | int index = -1; 7 | for ( int i = 0 ; i < Setting::kMaxRobots ; i ++ ) 8 | { 9 | if ( i == mask ) 10 | continue; 11 | if ( OppRobot[i].seenState == CompletelyOut ) 12 | continue; 13 | if ( ( fabs ( OppRobot[i].Position.X ) > field_width ) || 14 | ( fabs ( OppRobot[i].Position.Y ) > field_height ) ) 15 | continue; 16 | if ((!acceptNearBall)&&(( DIS ( ball.Position , OppRobot[i].Position ) < 500 ))) { 17 | continue; 18 | } 19 | if ( ( DIS ( pos , OppRobot[i].Position ) < mdis ) ) 20 | { 21 | mdis = DIS ( pos , OppRobot[i].Position ); 22 | index = i; 23 | } 24 | } 25 | 26 | return index; 27 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/one_touch_score.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | float ai09::oneTouchScore ( int robot_num ) 4 | { 5 | TVec2 oneTouchPos = CalculatePassPos(robot_num,Vec2(-side*3025, 0),OwnRobot[robot_num].State.Position, 95); 6 | float travelTime = calculateRobotReachTime(robot_num, oneTouchPos, &VELOCITY_PROFILE_MAMOOLI); 7 | TVec2 ballPosAtReach = predictBallForwardAI ( travelTime ); 8 | return 1.0; 9 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/pass_gool.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::WaitForGool ( int robot_num , bool chip ) 4 | { 5 | TVec2 pos = CalculatePassPos(robot_num,Vec2(-side*3025, 0),OwnRobot[robot_num].State.Position,-1600); 6 | 7 | OwnRobot[robot_num].face(Vec2(-side*field_width, 0)); 8 | 9 | ERRTSetObstacles ( robot_num ,0,1,1,0); 10 | ERRTNavigate2Point ( robot_num ,pos,0,100,&VELOCITY_PROFILE_MAMOOLI ); 11 | 12 | OwnRobot[robot_num].Shoot( 100 ); 13 | OwnRobot[robot_num].Dribble( 15 ); 14 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/pass_omghi.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::WaitForOmghi ( int robot_num , bool chip ) 4 | { 5 | Line ball_line = Line::makeLineFromPositionAndAngle ( VecPosition ( ball.Position.X , ball.Position.Y ) , ball.velocity.direction ); 6 | if (chip_head<180) { 7 | ball_line = Line::makeLineFromPositionAndAngle ( VecPosition ( ball.Position.X , ball.Position.Y ) , chip_head ); 8 | std::cout << " calcing with static head: " << chip_head << std::endl; 9 | } 10 | Line to_goal_line = Line::makeLineFromTwoPoints(VecPosition(OwnRobot[robot_num].State.Position.X,OwnRobot[robot_num].State.Position.Y) , VecPosition(-side*field_width,0) ); 11 | 12 | VecPosition ans = ball_line.getIntersection ( to_goal_line ); 13 | 14 | float sBAR; 15 | sBAR = ans.getDistanceTo ( VecPosition ( ball.Position.X , ball.Position.Y ) ); 16 | sBAR /= ball.velocity.magnitude; 17 | sBAR = ans.getDistanceTo ( VecPosition ( OwnRobot[robot_num].State.Position.X , OwnRobot[robot_num].State.Position.Y ) ) / sBAR; 18 | sBAR /= 63.0; 19 | //sBAR /= 10.0; 20 | //sBAR /= 1500000; 21 | 22 | std::cout << "old sBAR: " << sBAR << " " 23 | ; 24 | if ( sBAR < 5 ) sBAR = 5; 25 | if ( sBAR > 70 ) sBAR = 70; 26 | 27 | TVec2 target = Vec2(ans.getX(), ans.getY());//CalculatePassPos(robot_num, 89); 28 | 29 | OwnRobot[robot_num].target.Angle = calculateOneTouchAngle ( robot_num , target ); 30 | OwnRobot[robot_num].face(Vec2(-side*field_width, -sgn(OwnRobot[robot_num].State.Position.Y)*300)); 31 | 32 | ERRTSetObstacles ( robot_num ); 33 | 34 | target = CalculatePassPos(robot_num,Vec2(-side*field_width, 0), OwnRobot[robot_num].State.Position, -200); 35 | 36 | std::cout << "sBAR: " << sBAR << std::endl; 37 | ERRTNavigate2Point ( robot_num , target , 0 , sBAR , &VELOCITY_PROFILE_KHARAKI); 38 | 39 | OwnRobot[robot_num].Shoot( 100 ); 40 | OwnRobot[robot_num].Dribble( 15 ); 41 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/penalty.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | #include "helpers.h" 4 | 5 | void ai09::PenaltyUs ( int robot_num , float angle , int kick , int chip ) 6 | { 7 | TVec2 PredictedBall = ball.Position; 8 | 9 | float r = 180.0f; 10 | 11 | float tetta = 25.0f; 12 | 13 | if ( ( kick > 0 ) || ( chip > 0 ) ) 14 | { 15 | r = 110.0f; 16 | tetta = 15.0f; 17 | } 18 | 19 | OwnRobot[robot_num].face ( PredictedBall ); 20 | 21 | float hehe = AngleWith ( PredictedBall , OwnRobot[robot_num].State.Position ); 22 | hehe = NormalizeAngle ( angle - hehe ); 23 | 24 | ERRTSetObstacles ( robot_num, false, false, true, true ); 25 | 26 | if ( fabs ( hehe ) < tetta ) 27 | { 28 | //hehe = angle; 29 | //if ( OwnRobot[2].State.Angle < 0 ) 30 | if (( kick) ||(chip )) 31 | ERRTNavigate2Point ( robot_num , CircleAroundPoint ( PredictedBall , angle , min ( r , fabs(hehe)*280.0f/tetta ) ) ); 32 | else 33 | { 34 | //OwnRobot[robot_num].target.Angle = 90+side*90; 35 | ERRTNavigate2Point ( robot_num , CircleAroundPoint ( PredictedBall , angle+hehe*0.0f , r/1.5f ) ,0, 100 , &VELOCITY_PROFILE_AROOM ); 36 | } 37 | std::cout<<"IN_HEHE"< 0 ) || ( chip > 0 ) ) 47 | { 48 | std::cout<<"HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH"< 360 ) 62 | t1 -= 360.0f; 63 | while ( t2 < 0 ) 64 | t2 += 360.0f; 65 | while ( t2 > 360 ) 66 | t2 -= 360.0f; 67 | 68 | float ot = tmpAng; 69 | while ( ot < 0 ) 70 | ot += 360.0f; 71 | while ( ot > 360 ) 72 | ot -= 360.0f; 73 | 74 | //if ( ( ot > t2 ) && ( ot < t1 ) ) 75 | //if ( fabs ( NormalizeAngle ( OwnRobot[robot_num].State.Angle - AngleWith ( OwnRobot[robot_num].State.Position , Vec2 ( -3025 , 0 ) ) ) ) < 20 ) 76 | if ( ( ( side == -1 ) && ( fabs ( OwnRobot[robot_num].State.Angle ) < 120 ) ) || 77 | ( ( side == 1 ) && ( fabs ( OwnRobot[robot_num].State.Angle ) > 60 ) ) ) 78 | { 79 | if ( fabs ( NormalizeAngle ( 180+angle - OwnRobot[robot_num].State.Angle ) ) < 30 ) 80 | { 81 | //if ( chip ) 82 | OwnRobot[robot_num].Chip(chip); 83 | //else 84 | OwnRobot[robot_num].Shoot(kick); 85 | } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/planner.h: -------------------------------------------------------------------------------- 1 | #include "Geom.h" 2 | #include "helpers.h" 3 | 4 | class Obstacle 5 | { 6 | public: 7 | Circle circle; 8 | 9 | }obstacle[100],tempobs[100],showobs[100]; 10 | int obs_num,waypoints; 11 | VecPosition path[100]; 12 | 13 | VecPosition Plan ( VecPosition start , VecPosition end ) 14 | { 15 | VecPosition current = start; 16 | VecPosition* p1 = new VecPosition ( ); 17 | VecPosition* p2 = new VecPosition ( ); 18 | Rect* r; 19 | int colls = 0; 20 | 21 | waypoints = 0; 22 | 23 | while ( ( current.getDistanceTo ( end ) > 1 ) && ( waypoints < 1 ) ) 24 | { 25 | r = new Rect ( VecPosition ( min ( current.getX ( ) , end.getX ( ) ) - 19 , min ( current.getY ( ) , end.getY ( ) ) - 19 ) , VecPosition ( max ( current.getX ( ) , end.getX ( ) + 19 ) , max ( current.getY ( ) , end.getY ( ) ) + 19 ) ); 26 | int collision_index=-1; 27 | float pp = 1000000; 28 | 29 | for ( int i = 0 ; i < obs_num ; i++ ) 30 | { 31 | if ( ( obstacle[i].circle.getRadius ( ) > 0 ) && 32 | ( r->isInside ( obstacle[i].circle.getCenter ( ) ) ) && 33 | ( Line::makeLineFromTwoPoints ( current , end ).getCircleIntersectionPoints ( obstacle[i].circle , p1 , p2 ) ) 34 | ) 35 | { 36 | if ( current.getDistanceTo ( obstacle[i].circle.getCenter ( ) ) < pp ) 37 | { 38 | collision_index = i; 39 | pp = current.getDistanceTo ( obstacle[i].circle.getCenter ( ) ); 40 | } 41 | } 42 | } 43 | 44 | if ( collision_index == -1 ) 45 | { 46 | current = end; 47 | path[waypoints] = end; 48 | waypoints++; 49 | } 50 | 51 | else 52 | { 53 | while (!( colls = Circle( current , sqrt ( pow ( current.getDistanceTo ( obstacle[collision_index].circle.getCenter ( ) ) , 2 ) - pow ( obstacle[collision_index].circle.getRadius ( ) , 2 ) ) ).getIntersectionPoints ( obstacle[collision_index].circle , p1 , p2 ) )) 54 | obstacle[collision_index].circle.setRadius ( obstacle[collision_index].circle.getRadius ( ) -1 ); 55 | 56 | if ( colls == 1 ) 57 | path[waypoints] = *p1; 58 | else 59 | { 60 | if ( Line::makeLineFromTwoPoints ( current , end ).getDistanceWithPoint ( *p1 ) < Line::makeLineFromTwoPoints ( current , end ).getDistanceWithPoint ( *p2 ) ) 61 | path[waypoints] = *p1; 62 | else 63 | path[waypoints] = *p2; 64 | } 65 | current = path[waypoints]; 66 | //obstacle[collision_index].circle.setRadius ( 0 ); 67 | waypoints ++; 68 | } 69 | } 70 | return path[0]; 71 | } 72 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/play_book.cpp: -------------------------------------------------------------------------------- 1 | #include "ai09.h" 2 | 3 | void ai09::InitAIPlayBook ( void ) 4 | { 5 | AIPlayBook.clear(); 6 | 7 | AIPlayBook["my_test"] = &ai09::my_test; 8 | AIPlayBook["NormalPlay"] = &ai09::NormalPlay; 9 | AIPlayBook["NewNormalPlay"] = &ai09::NewNormalPlay; 10 | AIPlayBook["NormalPlayDef"] = &ai09::NormalPlayDef; 11 | AIPlayBook["NormalPlayAtt"] = &ai09::NormalPlayAtt; 12 | AIPlayBook["Stop"] = &ai09::Stop; 13 | AIPlayBook["tech_challenge"] = &ai09::tech_challenge; 14 | AIPlayBook["tech_cmu"] = &ai09::tech_cmu; 15 | AIPlayBook["tech_mexico"] = &ai09::tech_mexico; 16 | AIPlayBook["corner_simple_pass"] = &ai09::corner_simple_pass; 17 | AIPlayBook["corner_simple_chip"] = &ai09::corner_simple_chip; 18 | AIPlayBook["corner_switch_pass"] = &ai09::corner_switch_pass; 19 | AIPlayBook["kickoff_us_pass"] = &ai09::kickoff_us_pass; 20 | AIPlayBook["kickoff_us_farar"] = &ai09::kickoff_us_farar; 21 | AIPlayBook["kickoff_us_zamini"] = &ai09::kickoff_us_zamini; 22 | AIPlayBook["kickoff_us_chip"] = &ai09::kickoff_us_chip; 23 | AIPlayBook["throwin_chip_shoot"] = &ai09::throwin_chip_shoot; 24 | AIPlayBook["kickoff_their_one_wall"] = &ai09::kickoff_their_one_wall; 25 | AIPlayBook["kickoff_their_back_def"] = &ai09::kickoff_their_back_def; 26 | AIPlayBook["corner_their_marker_ajor"] = &ai09::corner_their_marker_ajor; 27 | AIPlayBook["corner_their_marker_karkas"] = &ai09::corner_their_marker_karkas; 28 | AIPlayBook["corner_their_def_karkas"] = &ai09::corner_their_def_karkas; 29 | AIPlayBook["corner_their_def_ajor"] = &ai09::corner_their_def_ajor; 30 | AIPlayBook["throwin_their_khafan"] = &ai09::throwin_their_khafan; 31 | AIPlayBook["Stop_def"] = &ai09::Stop_def; 32 | AIPlayBook["strategy_maker"] = &ai09::strategy_maker; 33 | AIPlayBook["penalty_us_ghuz"] = &ai09::penalty_us_ghuz; 34 | AIPlayBook["penalty_us_shootout"] = &ai09::penalty_us_shootout; 35 | AIPlayBook["penalty_their_gool"] = &ai09::penalty_their_gool; 36 | AIPlayBook["penalty_their_simple"] = &ai09::penalty_their_simple; 37 | 38 | AIPlayBook["throwin_tu_omgh"] = &ai09::throwin_tu_omgh; 39 | AIPlayBook["corner_their_global"] = &ai09::corner_their_global; 40 | AIPlayBook["tech_khers_pass"] = &ai09::tech_khers_pass; 41 | AIPlayBook["tech_khers_def"] = &ai09::tech_khers_def; 42 | AIPlayBook["corner_their_skuba"] = &ai09::corner_their_skuba; 43 | AIPlayBook["corner_their_mrl"] = &ai09::corner_their_mrl; 44 | AIPlayBook["tech_motion_ann"] = &ai09::tech_motion_ann; 45 | AIPlayBook["throwin_us_outgir"] = &ai09::throwin_us_outgir; 46 | AIPlayBook["our_place_ball_shoot"] = &ai09::our_place_ball_shoot; 47 | AIPlayBook["our_place_ball_shoot_V2"] = &ai09::our_place_ball_shoot_V2; 48 | AIPlayBook["our_place_ball_shoot_taki"] = &ai09::our_place_ball_shoot_taki; 49 | AIPlayBook["their_place_ball"] = &ai09::their_place_ball; 50 | AIPlayBook["penalty_our_Shoot_Out"] = &ai09::penalty_our_Shoot_Out; 51 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/NewNormalPlay.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | Timer activeShootTimer_omid; 4 | 5 | void ai09::NewNormalPlay ( void ) 6 | { 7 | // GKHi(gk, 0); 8 | //side = -side; 9 | // GKHi_Simple(gk,0); 10 | GKHi(gk,0); 11 | //side = -side;//TODO #8 comment this ... 12 | 13 | // DefHi(def,NULL, 0); 14 | // side = -side; 15 | // DefHi(def,NULL, 0); 16 | DefMid(def, rw, lw, NULL, false); 17 | // side = -side; 18 | 19 | CalcIsDefending(); 20 | 21 | if (isDefending) { 22 | NormalPlayDef(); 23 | } 24 | else { 25 | NormalPlayAtt(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/NormalPlayDef.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::NormalPlayDef ( void ) 4 | { 5 | ManageAttRoles(); 6 | 7 | MarkManager(false); 8 | 9 | for (std::map::const_iterator i=markMap.begin(); i!=markMap.end(); ++i) { 10 | int opp = i->second; 11 | int own = *i->first; 12 | 13 | if (0) {//oneTouchDetector[own].IsArriving()) { 14 | WaitForPass(own, false); 15 | } 16 | else 17 | { 18 | 19 | if (opp==-1) { 20 | int oppAttacker = findKickerOpp(-1); 21 | 22 | OwnRobot[own].face(Vec2(-side*field_width, 0)); 23 | ERRTSetObstacles(own, 0, 1, 1, 0); 24 | 25 | if (own==dmf) { 26 | ERRTNavigate2Point(dmf, PointOnConnectingLine(ball.Position, Vec2(side*field_width, 0), 1800), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 27 | } 28 | else if (own==mid1) { 29 | if (oppAttacker != -1) 30 | Mark2Goal(own,oppAttacker, 500); 31 | else 32 | ERRTNavigate2Point(own, Vec2(ball.Position.X, 1000), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 33 | } 34 | else if (own==mid2) { 35 | if (oppAttacker != -1) 36 | Mark2Goal(own,oppAttacker, 500); 37 | else 38 | ERRTNavigate2Point(own, Vec2(ball.Position.X, -1000), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 39 | } 40 | } 41 | else { 42 | Mark(own, opp, 500); 43 | } 44 | } 45 | } 46 | 47 | TVec2 openAngle = calculateOpenAngleToGoal(ball.Position, attack); 48 | float shootAngle = shootAngle = NormalizeAngle( 180+openAngle.X); 49 | 50 | float shoot_pow = 1; 51 | float chip_pow = 1; 52 | if (DIS(OwnRobot[attack].State.Position,ball.Position) > 400 ) { 53 | chip_pow = 1; 54 | } 55 | if (goal_blocked(ball.Position, 200, 90)) { 56 | chip_pow = 50; 57 | } 58 | else if (!goal_blocked(ball.Position, 3000, 130)) { 59 | shoot_pow = 50 - OwnRobot[attack].State.velocity.magnitude * 0.005;; 60 | chip_pow = 0; 61 | } 62 | else 63 | { 64 | shoot_pow = 0; 65 | chip_pow = 10; 66 | } 67 | 68 | // chip the ball out if in a dangerous position 69 | #if 1 70 | if (attackFuckingAngle() && findKickerOpp(-1)) { 71 | shootAngle = AngleWith(ball.Position, Vec2(side*field_width, 0)); 72 | shoot_pow = 1; 73 | chip_pow = 0; 74 | } 75 | #endif 76 | 77 | if (0)//findKickerOpp(-1)) 78 | { 79 | shootAngle = AngleWith(ball.Position, OwnRobot[attack].State.Position); 80 | shoot_pow = 0; 81 | chip_pow = 500; 82 | 83 | OwnRobot[attack].face(ball.Position); 84 | ERRTSetObstacles(attack); 85 | ERRTNavigate2Point(attack, ball.Position,1,100,&VELOCITY_PROFILE_KHARAKI); 86 | OwnRobot[attack].Chip(500); 87 | } 88 | else 89 | { 90 | debugDraw = true; 91 | tech_circle(attack, shootAngle, shoot_pow, chip_pow, 1, 0, 0, 1); 92 | //circle_ball(attack, 90, 80, 0, 1.0f); 93 | debugDraw = false; 94 | } 95 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_simple_chip.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_simple_chip ( void ) 4 | { 5 | //GK ( gk , 1 ); 6 | //OneDef ( def ); 7 | 8 | GKHi(gk, 0); 9 | DefHi(def, NULL, false); 10 | 11 | ERRTSetObstacles ( dmf , false , true , true , true ); 12 | OwnRobot[dmf].face(ball.Position); 13 | ERRTNavigate2Point ( dmf , PointOnConnectingLine(ball.Position, Vec2(side*3025, 0), 1500) ,0 , 100,&VELOCITY_PROFILE_MAMOOLI); 14 | 15 | Halt(lmf); 16 | 17 | TVec2 jagir; 18 | if ( reached ) 19 | jagir = Vec2(-side*2200, -sgn(ball.Position.Y )* 700 ); 20 | else 21 | jagir = Vec2(-side*1400, -sgn(ball.Position.Y )* 900 ); 22 | 23 | //swap(attack, passgir); 24 | 25 | if ( ( ( DIS ( ball.Position , OwnRobot[attack].State.Position ) < 250 ) && ( OwnRobot[attack].State.velocity.magnitude < 100 ) )|| ( reached ) ) 26 | { 27 | float waitTime = 2.0; 28 | if ( ball.Position.X * side > -2000 ) 29 | waitTime = 2.5; 30 | timer.end(); 31 | if ( timer.time() < waitTime ) 32 | { 33 | ERRTSetObstacles ( attack ); 34 | tech_circle(attack,90-side*90 ,0,0,0,1,0,0); 35 | 36 | } 37 | else if ( timer.time() < waitTime*2 ) 38 | { 39 | ERRTSetObstacles ( attack ); 40 | tech_circle(attack,AngleWith ( Vec2 ( ball.Position.X,-2000 ) , ball.Position ) ,0,0,0,1,0,0); 41 | } 42 | else if ( timer.time() < waitTime*2 ) 43 | { 44 | ERRTSetObstacles ( attack ); 45 | tech_circle(attack,AngleWith ( Vec2 ( ball.Position.X,-2000 ) , ball.Position ) ,0,0,0,1,0,0); 46 | } 47 | else 48 | { 49 | ERRTSetObstacles ( attack ); 50 | tech_circle(attack,AngleWith ( Vec2 ( ball.Position.X,-2000 ) , ball.Position ) ,0,5,0,1,0,0); 51 | } 52 | reached = true; 53 | } 54 | else 55 | { 56 | ERRTSetObstacles ( attack ); 57 | tech_circle(attack,90-side*90 ,0,0); 58 | } 59 | 60 | //////// 61 | 62 | if (oneTouchDetector[rmf].IsArriving(70)) { 63 | WaitForPass ( rmf ); 64 | } 65 | else { 66 | OwnRobot[rmf].face ( Vec2 ( -side*2995 , 0 ) ); 67 | ERRTSetObstacles(rmf, 1, 1, 1, 0); 68 | if ( timer.time() < 1.5 ) 69 | {if ( ball.Position.X * side > -2000 ) 70 | ERRTNavigate2Point ( rmf , Vec2 ( -side*2500 , -sgn(ball.Position.Y )* 1500 ) ); 71 | else 72 | ERRTNavigate2Point ( rmf , jagir ); 73 | } 74 | else { 75 | if ( ball.Position.X * side > -2000 ) 76 | ERRTNavigate2Point ( rmf , Vec2 ( -side*2500 , -sgn(ball.Position.Y )* 1500 ) ); 77 | else 78 | ERRTNavigate2Point ( rmf , jagir ); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_switch_pass.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_switch_pass ( void ) 4 | { 5 | TVec2 goolZanak1; 6 | TVec2 goolZanak2; 7 | 8 | if ( ball.Position.X * side > -2000 ) 9 | { 10 | goolZanak1 = Vec2 ( -side*2500 , -sgn ( ball.Position.Y ) * 1500 ); 11 | goolZanak2 = Vec2 ( ball.Position.X +side*700, -sgn ( ball.Position.Y ) * 1500 ); 12 | } 13 | else 14 | { 15 | goolZanak1 = Vec2 ( -side*1600 , -sgn ( ball.Position.Y ) * 1000 ); 16 | goolZanak2 = Vec2 ( -side*600 , -sgn ( ball.Position.Y ) * 0 ); 17 | } 18 | 19 | if (reached)//( ( DIS ( ball.Position , OwnRobot[attack].State.Position ) < 250 ) && ( OwnRobot[attack].State.velocity.magnitude < 100 ) )|| ( reached ) ) 20 | { 21 | GK(gk, 1); 22 | OneDef(def); 23 | //Halt(dmf); 24 | Halt(lmf); 25 | 26 | OwnRobot[dmf].face(Vec2(-side*3025, 0)); 27 | ERRTSetObstacles(dmf, 1, 1, 1, 1); 28 | ERRTNavigate2Point(dmf, Vec2(side*800, sgn(ball.Position.Y)*1400), 0, 100); 29 | 30 | if ( timer.time() < 3.5 ) 31 | { 32 | ERRTSetObstacles ( attack ); 33 | tech_circle(attack,AngleWith ( goolZanak1 , ball.Position ) ,0,0); 34 | } 35 | else 36 | { 37 | ERRTSetObstacles ( attack ); 38 | tech_circle(attack,AngleWith ( goolZanak2 , ball.Position ) ,6,0,0,1); 39 | } 40 | 41 | //reached = true; 42 | } 43 | else 44 | { 45 | GK ( gk , 1 ); 46 | OneDef ( def ); 47 | 48 | Halt(dmf); 49 | Halt(lmf); 50 | 51 | ERRTSetObstacles ( attack ); 52 | tech_circle(attack,90-side*90 ,0,0); 53 | 54 | if ( timer.time() > 1.5 ) 55 | { 56 | //if ( !reached ) 57 | //swap(attack, passgir); 58 | int hehet = OwnRobot[rmf].vision_id; 59 | OwnRobot[rmf].set_vision_id(OwnRobot[dmf].vision_id); 60 | OwnRobot[dmf].set_vision_id(hehet); 61 | reached = true; 62 | } 63 | } 64 | 65 | if ( oneTouchDetector[rmf].IsArriving(70) ) 66 | { 67 | WaitForPass ( rmf ); 68 | } 69 | else 70 | { 71 | OwnRobot[rmf].face ( Vec2 ( -side*2995 , 0 ) ); 72 | ERRTSetObstacles ( rmf ); 73 | if ( timer.time() < 1.5 ) 74 | { 75 | ERRTNavigate2Point ( rmf , goolZanak1 ); 76 | } 77 | else 78 | { 79 | ERRTNavigate2Point ( rmf , goolZanak2 ); 80 | } 81 | 82 | } 83 | 84 | //OwnRobot[def2].face ( Vec2 ( -side*2995 , 0 ) ); 85 | //Navigate2Point ( def2 , Vec2 ( -side*1500 , 0 ) ); 86 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_def_ajor.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_def_ajor ( void ) 4 | { 5 | GK ( gk , 2 ); 6 | TwoDef(def, dmf); 7 | 8 | Halt(lmf); 9 | 10 | ERRTSetObstacles ( rmf , true , true , true , false ); 11 | ERRTNavigate2Point ( rmf , Vec2 ( side * 2350 , 0 ) ); 12 | 13 | DefenceWall(attack); 14 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_def_karkas.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_def_karkas ( void ) 4 | { 5 | GK ( gk , 1 ); 6 | TwoDef(def, dmf); 7 | 8 | Halt(lmf); 9 | 10 | ERRTSetObstacles ( rmf , true , true , true , true ); 11 | OwnRobot[rmf].face ( Vec2 ( -side*2995,0 ) ); 12 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( Vec2 ( side*2995 , 0 ) , ball.Position , 1350 ) ); 13 | 14 | DefenceWall(attack); 15 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_global.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_global ( void ) 4 | { 5 | if (side*ball.Position.X > field_width - 1000) 6 | { 7 | ERRTSetObstacles(gk, 0, 0, 1, 0); 8 | OwnRobot[gk].target.Angle = (1 + side)*90.0f; 9 | ERRTNavigate2Point(gk, Vec2(side*(field_width - 100), 0), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 10 | 11 | DefMid(def, rw, lw, NULL, false); 12 | } 13 | else 14 | { 15 | GKHi(gk, 0); 16 | DefMid(def, rw, lw, NULL, false); 17 | } 18 | 19 | isDefending = true; 20 | DefenceWall(attack, false); 21 | 22 | std::map static_pos; 23 | static_pos[dmf] = Vec2(side * 3500, -sgn(ball.Position.Y) * 1100); 24 | static_pos[mid1] = Vec2(side * 3200, 600); 25 | static_pos[mid2] = Vec2(side * 3200, 0); 26 | 27 | MarkManager(true); 28 | 29 | for (std::map::const_iterator i = markMap.begin(); i != markMap.end(); ++i) { 30 | int opp = i->second; 31 | int own = *i->first; 32 | 33 | if (opp == -1) { 34 | if (static_pos.find(own) != static_pos.end()) 35 | { 36 | OwnRobot[own].face(Vec2(-side * field_width, 0)); 37 | ERRTSetObstacles(own, 1, 1, 1, 1); 38 | ERRTNavigate2Point(own, static_pos[own], 0, 100, &VELOCITY_PROFILE_MAMOOLI); 39 | } 40 | } 41 | else { 42 | Mark(own, opp, 500); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_marker_ajor.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_marker_ajor ( void ) 4 | { 5 | GK ( gk , 1 ); 6 | OneDef ( def ); 7 | 8 | Halt(lmf); 9 | 10 | ERRTSetObstacles ( dmf , true , true , true , false ); 11 | ERRTNavigate2Point ( dmf , Vec2 ( side * 2350 , 0 ) ); 12 | 13 | int index = findCruncherOpp(-1); 14 | if ( index == -1 ) 15 | { 16 | ERRTSetObstacles ( rmf , true , true , true , false ); 17 | OwnRobot[rmf].face(Vec2(ball.Position.X,ball.Position.Y)); 18 | ERRTNavigate2Point ( rmf , CircleAroundPoint(Vec2(ball.Position.X,ball.Position.Y),NormalizeAngle(20+AngleWith(ball.Position , Vec2(side*2995,0))),590) ,0 , 100); 19 | } 20 | else 21 | { 22 | ERRTSetObstacles ( rmf , 1 ); 23 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( OppRobot[index].Position , Vec2 ( side*2995 , 0 ) , 220.0f ) ); 24 | } 25 | 26 | DefenceWall(attack); 27 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_marker_karkas.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_marker_karkas ( void ) 4 | { 5 | /*GK ( gk , 1 ); 6 | OneDef ( def );*/ 7 | 8 | GKHi(gk); 9 | DefHi(def); 10 | 11 | Halt(lmf); 12 | 13 | int index = findCruncherOpp(-1); 14 | if ( index == -1 ) 15 | { 16 | ERRTSetObstacles ( dmf , true , true , true , false ); 17 | OwnRobot[dmf].face(Vec2(ball.Position.X,ball.Position.Y)); 18 | ERRTNavigate2Point ( dmf , CircleAroundPoint(Vec2(ball.Position.X,ball.Position.Y),NormalizeAngle(-20+AngleWith(ball.Position , Vec2(side*2995,0))),590) ,0 , 100); 19 | } 20 | else 21 | { 22 | ERRTSetObstacles ( dmf , 1 ); 23 | ERRTNavigate2Point ( dmf, PointOnConnectingLine ( OppRobot[index].Position , Vec2 ( side*2995 , 0 ) , 220.0f ) ); 24 | } 25 | 26 | ERRTSetObstacles ( rmf , true , true , true , true ); 27 | OwnRobot[rmf].face ( Vec2 ( -side*2995,0 ) ); 28 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( Vec2 ( side*2995 , 0 ) , ball.Position , 1350 ) ); 29 | 30 | DefenceWall(attack); 31 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/corner_their_mrl.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::corner_their_mrl ( void ) 4 | { 5 | if (side*ball.Position.X > field_width - 1000) 6 | { 7 | ERRTSetObstacles(gk, 0, 0, 1, 0); 8 | OwnRobot[gk].target.Angle = (1 + side)*90.0f; 9 | ERRTNavigate2Point(gk, Vec2(side*(field_width - 100), 0), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 10 | 11 | ERRTSetObstacles(def, 1, 1, 1, 1); 12 | OwnRobot[def].face(ball.Position); 13 | auto defTarget = PointOnConnectingLine(Vec2(side*field_width, 0), ball.Position, 2000); 14 | ERRTNavigate2Point(def, defTarget, 0, 100, &VELOCITY_PROFILE_MAMOOLI); 15 | } 16 | else 17 | { 18 | GKHi(gk, 0); 19 | DefHi(def, NULL, true); 20 | } 21 | 22 | isDefending = true; 23 | DefenceWall(attack, false); 24 | 25 | std::map static_pos; 26 | static_pos[dmf] = Vec2(side*3500, -sgn(ball.Position.Y)*1100); 27 | static_pos[mid1] = Vec2(side*3200, 600); 28 | static_pos[mid2] = Vec2(side*3200, 0); 29 | 30 | int gooshe = findGusheRobot(-1); 31 | markMap[&dmf] = gooshe; 32 | if (gooshe != -1) { 33 | Mark2Goal(dmf, gooshe, 180); 34 | } 35 | else { 36 | ERRTSetObstacles(dmf, 1, 1, 1, 1); 37 | ERRTNavigate2Point(dmf, static_pos[dmf], 0, 100, &VELOCITY_PROFILE_MAMOOLI); 38 | OwnRobot[dmf].face(ball.Position); 39 | } 40 | 41 | int jelos[Setting::kMaxRobots]; 42 | int jelos_num = findJeloOpps(-1000, jelos, gooshe,-1, 0,0); 43 | 44 | std::cout << " jelos_num: " << jelos_num << std::endl; 45 | 46 | if (jelos_num == 0) { 47 | ERRTSetObstacles(mid1, 1, 1, 1, 1); 48 | ERRTNavigate2Point(mid1, static_pos[mid1], 0, 100, &VELOCITY_PROFILE_MAMOOLI); 49 | OwnRobot[mid1].face(ball.Position); 50 | markMap[&mid1] = -1; 51 | } 52 | else { 53 | float mark_dis = min(2000, DIS(Vec2(side*field_width, 0), OppRobot[jelos[0]].Position)-180); 54 | TVec2 markPoint = PointOnConnectingLine(Vec2(side*field_width, 0), OppRobot[jelos[0]].Position, mark_dis); 55 | 56 | ERRTSetObstacles(mid1, 1, 1, 1, 1); 57 | ERRTNavigate2Point(mid1, markPoint, 0, 100, &VELOCITY_PROFILE_KHARAKI); 58 | OwnRobot[mid1].face(ball.Position); 59 | markMap[&mid1] = jelos[0]; 60 | } 61 | 62 | 63 | int remaining_jelos[Setting::kMaxRobots]; 64 | int remaining_jelos_num = findJeloOpps(-1000, remaining_jelos, gooshe,jelos[0], 0, 1); 65 | std::cout << " remaining jelos_num: " << remaining_jelos_num << std::endl; 66 | 67 | if (remaining_jelos_num == 0) { 68 | ERRTSetObstacles(mid2, 1, 1, 1, 1); 69 | ERRTNavigate2Point(mid2, static_pos[mid2], 0, 100, &VELOCITY_PROFILE_MAMOOLI); 70 | OwnRobot[mid2].face(ball.Position); 71 | markMap[&mid2] = -1; 72 | } 73 | else { 74 | float mark_dis = min(2500, DIS(Vec2(side*field_width, 0), OppRobot[remaining_jelos[0]].Position)-180); 75 | TVec2 markPoint = PointOnConnectingLine(Vec2(side*field_width, 0), OppRobot[remaining_jelos[0]].Position, mark_dis); 76 | 77 | ERRTSetObstacles(mid2, 1, 1, 1, 1); 78 | ERRTNavigate2Point(mid2, markPoint, 0, 100, &VELOCITY_PROFILE_KHARAKI); 79 | OwnRobot[mid2].face(ball.Position); 80 | markMap[&mid2] = remaining_jelos[0]; 81 | } 82 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/far_penalty_shoot.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 6/16/18. 3 | // 4 | 5 | #include "../ai09.h" 6 | 7 | void ai09::far_penalty_shoot( void ){ 8 | 9 | bool canKickBall = bool(currentPlayParam); 10 | 11 | 12 | } 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/kickoff_their_back_def.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::kickoff_their_back_def ( void ) 4 | { 5 | GKHi ( gk , 1 ); 6 | DefHi ( def ); 7 | 8 | ERRTSetObstacles ( dmf , true , true , true , true ); 9 | OwnRobot[dmf].face(ball.Position); 10 | ERRTNavigate2Point ( dmf , PointOnConnectingLine(ball.Position, Vec2(side*3025, 0), DIS(ball.Position, Vec2(side*3025, 0))/3.0f) ,0 , 40,&VELOCITY_PROFILE_MAMOOLI); 11 | 12 | int indexP = -1; 13 | int indexN = -1; 14 | 15 | for ( int i = 0 ; i < Setting::kMaxRobots ; i ++ ) 16 | { 17 | if ( ( fabs ( OppRobot[i].Position.X ) < 600 ) && ( fabs ( OppRobot[i].Position.Y ) > 600 ) && ( OppRobot[i].seenState != CompletelyOut ) ) 18 | { 19 | if ( OppRobot[i].Position.Y > 0 ) 20 | indexP = i; 21 | if ( OppRobot[i].Position.Y < 0 ) 22 | indexN = i; 23 | } 24 | } 25 | 26 | std::cout << indexN << " " << indexP << std::endl; 27 | 28 | if ( indexN != -1 ) 29 | { 30 | 31 | ERRTSetObstacles ( lmf , true , true , true , false ); 32 | OwnRobot[lmf].face(OppRobot[indexN].Position); 33 | ERRTNavigate2Point ( lmf , PointOnConnectingLine ( Vec2(side*2995,-150) , OppRobot[indexN].Position , 900 ) ); 34 | } 35 | else 36 | { 37 | 38 | ERRTSetObstacles ( lmf , true , true , true , false ); 39 | OwnRobot[lmf].face(Vec2(-side*200, -2000)); 40 | ERRTNavigate2Point ( lmf , PointOnConnectingLine ( Vec2(side*2995,-150) , Vec2(-side*200, -2000) , 900 ) ); 41 | } 42 | 43 | if ( indexP != -1 ) 44 | { 45 | ERRTSetObstacles ( rmf , true , true , true , false ); 46 | OwnRobot[rmf].face(OppRobot[indexP].Position); 47 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( Vec2(side*2995,150) , OppRobot[indexP].Position , 900 ) ); 48 | } 49 | else 50 | { 51 | ERRTSetObstacles ( rmf , true , true , true , false ); 52 | OwnRobot[rmf].face(Vec2(-side*200, 2000)); 53 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( Vec2(side*2995,150) , Vec2(-side*200, 2000) , 900 ) ); 54 | } 55 | 56 | DefenceWall(attack,true); 57 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/kickoff_us_chip.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::kickoff_us_chip ( void ) 4 | { 5 | bool canKickBall = bool(currentPlayParam); 6 | GKHi ( gk ); 7 | DefMid(def, rw, lw, NULL, false); 8 | 9 | ERRTSetObstacles ( dmf , true , true , true , true ); 10 | OwnRobot[dmf].face(ball.Position); 11 | ERRTNavigate2Point ( dmf , PointOnConnectingLine(ball.Position, Vec2(side*field_width, 0), DIS(ball.Position, Vec2(side*field_width, 0))/3.0f) ,0 , 40,&VELOCITY_PROFILE_MAMOOLI); 12 | 13 | if (timer.time()<0.5) { 14 | if ( OwnRobot[mid1].State.Position.Y > OwnRobot[mid2].State.Position.Y ) 15 | { 16 | std::swap(mid1, mid2); 17 | } 18 | } 19 | 20 | OwnRobot[mid2].face ( Vec2 ( -side*field_width , 0 ) ); 21 | ERRTSetObstacles ( mid2 , true , true , true , true ); 22 | ERRTNavigate2Point ( mid2 , Vec2 ( ball.Position.X+side*150 , (field_height-300) ) ); 23 | OwnRobot[mid1].face ( Vec2 ( -side*field_width , 0 ) ); 24 | ERRTSetObstacles ( mid1 , true , true , true , true ); 25 | ERRTNavigate2Point ( mid1 , Vec2 ( ball.Position.X+side*150 , -(field_height-300) ) ); 26 | TVec2 chip_target = Vec2(-side*2000, 0); 27 | if ( canKickBall ) 28 | { 29 | tech_circle(attack,AngleWith ( chip_target , ball.Position ), 0,80,0,1,0,1); 30 | //circle_ball(attack, AngleWith ( chip_target , ball.Position ), 100, 0, 1.0f); 31 | std::cout<<"IN THE IFFFFFFFF!!!"<0.5f)?-2600:2600 ) ); 55 | } 56 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/kickoff_us_pass.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::kickoff_us_pass ( void ) 4 | { 5 | bool canKickBall = bool(currentPlayParam); 6 | GKHi(gk, 0); 7 | DefHi(def); 8 | 9 | ERRTSetObstacles ( dmf , true , true , true , true ); 10 | OwnRobot[dmf].face(ball.Position); 11 | ERRTNavigate2Point ( dmf , PointOnConnectingLine(ball.Position, Vec2(side*field_width, 0), DIS(ball.Position, Vec2(side*field_width, 0))/3.0f) ,0 , 40,&VELOCITY_PROFILE_MAMOOLI); 12 | 13 | 14 | 15 | int oneTouchSide = 1; 16 | if ( canKickBall ) 17 | { 18 | /*if (( ( DIS ( ball.Position , OwnRobot[attack].State.Position ) < 155 ) && ( OwnRobot[attack].State.velocity.magnitude < 100 ) )|| ( reached ) ) 19 | { 20 | ERRTSetObstacles ( attack ); 21 | tech_circle(attack,AngleWith ( Vec2 ( -side*80 , oneTouchSide * 1700 ) , ball.Position ) ,4,0,0,1); 22 | reached = true; 23 | } 24 | else 25 | { 26 | ERRTSetObstacles ( attack ); 27 | tech_circle(attack,AngleWith ( Vec2 ( -side*80 , oneTouchSide * 1700 ) , ball.Position ) ,0,0,0,1); 28 | }*/ 29 | 30 | TVec2 pass_pos; 31 | int shoot_pow = 0; 32 | int chip_pow = 0; 33 | if (OwnRobot[mid1].State.seenState != CompletelyOut && OwnRobot[mid2].State.seenState != CompletelyOut) 34 | { 35 | pass_pos = OwnRobot[(randomParam<0.0)?mid1:mid2].State.Position; 36 | pass_pos.X += -side*900.0f; 37 | shoot_pow = 30; 38 | } 39 | else if (OwnRobot[mid1].State.seenState != CompletelyOut) 40 | { 41 | pass_pos = OwnRobot[mid1].State.Position; 42 | pass_pos.X += -side*900.0f; 43 | shoot_pow = 30; 44 | } 45 | else if (OwnRobot[mid2].State.seenState != CompletelyOut) 46 | { 47 | pass_pos = OwnRobot[mid2].State.Position; 48 | pass_pos.X += -side*900.0f; 49 | shoot_pow = 30; 50 | } 51 | else 52 | { 53 | pass_pos = Vec2(-side * field_width, 0); 54 | chip_pow = 200; 55 | } 56 | circle_ball(attack, AngleWith ( pass_pos , ball.Position ), shoot_pow, chip_pow, 1.0f); 57 | 58 | } 59 | else 60 | { 61 | ERRTSetObstacles ( attack ); 62 | tech_circle(attack,90-sgn(side)*90 ,0); 63 | } 64 | 65 | allafPos[mid1] = Vec2 ( side*150 , -oneTouchSide * 2700 ); 66 | allafPos[mid2] = Vec2 ( side*150 , oneTouchSide * 2700 ); 67 | 68 | recievePass(mid1, allafPos[mid1]); 69 | recievePass(mid2, allafPos[mid2]); 70 | 71 | oneTouchType[mid1] = oneTouch; 72 | oneTouchType[mid2] = oneTouch; 73 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/kickoff_us_zamini.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::kickoff_us_zamini ( void ) 4 | { 5 | bool canKickBall = bool(currentPlayParam); 6 | GKHi(gk, 0); 7 | DefHi(def); 8 | 9 | ERRTSetObstacles ( dmf , true , true , true , true ); 10 | OwnRobot[dmf].face(ball.Position); 11 | ERRTNavigate2Point ( dmf , PointOnConnectingLine(ball.Position, Vec2(side*3025, 0), DIS(ball.Position, Vec2(side*3025, 0))/3.0f) ,0 , 40,&VELOCITY_PROFILE_MAMOOLI); 12 | 13 | float waitTime = 1.0f; 14 | 15 | int shootSide = 1; 16 | if (randomParam<1.5) { 17 | shootSide = -1; 18 | } 19 | 20 | if ( canKickBall ) 21 | { 22 | OwnRobot[attack].face ( Vec2 ( -side*2995 , 0 ) ); 23 | OwnRobot[lmf].face ( Vec2 ( -side*2995 , 0 ) ); 24 | 25 | if ( timer.time() < waitTime*2 ) 26 | { 27 | ERRTSetObstacles(attack, 0, 1, 1, 1); 28 | ERRTNavigate2Point ( attack , Vec2 ( side*100 , shootSide*1800 ) ); 29 | ERRTSetObstacles(lmf, 1, 1, 1, 1); 30 | ERRTNavigate2Point ( lmf , Vec2 ( side*100 , -shootSide*1800 ) ); 31 | tech_circle(rmf,AngleWith ( Vec2 ( -side*2995,shootSide*4000 ) , ball.Position ), 0,0,0,1,0,0); 32 | } 33 | else if ( timer.time() < waitTime * 2.0f ) 34 | { 35 | ERRTSetObstacles(attack, 0, 1, 1, 1); 36 | ERRTNavigate2Point ( attack , Vec2 ( side*100 , shootSide*1800 ) ); 37 | ERRTSetObstacles(lmf, 1, 1, 1, 1); 38 | ERRTNavigate2Point ( lmf , Vec2 ( side*100 , -shootSide*1800 ) ); 39 | tech_circle(rmf,AngleWith ( Vec2 ( -side*2995,shootSide*4000 ) , ball.Position ), 0,0,0,1,1,0); 40 | } 41 | else { 42 | ERRTSetObstacles(attack, 0, 1, 1, 1); 43 | ERRTNavigate2Point ( attack , Vec2 ( side*100 , shootSide*1800 ) ); 44 | ERRTSetObstacles(lmf, 1, 1, 1, 1); 45 | ERRTNavigate2Point ( lmf , Vec2 ( side*100 , -shootSide*1800 ) ); 46 | tech_circle(rmf,AngleWith ( Vec2 ( -side*2995,shootSide*4000 ) , ball.Position ), 6,0,0,1,0,0); 47 | } 48 | } 49 | else 50 | { 51 | tech_circle(rmf,AngleWith ( Vec2 ( -side*2995,shootSide*2000 ) , ball.Position ),0,0,0,1,0,0); 52 | 53 | OwnRobot[lmf].face ( Vec2 ( -side*2995 , 0 ) ); 54 | ERRTSetObstacles(lmf, 1, 1, 1, 1); 55 | ERRTNavigate2Point ( lmf , Vec2 ( side*100 , -shootSide*1600 ) ); 56 | 57 | OwnRobot[attack].face ( Vec2 ( -side*2995 , 0 ) ); 58 | ERRTSetObstacles(attack, 1, 1, 1, 1); 59 | ERRTNavigate2Point ( attack , Vec2 ( side*100 , shootSide*1600 ) ); 60 | } 61 | 62 | //swap(attack, passgir); 63 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/penalty_their_gool.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::penalty_their_gool ( void ) 4 | { 5 | bool canKickBall = bool(currentPlayParam); 6 | canKickBall = true; 7 | int index = findCruncherOpp(-1, -1, true); 8 | 9 | if (( index == -1 )||(!canKickBall)) 10 | { 11 | OwnRobot[gk].target.Angle = (1+side)*90.0f; 12 | Navigate2Point ( gk , Vec2 ( side*(field_width-100) , 0 ) ); 13 | } 14 | else 15 | { 16 | std::cout << " Penalty zan harif: " << index << std::endl; 17 | if (OppRobot[index].velocity.magnitude>10) { 18 | Navigate2Point(gk, Vec2(side*(field_width-100), 250.0f*sgn(randomParam-0.5f)), 0, 100, &VELOCITY_PROFILE_KHARAKI); 19 | } 20 | else { 21 | Navigate2Point ( gk , Vec2 ( side*(field_width-100) , 0 ) ); 22 | } 23 | 24 | } 25 | ERRTSetObstacles ( def , true , true , true , true ); 26 | ERRTNavigate2Point ( def , Vec2 ( side*2000 , -800 ) ); 27 | ERRTSetObstacles ( dmf , true , true , true , true ); 28 | ERRTNavigate2Point ( dmf , Vec2 ( side*2000 , -500 ) ); 29 | Halt(lmf); 30 | ERRTSetObstacles ( rmf , true , true , true , true ); 31 | ERRTNavigate2Point ( rmf , Vec2 ( side*2000 , 800 ) ); 32 | ERRTSetObstacles ( attack , true , true , true , true ); 33 | ERRTNavigate2Point ( attack , Vec2 ( side*2000 , 500 ) ); 34 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/penalty_their_simple.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::penalty_their_simple ( void ) 4 | { 5 | float penalty_x = field_width - 85.0; 6 | 7 | static VelocityProfile VELOCITY_PROFILE_KILLER= VELOCITY_PROFILE_KHARAKI; 8 | VELOCITY_PROFILE_KILLER.max_spd=Vec2(40.0f); 9 | VELOCITY_PROFILE_KILLER.max_dec=Vec2(1.8f); 10 | VELOCITY_PROFILE_KILLER.max_acc=Vec2(1.3f); 11 | 12 | int index = findKickerOpp(-1); 13 | if ( index == -1 ) 14 | { 15 | OwnRobot[gk].target.Angle = (1+side)*90.0f; 16 | Navigate2Point ( gk , Vec2 ( side*penalty_x , 0 ) ); 17 | } 18 | else 19 | { 20 | // float gkp_y = Line::makeLineFromTwoPoints ( VecPosition ( OppRobot[index].Position.X , OppRobot[index].Position.Y ) , VecPosition ( ball.Position.X , ball.Position.Y ) ).getIntersection ( Line::makeLineFromTwoPoints ( VecPosition ( side * penalty_x , 100 ) , VecPosition ( side * penalty_x , -100 ) ) ).getY ( ); 21 | //TODO #7 check this!!!! 22 | float gkp_y = Line::makeLineFromPositionAndAngle(VecPosition ( ball.Position.X , ball.Position.Y ),OppRobot[index].Angle).getIntersection ( Line::makeLineFromTwoPoints ( VecPosition ( side * penalty_x , 100 ) , VecPosition ( side * penalty_x , -100 ) ) ).getY ( ); 23 | float max_reach_y = (goal_width/2.0) - 50.0; 24 | if(max_reach_y < gkp_y) 25 | gkp_y = max_reach_y; 26 | if(-max_reach_y > gkp_y) 27 | gkp_y = -max_reach_y; 28 | 29 | OwnRobot[gk].face(ball.Position); 30 | 31 | Navigate2Point ( gk , Vec2 ( side * penalty_x , gkp_y ),false,100,&VELOCITY_PROFILE_KILLER ); 32 | } 33 | ERRTSetObstacles ( lw , true , true , true , true ); 34 | ERRTNavigate2Point ( lw , Vec2 ( -side*4300 , 500 ), false, 80, &VELOCITY_PROFILE_AROOM ); 35 | ERRTSetObstacles ( rw , true , true , true , true ); 36 | ERRTNavigate2Point ( rw , Vec2 ( -side*4300 , -500 ), false, 80, &VELOCITY_PROFILE_AROOM ); 37 | ERRTSetObstacles ( def , true , true , true , true ); 38 | ERRTNavigate2Point ( def , Vec2 ( -side*4300 , 800 ), false, 80, &VELOCITY_PROFILE_AROOM ); 39 | ERRTSetObstacles ( dmf , true , true , true , true ); 40 | ERRTNavigate2Point ( dmf , Vec2 ( -side*4300 , -800 ), false, 80, &VELOCITY_PROFILE_AROOM ); 41 | ERRTSetObstacles ( mid1 , true , true , true , true ); 42 | ERRTNavigate2Point ( mid1, Vec2 ( -side*4300 , -1500 ), false, 80, &VELOCITY_PROFILE_AROOM ); 43 | ERRTSetObstacles ( mid2 , true , true , true , true ); 44 | ERRTNavigate2Point ( mid2, Vec2 ( -side*4300 , 1500 ), false, 80, &VELOCITY_PROFILE_AROOM ); 45 | ERRTSetObstacles ( attack , true , true , true , true ); 46 | ERRTNavigate2Point ( attack , Vec2 ( -side*4300 , 0 ), false, 80, &VELOCITY_PROFILE_AROOM ); 47 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/stop_def.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::Stop_def ( void ) 4 | { 5 | for (std::map::const_iterator i = markMap.begin(); i != markMap.end(); ++i) { 6 | markMap[i->first] = -1; 7 | } 8 | 9 | if (OwnRobot[attack].State.OutForSubsitute) 10 | { 11 | if (!OwnRobot[mid1].State.OutForSubsitute) 12 | { 13 | std::swap(attack, mid1); 14 | } 15 | else if (!OwnRobot[mid2].State.OutForSubsitute) 16 | { 17 | std::swap(attack, mid2); 18 | } 19 | } 20 | if ( OwnRobot[mid1].State.Position.Y < OwnRobot[mid2].State.Position.Y ) 21 | { 22 | std::swap(mid1, mid2); 23 | } 24 | 25 | GKHi( gk , true ); 26 | //DefHi(def,NULL, true); 27 | DefMid(def, rw, lw, NULL, true); 28 | 29 | std::map static_pos; 30 | static_pos[dmf] = Vec2(side*4500, -sgn(ball.Position.Y)*3000); 31 | static_pos[mid1] = Vec2(side*4200, 1000); 32 | static_pos[mid2] = Vec2(side*4200, -1000); 33 | 34 | ERRTSetObstacles ( dmf , true , true , true , true ); 35 | OwnRobot[dmf].face(ball.Position); 36 | ERRTNavigate2Point ( dmf , static_pos[dmf] ,0 , 40,&VELOCITY_PROFILE_AROOM); 37 | 38 | ERRTSetObstacles ( mid1 , true , true , true , true ); 39 | OwnRobot[mid1].face(Vec2(ball.Position.X,ball.Position.Y)); 40 | ERRTNavigate2Point ( mid1 , static_pos[mid1] ,0 , 40,&VELOCITY_PROFILE_AROOM); 41 | 42 | ERRTSetObstacles ( mid2 , true , true , true , true ); 43 | OwnRobot[mid2].face(Vec2(ball.Position.X,ball.Position.Y)); 44 | ERRTNavigate2Point ( mid2 , static_pos[mid2] ,0 , 40,&VELOCITY_PROFILE_AROOM); 45 | 46 | ERRTSetObstacles ( attack , true , true , true , true ); 47 | OwnRobot[attack].face(Vec2(ball.Position.X,ball.Position.Y)); 48 | ERRTNavigate2Point ( attack , CircleAroundPoint(Vec2(ball.Position.X,ball.Position.Y),NormalizeAngle(AngleWith(ball.Position , Vec2(side*field_width,0))),580) ,0 , 40,&VELOCITY_PROFILE_AROOM); 49 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/tech_cmu.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | int state = 0; 4 | int tside = 1; 5 | 6 | void ai09::tech_cmu ( void ) 7 | { 8 | if ( state == 0 ) 9 | { 10 | state = 1; 11 | 12 | for ( int i = 0 ; i < 6 ; i ++ ) 13 | { 14 | if ( dis ( OwnRobot[i].State.Position.X , OwnRobot[i].State.Position.Y , 1200.0f - 250.0f * i , tside*1200.0f ) > 20 ) 15 | state = 0; 16 | } 17 | } 18 | else if ( state >= 7 ) 19 | { 20 | tside = -tside; 21 | state = 0; 22 | } 23 | else 24 | { 25 | if ( dis ( OwnRobot[state-1].State.Position.X , OwnRobot[state-1].State.Position.Y , 1200.0f - ( state - 1 ) * 250.0f , tside*1450.0f ) < 20 ) 26 | state ++; 27 | } 28 | 29 | for ( int i = state ; i < 6 ; i ++ ) 30 | { 31 | ERRTSetObstacles ( i , true , false , true , true ); 32 | OwnRobot[i].target.Angle = tside*90.0f; 33 | //OwnRobot[i].face(ball.Position); 34 | //OwnRobot[i].target.Angle += 180.0f; 35 | 36 | ERRTNavigate2Point ( i , Vec2 ( 1200.0f - i * 250.0f , tside*1200.0f ) , 0 , 100 ); 37 | } 38 | for ( int i = 0 ; i < min(6,state) ; i ++ ) 39 | { 40 | ERRTSetObstacles ( i , true , false , true , true ); 41 | OwnRobot[i].target.Angle = -tside*60.0f; 42 | ERRTNavigate2Point ( i , Vec2 ( 1200.0f - i * 250.0f , tside*1450.0f ) , 0 , 100 ); 43 | } 44 | //std::cout< time_needed) { 33 | t -= 1; 34 | } 35 | else if (t < time_needed) { 36 | t += 1; 37 | } 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/tech_motion_ann.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::tech_motion_ann ( void ) 4 | { 5 | const float v_max = 3000.0f; 6 | static float vmag; 7 | static float vdir; 8 | static Timer ann_timer; 9 | if (timer.time()<1.0) { 10 | vmag = v_max/10.0f; 11 | vdir = 0.0f; 12 | ann_timer.start(); 13 | return; 14 | } 15 | 16 | OwnRobot[attack].target.Angle = 90.0f; 17 | 18 | if (ann_timer.time()<2.0) { 19 | ERRTSetObstacles(attack, 0, 1, 1, 1); 20 | ERRTNavigate2Point(attack, Vec2(1500, 0), 1, 100, &VELOCITY_PROFILE_AROOM); 21 | } 22 | else { 23 | TVec2 robo_d = OwnRobot[attack].State.Position - Vec2(1500, 0); 24 | if ((fabs(robo_d.X)>1300)||(fabs(robo_d.Y)>1800)) { 25 | vdir += 40.0f; 26 | if (vdir>=360) { 27 | vdir = 0.0f; 28 | vmag += v_max/10.0f; 29 | } 30 | ann_timer.start(); 31 | } 32 | else { 33 | float vmag_conv = vmag / 42.5; 34 | extern TVec2 vdes_ann; 35 | vdes_ann = Vec2(vmag_conv*cosDeg(vdir), vmag_conv*sinDeg(vdir)); 36 | Navigate2Point(attack, Vec2(0, 0), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 37 | } 38 | 39 | } 40 | 41 | 42 | /*for (float vmag = v_max/10.0f ; vmag < v_max ; vmag += v_max/10.0f ) { 43 | for (float vdir = 0; vdir < 360 ; vdir += 10) { 44 | float vmag_conv = vmag / 42.5; 45 | extern TVec2 vdes_ann; 46 | vdes_ann = Vec2(vmag_conv*cosDeg(vdir), vmag_conv*sinDeg(vdir)); 47 | 48 | Timer ann_timer; 49 | ann_timer.start(); 50 | if (ann_timer.time()<2.0) { 51 | ERRTSetObstacles(attack, 0, 1, 1, 1, 0, 0); 52 | ERRTNavigate2Point(attack, Vec2(1500, 0), 1, 100, &VELOCITY_PROFILE_MAMOOLI); 53 | } 54 | else { 55 | TVec2 robo_d = OwnRobot[attack].State.Position - Vec2(1500, 0); 56 | if ((fabs(robo_d.X)>1300)||(fabs(robo_d.Y)>1800)) { 57 | continue; 58 | } 59 | Navigate2Point(attack, Vec2(0, 0), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 60 | } 61 | 62 | } 63 | }*/ 64 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/throwin_chip_shoot.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::throwin_chip_shoot ( void ) 4 | { 5 | //swap ( mid2 , attack ); 6 | //swap(attack, gk); 7 | 8 | GKHi(gk); 9 | DefMid(def, rw, lw, NULL, false); 10 | 11 | /*ERRTSetObstacles ( mid2 , true , true , true , true ); 12 | OwnRobot[mid2].face(ball.Position); 13 | ERRTNavigate2Point ( mid2 , Vec2(side*500, -sgn(ball.Position.Y)*1500) ,0 , 70,&VELOCITY_PROFILE_MAMOOLI); 14 | 15 | ERRTSetObstacles ( mid1 , true , true , true , true ); 16 | OwnRobot[mid1].face(ball.Position); 17 | ERRTNavigate2Point ( mid1 , Vec2(-side*500, -sgn(ball.Position.Y)*1800) ,0 , 70,&VELOCITY_PROFILE_MAMOOLI);*/ 18 | 19 | ERRTSetObstacles ( mid2 , true , true , true , true ); 20 | OwnRobot[mid2].face(ball.Position); 21 | ERRTNavigate2Point ( mid2 , Vec2(-side*1500, sgn(ball.Position.Y)*2500.0f) ,0 , 70,&VELOCITY_PROFILE_MAMOOLI); 22 | oneTouchType[mid2] = shirje; 23 | 24 | ERRTSetObstacles ( mid1 , true , true , true , true ); 25 | OwnRobot[mid1].face(ball.Position); 26 | ERRTNavigate2Point ( mid1 , Vec2(-side*3500, sgn(ball.Position.Y)*2500.0f) ,0 , 70,&VELOCITY_PROFILE_MAMOOLI); 27 | oneTouchType[mid1] = shirje; 28 | 29 | 30 | 31 | if (timer.time()>4 ) { 32 | //tech_circle(dmf,AngleWith ( Vec2 ( -side*2995 , 0 ) , ball.Position ) ,0,30,0,1); 33 | circle_ball(dmf, AngleWith ( Vec2 ( -side*field_width , sgn(ball.Position.Y)*200.0f ) , ball.Position ), 0, 20, 1.0f); 34 | } 35 | else 36 | { 37 | //tech_circle(dmf,AngleWith ( Vec2 ( -side*2995 , 0 ) , ball.Position ) ,0,0,0,1); 38 | circle_ball(dmf, AngleWith ( Vec2 ( -side*field_width , 0 ) , ball.Position ), 0, 0, 1.0f); 39 | } 40 | 41 | OwnRobot[attack].face ( Vec2 ( -side*field_width , 0 ) ); 42 | ERRTSetObstacles ( attack , 0,1,1,1 );//TODO the Obstacle avoidance for Opp was disabled (just added it) 43 | AddCircle(ball.Position.X, ball.Position.Y, 320); 44 | if ( randomParam < 0.0 ) 45 | ERRTNavigate2Point ( attack , PointOnConnectingLine ( ball.Position , Vec2 ( -side*field_width , 0 ) , 350+700*reached ) ); 46 | else if ( randomParam < 0.5 ) 47 | ERRTNavigate2Point ( attack , PointOnConnectingLine ( ball.Position , Vec2 ( -side*field_width , -sgn(ball.Position.X)*2000 ) , 350+700*reached ) ); 48 | else 49 | ERRTNavigate2Point ( attack , PointOnConnectingLine ( ball.Position , Vec2 ( -side*field_width , sgn(ball.Position.X)*2000 ) , 350+700*reached ) ); 50 | 51 | //swap(attack, gk); 52 | //swap ( mid2 , attack ); 53 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/throwin_their_khafan.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::throwin_their_khafan ( void ) 4 | { 5 | GK(gk, 1); 6 | OneDef(def); 7 | DefenceWall(attack); 8 | 9 | Halt(lmf); 10 | 11 | int attackerDoor , attackerNazdik; 12 | attackerNazdik = findCruncherOpp(-1); 13 | attackerDoor = findCruncherOpp(attackerNazdik); 14 | 15 | if ( ( attackerDoor == -1 ) || ( attackerNazdik == -1 ) ) 16 | corner_their_def_ajor(); 17 | else 18 | { 19 | GK(gk, 1); 20 | OneDef(def); 21 | DefenceWall(attack); 22 | 23 | OneDef(dmf, &OppRobot[attackerNazdik].Position); 24 | 25 | ERRTSetObstacles ( rmf , 1 ); 26 | ERRTNavigate2Point ( rmf , PointOnConnectingLine ( OppRobot[attackerDoor].Position , Vec2 ( side*2995 , 0 ) , 520.0f ) ); 27 | } 28 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/throwin_tu_omgh.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::throwin_tu_omgh ( void ) 4 | { 5 | side=-side; 6 | GK ( gk , 2 ); 7 | TwoDef ( def , dmf ); 8 | Halt(lmf); 9 | side=-side; 10 | 11 | if ( ( ( DIS ( ball.Position , OwnRobot[attack].State.Position ) < 250 ) && ( OwnRobot[attack].State.velocity.magnitude < 100 ) )|| ( reached ) ) 12 | { 13 | float waitTime = 1.5; 14 | if ( ball.Position.X * side > -2000 ) 15 | waitTime = 1.5; 16 | if ( timer.time() < waitTime ) 17 | { 18 | ERRTSetObstacles ( attack ); 19 | tech_circle(attack,90-side*90 ,0,0,0,1,0,0); 20 | 21 | } 22 | else 23 | { 24 | ERRTSetObstacles ( attack ); 25 | tech_circle(attack,AngleWith ( Vec2 ( -side*2000 , -sgn ( ball.Position.Y ) * 1600 ) , ball.Position ) ,5,0,0,1,0,0); 26 | } 27 | reached = true; 28 | } 29 | else 30 | { 31 | ERRTSetObstacles ( attack ); 32 | tech_circle(attack,90-side*90 ,0,0,0,1,0,0); 33 | } 34 | 35 | if ( oneTouchDetector[rmf].IsArriving(70) ) 36 | { 37 | WaitForOmghi ( rmf ); 38 | } 39 | else 40 | { 41 | OwnRobot[rmf].face ( Vec2 ( -side*2995 , 0 ) ); 42 | ERRTSetObstacles ( rmf ); 43 | if ( timer.time() < 0.0 ) 44 | { 45 | ERRTNavigate2Point ( rmf , Vec2 ( -side*2300 , -sgn(ball.Position.Y )* 1000 ) ); 46 | } 47 | else { 48 | ERRTNavigate2Point ( rmf , Vec2 ( -side*200 , -sgn(ball.Position.Y )* 1600 ) ); 49 | } 50 | 51 | } 52 | 53 | //OwnRobot[def2].face ( Vec2 ( -side*2995 , 0 ) ); 54 | //Navigate2Point ( def2 , Vec2 ( -side*1500 , 0 ) ); 55 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/plays/throwin_us_outgir.cpp: -------------------------------------------------------------------------------- 1 | #include "../ai09.h" 2 | 3 | void ai09::throwin_us_outgir ( void ) 4 | { 5 | GKHi(gk, 0); 6 | DefHi(def,NULL, 0); 7 | 8 | ERRTSetObstacles(dmf, 1, 1, 1, 1); 9 | ERRTNavigate2Point(dmf, PointOnConnectingLine(ball.Position, Vec2(side*field_width, 0), 2000), 0, 100, &VELOCITY_PROFILE_MAMOOLI); 10 | 11 | if ( timer.time() < 2.0 ) 12 | { 13 | float passAngle = 90-side*90; 14 | circle_ball(attack, passAngle, 0, 0, 1.0f); 15 | } 16 | else if ( timer.time() < 4.0 ) 17 | { 18 | float passAngle = sgn(ball.Position.Y) * 90.0f; 19 | circle_ball(attack, passAngle, 0, 0, 1.0f); 20 | } 21 | 22 | else if ( timer.time() < 5.0 ) 23 | { 24 | float passAngle = AngleWith(Vec2(-side*field_width,0),ball.Position); 25 | PenaltyUs(attack, passAngle, 0 ); 26 | } 27 | 28 | /*else if ( timer.time() < 5.2 ) 29 | { 30 | float passAngle = AngleWith(Vec2(-side*field_width,0),ball.Position); 31 | PenaltyUs(attack, passAngle, 1 ); 32 | 33 | }*/ 34 | else //if ( timer.time() < 5.3 ) 35 | { 36 | float passAngle = 90-side*90; 37 | //circle_ball(attack, passAngle, 100, 0, 1.0f); 38 | //tech_circle ( attack , passAngle , 100 , 0 , false , false , false , true , false); 39 | PenaltyUs(attack, passAngle, 100 ); 40 | 41 | } 42 | 43 | if ( timer.time() < 1.0 ) 44 | { 45 | Halt(lmf); 46 | Halt(rmf); 47 | } 48 | else 49 | { 50 | ERRTSetObstacles ( lmf , true , true , true, true); 51 | ERRTNavigate2Point ( lmf , Vec2(-side*(field_width-800),-sgn(ball.Position.Y)*1800) , true , 100 , &VELOCITY_PROFILE_MAMOOLI ); 52 | 53 | ERRTSetObstacles ( rmf , true , true , true, true); 54 | ERRTNavigate2Point ( rmf , Vec2(-side*100,-sgn(ball.Position.Y)*1000) , true , 100 , &VELOCITY_PROFILE_MAMOOLI ); 55 | } 56 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/strategyWeight.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ai09.h" 3 | 4 | int ai09::strategy_weight ( void ) 5 | { 6 | if (!playBook) { 7 | std::cout<<"strategy_weight__+: 444"<strategy_size() == 0) { 12 | std::cout<<"strategy_weight__+: 555"< good_strs; 18 | 19 | float sigma_w = 0; 20 | 21 | std::cout << " strategy: " ; 22 | for (int i = 0; i < playBook->strategy_size(); i++) { 23 | if ( 24 | (side*ball.Position.X>playBook->strategy(i).minx()) && 25 | (side*ball.Position.Xstrategy(i).maxx()) && 26 | (fabs(ball.Position.Y)>playBook->strategy(i).miny()) && 27 | (fabs(ball.Position.Y)strategy(i).maxy()) && 28 | (playBook->weight(i)>0) 29 | ) 30 | { 31 | std::cout << i << "|" << playBook->weight(i) << " "; 32 | good_strs[i] = sigma_w + playBook->weight(i); 33 | sigma_w += playBook->weight(i); 34 | } 35 | 36 | } 37 | std::cout << std::endl; 38 | 39 | if (sigma_w == 0) { 40 | return -1; 41 | } 42 | 43 | 44 | int ans_str = -1; 45 | for (std::map::const_iterator it = good_strs.begin(); it!=good_strs.end(); ++it) { 46 | if (randomParam*sigma_w <= it->second) { 47 | ans_str = it->first; 48 | break; 49 | } 50 | } 51 | 52 | return ans_str; 53 | 54 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by dot_blue on 5/9/18. 3 | // 4 | 5 | #include "ai09.h" 6 | 7 | 8 | void ai09::my_test() { 9 | static Timer time_dis; 10 | static bool first_call=true; 11 | if(first_call) { 12 | time_dis.start(); 13 | first_call = false; 14 | } 15 | VelocityProfile VELOCITY_PROFILE_TEST; 16 | // VELOCITY_PROFILE_TEST.max_spd = Vec2 ( 3000.0f ); 17 | // VELOCITY_PROFILE_TEST.max_dec = Vec2 ( 2f ); 18 | // VELOCITY_PROFILE_TEST.max_acc = Vec2 ( 1500.0f ); 19 | // VELOCITY_PROFILE_TEST.max_w_acc = 40.0f; 20 | // VELOCITY_PROFILE_TEST.max_w_dec = 140.0f; 21 | VELOCITY_PROFILE_TEST = VELOCITY_PROFILE_KHARAKI; 22 | VELOCITY_PROFILE_TEST.max_spd = Vec2 ( 150.0f ); 23 | VELOCITY_PROFILE_TEST.max_dec = Vec2 ( 1.5f );//1.8 24 | VELOCITY_PROFILE_TEST.max_acc = Vec2 ( 1.5f );//2.3 25 | 26 | if(time_dis.time()<6.0){ 27 | OwnRobot[cmf].target.Angle = 90; 28 | // Navigate2Point_2018(cmf,Vec2(-2000,-2000)); 29 | // ERRTNavigate2Point(cmf,Vec2(-2000,-1500),0,80); 30 | Navigate2Point(cmf,Vec2(-1000,700),0,30,&VELOCITY_PROFILE_TEST,false); 31 | 32 | //std::cout<<"first part"<BLUE_pushData(OwnRobot[cmf].State.velocity.x); 60 | 61 | // integral_PosFilterX += OwnRobot[cmf].State.velocity.x*0.9*worldState->delta_t_capture; 62 | plot->GREEN_pushData(OwnRobot[cmf].target.velocity.x * 48); 63 | 64 | std::cout<<"ALPHA-> "<<(OwnRobot[cmf].State.velocity.x/OwnRobot[cmf].target.velocity.x)<delta_t_capture<send_data(); 73 | 74 | 75 | 76 | 77 | 78 | } -------------------------------------------------------------------------------- /Source/Soccer/ai09/trapezoid.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../Common/Vector.h" 4 | #include "../../Reality/WorldState.h" 5 | 6 | class TrapezoidPlanner 7 | { 8 | private: 9 | TVec2 max_acc; 10 | TVec2 max_dec; 11 | TVec2 max_spd; 12 | 13 | float period; 14 | 15 | RobotState * init_state; 16 | RobotState * final_state; 17 | 18 | TVec3 oldAns; 19 | 20 | float Plan1D ( float d , float v , float tmp_max_spd , float tmp_max_acc , float tmp_max_dec ); 21 | 22 | public: 23 | TrapezoidPlanner ( ); 24 | TrapezoidPlanner ( TVec2 _max_acc , TVec2 _max_dec , TVec2 _max_spd , float _period ); 25 | 26 | void init ( TVec2 _max_acc , TVec2 _max_dec , TVec2 _max_spd , float _period ); 27 | 28 | TVec3 Plan ( RobotState * _init , RobotState * _final ); 29 | }; -------------------------------------------------------------------------------- /Source/Soccer/aiBase.cpp: -------------------------------------------------------------------------------- 1 | #include "aiBase.h" 2 | 3 | void aiBase::AddDebugPoint ( const TVec2& p , const CommonColor _color ) 4 | { 5 | debug().drawPoint(p); 6 | } 7 | 8 | void aiBase::AddDebugLine ( const TVec2& p1 , const TVec2& p2 , const CommonColor _color ) 9 | { 10 | debug().drawLineSegment(p1, p2); 11 | } 12 | 13 | void aiBase::AddDebugRect ( const TVec2& p , const float w , const float h , const CommonColor _color ) 14 | { 15 | debug().drawRect(p, w, h); 16 | } 17 | 18 | void aiBase::AddDebugCircle ( const TVec2& p , const float r , const CommonColor _color ) 19 | { 20 | debug().drawCircle(p, r); 21 | } -------------------------------------------------------------------------------- /Source/Soccer/aiBase.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../Common/Vector.h" 4 | #include "../Common/common_colors.h" 5 | #include "../Reality/WorldState.h" 6 | #include "../Common/GameSetting.h" 7 | #include "../Reality/Plotter/plotter.h" 8 | 9 | class aiBase 10 | { 11 | protected: 12 | bool debugDraw; 13 | void AddDebugPoint ( const TVec2& p , const CommonColor _color = White ); 14 | void AddDebugLine ( const TVec2& p1 , const TVec2& p2 , const CommonColor _color = White ); 15 | void AddDebugRect ( const TVec2& p , const float w , const float h , const CommonColor _color = White ); 16 | void AddDebugCircle ( const TVec2& p , const float r , const CommonColor _color = White ); 17 | 18 | // void addPointToFunc1(const float&) 19 | 20 | public: 21 | virtual void Process ( WorldState * worldState , GameSetting * setting ) = 0; 22 | plotter *plot; 23 | 24 | 25 | aiBase() { 26 | plot = new plotter("127.0.0.1", 10067); 27 | } 28 | ~aiBase(){ 29 | delete plot; 30 | } 31 | }; -------------------------------------------------------------------------------- /Source/grsim_fwd.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 16.06.18. 3 | // 4 | 5 | #include "grsim_fwd.h" 6 | 7 | #include "Network/Protobuf/grSim_Packet.pb.h" 8 | 9 | GrsimForwarder::GrsimForwarder(const char *const ip, const short port) : 10 | ip(ip), port(port) 11 | { 12 | socket = new UDPSocket; 13 | } 14 | 15 | void GrsimForwarder::SendData(const Robot *const robots, const int robot_count, bool color) 16 | { 17 | grSim_Packet packet; 18 | packet.mutable_commands()->set_isteamyellow(color); 19 | packet.mutable_commands()->set_timestamp(0.0); 20 | 21 | for (int robot_idx = 0; robot_idx < robot_count; ++robot_idx) 22 | { 23 | const Robot *const robot = robots + robot_idx; 24 | 25 | grSim_Robot_Command* command = packet.mutable_commands()->add_robot_commands(); 26 | command->set_id(robot->vision_id); 27 | 28 | command->set_wheelsspeed(false); 29 | /*command->set_wheel1(edtV1->text().toDouble()); 30 | command->set_wheel2(edtV2->text().toDouble()); 31 | command->set_wheel3(edtV3->text().toDouble()); 32 | command->set_wheel4(edtV4->text().toDouble());*/ 33 | 34 | const int cmd_idx = robots[robot_idx].lastCMDs[10].X; 35 | const TVec3 motion = robots[robot_idx].lastCMDs[cmd_idx]; 36 | float robot_ang = (90-robot->State.Angle) * 3.1415/180.0; 37 | float new_VelX = motion.X * cos(robot_ang) - motion.Y * sin(robot_ang); 38 | float new_VelY = motion.X * sin(robot_ang) + motion.Y * cos(robot_ang); 39 | 40 | 41 | command->set_veltangent(new_VelY / 20.0); 42 | command->set_velnormal(-new_VelX / 20.0); 43 | 44 | float w = robot->target.Angle - robot->State.Angle; 45 | while (w > 180) 46 | { 47 | w -= 360; 48 | } 49 | while (w < -180) 50 | { 51 | w += 360; 52 | } 53 | w /= 10.0f; 54 | 55 | command->set_velangular(w); 56 | //command->set_velangular(0); 57 | 58 | if (robot->shoot > 0) 59 | { 60 | command->set_kickspeedx(robot->shoot/10.f); 61 | command->set_kickspeedz(0); 62 | } 63 | else if (robot->chip > 0) 64 | { 65 | float chip = 0.f;//robot->chip / 25.0f; 66 | command->set_kickspeedx(chip * 0.707f); 67 | command->set_kickspeedz(chip / 0.707f); 68 | } 69 | else 70 | { 71 | command->set_kickspeedx(.0f); 72 | command->set_kickspeedz(.0f); 73 | } 74 | 75 | command->set_spinner(robot->dribbler); 76 | 77 | const size_t dgram_len = packet.ByteSize(); 78 | char *const dgram = new char[dgram_len]; 79 | packet.SerializeToArray(dgram, dgram_len); 80 | socket->sendTo(dgram, dgram_len, ip, port); 81 | delete[] dgram; 82 | } 83 | } 84 | 85 | GrsimForwarder::~GrsimForwarder() 86 | { 87 | delete socket; 88 | } 89 | -------------------------------------------------------------------------------- /Source/grsim_fwd.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by Ali Salehi on 16.06.18. 3 | // 4 | 5 | #ifndef IMMORTALSSSL_GRSIM_FWD_H 6 | #define IMMORTALSSSL_GRSIM_FWD_H 7 | 8 | #include "Soccer/ai09/Robot.h" 9 | #include "Network/PracticalSocket.h" 10 | #include 11 | 12 | class GrsimForwarder 13 | { 14 | private: 15 | UDPSocket *socket; 16 | std::string ip; 17 | short port; 18 | 19 | public: 20 | GrsimForwarder(const char *const ip, const short port); 21 | ~GrsimForwarder(); 22 | void SendData(const Robot *const robots, const int robot_count, bool color); 23 | }; 24 | 25 | #endif //IMMORTALSSSL_GRSIM_FWD_H 26 | -------------------------------------------------------------------------------- /Source/pch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "Common/services.h" 27 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "immortals-ssl", 3 | "version-string": "2023.0.0", 4 | "dependencies": [ 5 | "asio", 6 | "protobuf", 7 | "tomlplusplus", 8 | "quill" 9 | ] 10 | } --------------------------------------------------------------------------------