Пример #1
0
 private void btnCreateTeam_Click(object sender, RoutedEventArgs e)
 {
     Team team = new Team(this.txbTeamName.Text, null);
     this._logics.SaveTeam(team);
     this.pnlCreateTeam.Visibility = Visibility.Hidden;
     BintTeams();
 }
Пример #2
0
 public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
 {
     foreach (var player in myTeam.Players)
     {
         if (player.CanPickUpBall(ball))
         {
             player.ActionPickUpBall();
         }
         else if (player == ball.Owner)
         {
             player.ActionShootGoal();
         }
         else if (ball.Owner != null && ball.Owner.Team != myTeam && player.CanTackle(ball.Owner))
         {
             player.ActionTackle(ball.Owner);
         }
         else if (WallPositions[player.PlayerType].GetDistanceTo(player) > 1.0)
         {
             player.ActionGo(WallPositions[player.PlayerType]);
         }
         else
         {
             player.ActionWait();
         }
     }
 }
Пример #3
0
 public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
 {
     foreach (var player in myTeam.Players)
     {
         player.ActionWait();
     }
 }
Пример #4
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            var pl1 = myTeam.Players.First(pl => pl.PlayerType == PlayerType.RightDefender);

            myTeam.DevMessage = string.Format("speed {0}", pl1.Velocity.Length);

            if (maxReached)
            {
                if (pl1.Velocity.Length > 0.05)
                {
                    pl1.ActionWait();
                    return;
                }

                myTeam.DevMessage += "\r\n0.05 minReached";
                maxReached = false;
                point = pl1.Position.X < Field.Borders.Center.X ? Field.EnemyGoal : Field.MyGoal;
            }

            if (pl1.Velocity.Length > 3 * 0.95)
            {
                myTeam.DevMessage += "\r\n0.95 maxReached";
                maxReached = true;
                prevVelocity = 0;
                pl1.ActionWait();
            }
            else
            {
                pl1.ActionGo(point);
                prevVelocity = pl1.Velocity.Length;
            }
        }
Пример #5
0
 public Player(TcpClient client, Team equipa)
 {
     this.client = client;
     this.equipa = equipa;
     this.playerStatus = PlayerStatus.Waiting;
     this.MsgCounter = 0;
 }
Пример #6
0
 public Pitch(Team my, Team enemy, Ball ball, MatchInfo info)
 {
     My = my;
     Enemy = enemy;
     Ball = ball;
     Info = info;
 }
Пример #7
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);

                if (ball.Owner == player)  //Allways shoots for the enemy goal.
                    player.ActionShootGoal();
                else if (player.CanPickUpBall(ball))  //Picks up the ball if posible.
                    player.ActionPickUpBall();
                else if (player.CanTackle(closestEnemy))  //Tackles any enemy that is close.
                    player.ActionTackle(closestEnemy);
                else  //If the player cannot do anything urgently usefull, move to a good position.
                {
                    if (player == ball.GetClosest(myTeam))  //If the player is closest to the ball, go for it.
                        player.ActionGo(ball);
                    else if (player.PlayerType == PlayerType.Keeper)  //The keeper protects the goal.
                        player.ActionGo(new Vector(50, Math.Max(Math.Min(ball.Position.Y, Field.MyGoal.Bottom.Y), Field.MyGoal.Top.Y))); //The keeper positions himself 50 units out from the goal                                                                                                            //at the same height as the ball, although never leaving the goal
                    else if (player.PlayerType == PlayerType.LeftDefender)
                        player.ActionGo(new Vector(Field.Borders.Width * 0.2, ball.Position.Y));  //The left defender helps protect the goal
                    else if (player.PlayerType == PlayerType.RightDefender)
                        player.ActionGo(Field.MyGoal.GetClosest(enemyTeam));   //The right defender chases the enemy closest to myGoal
                    else if (player.PlayerType == PlayerType.RightForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Bottom + ball.Position) / 3);  //Right forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.LeftForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Top + ball.Position) / 3);   //Left forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.CenterForward)
                        player.ActionGo((Field.Borders.Center + Field.EnemyGoal.Center + ball.Position) / 3);    //Center forward stays in position on the enemy side of the field.
                }
            }
        }
