public void Init() { currentMoveNumber = this.Game.NextMoveNo; isWhite = this.Game.NextMoveIsWhite; GameWrapper = new GameW(ChessLibrary.FenParser.InitialBoardFen); this.UciEngine.InfoReceived += new UCIEngine.InfoReceivedHandler(this.UciEngine_InfoReceived); this.Game.AfterSwapPlayers += new EventHandler(Game_AfterSwapPlayers); if (IsKibitzer) { return; } switch (this.Game.GameMode) { case GameMode.HumanVsEngine: case GameMode.OnlineHumanVsEngine: case GameMode.OnlineEngineVsEngine: if (Game.DefaultBook != null) { Game.DefaultBook.MoveReceived += new UCIEngine.MoveReceivedHandler(Book_MoveReceived); } break; case GameMode.EngineVsEngine: if (AmIPlayer1) { if (Game.Player1.Book != null) { Game.Player1.Book.MoveReceived += new UCIEngine.MoveReceivedHandler(Book_MoveReceived); } } else { if (Game.Player2.Book != null) { Game.Player2.Book.MoveReceived += new UCIEngine.MoveReceivedHandler(Book_MoveReceived); } } break; case GameMode.Kibitzer: break; default: break; } }
private void LoadPvMoves() { g = new Game(); GameWrapper = new GameW(fen); string s = "test"; for (int i = 0; i < 10000; i++) { string pv = "b1c3 g8f6 g1f3 b8c6 e2e4 e7e6 d2d4 d7d5 e4d5 f6d5 f1d3 f8e7"; Moves moves = LoadMoves(pv); s = GetMovesString(moves); moves = null; GC.Collect(); } MessageForm.Show("Finished : " + s); }
public Game() { RootMove = GetRootMove(); CurrentMove = RootMove.Clone(); Flags = new GameFlags(this); //PlayingMode = new PlayingMode(this); Clipboard = new Clipboard(this); Notations = new Notations(this); GameTime = new GameTime(this); GameData = new GameData(this); Book = new Book(this); Clock = new Clock(this); CapturedPieces = new CapturedPieces(this); Moves = new Moves(this); GameValidator = new GameW(this.InitialBoardFen); Player1 = new Player(this, PlayerColorE.White); Player2 = new Player(this, PlayerColorE.Black); }
public void SetFen(string fen) { if (string.IsNullOrEmpty(fen) || !GameValidator.IsValidFen(fen)) { return; } if (BeforeSetFen != null) { BeforeSetFen(this, EventArgs.Empty); } GameValidator = new GameW(fen); if (Flags.IsOffline) { if (Flags.IsClickedByUser) { if (IsSwapPlayersRequired) { SwapPlayers(); } } else { Clock.Reset(); Clock.Stop(); GameResult = GameResultE.InProgress; } Flags.EnPassant = SquareE.NoSquare; ResetCounters(); } if (AfterSetFen != null) { AfterSetFen(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); } }