void moveToWorker_DoWork(object sender, DoWorkEventArgs e) { if (BeforePaste != null) { BeforePaste(this, EventArgs.Empty); } DataTable moves = e.Argument as DataTable; Moves.DataTable.Clear(); Notations.NotationView.Clear(); bool b = Flags.IsEngineOn; Flags.IsEngineOn = false; AddMoves(moves); Flags.IsEngineOn = b; if (Flags.IsOffline) { CurrentMove = RootMove.Clone(); Clock.Reset(); Clock.Stop(); GameResult = GameResultE.InProgress; } }
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); } }
private void SetInitialPosition() { CurrentMove = RootMove.Clone(); SetFen(InitialBoardFen); Book.MoveTo(CurrentMove); }