Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.49 KB | None | 0 0
  1. /*
  2.  * "Debreceni Hivatásos FC++"
  3.  *
  4.  * lobogofcpp.h
  5.  *
  6.  * This agent, called "Debreceni Lobogó FC++", is a simple threaded version of
  7.  * rcssserver/client.cpp It is used in our Programming laboratory exercises
  8.  * at the University of Debrecen. For details, see the books "Bátfai
  9.  * Norbert: Programozó Páternoszter újratöltve: C, C++, Java, Python és
  10.  * AspectJ esettanulmányok"
  11.  * http://www.inf.unideb.hu/~nbatfai/konyvek/PROP/prop.book.xml.pdf
  12.  * and "Bátfai Norbert: Mesterséges intelligencia a gyakorlatban: bevezetés
  13.  * a  robotfoci programozásba"
  14.  * http://www.inf.unideb.hu/~nbatfai/konyvek/MIRC/mirc.book.xml.pdf
  15.  *
  16.  * Norbert Bátfai, PhD
  17.  * batfai.norbert@inf.unideb.hu, nbatfai@gmail.com
  18.  * IT Dept, University of Debrecen
  19.  *
  20.  * Version history, see book PARP and POPR http://www.inf.unideb.hu/~nbatfai/konyvek/PROP/prop.book.xml.pdf
  21.  *
  22.  * May.04.2012, "A Bolyongó FC++", bolyongofcpp.h
  23.  * May.11.2012, "Debreceni Lobogó FC++": this version knows the flags.
  24.  * May.12.2012, "Debreceni Egyetértés FC++"
  25.  * May.13.2012, "Debreceni Hivatásos FC++"
  26.  * Aug.13.2012, "Debrecen Great Forest FC++"
  27.  * Aug.18.2012, "Debrecen Deep Forest FC++"
  28.  * Aug.23.2012, "Debrecen Round Forest FC++"
  29.  *
  30.  */
  31.  
  32. /*
  33.  * This program is free software: you can redistribute it and/or modify
  34.  * it under the terms of the GNU General Public License as published by
  35.  * the Free Software Foundation, either version 3 of the License, or
  36.  * (at your option) any later version.
  37.  *
  38.  * This program is distributed in the hope that it will be useful,
  39.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  41.  * GNU General Public License for more details.
  42.  *
  43.  * http://www.gnu.org/licenses/gpl.html
  44.  */
  45.  
  46. /*
  47.  * References
  48.  * Felhasznált és ajánlott irodalom:
  49.  *
  50.  * Don Blaheta: Project 2: Lexer
  51.  * http://torvalds.cs.longwood.edu/courses/cmsc445/s12/proj2.pdf
  52.  *
  53.  * John R. Levine: flex & bison, O’Reilly, 2009
  54.  *
  55.  * Lexical Analysis With Flex
  56.  * http://flex.sourceforge.net/manual
  57.  *
  58.  * Bison - GNU parser generator
  59.  * www.gnu.org/software/bison/manual/
  60.  * A Complete C++ Example
  61.  * http://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html#A-Complete-C_002b_002b-Example
  62.  * http://www.gnu.org/software/bison/manual/html_node/C_002b_002b-Parsers.html#C_002b_002b-Parsers
  63.  */
  64.  
  65. #ifndef LOBOGOFCPP_H
  66. #define LOBOGOFCPP_H
  67.  
  68. #ifndef __FLEX_LEXER_H
  69. #include <FlexLexer.h>
  70. #endif
  71.  
  72. #include <iostream>
  73. #include <sstream>
  74. #include <cstring>
  75. #include <cmath>
  76.  
  77. enum RefereePlayMode {
  78.     before_kick_off,
  79.     play_on,
  80.     half_time,
  81.     drop_ball,
  82.     kick_off_r,
  83.     kick_off_l,
  84.     corner_kick_r,
  85.     corner_kick_l,
  86.     free_kick_l,
  87.     free_kick_r,
  88.     kick_in_l,
  89.     kick_in_r,
  90.     goal_l,
  91.     goal_r,
  92.     free_kick_fault_l,
  93.     free_kick_fault_r,
  94.     offside_l,
  95.     offside_r
  96. };
  97.  
  98. class Formations
  99. {
  100. public:
  101.  
  102.     static int const F_4_3_3_H = 0;
  103.     static int const F_4_3_3_F = 1;
  104.     static int const F_4_4_2_H = 2;
  105.     static int const F_4_4_2_F = 3;
  106.  
  107.     static int const Chelsea_H = 4;
  108.     static int const Chelsea_F = 5;
  109.  
  110.     static int const Penta1 = 6;
  111.     static int const Penta2 = 7;
  112.  
  113.     static int const F_CORNER_ATT = 8;
  114.     static int const F_CORNER_DEF = 9;
  115.  
  116.     // number of all formations
  117.     static int const NOF = F_CORNER_DEF+1;
  118.  
  119. };
  120.  
  121. class Formation
  122. {
  123. public:
  124.     Formation(int p0x, int p0y,
  125.               int p1x, int p1y,
  126.               int p2x, int p2y,
  127.               int p3x, int p3y,
  128.               int p4x, int p4y,
  129.               int p5x, int p5y,
  130.               int p6x, int p6y,
  131.               int p7x, int p7y,
  132.               int p8x, int p8y,
  133.               int p9x, int p9y,
  134.               int p10x, int p10y)
  135.     {
  136.         formation[0][0] = p0x;
  137.         formation[0][1] = p0y;
  138.  
  139.         formation[1][0] = p1x;
  140.         formation[1][1] = p1y;
  141.  
  142.         formation[2][0] = p2x;
  143.         formation[2][1] = p2y;
  144.  
  145.         formation[3][0] = p3x;
  146.         formation[3][1] = p3y;
  147.  
  148.         formation[4][0] = p4x;
  149.         formation[4][1] = p4y;
  150.  
  151.         formation[5][0] = p5x;
  152.         formation[5][1] = p5y;
  153.  
  154.         formation[6][0] = p6x;
  155.         formation[6][1] = p6y;
  156.  
  157.         formation[7][0] = p7x;
  158.         formation[7][1] = p7y;
  159.  
  160.         formation[8][0] = p8x;
  161.         formation[8][1] = p8y;
  162.  
  163.         formation[9][0] = p9x;
  164.         formation[9][1] = p9y;
  165.  
  166.         formation[10][0] = p10x;
  167.         formation[10][1] = p10y;
  168.  
  169.     };
  170.     friend std::ostream & operator<< (std::ostream & os, Formation & f)
  171.     {
  172.         for (int i=0; i<11; ++i)
  173.             os << "(" << f.formation[i][0] << ", " << f.formation[i][1] << ")" << std::endl;
  174.  
  175.         return os;
  176.     }
  177.     int get_formation_x(int squad_number, char lr) const
  178.     {
  179.         return (lr=='l') ? formation[squad_number][0] : -formation[squad_number][0];
  180.     }
  181.     int get_formation_y(int squad_number) const
  182.     {
  183.         return formation[squad_number][1];
  184.     }
  185.  
  186. private:
  187.     int formation[11][2];
  188. };
  189.  
  190.  
  191. class Flag
  192. {
  193. public:
  194.  
  195.     // See the figure entitled "Figure 4.2: The fags and lines in the simulation."
  196.     // in the RCSS manual, version "February 11, 2003" pp. 47. at http://sourceforge.net/projects/sserver/files/rcssmanual/9-20030211/
  197.     static int const FCB = 0;
  198.     static int const FC = 1;
  199.     static int const FCT = 2;
  200.  
  201.     static int const GRB = 3;
  202.     static int const GR = 4;
  203.     static int const GRT = 5;
  204.  
  205.     static int const GLB = 6;
  206.     static int const GL = 7;
  207.     static int const GLT = 8;
  208.  
  209.     static int const PRB = 9;
  210.     static int const PR = 10;
  211.     static int const PRT = 11;
  212.  
  213.     static int const PLB = 12;
  214.     static int const PL = 13;
  215.     static int const PLT = 14;
  216.  
  217.     static int const RB = 15;
  218.     static int const RT = 16;
  219.  
  220.     static int const LB = 17;
  221.     static int const LT = 18;
  222.  
  223.     static int const FRB30 = 19;
  224.     static int const FRB20 = 20;
  225.     static int const FRB10 = 21;
  226.     static int const FR0 = 22;
  227.     static int const FRT10 = 23;
  228.     static int const FRT20 = 24;
  229.     static int const FRT30 = 25;
  230.  
  231.     static int const FLB30 = 26;
  232.     static int const FLB20 = 27;
  233.     static int const FLB10 = 28;
  234.     static int const FL0 = 29;
  235.     static int const FLT10 = 30;
  236.     static int const FLT20 = 31;
  237.     static int const FLT30 = 32;
  238.  
  239.     static int const FTR50 = 33;
  240.     static int const FTR40 = 34;
  241.     static int const FTR30 = 35;
  242.     static int const FTR20 = 36;
  243.     static int const FTR10 = 37;
  244.     static int const FT0 = 38;
  245.     static int const FTL10 = 39;
  246.     static int const FTL20 = 40;
  247.     static int const FTL30 = 41;
  248.     static int const FTL40 = 42;
  249.     static int const FTL50 = 43;
  250.  
  251.     static int const FBR50 = 44;
  252.     static int const FBR40 = 45;
  253.     static int const FBR30 = 46;
  254.     static int const FBR20 = 47;
  255.     static int const FBR10 = 48;
  256.     static int const FB0 = 49;
  257.     static int const FBL10 = 50;
  258.     static int const FBL20 = 51;
  259.     static int const FBL30 = 52;
  260.     static int const FBL40 = 53;
  261.     static int const FBL50 = 54;
  262.  
  263.     // number of all flags
  264.     static int const NOF = FBL50+1;
  265.  
  266. };
  267.  
  268. class SeenFlag
  269. {
  270. public:
  271.     SeenFlag(float x, float y):
  272.             x(x),
  273.             y(y),
  274.             time_stamp(-1000) // a long time ago
  275.     {};
  276.     friend std::ostream & operator<< (std::ostream & os, SeenFlag & sf)
  277.     {
  278.         os << "x: " << sf.x << std::endl;
  279.         os << "y: " << sf.y << std::endl;
  280.         os << "time_stamp: " << sf.time_stamp << std::endl;
  281.  
  282.         return os;
  283.     }
  284.     int get_time_stamp() const
  285.     {
  286.         return time_stamp;
  287.     }
  288.     void set_time_stamp(int time_stamp)
  289.     {
  290.         this->time_stamp = time_stamp;
  291.     }
  292.     void setDist(int time_stamp, float dist) {
  293.         this->time_stamp = time_stamp;
  294.         this->dist = dist;
  295.     }
  296.     void setAng(int time_stamp, float ang) {
  297.         this->time_stamp = time_stamp;
  298.         this->ang = ang;
  299.     }
  300.     void setDistAng(int time_stamp, float dist, float ang) {
  301.         this->time_stamp = time_stamp;
  302.         this->dist = dist;
  303.         this->ang= ang;
  304.     }
  305.  
  306.     void setDistAngForSelfAng(int time_stamp, int ex, int ey, float estn, float & esta, float dist, float ang) {
  307.         this->time_stamp = time_stamp;
  308.         this->dist = dist;
  309.         this->ang= ang;
  310.  
  311.         if (dist > 0.0 && dist < 30.0) {
  312.             /* még áganként kettébontani, hogy tg vagy ctg attól függően, hogy az irány alatt vagy felett van-e a zászló */
  313.             if (x <= ex && y <= ey) {
  314.                 esta = 90 + (std::atan((x-ex)/(y-ey))* (180.0 / 3.14159265359) - ang - estn);
  315.  
  316.                 //std::cout << "A**********" <<  " esta = " << esta << " ang = " << ang << " dist = " << dist << std::endl;
  317.  
  318.             } else if (x >= ex && y >= ey) {
  319.                 esta = std::atan((y-ey)/(x-ex))* (180.0 / 3.14159265359) - ang - estn;
  320.  
  321.                 //std::cout << "B**********" <<  " esta = " << esta << " ang = " << ang << " dist = " << dist << std::endl;
  322.             }
  323.             else if (x <= ex && y >= ey) {
  324.                 esta = 90 - std::atan((x-ex)/(y-ey))* (180.0 / 3.14159265359) - ang - estn;
  325.  
  326.                 //std::cout << "C**********" <<  " esta = " << esta << " ang = " << ang << " dist = " << dist << std::endl;
  327.  
  328.             } else if (x >= ex && y <= ey) {
  329.                 esta = std::atan((y-ey)/(x-ex))* (180.0 / 3.14159265359) - ang - estn;
  330.  
  331.                 //std::cout << "D**********" <<  " esta = " << esta << " ang = " << ang << " dist = " << dist << std::endl;
  332.             } else {
  333.                 std::cout << "ZAVAR AZ EROBEN" << std::endl;
  334.             }
  335.         }
  336.  
  337.     }
  338.     float getDist()  const {
  339.  
  340.         return dist;
  341.     }
  342.     float getAng()  const {
  343.  
  344.         return ang;
  345.     }
  346.     float getX()  const {
  347.  
  348.         return x;
  349.     }
  350.     float getY()  const {
  351.  
  352.         return y;
  353.     }
  354.  
  355. protected:
  356.     float x, y;
  357.     int time_stamp;
  358.     float dist, ang;
  359. };
  360.  
  361. class SeenBall : public SeenFlag
  362. {
  363. public:
  364.     SeenBall(float x = 0, float y = 0):SeenFlag(x, y)
  365.     {};
  366.     friend std::ostream & operator<< (std::ostream & os, SeenBall & sf)
  367.     {
  368.         os << "x: " << sf.x << std::endl;
  369.         os << "y: " << sf.y << std::endl;
  370.         os << "time_stamp: " << sf.time_stamp << std::endl;
  371.  
  372.         return os;
  373.     }
  374.     void setDistAngDistAng(int time_stamp, float dist, float ang, float edist, float eang) {
  375.         this->time_stamp = time_stamp;
  376.         this->dist = dist;
  377.         this->ang= ang;
  378.         this->edist = edist;
  379.         this->eang= eang;
  380.     }
  381. protected:
  382.     float edist, eang;
  383. };
  384.  
  385. class SeenPlayer
  386. {
  387. public:
  388.     SeenPlayer():
  389.             time_stamp(-1000) // a long time ago
  390.     {};
  391.     friend std::ostream & operator<< (std::ostream & os, SeenPlayer & sf)
  392.     {
  393.         os << "dist: " << sf.dist << std::endl;
  394.         os << "ang: " << sf.ang << std::endl;
  395.         os << "time_stamp: " << sf.time_stamp << std::endl;
  396.  
  397.         return os;
  398.     }
  399.     int get_time_stamp() const
  400.     {
  401.         return time_stamp;
  402.     }
  403.     void set_time_stamp(int time_stamp)
  404.     {
  405.         this->time_stamp = time_stamp;
  406.     }
  407.     void setDist(int time_stamp, float dist) {
  408.         this->time_stamp = time_stamp;
  409.         this->dist = dist;
  410.     }
  411.     void setAng(int time_stamp, float ang) {
  412.         this->time_stamp = time_stamp;
  413.         this->ang = ang;
  414.     }
  415.     void setDistAng(int time_stamp, float px, float py, float pang, float dist, float ang) {
  416.         this->time_stamp = time_stamp;
  417.         this->dist = dist;
  418.         this->ang= ang;
  419.         this->x = px + std::cos(pang - ang) * dist;
  420.         this->y = py + std::sin(pang - ang) * dist;
  421.     }
  422.     float getDist()  const {
  423.  
  424.         return dist;
  425.     }
  426.     float getAng()  const {
  427.  
  428.         return ang;
  429.     }
  430.     float getX()  const {
  431.  
  432.         return x;
  433.     }
  434.     float getY()  const {
  435.  
  436.         return y;
  437.     }
  438.     bool fwd(char lr, float fromx) const {
  439.         if (lr == 'l') {
  440.  
  441.             if (fromx < this->x)
  442.                 return true;
  443.             else
  444.                 return false;
  445.  
  446.         } else {
  447.  
  448.             if (fromx > this->x)
  449.                 return true;
  450.             else
  451.                 return false;
  452.  
  453.         }
  454.     }
  455.  
  456. private:
  457.     float x, y;
  458.     int time_stamp;
  459.     float dist, ang;
  460. };
  461.  
  462.  
  463. class LobogoLexer : public yyFlexLexer
  464. {
  465. public:
  466.     LobogoLexer(int time = 0, int squad_number=0, char lr = 'l'):
  467.             time(time),
  468.             squad_number(squad_number),
  469.             lr(lr)
  470.     {
  471.         own_team = new SeenPlayer[11];
  472.         other_team = new SeenPlayer[11];
  473.  
  474.         flags = new SeenFlag[Flag::NOF] {
  475.             // halfway line
  476.             // kozepvonal
  477.             // 0: "f c b" see the constants of the class Flag
  478.             {0.0, 34.0},
  479.             // 1: "f c"
  480.             {0.0, 0.0},
  481.             // 2: "f c t"
  482.             {0.0, -34.0},
  483.             // right (east) goal line
  484.             // keleti golvonal
  485.             {52.5, 7.0},
  486.             {52.5, 0.0},
  487.             {52.5, -7.0},
  488.             // left goal line
  489.             // nyugati golvonal
  490.             {-52.5, 7.0},
  491.             {-52.5, 0.0},
  492.             {-52.5, -7.0},
  493.             // right penalty area
  494.             // keleti bunteto
  495.             {36.0, 20.0},
  496.             {36.0, 0.0},
  497.             {36.0, -20.0},
  498.             // left penalty point
  499.             // nyugati bunteto
  500.             {-36.0, 20.0},
  501.             {-36.0, 0.0},
  502.             {-36.0, -20.0},
  503.             // right corner flagpost
  504.             // keleti szoglet
  505.             {52.5, 34.0},
  506.             {52.5, -34.0},
  507.             // east corner flagpost
  508.             // nyugati szoglet
  509.             {-52.5, 34.0},
  510.             {-52.5, -34.0},
  511.             // keleti alapv
  512.             {57.5, 30.0},
  513.             {57.5, 20.0},
  514.             {57.5, 10.0},
  515.             {57.5, 0.0},
  516.             {57.5, -10.0},
  517.             {57.5, -20.0},
  518.             {57.5, -30.0},
  519.             // nyugati alapv
  520.             {-57.5, 30.0},
  521.             {-57.5, 20.0},
  522.             {-57.5, 10.0},
  523.             {-57.5, 0.0},
  524.             {-57.5, -10.0},
  525.             {-57.5, -20.0},
  526.             {-57.5, -30.0},
  527.             // felso oldalv.
  528.             // (Ne felejtsem el, a Java-s verzióban a felső és alsó oldalvonal
  529.             // zászlóinak rosszak a koordinátái, csak az egyik oldalt adják
  530.             // mindig, itt javítva: a második ötös blokk elsője itt már negatív.)
  531.             {50.0, -39.0},
  532.             {40.0, -39.0},
  533.             {30.0, -39.0},
  534.             {20.0, -39.0},
  535.             {10.0, -39.0},
  536.             {0.0, -39.0},
  537.             {-10.0, -39.0},
  538.             {-20.0, -39.0},
  539.             {-30.0, -39.0},
  540.             {-40.0, -39.0},
  541.             {-50.0, -39.0},
  542.             // also oldalv.
  543.             {50.0, 39.0},
  544.             {40.0, 39.0},
  545.             {30.0, 39.0},
  546.             {20.0, 39.0},
  547.             {10.0, 39.0},
  548.             {0.0, 39.0},
  549.             {-10.0, 39.0},
  550.             {-20.0, 39.0},
  551.             {-30.0, 39.0},
  552.             {-40.0, 39.0},
  553.             {-50.0, 39.0}
  554.         };
  555.  
  556.     };
  557.  
  558.     int nof_kickin_quantums;
  559.     int nof_possessing_quantums;
  560.  
  561.     ~LobogoLexer() {
  562.  
  563.         delete[] flags;
  564.         delete[] own_team;
  565.         delete[] other_team;
  566.     }
  567.     virtual int yylex ();
  568.     friend std::ostream & operator<< (std::ostream & os, LobogoLexer & bl)
  569.     {
  570.         os << "time: " << bl.time << std::endl;
  571.         os << "squad_number: " << bl.squad_number << std::endl;
  572.         os << "lr: " << bl.lr << std::endl;
  573.  
  574.         return os;
  575.     }
  576.  
  577.     int get_time() const
  578.     {
  579.         return time;
  580.     }
  581.     char get_lr() const
  582.     {
  583.         return lr;
  584.     }
  585.     int get_squad_number() const
  586.     {
  587.         return squad_number;
  588.     }
  589.     bool get_see_ball() const {
  590.  
  591.         if (time - ball.get_time_stamp() <4)
  592.             return true;
  593.         else
  594.             return false;
  595.     }
  596.     float get_ball_dist() const {
  597.  
  598.         return ball.getDist();
  599.     }
  600.     float get_ball_ang() const {
  601.  
  602.         return ball.getAng();
  603.     }
  604.  
  605.     // from light response
  606.     float x;
  607.     float y;
  608.     float head_angle; // neck angle (rad)
  609.     float body_angle; // (rad)
  610.  
  611.     // from classical estimations
  612.     float estx; // x
  613.     float esty; // y
  614.     float esta; // body_angle (deg)
  615.     float estn; // head_angle (deg) (from body_sense/head_angle)
  616.  
  617.     float d_estx, d_esty;
  618.  
  619.     float get_estx() const
  620.     {
  621.         return estx;
  622.     }
  623.     float get_esty() const
  624.     {
  625.         return esty;
  626.     }
  627.     float get_esta() const
  628.     {
  629.         return esta;
  630.     }
  631.     void set_estx(float estx)
  632.     {
  633.         this->estx = estx;
  634.     }
  635.     void set_esty(float esty)
  636.     {
  637.         this->esty = esty;
  638.     }
  639.  
  640.     // See the book "Bátfai Norbert: Mesterséges intelligencia a gyakorlatban: bevezetés
  641.     // a  robotfoci programozásba" http://www.inf.unideb.hu/~nbatfai/konyvek/MIRC/mirc.book.xml.pdf
  642.     void gps(float u, float v, float r, float a, float b, float m) {
  643.  
  644.         float K = r * r - m * m + a * a + b * b - u * u - v * v;
  645.  
  646.         float oszto = 2.0 * b - 2.0 * v;
  647.         if (oszto == 0.0) {
  648.             return;
  649.         }
  650.  
  651.         float Z = K / oszto;
  652.         float H = (2.0 * a - 2.0 * u) / oszto;
  653.         float A = 1.0 + H * H;
  654.         float B = 2.0 * v * H - 2.0 * u - 2.0 * Z * H;
  655.         float C = u * u + Z * Z - 2.0 * Z * v + v * v - m * m;
  656.  
  657.         float diszk = B * B - 4.0 * A * C;
  658.         if (diszk >= 0.0) {
  659.  
  660.             float gyokalatt = std::sqrt(B * B - 4.0 * A * C);
  661.  
  662.             if (2.0 * A == 0.0) {
  663.                 return;
  664.             }
  665.  
  666.             float x1 = (-B + gyokalatt) / (2.0 * A);
  667.             float x2 = (-B - gyokalatt) / (2.0 * A);
  668.  
  669.             float y1 = Z - H * x1;
  670.             float y2 = Z - H * x2;
  671.  
  672.             //
  673.  
  674.             float tav1 = (estx - x1) * (estx - x1) + (esty - y1) * (esty - y1);
  675.             float tav2 = (estx - x2) * (estx - x2) + (esty - y2) * (esty - y2);
  676.  
  677.             if (tav1 < tav2) {
  678.  
  679.                 estx = x1;
  680.                 esty = y1;
  681.  
  682.             } else {
  683.  
  684.                 estx = x2;
  685.                 esty = y2;
  686.  
  687.             }
  688.         }
  689.     }
  690.  
  691.     static double const PI = 3.14159265359;
  692.  
  693.     // See the book "Bátfai Norbert: Mesterséges intelligencia a gyakorlatban: bevezetés
  694.     // a  robotfoci programozásba" http://www.inf.unideb.hu/~nbatfai/konyvek/MIRC/mirc.book.xml.pdf
  695.     void positioning() {
  696.  
  697.         int itime = time;
  698.         int smallest = 1000;
  699.         int secondsmallest = 1000;
  700.  
  701.         float long_dist = 100000.0, dist, secdist = 100000.0, x, y;
  702.         int time_stamp;
  703.  
  704.         for (int i = 0; i < Flag::NOF; ++i) {
  705.  
  706.             time_stamp = flags[i].get_time_stamp();
  707.             x = flags[i].getX();
  708.             y = flags[i].getY();
  709.  
  710.             if (itime - time_stamp < 2) {
  711.  
  712.                 dist = (estx - x) * (estx - x) + (esty - y) * (esty - y);
  713.                 if (dist < long_dist) {
  714.  
  715.                     long_dist = secdist;
  716.                     secdist = dist;
  717.  
  718.                     secondsmallest = smallest;
  719.                     smallest = i;
  720.  
  721.                 }
  722.             }
  723.  
  724.         }
  725.  
  726.         if (secondsmallest != 1000) {
  727.             gps(flags[smallest].getX(), flags[smallest].getY(), flags[smallest].getDist(),
  728.                 flags[secondsmallest].getX(), flags[secondsmallest].getY(), flags[secondsmallest].getDist());
  729.  
  730.             if (d_estx != estx || d_esty != esty) {
  731.  
  732.                 /* // ezt az elmozdulás alapú body angle maghatározást
  733.                  * // elrontja a pos parancs használata, mert akkor nem arra mozog, amerre a body angle mutat
  734.                       if (estx == 0.0) {
  735.                           estx = 0.001;
  736.                       }
  737.  
  738.                       esta = (std::asin((esty - d_esty) / (estx - d_estx))) * (180.0 /  PI);
  739.                 */
  740.  
  741.                 d_estx = estx;
  742.                 d_esty = esty;
  743.  
  744.             }
  745.  
  746.         }
  747.  
  748.     }
  749.  
  750.     int pass_to_farthest(int sharp) {
  751.  
  752.         int itime = time;
  753.         int farthest = -1;
  754.  
  755.         float small_dist = 0.0001, dist;
  756.         int time_stamp;
  757.  
  758.         for (int i = 0; i < 11; ++i) {
  759.  
  760.             time_stamp = own_team[i].get_time_stamp();
  761.  
  762.             if (itime - time_stamp < sharp) {
  763.  
  764.                 dist = own_team[i].getDist();
  765.                 if (dist > small_dist) {
  766.  
  767.                     small_dist = dist;
  768.                     farthest = i;
  769.  
  770.                 }
  771.             }
  772.  
  773.         }
  774.  
  775.         return farthest;
  776.     }
  777.  
  778.     int pass_to_nearest(int sharp) {
  779.  
  780.         int itime = time;
  781.         int nearest = -1;
  782.  
  783.         float small_dist = 150.0, dist;
  784.         int time_stamp;
  785.  
  786.         for (int i = 0; i < 11; ++i) {
  787.  
  788.             time_stamp = own_team[i].get_time_stamp();
  789.  
  790.             if (itime - time_stamp < sharp) {
  791.  
  792.                 dist = own_team[i].getDist();
  793.                 if (dist < small_dist) {
  794.  
  795.                     small_dist = dist;
  796.                     nearest = i;
  797.  
  798.                 }
  799.             }
  800.  
  801.         }
  802.  
  803.         return nearest;
  804.     }
  805.  
  806.     int pass_to_farthest_fwd(void) {
  807.  
  808.         int itime = time;
  809.         int farthest = -1;
  810.  
  811.         float small_dist = 0.0001, dist;
  812.         int time_stamp;
  813.  
  814.         for (int i = 0; i < 11; ++i) {
  815.  
  816.             time_stamp = own_team[i].get_time_stamp();
  817.  
  818.             if (itime - time_stamp < 2) {
  819.  
  820.                 dist = own_team[i].getDist();
  821.                 if (dist > small_dist && own_team[i].fwd(lr, x)) {
  822.                     small_dist = dist;
  823.                     farthest = i;
  824.  
  825.                 }
  826.             }
  827.  
  828.         }
  829.  
  830.         return farthest;
  831.     }
  832.  
  833.     int tavhozEro(float dist) {
  834.  
  835.         if (dist < 3.0) {
  836.  
  837.             return 20;
  838.  
  839.         } else if (dist < 6.0) {
  840.  
  841.             return 40;
  842.  
  843.         } else if (dist < 9.0) {
  844.  
  845.             return 60;
  846.  
  847.         } else if (dist < 12.0) {
  848.  
  849.             return 80;
  850.  
  851.         } else if (dist < 15.0) {
  852.  
  853.             return 100;
  854.  
  855.         } else if (dist < 19.0) {
  856.  
  857.             return 100;
  858.  
  859.         } else if (dist < 24.0) {
  860.  
  861.             return 100;
  862.  
  863.         } else if (dist < 30.0) {
  864.  
  865.             return 100;
  866.  
  867.         } else {
  868.  
  869.             return 100;
  870.         }
  871.     }
  872.  
  873. /*
  874.     int tavhozEro(float dist) {
  875.  
  876.         if (dist < 3.0) {
  877.  
  878.             return 10;
  879.  
  880.         } else if (dist < 6.0) {
  881.  
  882.             return 20;
  883.  
  884.         } else if (dist < 9.0) {
  885.  
  886.             return 30;
  887.  
  888.         } else if (dist < 12.0) {
  889.  
  890.             return 40;
  891.  
  892.         } else if (dist < 15.0) {
  893.  
  894.             return 50;
  895.  
  896.         } else if (dist < 19.0) {
  897.  
  898.             return 60;
  899.  
  900.         } else if (dist < 24.0) {
  901.  
  902.             return 70;
  903.  
  904.         } else if (dist < 30.0) {
  905.  
  906.             return 80;
  907.  
  908.         } else {
  909.  
  910.             return 100;
  911.         }
  912.     }
  913. */
  914.     int nof_seen_teammates(void) {
  915.  
  916.         int itime = time;
  917.         int nof = 0;
  918.  
  919.         float small_dist = 0.0001, dist;
  920.         int time_stamp;
  921.  
  922.         for (int i = 0; i < 11; ++i) {
  923.  
  924.             time_stamp = own_team[i].get_time_stamp();
  925.  
  926.             if (itime - time_stamp < 2) {
  927.  
  928.                 ++nof;
  929.             }
  930.  
  931.         }
  932.  
  933.         return nof;
  934.     }
  935.  
  936.     void setTeam(const std::string & team) {
  937.         this->team = team;
  938.     }
  939.  
  940.     SeenPlayer & get_own_player(int i) {
  941.  
  942.         return own_team[i];
  943.  
  944.     }
  945.     SeenFlag & get_flag(int i) {
  946.  
  947.         return flags[i];
  948.  
  949.     }
  950.  
  951.     SeenBall & get_ball() {
  952.  
  953.         return ball;
  954.  
  955.     }
  956.  
  957.     RefereePlayMode & get_play_mode() {
  958.  
  959.         return play_mode;
  960.  
  961.     }
  962.  
  963. private:
  964.     SeenBall ball;
  965.     // The flags that are seen by the player.
  966.     SeenFlag * flags;
  967.     // The teammates
  968.     SeenPlayer * own_team;
  969.     // The opponent players
  970.     SeenPlayer * other_team;
  971.     // teamname
  972.     std::string team;
  973.     char teamname_buffer[128];
  974.     //
  975.     int squadnumber_buffer;
  976.     float dist_buffer, ang_buffer;
  977.     float dist_buffer2, ang_buffer2;
  978.     // hear
  979.     char hear_buffer[1024];
  980.     char sender_buffer[128];
  981.     //
  982.     RefereePlayMode play_mode;
  983.     // see, sense_body
  984.     int time;
  985.     // init
  986.     int squad_number;
  987.     char lr;
  988.  
  989.     // nocopyable
  990.     LobogoLexer (const LobogoLexer &);
  991.     LobogoLexer & operator= (const LobogoLexer &);
  992.  
  993. };
  994.  
  995. class Coach
  996. {
  997. public:
  998.     Coach(int formi = 0):formi(formi)
  999.     {
  1000.         if (formi >= Formations::NOF || formi <0)
  1001.             formi = 0;
  1002.         formations = new Formation[Formations::NOF] {
  1003.             // (a +--os megadásokkal már tisztára FerSML feeling)
  1004.             // 4_3_3 h
  1005.             {-51, 0,
  1006.                 // att
  1007.                 -4, 10, -1, 0, -3, -11,
  1008.                 // mid
  1009.                 -18, -16, -17, 2, -18, 17,
  1010.                 // def
  1011.                 -35, -19, -33, -10, -34, 12, -35, 24},
  1012.  
  1013.             // 4_3_3 f
  1014.             { /*-40, -9,*/ -49, 0,
  1015.               // att
  1016.               -4 + 40, 10, -1 + 45, 1, -3 + 40, -11,
  1017.               // mid
  1018.               -18 + 23, -16,           -17 + 12 , 2,          -18 + 25, 17,
  1019.               // def
  1020.               -40, -13,    -31, -8,    -32, 9,    -40, 14},
  1021.  
  1022.             // 4_4_2 h
  1023.             {-51, 0,
  1024.              // att
  1025.              -4, 6, -3, -6,
  1026.              // mid
  1027.              -18, -19, -17, -10, -17, 12, -18, 24,
  1028.              // def
  1029.              -35, -19, -33, -10, -34, 12, -35, 24},
  1030.  
  1031.             // 4_4_2 f
  1032.             {-50, 0,
  1033.              // att
  1034.              -4 + 40, 6, -3 + 40, -6,
  1035.              // mid
  1036.              -18 + 30, -19, -17 + 25, -10, -17 + 25, 12, -18 + 30, 24,
  1037.              // def
  1038.              -35, -19, -33, -10, -34, 12, -35, 24},
  1039.  
  1040.             {//h
  1041.                 -44, 0,
  1042.                 -15, -25, -4, 0, -33, -29, -35, -9, -22 , -9, -15, 0,
  1043.                 -35, 9, -22, 9, -33, 29, -15, 25
  1044.             },
  1045.  
  1046.             {//f
  1047.                 -42, 0,
  1048.                 -25, -36, 0, -11, 0, 11, -25, -9, -25, 9, -25, 36, 20, -21, 20, 21, 20, 0, 44, 0
  1049.             },
  1050.  
  1051.             {
  1052.                 -27, 0,
  1053.                 -35, -12, //1
  1054.                 -17, -12, //2
  1055.                 -12, 5, //3
  1056.                 -27, 17, //4
  1057.                 -41, 5, //5
  1058.                 -27, -5, //6
  1059.                 -21, -1, //7
  1060.                 -23, 5, //8
  1061.                 -30, 5, //9
  1062.                 -32, -1  //10
  1063.             },
  1064.  
  1065.             {
  1066.                 -27, 0,
  1067.                 -30, -5, //9
  1068.                 -23, -5, //8
  1069.                 -21, 1, //7
  1070.                 -27, 5, //6
  1071.                 -32, 1, //10
  1072.                 -27, -17, //4
  1073.                 -12, -5, //3
  1074.                 -17, 12, //2
  1075.                 -35, 12, //1
  1076.                 -41, -5 //5
  1077.             },
  1078.  
  1079.             // c a
  1080.             {-50, 0,
  1081.              // att
  1082.              -4 + 40 +8 , 6, -3 + 40 +8, -6,
  1083.              // mid
  1084.              -18 + 30 +30, -19,     -17 + 25 +35, -10,      -17 + 25+35, 12,        -18 + 30 +30, 24,
  1085.              // def
  1086.              -35 +20, -19,      -33+15, -7,                 -34+15, 8,                  -35+20, 24},
  1087.  
  1088.             // c d
  1089.             {-50, 0,
  1090.              // att
  1091.              -4 - 40, 6, -3 - 40, -6,
  1092.              // mid
  1093.              -18 - 30 , -19, -17 - 25 , -10, -17 - 25, 12, -18 - 30 , 24,
  1094.              // def
  1095.              -35 -15,-19,         -52, -8,            -52, 8,             -35 -15, 24}
  1096.  
  1097.  
  1098.         };
  1099.     }
  1100.     ~Coach() {
  1101.  
  1102.         delete[] formations;
  1103.     }
  1104.     Formation & get_formation() const
  1105.     {
  1106.         return formations[formi];
  1107.     }
  1108.     void set_formation(int formi)
  1109.     {
  1110.         this->formi = formi;
  1111.     }
  1112. private:
  1113.     //
  1114.     Formation * formations;
  1115.     int formi;
  1116.  
  1117. };
  1118.  
  1119. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement