public void OnActivate(MatchStateMachine matchStateMachine) { this.matchStateMachine = matchStateMachine; this.matchStateMachine.MatchInputProvider.Reset(); // this is done to change the list we add new messages to while we process a list // so one list will always be the one receiving messages, while the other will be processed in that frame // we switch to the other list at the beginning of the frame // This also avoids having to do list copy etc. which can lead to memory fragmentation unitStateMessageBuffer[0] = new List <UnitStateMessage>(); unitStateMessageBuffer[1] = new List <UnitStateMessage>(); PCMBuffer[0] = new List <PositionConfirmationMessage>(); PCMBuffer[1] = new List <PositionConfirmationMessage>(); unitAbilityMessageBuffer[0] = new List <UnitAbilityActivationMessage>(); unitAbilityMessageBuffer[1] = new List <UnitAbilityActivationMessage>(); unitSpawnMessageBuffer[0] = new List <UnitSpawnMessage>(); unitSpawnMessageBuffer[1] = new List <UnitSpawnMessage>(); messageReceiveDisposable = this.matchStateMachine.UDPClient.OnMessageReceive .Subscribe(OnMessageReceived); matchSimulation = new MatchSimulation(matchStateMachine.LocalPlayerId, matchStateMachine.MatchStartTimestamp, matchStateMachine.MatchInputProvider, matchStateMachine.MatchEventProvider, matchStateMachine.UDPClient, matchStateMachine.NetworkTimeService); }
public override void OnSpawn(MatchSimulationUnit unitState, MatchSimulation matchSimulation) { base.OnSpawn(unitState, matchSimulation); MatchSimulationLocalPlayer localPlayer = unitState as MatchSimulationLocalPlayer; if (localPlayer != null) { localPlayer.LocalAimingSubject .Subscribe(OnLocalAimingUpdate); } }
private void btnQuickSim_Click(object sender, EventArgs e) { MatchSimulation simulate = new MatchSimulation(); rctConsoleOutput.Clear(); simulate.T1winCount = 0; simulate.T2winCount = 0; simulate.DrawCount = 0; int limit = 1000; for (int i = 0; i < limit; i++) { rctConsoleOutput.AppendText($"\nSimulation #{i+1} " + simulate.quickSim(3, 5)); } rctConsoleOutput.AppendText($"\n----{limit} simulations were run - Results----" + "\nPuntarenas FC win count: " + simulate.T1winCount.ToString() + "\nJuventus win count: " + simulate.T2winCount.ToString() + "\nBoth teams drew: " + simulate.DrawCount.ToString()); }
public virtual void OnSpawn(MatchSimulationUnit unitState, MatchSimulation matchSimulation) { InitializeChildComponents(); transform.position = unitState.MovementState.Value.GetUnityPosition(); transform.rotation = unitState.MovementState.Value.GetUnityRotation(); unitState.MovementState .Subscribe(OnPositionRotationUpdate) .AddTo(this); healthbar.Initialize(unitState); matchSimulation.SimulationFrameSubject .Subscribe(UpdateToNextState) .AddTo(this); unitState.AbilityActivationSubject .Subscribe(abilityActivation => OnAbilityActivation(abilityActivation.Rotation, abilityActivation.StartFrame, abilityActivation.ActivationFrame)); }
private async Task RandSim(string token) { string caption; string imagePath; List <Team> teamList = new List <Team>(); MatchSimulation newMatch = new MatchSimulation(); ArrayList roster = new ArrayList(); delUpdateTextBox dlu = new delUpdateTextBox(updateTextBox); BotPost newPost = new BotPost(); teamList.Add(new Team() { TeamName = "Monarcas Morelia", TeamLeague = "Liga MX", TeamStrength = 65, TeamRoster = roster }); teamList.Add(new Team() { TeamName = "Real Madrid", TeamLeague = "La Liga", TeamStrength = 92, TeamRoster = roster }); teamList.Add(new Team() { TeamName = "LA FC", TeamLeague = "MLS", TeamStrength = 69, TeamRoster = roster }); teamList.Add(new Team() { TeamName = "Puntarenas FC", TeamLeague = "Liga FPD", TeamStrength = 99, TeamRoster = roster }); teamList.Add(new Team() { TeamName = "C.D. Olimpia", TeamLeague = "LNFPH", TeamStrength = 60, TeamRoster = roster }); teamList.Add(new Team() { TeamName = "Juventus", TeamLeague = "Serie A", TeamStrength = 91, TeamRoster = roster }); for (int i = 0; i < 5; i++) { rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + $"\n---Now simulating {teamList[i].TeamName} v. {teamList[i + 1].TeamName}---"); rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + $"\n---Now simulating {teamList[i].TeamName} v. {teamList[i + 1].TeamName}---"); caption = newMatch.simulateMatch(teamList[i].TeamName, teamList[i + 1].TeamName, teamList[i].TeamStrength, teamList[i + 1].TeamStrength); rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + "Match Result: " + caption); rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + "Attempting to post to Facebook..."); //postToFbText(token, caption); imagePath = newMatch.generateImage(i, i + 1, MatchSimulation.team1Score, MatchSimulation.team2Score, teamList[i].TeamName, teamList[i + 1].TeamName); imagePath = newMatch.generateImage(i, i + 1, MatchSimulation.team1Score, MatchSimulation.team2Score, teamList[i].TeamName, teamList[i + 1].TeamName); newPost.postToFbImage(BotPost.FB_PAGE_ID, token, imagePath, caption); string time = DateTime.Now.ToString("h:mm:ss:ffff tt"); rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + $"Match simulation has been posted to Facebook @ {time}. Next simulation will be run in 5 minute(s)..."); if (i == 5) { break; } Stopwatch timer = new Stopwatch(); timer.Start(); while (timer.Elapsed.TotalSeconds < 300) { } timer.Stop(); //await Task.Delay(10000); if (simStop == true) { rctConsoleOutput.BeginInvoke(dlu, $"\n\nSimulation Terminated @{DateTime.Now.ToString("h:mm:ss:ff tt")}"); btnRandomSim.Enabled = true; break; } } rctConsoleOutput.BeginInvoke(dlu, Environment.NewLine + "\n---All simulations completed---"); btnRandomSim.Enabled = true; }
public override void Display() { base.Display(); CurrentSeason.ProgressToNextWeek(); var fixtureRound = CurrentSeason.League.GetMatchWeekFixtures(CurrentSeason.Week); if (fixtureRound.LeagueRound > 0) { Output.WriteLine($"\nMatch Round {fixtureRound.LeagueRound}\n"); } foreach (LeagueFixture fixture in fixtureRound.LeagueRoundFixtures) { var homeTeam = fixture.HomeTeam.Name; var awayTeam = fixture.AwayTeam.Name; MatchSimulation.GetMatchResult(fixture); Output.WriteLine($"{homeTeam} {fixture.HomeGoals} - {fixture.AwayGoals} {awayTeam}"); } Output.WriteLine("\n"); Output.WriteLine("Takeovers"); var chairmanMoved = TakeoverSimulation.GetTakeovers(CurrentSeason.ChairmenList); foreach (FootballChairman chairman in chairmanMoved) { Output.WriteLine("{0,30}{1,30}{2,10}{3,10}{4,10}{5,10}{6,10}", chairman.ShortName, chairman.Happiness, chairman.CurrentClub != null ? chairman.CurrentClub.Name : "Free Agent", chairman.PreviousClub != null ? chairman.PreviousClub.Name : "Free Agent", chairman.Type, chairman.OverallRating, chairman.JustMoved); } Output.WriteLine("\n"); Output.WriteLine("Transfers"); var playersMoved = TransferSimulation.GetWeeklyTransfers(CurrentSeason.PlayerList); foreach (FootballPlayer player in playersMoved) { Output.WriteLine("{0,30}{1,30}{2,10}{3,10}{4,10}{5,10}{6,10}", player.ShortName, player.CurrentClub.Name, player.PreviousClub.Name, player.Position, player.Value, player.OverallRating, player.JustMoved); } Output.WriteLine("\n"); Output.WriteLine("Manager Movement"); var managerMovements = TransferManagerSimulation.GetManagerChanges(CurrentSeason.ManagerList); foreach (FootballManager manager in managerMovements) { Output.WriteLine("{0,30}{1,30}{2,10}{3,10}{4,10}{5,10}{6,10}", manager.ShortName, manager.CurrentClub != null ? manager.CurrentClub.Name : "Free Agent", manager.PreviousClub != null ? manager.PreviousClub.Name : "Free Agent", manager.OverallRating, manager.JustMoved); } Output.WriteLine("\n"); Input.ReadString("Press [Enter] to navigate home"); Program.NavigateHome(); }
public void OnUnitSpawn(byte unitId, byte unitType, MatchSimulationUnit unitState, MatchSimulation matchSimulation, bool isLocalPlayer = false) { GameObject unitGameobject; if (viewUnitPrefabs.TryGetValue(unitType, out unitGameobject)) { // TODO: get from pool instead GameObject spawnedGameObject = MonoBehaviour.Instantiate(unitGameobject); MatchSimulationViewUnit matchSimulationViewUnit; if (isLocalPlayer) { matchSimulationViewUnit = spawnedGameObject.AddComponent <MatchSimulationLocalPlayerViewUnit>(); CameraRoot.transform.SetParent(spawnedGameObject.transform); } else { matchSimulationViewUnit = spawnedGameObject.AddComponent <MatchSimulationViewUnit>(); } spawnedGameObject.SetActive(true); matchSimulationViewUnit.OnSpawn(unitState, matchSimulation); } }