Ejemplo n.º 1
0
        /// <summary>
        /// Run all the matches for the current game date
        /// </summary>
        /// <param name="MatchCallback"></param>
        public void Run(IMatchCallback MatchCallback)
        {
            MatchPlayer    mp = new MatchPlayer();
            WorldAdapter   wa = new WorldAdapter();
            FixtureAdapter fa = new FixtureAdapter();
            TeamAdapter    ta = new TeamAdapter();
            ManagerAdapter ma = new ManagerAdapter();

            foreach (Fixture f in fa.GetFixtures(wa.CurrentDate))
            {
                mp.Fixture     = f;
                mp.Interactive = false;

                for (int t = 0; t <= 1; t++)
                {
                    if (ma.GetManager(ta.GetTeam(f.TeamIDs[t]).ManagerID).Human)
                    {
                        mp.Interactive = true;
                        break;
                    }
                }

                mp.MatchCallback = MatchCallback;
                mp.StartMatch();
            }

            MatchCallback.MatchdayComplete();
        }
Ejemplo n.º 2
0
        public void MatchDayEnd()
        {
            DirectorLogic  dl       = new DirectorLogic();
            List <Fixture> fixtures = new FixtureAdapter().GetFixtures(new WorldAdapter().CurrentDate);

            dl.GoodAndBadFixtureFeedback(fixtures);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loop round all AI teams, and select a team appropriate to play the fixture.
        /// </summary>
        public void SelectTeamIfPlaying()
        {
            FixtureAdapter fa = new FixtureAdapter();
            WorldAdapter   wa = new WorldAdapter();
            TeamAdapter    ta = new TeamAdapter();
            ManagerAdapter ma = new ManagerAdapter();

            List <Fixture> AllFixtures = fa.GetFixtures(wa.CurrentDate);

            int TESTf = 0;

            foreach (Fixture f in AllFixtures)
            {
                TESTf++;
                Debug.Print("Fixture " + f.ToString());

                for (int t = 0; t <= 1; t++)
                {
                    Team    ThisTeam = ta.GetTeam(f.TeamIDs[t]);
                    Manager M        = ma.GetManager(ThisTeam.ManagerID);


                    if (!M.Human)
                    {
                        Team          Opposition = ta.GetTeam(f.TeamIDs[1 - t]);
                        PlayerAdapter pa         = new PlayerAdapter();
                        int[,] PlayerGridPositions = new int[5, 8]; // TODO: Maybe not hard code these...
                        for (int x = 0; x <= PlayerGridPositions.GetUpperBound(0); x++)
                        {
                            for (int y = 0; y <= PlayerGridPositions.GetUpperBound(1); y++)
                            {
                                PlayerGridPositions[x, y] = -1;
                            }
                        }


                        Formation TeamFormation      = new FormationAdapter().GetFormation(ThisTeam.CurrentFormation);
                        List <AvailablePlayer> avail = GetEligiblePlayers(ThisTeam, f);

                        foreach (Point2 point in TeamFormation.Points)
                        {
                            AvailablePlayer SelPlayer = FindBestPlayerForPosition(point, avail);
                            if (SelPlayer == null)
                            {
                                throw new Exception("Unable to find a player for this position");
                            }

                            PlayerGridPositions[point.X, point.Y] = SelPlayer.PlayerID;
                            avail.Remove(SelPlayer);
                        }

                        ta.SavePlayerFormation(ThisTeam.UniqueID, TeamFormation.UniqueID, PlayerGridPositions);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void MatchDayEnd()
        {
            SeasonStats ss = new SeasonStats();

            ss.UpdateLastKnownPicks();

            List <Fixture> fixtures = new FixtureAdapter().GetFixtures(new WorldAdapter().CurrentDate);

            ss.UpdateMatchStats(fixtures);
        }
Ejemplo n.º 5
0
        public void AllPlayersDailyUpdate()
        {
            const double standardDailyIncrement = 7;

            PlayerAdapter  pa      = new PlayerAdapter();
            TeamAdapter    ta      = new TeamAdapter();
            FixtureAdapter fa      = new FixtureAdapter();
            List <Player>  players = pa.GetPlayers();

            for (int i = 0; i < players.Count; i++)
            {
                Player p = players[i];

                if (p.Health < 100)
                {
                    // If player was not in a game today, then we increase their health
                    bool doUpdate = true;

                    if (p.CurrentTeam != -1)
                    {
                        if (ta.GetPlayerSelectionStatus(p.UniqueID, p.CurrentTeam, false) != PlayerSelectionStatus.None)
                        {
                            if (fa.IsTodayAMatchDay(p.CurrentTeam))
                            {
                                doUpdate = false;
                            }
                        }
                    }


                    if (doUpdate)
                    {
                        double increment = standardDailyIncrement * ((double)p.Fitness / 100);
                        if (increment < 1)
                        {
                            increment = 1;
                        }

                        p.Health += increment;

                        if (p.Health > 100)
                        {
                            p.Health = 100;
                        }

                        pa.UpdatePlayer(p);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public ScreenReturnData MainButtonClick(int buttonId)
        {
            if (!MatchdayComplete)
            {
                Thread rm = new Thread(this.RunMatchday);
                rm.IsBackground = true;
                rm.Start();

                return(new ScreenReturnData(ScreenReturnCode.None));
            }
            else
            {
                FixtureAdapter fa = new FixtureAdapter();
                WorldAdapter   wa = new WorldAdapter();

                SetupData.Parent.ShowResultsScreen(fa.GetFixtures(wa.CurrentDate));
                return(new ScreenReturnData(ScreenReturnCode.None));
            }
        }
Ejemplo n.º 7
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			Shared = this;

			var asm = Assembly.GetExecutingAssembly ();
			Title = asm.GetName ().Name;

			ListAdapter = new FixtureAdapter (
				this,
				from t in asm.GetTypes ()
				where t.GetCustomAttributes (typeof (global::NUnit.Framework.TestFixtureAttribute), true).Length > 0
				orderby t.FullName
				select t);

			ListView.ItemClick += (s, e) => {
				var f = ((FixtureAdapter)ListAdapter)[e.Position];
				var i = new Intent (this, typeof(FixtureActivity));
				i.PutExtra ("FixtureFullName", f.FullName);
				StartActivity (i);
			};
		}
Ejemplo n.º 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Shared = this;

            var asm = Assembly.GetExecutingAssembly();

            Title = asm.GetName().Name;

            ListAdapter = new FixtureAdapter(
                this,
                from t in asm.GetTypes()
                where t.GetCustomAttributes(typeof(global::NUnit.Framework.TestFixtureAttribute), true).Length > 0
                orderby t.FullName
                select t);

            ListView.ItemClick += (s, e) => {
                var f = ((FixtureAdapter)ListAdapter)[e.Position];
                var i = new Intent(this, typeof(FixtureActivity));
                i.PutExtra("FixtureFullName", f.FullName);
                StartActivity(i);
            };
        }
Ejemplo n.º 9
0
        private void NextManagerOrContinueDay()
        {
            ManagerAdapter ma = new ManagerAdapter();
            FixtureAdapter fa = new FixtureAdapter();
            WorldAdapter   wa = new WorldAdapter();
            TeamAdapter    ta = new TeamAdapter();

            if (HumanManagers == null)
            {
                // Going to first manager, which means we have to run Start Of Day, unless loading from a savegame
                if (!SaveGameJustLoaded)
                {
                    RunProcesses(false);
                }
                else
                {
                    SaveGameJustLoaded = false;
                }



                HumanManagers       = ma.GetHumanManagers();
                PlayingHumanManager = 0;
                wa.CurrentManagerID = HumanManagers[PlayingHumanManager].UniqueID;

                if (HumanManagers.Count() < 1)
                {
                    throw new Exception("No human managers");
                }
            }
            else
            {
                // Check selections if a matchday
                if (fa.IsTodayAMatchDay(HumanManagers[PlayingHumanManager].CurrentTeam))
                {
                    const int REQUIREDCOUNT = 11;
                    int       PlayerCount   = ta.CountSelectedPlayers(HumanManagers[PlayingHumanManager].CurrentTeam);
                    if (PlayerCount < REQUIREDCOUNT)
                    {
                        UiUtils.OpenDialogBox(UiUtils.MainWindowGrid, LangResources.CurLang.MatchDay,
                                              string.Format(LangResources.CurLang.YouHaveNotSelectedEnoughPlayers, PlayerCount, REQUIREDCOUNT),
                                              new List <DialogButton>()
                        {
                            new DialogButton(LangResources.CurLang.OK, null, null)
                        });

                        return;
                    }
                }

                // Go to next human manager
                PlayingHumanManager++;
                if (PlayingHumanManager >= HumanManagers.Count())
                {
                    HumanManagers       = null;
                    wa.CurrentManagerID = -1;
                }
                else
                {
                    wa.CurrentManagerID = HumanManagers[PlayingHumanManager].UniqueID;
                }
            }

            if (HumanManagers != null)
            {
                // Display home screen for the current manager
                Manager PlayingManager = HumanManagers[PlayingHumanManager];
                ShowHomeScreenForCurrentManager(PlayingManager);

                if (fa.IsTodayAMatchDay(PlayingManager.CurrentTeam))
                {
                    Fixture f          = fa.GetNextFixture(PlayingManager.CurrentTeam, wa.CurrentDate);
                    int     Opposition = (f.TeamIDs[0] != PlayingManager.CurrentTeam ? f.TeamIDs[0] : f.TeamIDs[1]);
                    string  Message    = string.Format(LangResources.CurLang.YouHaveAMatchAgainst, ta.GetTeam(Opposition).Name);

                    UiUtils.OpenDialogBox(UiUtils.MainWindowGrid, LangResources.CurLang.MatchDay, Message,
                                          new List <DialogButton>()
                    {
                        new DialogButton(LangResources.CurLang.OK, null, null)
                    });
                }
            }
            else
            {
                if (fa.IsTodayAMatchDay())
                {
                    ShowGameScreen(new MatchdayMain(), true);
                }
                else
                {
                    RunProcesses(true);
                }
            }
        }
Ejemplo n.º 10
0
        public void CreateSeasonFixtures()
        {
            // First find first available Saturday
            WorldAdapter wa             = new WorldAdapter();
            DateTime     FirstMatchDate = wa.MainSeasonDate;

            while (FirstMatchDate.DayOfWeek != DayOfWeek.Saturday)
            {
                FirstMatchDate = FirstMatchDate.AddDays(1);
            }

            FixtureAdapter fa = new FixtureAdapter();

            fa.ClearFixtures();

            LeagueAdapter la      = new LeagueAdapter();
            List <League> Leagues = la.GetLeagues();

            foreach (League L in Leagues)
            {
                // Get teams in the league we're looking at.
                TeamAdapter ta       = new TeamAdapter();
                List <Team> TeamList = ta.GetTeamsByLeague(L.UniqueID);

                // Create that league's fixtures (Circle Method)
                // https://en.wikipedia.org/wiki/Round-robin_tournament

                int NumberOfTeams = TeamList.Count();
                int Half          = NumberOfTeams / 2;

                int[] TeamIDs = new int[NumberOfTeams + 1]; // Create a grid with an additional blank space to allow rotation
                for (int i = 0; i < TeamList.Count(); i++)
                {
                    TeamIDs[i] = TeamList[i].UniqueID;
                }
                TeamIDs[NumberOfTeams] = -999; // For debugging

                DateTime MatchDate = FirstMatchDate;

                for (int HomeAwayLeg = 1; HomeAwayLeg <= 2; HomeAwayLeg++)
                {
                    bool homeFirst = (HomeAwayLeg == 1);

                    for (int wk = 1; wk <= NumberOfTeams - 1; wk++)
                    {
                        // Make the week's fixtures
                        for (int gridpos = 0; gridpos < Half; gridpos++)
                        {
                            Fixture f = new Fixture();
                            f.Date     = MatchDate;
                            f.LeagueID = L.UniqueID;
                            if (homeFirst)
                            {
                                f.TeamIDs[0] = TeamIDs[gridpos];
                                f.TeamIDs[1] = TeamIDs[gridpos + Half];
                            }
                            else
                            {
                                f.TeamIDs[1] = TeamIDs[gridpos];
                                f.TeamIDs[0] = TeamIDs[gridpos + Half];
                            }

                            fa.AddFixture(f);
                        }

                        // Rotate the grid! (Clockwise, as opposed to the description in the wiki link)
                        // Top "row" (first half) need to move L to R
                        // Bottom "row" (second half) need to move R to L
                        // Bottom left cell moves into position 1 and position 0 doesn't move
                        // Comments below refer to 16 teams, grid positions 0-7 (top), 8-15 (bottom), 16 spare.

                        TeamIDs[NumberOfTeams] = TeamIDs[Half - 1]; // Top right cell to bottom row, spare cell
                        for (int i = Half - 2; i >= 1; i--)         // Move top row, except cell zero and rightmost cell, right one
                        {
                            TeamIDs[i + 1] = TeamIDs[i];
                        }
                        TeamIDs[1] = TeamIDs[Half];                     // Bottom left cell to position 1
                        for (int i = Half; i <= NumberOfTeams - 1; i++) // Shift entire bottom row (including spare, excluding bottom left) left by one cell
                        {
                            TeamIDs[i] = TeamIDs[i + 1];
                        }

                        // Go to next date
                        MatchDate = MatchDate.AddDays(7);
                        homeFirst = !homeFirst;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public void StartMatch()
        {
            mps = new MatchPlayerSupport(Interactive);

            if (Fixture == null)
            {
                throw new ArgumentNullException("Fixture not set");
            }

            if (Interactive == true && MatchCallback == null)
            {
                throw new ArgumentNullException("MatchCallback not set");
            }


            MatchStatus = new MatchStatus();
            MatchCallback.MatchStarting(Fixture, Interactive);


            for (int h = 1; h <= 2; h++)
            {
                MatchStatus.Segment = (h == 1 ? MatchSegment.FirstHalf : MatchSegment.SecondHalf);

                mps.PopulatePlayerStatuses(MatchStatus, Fixture);

                MatchStatus.BallX          = BALLXCENTRE;
                MatchStatus.BallY          = BALLYCENTRE;
                MatchStatus.PossessionTeam = h - 1; // TODO: Randomise for the start, but opposite team for second half.

                RaiseEvent(MatchEventType.KickOff);

                // TODO: Just in case we change the grid, this may need to change. But gets us whole numbers.
                //MatchStatus.BallX = (PossessionHome() ? Math.Floor(MatchStatus.BallX) : Math.Ceiling(MatchStatus.BallX));

                for (int s = 0; s <= Constants.MinsPerHalf * 60 - Constants.EventIntervalSecs; s += Constants.EventIntervalSecs)
                {
                    MatchStatus.TotalTimeUnits++;
                    MatchStatus.SegmentTimeSeconds = s;
                    MatchStatus.MatchTimeSeconds  += Constants.EventIntervalSecs;

                    DetermineNextEvent();
                    mps.UpdatePlayerHealthForMatch(MatchStatus);
                }

                MatchStatus.BallX = BALLXCENTRE;
                MatchStatus.BallY = BALLYCENTRE;

                if (h == 1)
                {
                    RaiseEvent(MatchEventType.HalfTime);
                }
                else
                {
                    RaiseEvent(MatchEventType.FullTime);
                }

                RaiseEvent(h == 1 ? MatchEventType.HalfTime : MatchEventType.FullTime);
            }

            Fixture.Score[0] = MatchStatus.Score[0];
            Fixture.Score[1] = MatchStatus.Score[1];
            Fixture.Played   = true;

            FixtureAdapter fa = new FixtureAdapter();

            fa.UpdateFixture(Fixture);
            mps.UpdatePlayerHealthForWorld(MatchStatus);
            MatchCallback.MatchFinished(Fixture, Interactive);
        }