Пример #8
0
 public Game(MatchInfo info, Ball ball, Team enemy, Team my, bool inAttack)
 {
     Info = info;
     Ball = ball;
     Enemy = enemy;
     My = my;
     InAttack = inAttack;
 }
Пример #9
0
		public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
		{
			var info = TurnInfo.Create(myTeam, enemyTeam, ball, matchInfo);

			var queue = info.Own.Players.ToList();

			foreach (var role in Roles)
			{
				queue.Remove(role.Apply(info, queue));
			}
			Scenario.DefaultFieldplay.Apply(info, queue);
		}
Пример #10
0
 public static Player GetClosestInterceptor(this Player player, Team enemies)
 {
     var line = Line.One(player.Position, Field.EnemyGoal.Center);
     return (from ep in enemies.Players
             let y1 = line.K * ep.Position.X + line.B
             let dist = player.GetDistanceTo(ep.Position)
             where Math.Abs(ep.Position.Y - y1) < 100
             where ep.GetDistanceTo(Field.EnemyGoal.Center) < dist
             //where dist < 300
             orderby dist descending
             select ep).FirstOrDefault();
 }
Пример #11
0
 public static IEnumerable<Player> GetClosestInterceptors(this Player player, Team enemies, int dist)
 {
     var line = Line.One(player.Position, Field.EnemyGoal.Center);
     return (from ep in enemies.Players
             let eloc = ep.Position + ep.Velocity
             let y1 = line.K * eloc.X + line.B
             where Math.Abs(eloc.Y - y1) < 100
             //where ep.GetDistanceTo(Field.EnemyGoal.Center) < dist
             where player.GetDistanceTo(eloc) < dist
             //orderby player.GetDistanceTo(ep) descending
             select ep);
 }
Пример #12
0
        public static void Assign(Team my, Team enemy, Ball ball, MatchInfo info)
        {
            My = my;
            Enemy = enemy;
            Ball = ball;
            Info = info;

            LogInfoEnabled = true;

            ballFuturePosition = DistanceUtils.BuildBallFuturePosition(50);
            closest = null;
        }
Пример #13
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)                                       //Loop over all players in my team.
            {
                Player closestEnemy = player.GetClosest(enemyTeam);                         //Gets the closest enemy player.

                if (ball.Owner == player)                                                   //If this player has the ball.
                    player.ActionShootGoal();                                               //Tell this player to shoot towards the goal, at maximum strength!
                else if (player.CanPickUpBall(ball))
                    player.ActionPickUpBall();
                else player.ActionGo(ball.Position);                                                 //Worst case just go for the ball
            }                                                           //Return myTeam with the teams actions.
        }
Пример #14
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            var pitch = new Pitch(myTeam, enemyTeam, ball, matchInfo);

            var height = (int)Field.MyGoal.Height;
            var step = height/(myTeam.Players.Count + 1);

            var roles = Enumerable.Range(1, myTeam.Players.Count)
                .Select(p => new GateStanderRole(new Vector(0, Field.MyGoal.Y + p*step)))
                .Zip(myTeam.Players, Tuple.Create);

            foreach (var role in roles)
                role.Item1.DoAction(role.Item2, pitch);
        }
Пример #15
0
 public static Vector ShootGoal(Ball ball, Team enemies)
 {
     Player player = ball.Owner;
     Team friends = player.Team;
     double[] kks = (from ep in enemies.Players
                     let ktop = Line.K0(player.Position, Field.EnemyGoal.Top)
                     let kbot = Line.K0(player.Position, Field.EnemyGoal.Bottom)
                     let kep = Line.K0(player.Position, ep.Position)
                     where kep >= Math.Min(ktop, kbot) && kep <= Math.Max(ktop, kbot)
                     where ep.GetDistanceTo(Field.EnemyGoal.Center) < player.GetDistanceTo(Field.EnemyGoal.Center)
                     orderby kep
                     select kep).ToArray();
     return Field.EnemyGoal.Center;
 }
Пример #16
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            Pitch.Assign(myTeam, enemyTeam, ball, matchInfo);

            var height = (int)Field.MyGoal.Height;
            var step = height/(myTeam.Players.Count + 1);

            var roles = Enumerable.Range(1, myTeam.Players.Count)
                                  .Zip(myTeam.Players, Tuple.Create)
                                  .Select(p => new GateStander(p.Item2.PlayerType, new Vector(0, Field.MyGoal.Y + p.Item1*step)));
                                  
            foreach (var role in roles)
                role.DoAction();
        }
Пример #17
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            Pitch.Assign(myTeam, enemyTeam, ball, matchInfo);

            if (matchInfo.EnemyTeamScored || matchInfo.MyTeamScored)
            {
                Pitch.Log("=======================================");
                Pitch.Log("Someone scored, game stage set to reset");
                Pitch.Log("=======================================");
                Pitch.Stage = GameStage.Reset;
            }

            SetGameState();

            foreach (var assignedRole in assignedRoles)
                assignedRole.DoAction();
        }
Пример #18
0
        public static Vector CoverAttacker(Player player, Team enemies)
        {
            Team friends = player.Team;

            switch (player.PlayerType)
            {
                case PlayerType.LeftForward:
                    return Field.EnemyGoal.Left;
                case PlayerType.CenterForward:
                    return Field.EnemyGoal.Center;
                case PlayerType.RightForward:
                    return Field.EnemyGoal.Right;
                default:
                    // todo: implement
                    return player.Position;
            }
        }
Пример #19
0
		public static TurnInfo Create(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
		{
			var info = new TurnInfo()
			{
				Own = myTeam,
				Other = enemyTeam,
				Ball = ball,
				Match = matchInfo,
			};
			info.Path = BallPath.Create(info);
			info.CatchUps = info.Path.GetCatchUp(info.Players).OrderBy(c => c.Turn).ToList();
			info.HasPossession =
				myTeam.Players.Contains(ball.Owner) ||
				myTeam.Players.Any(p => p.CanPickUpBall(ball)) ||
				(info.CatchUps.Any() && myTeam.Players.Contains(info.CatchUps[0].Player));

			return info;
		}
Пример #20
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            if (!inAttack && ball.Owner != null && ball.Owner.Team == myTeam)
            {
                inAttack = true;
            }
            if (inAttack && ball.Owner != null && ball.Owner.Team == enemyTeam)
            {
                inAttack = false;
            }

            var game = new Game(matchInfo, ball, enemyTeam, myTeam, inAttack);


            foreach (var kv in players)
            {
                kv.Value.DoAction(game, myTeam.Players.First(pl => pl.PlayerType == kv.Key));
            }
        }
Пример #21
0
 public static Player GetClosestUncovered(this Player player, Team friends, Team enemies)
 {
     var partner = (from p in friends.Players
                    where p != player
                    where p.PlayerType != PlayerType.Keeper
                    let curdist = p.GetDistanceTo(Field.EnemyGoal.Center)
                    let dist = player.GetDistanceTo(p)
                    //let plrdist = player.Position.GetDistanceTo(Field.EnemyGoal.Center)
                    //where curdist < plrdist
                    //where dist < 500
                    orderby curdist descending, dist descending
                    let line = Line.One(p, player)
                    let es = from ep in enemies.Players
                             let y1 = line.K * ep.Position.X + line.B
                             where Math.Abs(ep.Position.Y - y1) > 50
                             where Math.Abs(ep.GetDistanceTo(p) - dist) > 50
                             select ep
                    where !es.Any()
                    select p).FirstOrDefault();
     return partner;
 }
Пример #22
0
        //shoot power table
        //speed will equal to shoot power                   in best case
        //                    previous in table shoot power in case of fumbled pass
        //10 : 11.8
        //9: 10.6
        //8: 9.4
        //7: 8.3
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            var setup = myTeam.Players.First(pl => pl.PlayerType == PlayerType.CenterForward);
            var pl1 = myTeam.Players.First(pl => pl.PlayerType == PlayerType.RightForward);
            var pl2 = myTeam.Players.First(pl => pl.PlayerType == PlayerType.LeftForward);

            if (!setupDone)
            {
                if (setup.CanPickUpBall(ball))
                {
                    setup.ActionPickUpBall();
                    return;
                }
                if (ball.Owner == setup)
                {
                    setup.ActionShoot(pl1, 8);
                    setupDone = true;
                    return;
                }
                setup.ActionGo(ball);
                return;
            }

            myTeam.DevMessage += string.Format("current power {0}, ball speed {1}", currentIter, ball.Velocity.Length);

            if (counter >= 9)
            {
                ++currentIter;
                counter = 0;
            }
            
            var currentPower = Constants.PlayerMaxShootStr*currentIter/10;

            if (ball.Owner == pl1)
            {
                pl1.ActionShoot(pl2, currentPower);
                shooter = pl1.PlayerType;
                myTeam.DevMessage += string.Format("\r\nshooting with power {0}", currentPower);
                ++counter;
                return;
            }
            if (ball.Owner == pl2)
            {
                pl2.ActionShoot(pl1, currentPower);
                shooter = pl2.PlayerType;
                myTeam.DevMessage += string.Format("\r\nshooting with power {0}", currentPower);
                ++counter;
                return;
            }

            if (ball.Velocity.Length < 20)
            {
                if (shooter != pl1.PlayerType && pl1.CanPickUpBall(ball))
                {
                    pl1.ActionPickUpBall();
                    return;
                }
                if (shooter != pl2.PlayerType && pl2.CanPickUpBall(ball))
                {
                    pl2.ActionPickUpBall();
                    return;
                }

                if (pl1.GetDistanceTo(ball) < pl2.GetDistanceTo(ball))
                {
                    if (shooter != pl1.PlayerType)
                    {
                        pl1.ActionGo(ball);
                        return;
                    }
                }
                else
                {
                    if (shooter != pl2.PlayerType)
                    {
                        pl2.ActionGo(ball);
                        return;
                    } 
                }
            }


        }
Пример #23
0
 public static Vector AttackGoal(Ball ball, Team enemies)
 {
     Player player = ball.Owner;
     Team friends = player.Team;
     return Field.EnemyGoal.Center;
 }
Пример #24
0
 public void SaveTeam(Team team)
 {
     this._dalLogics.SaveTeam(team);
 }
Пример #25
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            foreach (Player player in myTeam.Players)
            {
                Player closestEnemy = player.GetClosest(enemyTeam);
                switch (player.PlayerType)
                {
                    case PlayerType.Keeper:
                        if (ball.Owner == player)
                        {
                            var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                            if (partner != null)
                            {
                                var power = player.GetDistanceTo(partner) / 10;
                                player.ActionShoot(partner, power);
                                continue;
                            }
                            else
                            {
                                // todo: shoot just to enemy side
                                player.ActionShootGoal();
                                continue;
                            }
                        }
                        if (player.GetDistanceTo(ball) < 50 
                            && player.CanPickUpBall(ball))
                        {
                            player.ActionPickUpBall();
                            continue;
                        }
                        if (ball.GetClosest(myTeam) == player
                            && ball.GetClosest(enemyTeam).GetDistanceTo(ball) < player.GetDistanceTo(ball)
                            && ball.GetDistanceTo(Field.MyGoal.Center) < 400)
                        {
                            player.ActionGo(ball.Position);
                            continue;
                        }

                        var direction = GoalKeeper.ChooseDirection(player, ball);
                        player.ActionGo(direction);
                        continue;

                    default:
                        if (ball.Owner == player)
                            if (player.GetDistanceTo(Field.EnemyGoal.Center) > 400)
                            {
                                var inters = player.GetClosestInterceptors(enemyTeam, 400);
                                if (!inters.Any())
                                {
                                    player.ActionGo(Field.EnemyGoal.Center);
                                    continue;
                                }
                                else if (inters.Count() >= 3)
                                {
                                    var partner = player.GetClosestUncovered(myTeam, enemyTeam);
                                    if (partner != null) player.ActionShoot(partner, 100);
                                }
                                var goalDirect = (Field.EnemyGoal.Center - player.Position).GetDirection();
                                var direct = (from i in inters
                                              select (i.Velocity) + (player.Position - i.Position).GetDirection() * (1 - i.GetDistanceTo(player) / 500))
                                              .Aggregate(Vector.Zero, (acc, v) => acc + v).GetDirection() + goalDirect;
                                var dest = player.Position + direct;
                                //if (direct.X < -50 && partner != null)
                                //{
                                //    player.ActionShoot(partner, 100);
                                //    continue;
                                //}
                                //else 
                                //    if (dest.Y < Field.Borders.Top.Y + 200
                                //    || dest.Y > Field.Borders.Bottom.Y - 200)
                                //{
                                //    player.ActionGo(dest + goalDirect * 2);
                                //    continue;
                                //}
                                //else 
                                //        if (dest.X > Field.Borders.Right.X - 100)
                                //{
                                //    player.ActionGo(Field.Borders.Center);
                                //    continue;
                                //}
                                //else 
                                //if (Field.Borders.Contains(dest))
                                //{
                                    player.ActionGo(dest);
                                    continue;
                                //}
                                //else
                                //{
                                //    player.ActionGo(Field.EnemyGoal.Center);
                                //    continue;
                                //}
                            }
                            else
                            {
                                //var goalkepers = from ep in enemyTeam.InFrontOf(player)
                                //                 ;

                                player.ActionShootGoal();
                            }
                        break;
                }

                if (ball.Owner == player) //Allways shoots for the enemy goal.
                { }
                else if (player.CanPickUpBall(ball)) //Picks up the ball if posible.
                    player.ActionPickUpBall();

                else if (player.CanTackle(closestEnemy)
                         && ball.Owner == closestEnemy) //Tackles any enemy that is close.
                    player.ActionTackle(closestEnemy);

                else if (player == ball.GetClosest(myTeam)) //If the player is closest to the ball, go for it.
                {
                    var balldirect = ball.Velocity.GetDirection();
                    var ndirect = new Vector(-balldirect.Y, balldirect.X);
                    var direct = (ball.Position - player.Position).GetDirection() * 10;
                    if (direct.Length < 50)
                        player.ActionGo(ball);
                    else
                        player.ActionGo(direct + ndirect);
                }
                else if (player.CanTackle(closestEnemy)) //Tackles any enemy that is close.
                    player.ActionTackle(closestEnemy);
                else //If the player cannot do anything urgently usefull, move to a good position.
                {
                    if (player.PlayerType == PlayerType.Keeper) //The keeper protects the goal.
                    { }
                    //The keeper positions himself 50 units out from the goal                                                                                                            //at the same height as the ball, although never leaving the goal
                    else if (player.PlayerType == PlayerType.LeftDefender)
                        player.ActionGo(new Vector(Field.Borders.Width * 0.2, ball.Position.Y));
                    //The left defender helps protect the goal
                    else if (player.PlayerType == PlayerType.RightDefender)
                        player.ActionGo(Field.MyGoal.GetClosest(enemyTeam));
                    //The right defender chases the enemy closest to myGoal
                    else if (player.PlayerType == PlayerType.RightForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Bottom + ball.Position) / 3);
                    //Right forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.LeftForward)
                        player.ActionGo((Field.Borders.Center + Field.Borders.Top + ball.Position) / 3);
                    //Left forward stays in position on the midline, untill the ball comes close.
                    else if (player.PlayerType == PlayerType.CenterForward)
                        player.ActionGo((Field.Borders.Center + Field.EnemyGoal.Center + ball.Position) / 3);
                    //Center forward stays in position on the enemy side of the field.
                }
            }
        }
Пример #26
0
 public Game(Team teamA, Team teamB)
 {
     this.TeamA = teamA;
     this.TeamB = teamB;
     this.GameSnapshots = new List<GameSnapShot>();
 }