private void StartGameImmediately() { if (!Validate()) { return; } GamePlayer blackPlayer = BlackPlayer.Build(StoneColor.Black, TimeControl, BlackPlayerSettings); GamePlayer whitePlayer = WhitePlayer.Build(StoneColor.White, TimeControl, WhitePlayerSettings); BlackPlayerSettings.SaveAsInterfaceMementos(); WhitePlayerSettings.SaveAsInterfaceMementos(); LocalGame game = GameBuilder.CreateLocalGame(). BoardSize(SelectedGameBoardSize). Ruleset(SelectedRuleset). Komi(float.Parse(CompensationString, CultureInfo.InvariantCulture)). Handicap(Handicap). HandicapPlacementType( IsHandicapFixed ? HandicapPlacementType.Fixed : HandicapPlacementType.Free). WhitePlayer(whitePlayer). BlackPlayer(blackPlayer). Build(); Mvx.RegisterSingleton <IGame>(game); // Navigate to specific View Model if (_bundle.Style == GameCreationFormStyle.LocalGame) { OpenInNewActiveTab <LocalGameViewModel>(); } else { OpenInNewActiveTab <OnlineGameViewModel>(); } }
private bool Validate() { ValidationErrorMessage = ""; if (Bundle.SupportsOnlySquareBoards && !SelectedGameBoardSize.IsSquare) { ValidationErrorMessage = Localizer.Validation_YouMustSelectASquareBoard; return(false); } if (SelectedGameBoardSize.Width < 2 || SelectedGameBoardSize.Height < 2) { ValidationErrorMessage = Localizer.Validation_YouMustHave2x2OrGreater; return(false); } if (SelectedGameBoardSize.Width > 52 || SelectedGameBoardSize.Height > 52) { ValidationErrorMessage = Localizer.Validation_BoardTooExtreme; return(false); } if (Handicap != 0) { if (SelectedGameBoardSize.IsSquare) { if (SelectedGameBoardSize.Width != 9 && SelectedGameBoardSize.Width != 13 && SelectedGameBoardSize.Width != 19) { ValidationErrorMessage = LocalizedStrings.Validation_ImproperHandicapForSize; return(false); } } else { ValidationErrorMessage = LocalizedStrings.Validation_ImproperHandicapForSize; return(false); } } float compensation; if (float.TryParse(CompensationString, NumberStyles.Any, CultureInfo.InvariantCulture, out compensation)) { float fractionalpart = compensation - (int)compensation; // ReSharper disable CompareOfFloatsByEqualityOperator if (fractionalpart != 0 && fractionalpart != 0.5f) { ValidationErrorMessage = Localizer.Validation_YouMustHaveHalfInteger; return(false); } // ReSharper restore CompareOfFloatsByEqualityOperator if (Bundle.IsKgs) { if (compensation < -100 || compensation > 100) { ValidationErrorMessage = Localizer.Validation_YouMustHaveSmallerKomi; return(false); } } if (compensation < -500 || compensation > 500) { ValidationErrorMessage = Localizer.Validation_KomiTooExtreme; return(false); } } else { ValidationErrorMessage = Localizer.Validation_YouMustHaveHalfInteger; return(false); } string errorMessage = "Error loading AI information."; // <-- Should never display. if (!BlackPlayerSettings.Validate(this, ref errorMessage)) { ValidationErrorMessage = errorMessage; return(false); } if (!WhitePlayerSettings.Validate(this, ref errorMessage)) { ValidationErrorMessage = errorMessage; return(false); } string timeErrorMessage = "Error parsing time control settings."; // <-- Should never display. if (!TimeControl.Validate(ref timeErrorMessage)) { ValidationErrorMessage = timeErrorMessage; return(false); } if (Bundle.IsIgs) { if (SelectedGameBoardSize.Width < 5) { ValidationErrorMessage = Localizer.Validation_YouMustHave5x5OrGreater; return(false); } if (SelectedGameBoardSize.Width > 19) { ValidationErrorMessage = Localizer.Validation_YouMustHave19x19OrSmaller; return(false); } if (SelectedColor == StoneColor.None) { // This should never happen. ValidationErrorMessage = Localizer.Validation_NigiriIsForbidden; return(false); } } if (Bundle.IsKgs) { if (SelectedGameBoardSize.Width > 38) { ValidationErrorMessage = Localizer.Validation_YouMustHave38x38OrSmaller; return(false); } } return(true); }