public void PointTo(Move m) { if (IsClosed) { return; } if (PointToMove != null) { if (m != null) { if (PointToMove.Id == m.Id && PointToMove.IsWhite == m.IsWhite && PointToMove.MoveNo == m.MoveNo) { return; } } } PointToMove = m.Clone(); // move where book is currently pointing to BookMoves.LoadChilds(m, BookMovesCollection); if (OnPointTo != null) { OnPointTo(this, EventArgs.Empty); } }
public void MoveTo(Move m) { if (m == null) { return; } if (m.Id == CurrentMove.Id) { return; } if (BeforeMoveTo != null) { BeforeMoveTo(this, new MoveToEventArgs(m)); } Flags.IsRetracMove = false; CurrentMove = m.Clone(); Clock.MoveTo(CurrentMove); Notations.MoveTo(CurrentMove); Book.MoveTo(CurrentMove); CapturedPieces.MoveTo(CurrentMove); SetFen(CurrentMove.Fen); SwapPlayersIfNeeded(); if (AfterMoveTo != null) { AfterMoveTo(this, new MoveToEventArgs(CurrentMove)); } }
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 MoveTo(MoveToE moveTo, bool moveFromBook) { Move m = null; if ((Flags.IsFirstMoveSelected || Flags.IsRootMoveSelected) && (moveTo == MoveToE.Previous || moveTo == MoveToE.First)) { if (Flags.IsRootMoveSelected) { return; } SetInitialPosition(); return; } if (moveFromBook && moveTo == MoveToE.Next) { Book.MoveTo(moveTo, true); return; } if (Flags.IsFirtMove && moveTo == MoveToE.Next) { return; } switch (moveTo) { case MoveToE.First: m = Moves.First; break; case MoveToE.Last: m = Moves.Last; break; case MoveToE.Next: m = GetNextMove(CurrentMove); break; case MoveToE.Previous: m = Moves.Prev(CurrentMove); break; case MoveToE.Up: break; case MoveToE.Down: break; default: break; } Flags.IsRetracMove = false; CurrentMove = m.Clone(); Clock.MoveTo(moveTo); Notations.MoveTo(moveTo); Book.MoveTo(moveTo, false); CapturedPieces.MoveTo(moveTo); SetFen(CurrentMove.Fen); SwapPlayersIfNeeded(); }
public Move AddMove(string from, string to, Pieces fromPiece, string fen, Move m, bool isSetFen) { #region On Before if (m == null) { return(null); } if (BeforeAddMove != null) { EngineMoveEventArgs em = new EngineMoveEventArgs(); em.BestMove = from + to; em.PonderMove = PonderMove; BeforeAddMove(this, em); } #endregion #region Before CurrentMove Import if (Flags.IsOnline && Flags.IsGameFinished) // due to time expire etc. { return(null); } if (Flags.IsOnline && (Flags.IsNotMyTurn || Flags.IsGameFinished)) { Clock.ToggleClock(m); } else { #region Prepare Move if (!m.Flags.IsPromotion) // promoted piece is already assigned in promotion dialog { m.Piece = fromPiece; } m.Id = NextMoveId; m.Pid = NextMovePid; m.MoveNo = NextMoveNo; m.IsWhite = NextMoveIsWhite; m.From = from; m.To = to; m.Fen = fen; if (Flags.IsEvalRequired) { if (!String.IsNullOrEmpty(CurrentPlayer.Engine.Points) && !String.IsNullOrEmpty(CurrentPlayer.Engine.Depth)) { m.SetEval(CurrentPlayer.Engine.Points, CurrentPlayer.Engine.Depth); } } if (Flags.IsExpectedMoveRequired) { if (!String.IsNullOrEmpty(CurrentPlayer.Engine.ExpectedMove)) { m.ExpectedMove = CurrentPlayer.Engine.ExpectedMove; } } #endregion #region IsVariation if (AddVariationMove(m)) { PlaySounds(m); return(null); } else { m.Flags.VariationType = this.VariationType; } #endregion #region Set Clock if (Flags.IsOnline) { if (!m.IsWhite) { Clock.WhiteTime += DbGame.GainPerMoveMin; } else { Clock.BlackTime += DbGame.GainPerMoveMin; } } else { if (m.IsWhite) { Clock.BlackTime += GameTime.GainPerMove; } else { Clock.WhiteTime += GameTime.GainPerMove; } } m.MoveTimeWhite = Clock.WhiteTime; m.MoveTimeBlack = Clock.BlackTime; m.MoveTime = Clock.MoveTime; if (this.Flags.IsFirtMove && this.Flags.IsInfiniteAnalysisOff) { Clock.Start(); } #endregion } #endregion Notations.AddMove(m); CurrentMove = m.Clone(); Moves.Import(CurrentMove); #region After CurrentMove Import SetCurrentLine(CurrentMove); CheckNextLongGamePhase(CurrentMove); CheckThreefoldRepetition(); SetCastlingFlags(CurrentMove.Piece, CurrentMove.From, CurrentMove.To); Flags.IsPieceMovedSuccessfully = true; #region Point Book if (GameMode != GameMode.EngineVsEngine && GameMode != GameMode.OnlineEngineVsEngine) { Book.PointTo(CurrentMove); } #endregion #region Update Captured Pieces if (CurrentMove.Flags.IsCapture) { CapturedPieces.Update(CurrentMove); } #endregion Flags.IsMoveInProgress = false; Flags.IsForceEngineToMove = false; #region Check Game Finish if (!Flags.IsDatabaseGame) { #region Mated if (Flags.IsMated) { Mated(); Flags.IsMoveInProgress = true; } #endregion #region StaleMated if (Flags.IsStaleMated) { StaleMated(); } #endregion #region ThreefoldRepetition if (Flags.IsThreeFoldRepetition) { ThreefoldRepetition(false); } #endregion #region InsufficientMaterial if (Flags.IsInsufficientMaterial) { InsufficientMaterial(); } #endregion } #endregion #region SetFen if (isSetFen) { SetFen(CurrentMove.Fen); } #endregion #region FifityMoves if (this.HalfMovesCounter >= 100) { FifityMoves(); } #endregion #region Set ECO, Play Sound etc. SearchEco(); CheckMoveLimit(); PlaySounds(m); Clock.ResetMoveTime(); VariationType = VariationTypeE.None; if (Flags.IsClockStartRequired) { Clock.Start(); } #endregion #region Send Move To Opponent if (Flags.IsUpdateGameRequired) { SocketClient.UpdateGameDataByGameID(DbGame.GameID, GetLastMoveXml(), GameResult, Flags.Flags, DbGame.OpponentUserID); } #endregion #endregion #region On After if (AfterAddMove != null) { AfterAddMove(this, EventArgs.Empty); } #endregion return(CurrentMove); }
public void MoveTo(MoveToE moveTo) { Move m = null; switch (moveTo) { case MoveToE.First: m = Moves.First; //Notations.MoveTo(moveTo); break; case MoveToE.Last: m = Moves.Last; break; case MoveToE.Next: m = Moves.Next(CurrentMove); //Notations.MoveTo(moveTo); break; case MoveToE.Previous: m = Moves.Prev(CurrentMove); //Notations.MoveTo(moveTo); break; case MoveToE.Up: break; case MoveToE.Down: break; default: break; } if (m == null && moveTo == MoveToE.Previous) { return; } if (m == null) { Book.MoveTo(moveTo, true); return; } if (CurrentMove.Id == m.Id) { Book.MoveTo(moveTo, true); } else { CurrentMove = m.Clone(); Flags.IsMoveInProgress = true; Flags.IsClickedByUser = true; Clock.Stop(); Clock.SetClock(CurrentMove); Flags.IsRetracMove = false; Flags.IsMoveInProgress = false; Notations.Set(); Book.MoveTo(moveTo, false); SetCapturedPiecesParameters(); CapturedPieces.MoveTo(moveTo); SetFen(CurrentMove.Fen); } }
public Move AddMove(string from, string to, Pieces fromPiece, string fen, Move m, bool isPastGame, bool isSetFen) { #region On Before if (m == null) { return(null); } if (BeforeAddMove != null) { BeforeAddMove(this, EventArgs.Empty); } #endregion if (isPastGame) { Clock.SetClock(m); } else { #region IsVariation if (Flags.IsVariation) { if (AddVariationMove()) { return(null); } else { m.Flags.VariationType = this.VariationType; } } #endregion #region Prepare Move if (!m.Flags.IsPromotion) // promoted piece is already assigned in promotion dialog { m.Piece = fromPiece; } m.Id = NextMoveId; m.Pid = NextMovePid; m.MoveNo = NextMoveNo; m.IsWhite = NextMoveIsWhite; m.From = from; m.To = to; m.Fen = fen; #endregion #region Set Clock if (Flags.IsOnline) { if (!m.IsWhite) { Clock.WhiteTime += DbGame.GainPerMoveMin; } else { Clock.BlackTime += DbGame.GainPerMoveMin; } } m.MoveTimeWhite = Clock.WhiteTime; m.MoveTimeBlack = Clock.BlackTime; m.MoveTime = Clock.MoveTime; Clock.Start(); #endregion } CurrentMove = m.Clone(); SetFenCastlingNotation(m.Piece, m.From, m.To); Flags.IsPieceMovedSuccessfully = true; CompareFlags(CurrentMove); Notations.SetMove(CurrentMove); Book.SetMove(CurrentMove); //if (CurrentMove.CapturedPiece != Pieces.NONE) //{ // SetCapturedPiecesParameters(); // CapturedPieces.AddPiece(); //} Flags.IsMoveInProgress = false; Flags.IsForceEngineToMove = false; Flags.IsManualMove = false; Flags.IsSpacebarClick = false; if (Flags.IsMated) { Mated(); Flags.IsMoveInProgress = true; } if (Flags.IsStaleMated) { StaleMated(); } if (Flags.IsThreeFoldRepetition) { ThreefoldRepetition(false); } if (this.HalfMovesCounter >= 100) { FifityMoves(); } TogglePlayers(); if (isSetFen) { SetFen(m.Fen); } Moves.Import(CurrentMove); VariationType = VariationTypeE.None; #region On After if (AfterAddMove != null) { AfterAddMove(this, EventArgs.Empty); } #endregion return(m); }