private void ReplayButton_OnClick(object sender, RoutedEventArgs e) { if (ReplayDataGrid.SelectedValue == null) { return; } var replayFileName = ReplayDataGrid.SelectedItem as ReplayFile; if ((_visualizeWindow == null) || !_visualizeWindow.IsVisible) { _visualizeWindow?.Close(); _visualizeWindow = new VisualizeWindow(); _visualizeWindow.Show(); } _visualizeWindow.Visualize(replayFileName.FilePath); }
private void RunGameVsHuman() { Window.Dispatcher.BeginInvoke(new Action(() => { RandomTextBox.Text = _random.Next() + ""; var visualizeWindow = new VisualizeVsHumanWindow(GameConfig); visualizeWindow.Show(); var player1Property = Player1IsHumanCheckBox.IsChecked.GetValueOrDefault() ? AiProperty.CreateHumanProperty() : AiProperty.CreateProperty(Player1FileName); var player2Property = Player2IsHumanCheckBox.IsChecked.GetValueOrDefault() ? AiProperty.CreateHumanProperty() : AiProperty.CreateProperty(Player2FileName); visualizeWindow.Visualize(player1Property, player2Property); _visualizeWindow?.Close(); _visualizeWindow = visualizeWindow; StopGame(); })); }
private void RunGame() { var replayGameData = new ReplayGameData(); var currentRandom = new SpecialRand((uint)GameConfig.RandomSeed); GameConfig.Player1WonCount = 0; GameConfig.Player2WonCount = 0; for (var i = 0; i < MatchesCount; ++i) { while (true) { Thread.Sleep(30); if (_token.IsCancellationRequested) { return; } _gameMain.Update(); if (_gameMain.CurrentState != GameMain.GameStateEnum.Running) { _gameMain.GameLogger.WriteLine(_gameMain.CurrentState.ToString()); _ai1AiLogger.WaitEvents(); _ai2AiLogger.WaitEvents(); _gameLogger.WaitEvent(); var aiPlayer1 = _gameMain.GetPlayer(0) as AiPlayer; var aiPlayer2 = _gameMain.GetPlayer(1) as AiPlayer; var player1Replay = new ReplayPlayerData { LeftTimeOnLaunched = aiPlayer1.LeftTimeOnLaunched, OutputLines = aiPlayer1.AiOutputs, LeftThinkTimes = aiPlayer1.LeftThinkTimes }; var player2Replay = new ReplayPlayerData { LeftTimeOnLaunched = aiPlayer2.LeftTimeOnLaunched, OutputLines = aiPlayer2.AiOutputs, LeftThinkTimes = aiPlayer2.LeftThinkTimes }; var match = new ReplayMatchData { Player1ReplayData = player1Replay, Player2ReplayData = player2Replay, GameRandom = currentRandom, GameConfig = new GameConfig(GameConfig) }; replayGameData.Matches.Add(match); currentRandom = new SpecialRand(_gameMain.FixedRandom); Window.Dispatcher.BeginInvoke(new Action(() => { System.Windows.Forms.Application.DoEvents(); if (_gameMain.CurrentState == GameMain.GameStateEnum.Player1Won) { GameConfig.Player1WonCount++; } else if (_gameMain.CurrentState == GameMain.GameStateEnum.Player2Won) { GameConfig.Player2WonCount++; } BattleProgressTextBox.AppendText("Player1 " + GameConfig.Player1WonCount + "-" + GameConfig.Player2WonCount + " Player2\n"); BattleProgressTextBox.ScrollToEnd(); })).Wait(); _gameMain.Dispose(); if (i == MatchesCount - 1) { break; } var fileNames = new[] { Player1FileName, Player2FileName }; _gameMain = GameMain.Run(GameConfig, fileNames, true, _gameLogger, new[] { _ai1AiLogger, _ai2AiLogger }, _gameMain.FixedRandom); break; } } } var currentTime = DateTime.Now; var replayFileName = new StringBuilder(); replayFileName.Append(_replayFileFirectory); replayFileName.Append(currentTime.Year); replayFileName.Append($"{currentTime.Month:D2}"); replayFileName.Append($"{currentTime.Day:D2}_"); replayFileName.Append($"{currentTime.Hour:D2}"); replayFileName.Append($"{currentTime.Minute:D2}"); replayFileName.Append($"{currentTime.Second:D2}_"); replayFileName.Append(GameConfig.Player1WonCount + "-" + GameConfig.Player2WonCount + ".txt"); replayGameData.Save(replayFileName.ToString()); Window.Dispatcher.BeginInvoke(new Action(() => { if (_visualizeWindow == null) { _visualizeWindow = new VisualizeWindow(); } else { _visualizeWindow.Close(); } _visualizeWindow.Show(); _visualizeWindow.Visualize(replayFileName.ToString()); StopGame(); })); }