Esempio n. 1
0
        // tik strategie urcujici co se ma pri kazdem kroku vykonat
        public override void TickStrategy(StrategyStorage storage)
        {
            SetGoalkeeperStrategy(storage.myRobots[gameSetting.NUMBER_OF_ROBOTS - 1], storage);

            try
            {
                currentRule = FindBestRuleGraph(storage);
            }
            catch (Exception e)
            {
                currentRule = null;
            }

            SharedMutex.getMutex().WaitOne();
            if (currentRule != null)
            {
                int[] mapping = MapRobotsToMoveTo(storage, currentRule);
                for (int i = 0; i < gameSetting.NUMBER_OF_ROBOTS - 1; i++)
                {
                    storage.myRobots[mapping[i]].PositionMove = gStrategy.GridToReal(currentRule.Move[i], gameSetting);
                }
            }
            SharedMutex.getMutex().ReleaseMutex();

            // tactics
            SharedMutex.getMutex().WaitOne();
            tactic.chooseTactic(storage);
            SharedMutex.getMutex().ReleaseMutex();
        }
Esempio n. 2
0
        public override void doTactic(StrategyStorage storage)
        {
            int robot = findRobot(storage);

            robotCheck(robot);
            // smaz storage.myRobots[robot].tactic = true;

            // micek je pri kraji vlevo nebo vpravo
            if (storage.Ball.Position.X < x + border ||
                storage.Ball.Position.X > x + width - border)
            {
                // smaz storage.MyRobots[robot].GoTo(storage.Ball.Position.X, storage.Ball.Position.Y - step);
                storage.myRobots[robot].PositionMove = new Vector2D(storage.Ball.Position.X, storage.Ball.Position.Y - step);
            }
            // micek je pri kraji na hore nebo dole
            else if (storage.Ball.Position.Y < y + border ||
                     storage.Ball.Position.Y > y + height - border)
            {
                if (mirror)
                {
                    storage.myRobots[robot].PositionMove = new Vector2D(storage.Ball.Position.X + (3 * step), storage.Ball.Position.Y);
                }
                else
                {
                    storage.myRobots[robot].PositionMove = new Vector2D(storage.Ball.Position.X - (3 * step), storage.Ball.Position.Y);
                }
            }
        }
Esempio n. 3
0
        public override void doTactic(StrategyStorage storage)
        {
            int robot = findRobot(storage);

            //robotCheck(robot);

            //Vector2D ball_next_pos = Storage.Ball.Position + Storage.ball.Position * Storage.timestep * Storage.BALL_FRICTION;
            // smaz storage.myRobots[robot].tactic = true;


            //VYPOCET REGRESE pro vybraneho robota
            //robot = 4;
            RegreseOne(robot, storage.Ball, storage.myRobots, storage.oppntRobots);
            //storage.MyRobots[robot].PositionMove=storage.Ball.Position;

            for (int i = 0; i < gameSetting.NUMBER_OF_ROBOTS - 1; i++)
            {
                if (i == robot)
                {
                    continue;
                }
                RegreseMove(i, storage.myRobots[i].PositionMove, storage.myRobots, storage.oppntRobots);
            }

            //storage.LeftRobots[0].PositionMove = new Vector2D(-80, -60);
            //storage.LeftRobots[1].PositionMove = new Vector2D(-80, 60);
            //storage.LeftRobots[2].PositionMove = new Vector2D(-80, -60);
            //storage.LeftRobots[3].PositionMove = new Vector2D(-80, 60);
        }
Esempio n. 4
0
        protected override int findRobot(StrategyStorage storage)
        {
            //int robot = shootingArea(storage);
            int robot = ChooseOffensiveRobot(storage);

            return(robot);
        }
Esempio n. 5
0
        /**
         * Posleme brankare na pozici mice
         */
        public override void doTactic(StrategyStorage storage)
        {
            int robot = findRobot(storage);

            //robotCheck(robot);
            // smaz storage.myRobots[robot].tactic = true;
            storage.myRobots[robot].PositionMove = storage.Ball.Position;
        }
Esempio n. 6
0
        private int shootingArea(StrategyStorage storage)
        {
            Vector2D area_bottom = new Vector2D(x, y);                                // spodni bod hranicni primky
            Vector2D area_top    = new Vector2D(x, y + height);                       // horni bod hranicni primky

            Vector2D pC = storage.Ball.Position;                                      // micek
            Vector2D pB = getCoordinates(opp_goal_bottom, pC, area_bottom, area_top); // horni bod
            Vector2D pA = getCoordinates(opp_goal_top, pC, area_bottom, area_top);    // spodni bod

            double min    = double.MaxValue;                                          // pro vyber robota s nejmensi vzdalenosti od mice ve spravnem uhlu
            int    robot  = -1;                                                       // nejlepsi robot ve spravnem uhlu
            int    robot1 = -1;                                                       // robot nejblize spravneho uhlu
            double angle  = -1;                                                       // uhel nejblizsi spravnemu uhlu
            int    count  = 0;                                                        // pocitani robotu

            foreach (Robot r in storage.myRobots)
            {
                double pB_r  = pB.DistanceFrom(r.Position);
                double pB_pC = pB.DistanceFrom(pC);

                double pA_r  = pA.DistanceFrom(r.Position);
                double pA_pC = pA.DistanceFrom(pC);

                double pA_pB = pB.DistanceFrom(pA);
                double pC_r  = pC.DistanceFrom(r.Position);

                double alfa = Math.Acos((pC_r * pC_r + pA_r * pA_r - pA_pC * pA_pC) / (2 * pC_r * pA_r));
                alfa += Math.Acos((pA_r * pA_r + pB_r * pB_r - pA_pB * pA_pB) / (2 * pA_r * pB_r));
                alfa += Math.Acos((pB_r * pB_r + pC_r * pC_r - pB_pC * pB_pC) / (2 * pB_r * pC_r));
                alfa *= 180 / Math.PI;

                // pC_r ... vzdalenost robota od mice
                if (alfa > 355 && pC_r < min && r != storage.myRobots[gameSetting.NUMBER_OF_ROBOTS - 1])
                {
                    robot = count;
                    min   = pC_r;
                }

                // alternativni plan - robot nejblize spravneho uhlu
                if (alfa > angle && r != storage.myRobots[gameSetting.NUMBER_OF_ROBOTS - 1])
                {
                    angle  = alfa;
                    robot1 = count;
                }

                count++;
            }

            // nebyl vybran zaden ve spravnem uhlu, pouzijeme alternativni plan
            if (robot < 0)
            {
                return(robot1);
            }

            return(robot);
        }
Esempio n. 7
0
        public override void doTactic(StrategyStorage storage)
        {
            int robot = findRobot(storage);

            robotCheck(robot); //Zrusime oznaceni robotu, kteri meli vykonat taktiku v minulem kroku (definovana v Tactic)

            /*Vector2D ball_next_pos = Storage.ball.Position +
             *  Storage.ball.Position * Storage.timestep * Storage.BALL_FRICTION;
             *
             * storage.myRobots[robot].GoTo(ball_next_pos);*/

            storage.myRobots[robot].PositionMove = storage.Ball.Position;
            // smaz storage.myRobots[robot].tactic = true;
        }
Esempio n. 8
0
 // strategie s jakou zvoleny brankar chyta v brane
 private void SetGoalkeeperStrategy(Robot goalkeeper, StrategyStorage storage)
 {
     if (goalkeeper.Position.X < gameSetting.AREA_NET_X / 2)
     {
         double b_y = (storage.Ball.Position.Y < -gameSetting.AREA_NET_Y / 2) ? -gameSetting.AREA_NET_Y / 2 : (storage.Ball.Position.Y > gameSetting.AREA_NET_Y / 2) ? gameSetting.AREA_NET_Y / 2 : storage.Ball.Position.Y;
         goalkeeper.PositionMove.X = -gameSetting.AREA_X / 2 + gameSetting.ROBOT_EDGE_SIZE / 2;
         goalkeeper.PositionMove.Y = b_y;
     }
     else
     {
         double b_y = (storage.Ball.Position.Y < -gameSetting.AREA_NET_Y / 2) ? -gameSetting.AREA_NET_Y / 2 : (storage.Ball.Position.Y > gameSetting.AREA_NET_Y / 2) ? gameSetting.AREA_NET_Y / 2 : storage.Ball.Position.Y;
         goalkeeper.PositionMove.X = gameSetting.AREA_X / 2 - gameSetting.ROBOT_EDGE_SIZE / 2;
         goalkeeper.PositionMove.Y = b_y;
     }
 }
