private void DoNewGame(string fen, GameMode gameMode, GameType gameType, OptionsBlitzClock blitzClock, OptionsLongClock longClock) { NewGameEventArgs args = new NewGameEventArgs(); if (BeforeNewGame != null) { BeforeNewGame(this, args); } if (args.Cancel) { return; } if (SaveDocking != null) { SaveDocking(this, EventArgs.Empty); } GameStartTimeLocal = DateTime.Now; Ap.Options.CurrentGameGuid = string.Empty; Stop(); InitialBoardFen = fen; PreviousGameMode = GameMode; PreviousPonderMove = string.Empty; GameMode = gameMode; GameType = gameType; #region Init //GameValidator = new GameW(this.InitialBoardFen); GameValidator.SetFen(this.InitialBoardFen); SpaceBarCounter = 0; CloseEngines(); if (GameType == GameType.Long) { GameTime.Init(longClock, true); } else { GameTime.Init(blitzClock, true); } if (Flags.IsBookLoadRequired) { Book.Load(null); } GameResult = GameResultE.InProgress; Reset(); if (DbGame != null && DbGame.IsFinished) { this.GameResult = DbGame.GameResultIDE; this.Flags.SetFlags(DbGame.GameFlags); } CurrentMove = RootMove.Clone(); Moves.Clear(); CurrentLine = null; #endregion #region Switch GameMode switch (GameMode) { case GameMode.None: break; case GameMode.HumanVsHuman: #region HumanVsHuman GameTime.TimeMin = 0; GameTime.GainPerMove = 0; Player1.Engine = null; Player2.Engine = null; Player2.Book = Book; Player1.PlayerTitle = Ap.UserProfile.LastName; Player2.PlayerTitle = "InfinityChess"; GameData.SetPlayers(Player1.PlayerTitle, Ap.UserProfile.FirstName, Player2.PlayerTitle, ""); gameTypeTitle = Ap.GetGameTypeTitle(GameType); #endregion break; case GameMode.HumanVsEngine: #region HumanVsEngine Player2EngineFileName = InfinitySettings.Settings.DefaultEngineXml.FilePath; Player1.Engine = null; if (DefaultEngine == null) { Player2.Engine = UCIEngine.Load(Player2EngineFileName, Options.DefaultHashTableSize, this); Player2.Engine.UseTablebases = Ap.EngineOptions.UseTablebases; DefaultEngine = Player2.Engine; } else { Player2.Engine = DefaultEngine; } Player2.Book = Book; DefaultBook = Player2.Book; Player1.PlayerTitle = Ap.UserProfile.LastName; Player2.PlayerTitle = Player2.Engine.EngineName; GameData.SetPlayers(Player1.PlayerTitle, Ap.UserProfile.FirstName, Player2.PlayerTitle, ""); gameTypeTitle = Ap.GetGameTypeTitle(GameType); #endregion break; case GameMode.EngineVsEngine: #region EngineVsEngine Player1.Engine = UCIEngine.Load(Player1EngineFileName, Player1EngineHashTableSize, this); Player1.Engine.UseTablebases = Ap.EngineOptions.UseTablebases; Player2.Engine = UCIEngine.Load(Player2EngineFileName, Player2EngineHashTableSize, this); Player2.Engine.UseTablebases = Ap.EngineOptions.UseTablebases; Player1.PlayerTitle = Player1.Engine.EngineName; Player2.PlayerTitle = Player2.Engine.EngineName; if (Player1.Book != null) { Player1.Book.NewGame(); } if (Player2.Book != null) { Player2.Book.NewGame(); } GameData.SetPlayers(Player1.PlayerTitle, "", Player2.PlayerTitle, ""); gameTypeTitle = Ap.GetGameTypeTitle(GameType); InitE2eResult(); #endregion break; case GameMode.OnlineHumanVsHuman: #region OnlineHumanVsHuman StartOnlineH2HGame(); #endregion break; case GameMode.OnlineHumanVsEngine: #region OnlineHumanVsEngine gameTypeTitle = Ap.GetGameTypeTitle(GameType); #endregion break; case GameMode.OnlineEngineVsEngine: #region OnlineEngineVsEngine if (Ap.PlayingMode.SelectedEngine == null) { StartOnlineH2HGame(); } else { StartOnlineE2EGame(); } #endregion break; case GameMode.Kibitzer: #region Kibitzer GameTime.Set(DbGame); GameResult = DbGame.GameResultIDE; Player1.PlayerTitle = DbGame.WhiteUser.UserName + " " + DbGame.WhiteUser.Engine.Name; Player2.PlayerTitle = DbGame.BlackUser.UserName + " " + DbGame.BlackUser.Engine.Name; if (DbGame.IsRated) { gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "' + " + DbGame.GainPerMoveMin.ToString() + "'', " + "Rated"; if (DbGame.EloBlackBefore != 0 && !DbGame.BlackUser.IsGuest) { Player2.PlayerTitle += " " + DbGame.EloBlackBefore.ToString(); } if (DbGame.EloWhiteBefore != 0 && !DbGame.WhiteUser.IsGuest) { Player1.PlayerTitle += " " + DbGame.EloWhiteBefore.ToString(); } } else { gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "' + " + DbGame.GainPerMoveMin.ToString() + "'', " + "Unrated"; } GameData.SetPlayers(Player1.PlayerTitle, "", Player2.PlayerTitle, ""); #endregion break; default: break; } #endregion if (DefaultEngine != null) { if (DefaultEngine.IsClosed) { DefaultEngine.Load(); } } Flags.IsEngineBlack = true; #region Start Clock.NewGame(); Notations.NewGame(); if (Flags.IsBookLoadRequired) { Book.NewGame(); } CapturedPieces.NewGame(); GameData.NewGame(); Clipboard.Reset(); GameData.Tournament = GameTypeTitle; Ap.Options.GameType = gameType; Ap.Options.Save(); #endregion if (CreateDocking != null) { CreateDocking(this, EventArgs.Empty); } Flags.IsInfiniteAnalysisOn = false; MediaPlayer.PlaySound(SoundFileNameE.SetPieces); SetFen(fen); Flags.IsBoardSetByFen = fen != ChessLibrary.FenParser.InitialBoardFen; if (Flags.IsOnline && DbGame != null) { Flags.IsChallengerSendsGame = DbGame.IsChallengerSendsGame; } SetSuddenDeathMatchTime(); if (AfterNewGame != null) { AfterNewGame(this, EventArgs.Empty); } }
public void NewGame(string fen, GameMode gameMode, GameType gameType, OptionsBlitzClock blitzClock, OptionsLongClock longClock) { Stop(); InitialBoardFen = fen; GameMode = gameMode; GameType = gameType; if (BeforeNewGame != null) { BeforeNewGame(this, EventArgs.Empty); } #region Init GameValidator = new GameW(this.InitialBoardFen); SpaceBarCounter = 0; CloseEngines(); if (GameType == GameType.LongGame) { GameTime.Init(longClock, true); } else { GameTime.Init(blitzClock, true); } GameResult = GameResultE.InProgress; CurrentMove = null; Flags.Reset(); #endregion #region Switch gameMode switch (GameMode) { case GameMode.None: break; case GameMode.HumanVsHuman: Player1.PlayerType = PlayerType.Human; Player2.PlayerType = PlayerType.Human; Player1.Engine = null; Player2.Engine = null; Player1.PlayerTitle = GameData.WhiteTitle; Player2.PlayerTitle = GameData.BlackTitle; break; case GameMode.HumanVsEngine: Player1.PlayerType = PlayerType.Human; Player2.PlayerType = PlayerType.Engine; Player2EngineFileName = InfinitySettings.Settings.DefaultEngineXml.FilePath; Player1.Engine = null; if (DefaultEngine == null) { Player2.Engine = UCIEngine.Load(Player2EngineFileName, Options.DefaultHashTableSize); Player2.Engine.UseTablebases = EngineParameters.UseTablebases; DefaultEngine = Player2.Engine; } else { Player2.Engine = DefaultEngine; } Player2.Book = Book; DefaultBook = Player2.Book; Player1.PlayerTitle = Ap.UserProfile.LastName; Player2.PlayerTitle = Player2.Engine.EngineName; break; case GameMode.EngineVsEngine: Player1.PlayerType = PlayerType.Engine; Player2.PlayerType = PlayerType.Engine; Player1.Engine = UCIEngine.Load(Player1EngineFileName, Player1EngineHashTableSize); Player1.Engine.UseTablebases = EngineParameters.UseTablebases; Player2.Engine = UCIEngine.Load(Player2EngineFileName, Player2EngineHashTableSize); Player2.Engine.UseTablebases = EngineParameters.UseTablebases; Player1.PlayerTitle = Player1.Engine.EngineName; Player2.PlayerTitle = Player2.Engine.EngineName; break; case GameMode.OnlineHumanVsHuman: #region OnlineHumanVsHuman StartOnlineH2HGame(); #endregion break; case GameMode.OnlineHumanVsEngine: break; case GameMode.OnlineEngineVsEngine: if (PlayingMode.SelectedEngine == null) { StartOnlineH2HGame(); } else { StartOnlineE2EGame(); } break; case GameMode.Kibitzer: #region Kibitzer GameTime.Set(DbGame); GameResult = DbGame.GameResultIDE; //GameResultE.InProgress; Player1.PlayerType = PlayerType.Human; Player1.PlayerTitle = DbGame.WhiteUser.UserName; Player2.PlayerType = PlayerType.Human; Player2.PlayerTitle = DbGame.BlackUser.UserName; if (DbGame.IsRated) { gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "m + " + DbGame.GainPerMoveMin.ToString() + "s, " + "Rated"; if (DbGame.EloBlackBefore != 0 && !DbGame.BlackUser.IsGuest) { Player2.PlayerTitle += " " + DbGame.EloBlackBefore.ToString(); } if (DbGame.EloWhiteBefore != 0 && !DbGame.WhiteUser.IsGuest) { Player1.PlayerTitle += " " + DbGame.EloWhiteBefore.ToString(); } } else { gameTypeTitle = GameType.ToString() + " " + DbGame.TimeMin.ToString() + "m + " + DbGame.GainPerMoveMin.ToString() + "s, " + "Unrated"; } #endregion break; default: break; } #endregion if (DefaultEngine != null) { if (DefaultEngine.IsClosed) { DefaultEngine.Load(); } } Flags.IsEngineBlack = true; #region Start gameTypeTitle = Ap.GetGameTypeTitle(GameType); Player1.Active = true; Player2.Active = false; Notations.SetupNewGame(); CapturedPieces.SetupNewGame(); Clock.SetupNewGame(); Book.SetupNewGame(); Clipboard.Reset(); CurrentPlayer = Player1; GameData.SetupNewGame(); if (Flags.IsChangeNamesAllowed) { GameData.White1 = Player1.PlayerTitle; GameData.White2 = Ap.UserProfile.FirstName; GameData.Black1 = Player2.PlayerTitle; } GameData.Tournament = GameTypeTitle; InitTablebases(); Ap.Options.GameType = gameType; Ap.Options.Save(); #endregion if (CreateDocking != null) { CreateDocking(this, EventArgs.Empty); } Flags.IsInfiniteAnalysisOn = false; SetFen(fen); if (Flags.IsOnline) { // Flags.IsChallengerSendsGame = Flags.IsPositionSetupAllowed; } if (AfterNewGame != null) { AfterNewGame(this, EventArgs.Empty); } }