private async Task DoStart() { if (GameStatus == GameStatus.Finished) { gameService.StopGame(); GameProgress.Clear(); DebugMessages.Clear(); } GameStatus = GameStatus.Unloaded; if (string.IsNullOrWhiteSpace(DllPathInput)) { await NotificationService.Show(Captions.PvB_ErrorMsg_NoDllPath, Captions.ND_OkButtonCaption); return; } if (!File.Exists(DllPathInput)) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileDoesNotExist} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } Assembly dllToLoad; try { dllToLoad = Assembly.LoadFile(DllPathInput); } catch { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileIsNoAssembly} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } var uninitializedBotAndBotName = BotLoader.LoadBot(dllToLoad); if (uninitializedBotAndBotName == null) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_BotCanNotBeLoadedFromAsembly} [{dllToLoad.FullName}]", Captions.ND_OkButtonCaption); return; } MovesLeft = (Constants.GameConstraint.MaximalMovesPerGame + 1).ToString(); applicationSettingsRepository.LastUsedBotPath = DllPathInput; gameService.CreateGame(uninitializedBotAndBotName.Item1, uninitializedBotAndBotName.Item2, new GameConstraints(TimeSpan.FromSeconds(Constants.GameConstraint.BotThinkingTimeSeconds), Constants.GameConstraint.MaximalMovesPerGame)); ((Command)Capitulate).RaiseCanExecuteChanged(); }
private void OnNewBoardStateAvailable(BoardState boardState) { ((Command)Capitulate).RaiseCanExecuteChanged(); if (boardState == null) { GameStatus = GameStatus.Unloaded; TopPlayerName = "- - - - -"; TopPlayerWallCountLeft = 10; BottomPlayerWallCountLeft = 10; MovesLeft = "--"; TopPlayerRestTime = "--"; GameProgress.Clear(); } else { GameStatus = GameStatus.Active; TopPlayerName = boardState.TopPlayer.Player.Name; TopPlayerWallCountLeft = boardState.TopPlayer.WallsToPlace; BottomPlayerWallCountLeft = boardState.BottomPlayer.WallsToPlace; if (boardState.CurrentMover.PlayerType == PlayerType.BottomPlayer) { if (GameProgress.Count > 0) { GameProgress[GameProgress.Count - 1] = GameProgress[GameProgress.Count - 1] + $" {boardState.LastMove}"; } var currentMovesLeft = int.Parse(MovesLeft); MovesLeft = (currentMovesLeft - 1).ToString(); StopTimer(); } else { GameProgress.Add($"{GameProgress.Count + 1}: " + $"{boardState.LastMove}"); StartTimer(); } } }
public void OnButtonResetPressed() { GameProgress.Clear(); }
private async Task DoStartWithProgress(string filePath) { if (GameStatus == GameStatus.Finished) { gameService.StopGame(); GameProgress.Clear(); DebugMessages.Clear(); } GameStatus = GameStatus.Unloaded; if (string.IsNullOrWhiteSpace(DllPathInput)) { await NotificationService.Show(Captions.PvB_ErrorMsg_NoDllPath, Captions.ND_OkButtonCaption); return; } if (!File.Exists(DllPathInput)) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileDoesNotExist} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } Assembly dllToLoad; try { dllToLoad = Assembly.LoadFile(DllPathInput); } catch { await NotificationService.Show($"{Captions.PvB_ErrorMsg_FileIsNoAssembly} [{DllPathInput}]", Captions.ND_OkButtonCaption); return; } var uninitializedBotAndBotName = BotLoader.LoadBot(dllToLoad); if (uninitializedBotAndBotName == null) { await NotificationService.Show($"{Captions.PvB_ErrorMsg_BotCanNotBeLoadedFromAsembly} [{dllToLoad.FullName}]", Captions.ND_OkButtonCaption); return; } var progressFilePath = string.Empty; if (string.IsNullOrWhiteSpace(filePath)) { var dialog = new OpenFileDialog { Filter = "text-file|*.txt" }; var result = dialog.ShowDialog(); if (result.HasValue) { if (result.Value) { progressFilePath = dialog.FileName; } } } else { progressFilePath = filePath; } var progressText = File.ReadAllText(progressFilePath); var fileVerifier = progressFileVerifierFactory.CreateVerifier(); var verificationResult = fileVerifier.Verify(progressText, Constants.GameConstraint.MaximalMovesPerGame); switch (verificationResult) { case FileVerificationResult.EmptyOrInvalidFile: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_EmptyOrInvalidFile}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsInvalidMove: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsInvalidMove}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsTerminatedGame: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsTerminatedGame}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.FileContainsMoreMovesThanAllowed: { await NotificationService.Show($"{Captions.PvB_ErrorMsg_ProgressFileCannotBeLoaded} [{progressFilePath}]" + $"\n\n{Captions.PvB_ErrorMsg_Reason}:" + $"\n{Captions.FVR_FileContainsMoreMovesThanAllowed}", Captions.ND_OkButtonCaption); return; } case FileVerificationResult.ValidFile: { applicationSettingsRepository.LastUsedBotPath = DllPathInput; MovesLeft = (Constants.GameConstraint.MaximalMovesPerGame + 1).ToString(); gameService.CreateGame(uninitializedBotAndBotName.Item1, uninitializedBotAndBotName.Item2, new GameConstraints(TimeSpan.FromSeconds(Constants.GameConstraint.BotThinkingTimeSeconds), Constants.GameConstraint.MaximalMovesPerGame), progressText); ((Command)Capitulate).RaiseCanExecuteChanged(); return; } } }