Esempio n. 9
0
        //finds the best mapping between selected moveTo coordinates and the real robots
        private int[] MapRobotsToMoveTo(StrategyStorage storage, GridRule rule)
        {
            int[]   bestPerm = new int[4];
            int[][] indexes  = { new int[] { 1, 2, 3, 0 },
                                 new int[]  { 1, 2, 0, 3 },
                                 new int[]  { 1, 3, 2, 0 },
                                 new int[]  { 1, 3, 0, 2 },
                                 new int[]  { 1, 0, 2, 3 },
                                 new int[]  { 1, 0, 3, 2 },
                                 new int[]  { 2, 1, 3, 0 },
                                 new int[]  { 2, 1, 0, 3 },
                                 new int[]  { 2, 3, 1, 0 },
                                 new int[]  { 2, 3, 0, 1 },
                                 new int[]  { 2, 0, 1, 3 },
                                 new int[]  { 2, 0, 3, 1 },
                                 new int[]  { 3, 1, 2, 0 },
                                 new int[]  { 3, 1, 0, 2 },
                                 new int[]  { 3, 2, 1, 0 },
                                 new int[]  { 3, 2, 0, 1 },
                                 new int[]  { 3, 0, 1, 2 },
                                 new int[]  { 3, 0, 2, 1 },
                                 new int[]  { 0, 1, 2, 3 },
                                 new int[]  { 0, 1, 3, 2 },
                                 new int[]  { 0, 2, 1, 3 },
                                 new int[]  { 0, 2, 3, 1 },
                                 new int[]  { 0, 3, 1, 2 },
                                 new int[]  { 0, 3, 2, 1 } };

            double min = double.MaxValue;

            foreach (int[] i in indexes)
            {
                double moveRuleSize = gStrategy.GridToReal(rule.Move[0], gameSetting).DistanceFrom(storage.myRobots[i[0]].Position)
                                      + gStrategy.GridToReal(rule.Move[1], gameSetting).DistanceFrom(storage.myRobots[i[1]].Position)
                                      + gStrategy.GridToReal(rule.Move[2], gameSetting).DistanceFrom(storage.myRobots[i[2]].Position)
                                      + gStrategy.GridToReal(rule.Move[3], gameSetting).DistanceFrom(storage.myRobots[i[3]].Position);
                if (moveRuleSize < min)
                {
                    min      = moveRuleSize;
                    bestPerm = i;
                }
            }

            return(bestPerm);
        }
Esempio n. 10
0
        private int ChooseOffensiveRobot(StrategyStorage storage)
        {
            int    bestRobot = -1;
            double minDist   = Double.MaxValue;
            double minAngle  = Double.MaxValue;

            for (int i = 0; i < gameSetting.NUMBER_OF_ROBOTS - 1; i++)
            {
                Robot r = storage.myRobots[i];

                double dist = storage.Ball.Position.DistanceFrom(r.Position);
                if (dist < minDist)
                {
                    minDist   = dist;
                    bestRobot = i;
                }
            }

            return(bestRobot);
        }
Esempio n. 11
0
 //zmeneneee
 //public void chooseTactic(Storage storage)
 public void chooseTactic(StrategyStorage storage)
 {
     //offensiveShoot.doTactic(storage);
     if (goalkeeper.needOf(storage.Ball.Position))
     {
         goalkeeper.doTactic(storage);
     }
     else if (borders.needOf(storage.Ball.Position))
     {
         borders.doTactic(storage);
     }
     //else if (defensiveShoot.needOf(storage.Ball.Position))
     //{
     //    defensiveShoot.doTactic(storage);
     //}
     else //if (offensiveShoot.needOf(storage.Ball.Position))
     {
         offensiveShoot.doTactic(storage);
     }
 }
Esempio n. 12
0
        private int shootingArea(StrategyStorage storage)
        {
            Vector2D area_bottom = new Vector2D(x + width, y);                       // spodni bod hranicni primky
            Vector2D area_top    = new Vector2D(x + width, y + height);              // horni bod hranicni primky

            Vector2D pC = storage.Ball.Position;                                     // micek
            Vector2D pB = getCoordinates(my_goal_bottom, pC, area_bottom, area_top); // horni bod
            Vector2D pA = getCoordinates(my_goal_top, pC, area_bottom, area_top);    // spodni bod

            double min   = double.MaxValue;
            int    robot = -1;
            int    count = 0;

            foreach (Robot r in storage.myRobots)
            {
                double pB_r  = pB.DistanceFrom(r.Position);
                double pB_pC = pB.DistanceFrom(pC);

                double pA_r  = pA.DistanceFrom(r.Position);
                double pA_pC = pA.DistanceFrom(pC);

                double pA_pB = pB.DistanceFrom(pA);
                double pC_r  = pC.DistanceFrom(r.Position);

                double alfa = Math.Acos((pC_r * pC_r + pA_r * pA_r - pA_pC * pA_pC) / (2 * pC_r * pA_r));
                alfa += Math.Acos((pA_r * pA_r + pB_r * pB_r - pA_pB * pA_pB) / (2 * pA_r * pB_r));
                alfa += Math.Acos((pB_r * pB_r + pC_r * pC_r - pB_pC * pB_pC) / (2 * pB_r * pC_r));
                alfa *= 180 / Math.PI;

                // pC_r ... vzdalenost robota od mice
                if (alfa < 360 && pC_r < min && r != storage.myRobots[gameSetting.NUMBER_OF_ROBOTS - 1])
                {
                    robot = count;
                    min   = pC_r;
                }

                count++;
            }

            return(robot);
        }
Esempio n. 13
0
        /**
         * Vybere nejvhodnejsiho - nejblizsiho robota
         */
        protected override int findRobot(StrategyStorage storage)
        {
            double distance = double.MaxValue;

            int count = 0;
            int robot = -1;

            foreach (Robot r in storage.myRobots)
            {
                double temp = r.Position.DistanceFrom(storage.Ball.Position);

                if (temp < distance && r != storage.myRobots[gameSetting.NUMBER_OF_ROBOTS - 1])
                {
                    distance = temp;
                    robot    = count;
                }
                count++;
            }

            return(robot);
        }
Esempio n. 14
0
 /**
  * Vybrany robot je vzdy brankar
  */
 protected override int findRobot(StrategyStorage storage)
 {
     return(gameSetting.NUMBER_OF_ROBOTS - 1);
 }
Esempio n. 15
0
        protected override int findRobot(StrategyStorage storage)
        {
            int robot = shootingArea(storage);

            return(robot);
        }
Esempio n. 16
0
 protected abstract int findRobot(StrategyStorage storage);
Esempio n. 17
0
 //zmenene
 //public abstract void doTactic(Storage storage);
 public abstract void doTactic(StrategyStorage storage);
Esempio n. 18
0
 public abstract void TickStrategy(StrategyStorage storage);
Esempio n. 19
0
    void Starts()
    {
        this.currentTime  = 0;
        this.isGoal       = false;
        rightPlayerRobots = new List <RobotSoccerSimulator.RealSimulator.Robot>();
        leftPlayerRobots  = new List <RobotSoccerSimulator.RealSimulator.Robot>();

        for (int i = 0; i < 5; i++)
        {
            RobotSoccerSimulator.RealSimulator.Robot r1 = new RobotSoccerSimulator.RealSimulator.Robot(RobotSoccerSimulator.RealSimulator.Simulator.RobotTeam.RightPlayer);
            RobotSoccerSimulator.RealSimulator.Robot r2 = new RobotSoccerSimulator.RealSimulator.Robot(RobotSoccerSimulator.RealSimulator.Simulator.RobotTeam.LeftPlayer);
            rightPlayerRobots.Add(r1);
            leftPlayerRobots.Add(r2);
        }
        ball = new RobotSoccerSimulator.RealSimulator.Ball();

        //vytvoreni logu
        DateTime cas = DateTime.Now;                                                                      //aktualni cas

        _logFileCsv = (cas.Month + "-" + cas.Day + "_" + cas.Hour + ":" + cas.Minute + ":" + cas.Second); //nazev logu

        //GameSettingu
        SimulatorGameSetting                  = new GameSetting();
        SimulatorGameSetting.AREA_NET_X       = AREA_NET_X;
        SimulatorGameSetting.AREA_NET_Y       = AREA_NET_Y;
        SimulatorGameSetting.AREA_X           = AREA_X;
        SimulatorGameSetting.AREA_Y           = AREA_Y;
        SimulatorGameSetting.BALL_FRICTION    = BALL_FRICTION;
        SimulatorGameSetting.NUMBER_OF_ROBOTS = 5;
        SimulatorGameSetting.ROBOT_EDGE_SIZE  = ROBOT_EDGE_SIZE;
        SimulatorGameSetting.ROBOT_MAX_VEL    = ROBOT_MAX_VEL;

        storage = new Storage();

        storage.Ball.Position = this.ball.Position;
        storage.Ball.Velocity = this.ball.Velocity;

        storage.LeftRobots[0].Position  = leftPlayerRobots[0].Position;
        storage.LeftRobots[1].Position  = leftPlayerRobots[1].Position;
        storage.LeftRobots[2].Position  = leftPlayerRobots[2].Position;
        storage.LeftRobots[3].Position  = leftPlayerRobots[3].Position;
        storage.LeftRobots[4].Position  = leftPlayerRobots[4].Position;
        storage.RightRobots[0].Position = rightPlayerRobots[0].Position;
        storage.RightRobots[1].Position = rightPlayerRobots[1].Position;
        storage.RightRobots[2].Position = rightPlayerRobots[2].Position;
        storage.RightRobots[3].Position = rightPlayerRobots[3].Position;
        storage.RightRobots[4].Position = rightPlayerRobots[4].Position;

        storage.LeftRobots[0].PositionMove  = leftPlayerRobots[0].Position;
        storage.LeftRobots[1].PositionMove  = leftPlayerRobots[1].Position;
        storage.LeftRobots[2].PositionMove  = leftPlayerRobots[2].Position;
        storage.LeftRobots[3].PositionMove  = leftPlayerRobots[3].Position;
        storage.LeftRobots[4].PositionMove  = leftPlayerRobots[4].Position;
        storage.RightRobots[0].PositionMove = rightPlayerRobots[0].Position;
        storage.RightRobots[1].PositionMove = rightPlayerRobots[1].Position;
        storage.RightRobots[2].PositionMove = rightPlayerRobots[2].Position;
        storage.RightRobots[3].PositionMove = rightPlayerRobots[3].Position;
        storage.RightRobots[4].PositionMove = rightPlayerRobots[4].Position;

        storage.LeftRobots[0].Velocity  = leftPlayerRobots[0].Velocity;
        storage.LeftRobots[1].Velocity  = leftPlayerRobots[1].Velocity;
        storage.LeftRobots[2].Velocity  = leftPlayerRobots[2].Velocity;
        storage.LeftRobots[3].Velocity  = leftPlayerRobots[3].Velocity;
        storage.LeftRobots[4].Velocity  = leftPlayerRobots[4].Velocity;
        storage.RightRobots[0].Velocity = rightPlayerRobots[0].Velocity;
        storage.RightRobots[1].Velocity = rightPlayerRobots[1].Velocity;
        storage.RightRobots[2].Velocity = rightPlayerRobots[2].Velocity;
        storage.RightRobots[3].Velocity = rightPlayerRobots[3].Velocity;
        storage.RightRobots[4].Velocity = rightPlayerRobots[4].Velocity;

        //vytvorenie instancii pre left a right storage
        leftStorage  = new StrategyStorage();
        rightStorage = new StrategyStorage();
    }
Esempio n. 20
0
        // funkce, ktera podle daneho algoritmu najde nejlepsi (nejvyhodnejsi) pravidlo a toto vrati soucasne s mapovacim indexem pro roboty

        private GridRule FindBestRuleGraph(StrategyStorage storage)
        {
            double   treshold = 500;
            GridRule bestRule = null;
            int      x, y;

            //mine
            matrix = new List <int> [6, 4];
            for (int i = 0; i < storage.myRobots.Length - 1; i++)
            {
                Vector2D v = gStrategy.RealToGrid(storage.myRobots[i].Position, gameSetting);
                x = Convert.ToInt32(v.X);
                y = Convert.ToInt32(v.Y);
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            List <int> actMine = zorder.zOrderMain(matrix, 2);

            //oppnt
            matrix = new List <int> [6, 4];
            for (int i = 0; i < storage.oppntRobots.Length - 1; i++)
            {
                Vector2D v = gStrategy.RealToGrid(storage.oppntRobots[i].Position, gameSetting);
                x = Convert.ToInt32(v.X);
                y = Convert.ToInt32(v.Y);
                if (matrix[x, y] != null)
                {
                    matrix[x, y].Add(i);
                }
                else
                {
                    matrix[x, y] = new List <int>()
                    {
                        i
                    }
                };
            }
            List <int> actOppnt = zorder.zOrderMain(matrix, 2);

            //nejpodobnejsi pravidlo
            double min = Double.MaxValue;

            StringBuilder sb = new StringBuilder();

jump:

            if (lastRule == -1)
            {
                GridRule rule;
                for (int r = 0; r < gStrategy.Rules.Count; r++)
                {
                    rule = gStrategy.Rules[r];

                    double ballRuleSize = gStrategy.GridToReal(rule.Ball, gameSetting).DistanceFrom(storage.Ball.Position);

                    double mineSize = 0;
                    for (int i = 0; i < actMine.Count; i++)
                    {
                        mineSize += gStrategy.GridToReal(rule.Mine[rule.ZMine[i]], gameSetting).DistanceFrom(storage.myRobots[actMine[i]].Position);
                    }

                    double oppntSize = 0;
                    for (int i = 0; i < actOppnt.Count; i++)
                    {
                        oppntSize += gStrategy.GridToReal(rule.Oppnt[rule.ZOppnt[i]], gameSetting).DistanceFrom(storage.oppntRobots[actOppnt[i]].Position);
                    }

                    if (ballRuleSize + mineSize + oppntSize < min)
                    {
                        min      = ballRuleSize + mineSize + oppntSize;
                        bestRule = rule;
                        lastRule = r;
                    }

                    sb.AppendLine("rule: " + rule.Number + " dist: " + (ballRuleSize + mineSize + oppntSize));
                }
            }
            else
            {
                Node       actNode = graph.Nodes[lastRule];
                GridRule   rule;
                List <int> tempKeys = new List <int>(actNode.neighbours.Keys);
                tempKeys.Add(lastRule);

                foreach (int k in tempKeys)
                {
                    rule = (GridRule)graph.Nodes[k].data;

                    double ballRuleSize = gStrategy.GridToReal(rule.Ball, gameSetting).DistanceFrom(storage.Ball.Position);

                    double mineSize = 0;
                    for (int i = 0; i < actMine.Count; i++)
                    {
                        mineSize += gStrategy.GridToReal(rule.Mine[rule.ZMine[i]], gameSetting).DistanceFrom(storage.myRobots[actMine[i]].Position);
                    }

                    double oppntSize = 0;
                    for (int i = 0; i < actOppnt.Count; i++)
                    {
                        oppntSize += gStrategy.GridToReal(rule.Oppnt[rule.ZOppnt[i]], gameSetting).DistanceFrom(storage.oppntRobots[actOppnt[i]].Position);
                    }

                    if (ballRuleSize + mineSize + oppntSize < min)
                    {
                        min      = ballRuleSize + mineSize + oppntSize;
                        bestRule = rule;
                        lastRule = k;
                    }

                    sb.AppendLine("rule: " + rule.Number + " dist: " + (ballRuleSize + mineSize + oppntSize));
                }

                //pokud je hodnota podobnosti mensi nez nejaky nastaveny treshold, tak bych mel znovu prohledavat vsechna pravidla
                if (min > treshold)
                {
                    sb.AppendLine("-----SEARCH ALL RULES----");
                    lastRule = -1;
                    goto jump;
                }
            }

            if (bestRule != null)
            {
                sb.AppendLine("BESTrule: " + bestRule.Number + " MINdist: " + min);
                sb.AppendLine("----------------------------------------------------------------");
            }

            return(bestRule);
        }