private void AddMoveToMoveHistory(DetailedMove move, bool silent = false) { Player shouldBePlayer = Plies % 2 == 0 ? Player.White : Player.Black; if (move.Player != shouldBePlayer) { throw new ArgumentException(""); } ++Plies; if (move.Player == Player.White) { int No = Plies / 2 + 1; while (MoveHistory.Rows.Count < No) { MoveHistory.Rows.Add(); } MoveHistory.Last().No = No; MoveHistory.Last().WhiteDetailedMove = move; } else { MoveHistory.Last().BlackDetailedMove = move; } if (!silent) { SetSelection(Plies); } }
private void SetPosition(string fen) { IsSettingPosition = true; BoardHistory.SetInitialPosition(fen); MoveHistory.Clear(); Plies = 0; MoveHistory.Rows.Add(); MoveHistory.Last().No = 1; if (BoardHistory.Current().GCD.WhoseTurn == Player.Black) { BoardHistory.DuplicateLast(); MoveHistory.Last().WhiteDetailedMove = null; Plies = 1; SetSelection(1); } FirstPly = Plies; if (int.TryParse(fen.Split(' ').Last(), out int n)) { BaseMoveNumber = n; MoveHistory.BaseMoveNumber = n; foreach (MoveHistoryDataRow row in MoveHistory.Rows) { row.UpdateBaseMoveNumber(n); } } UpdateFenTextBox(fen); IsSettingPosition = false; }
public void UndoLastMove() { TicTacToeMove m = MoveHistory.Last() as TicTacToeMove; SetPosition(m.Position, 0); MoveHistory.RemoveAt(MoveHistory.Count - 1); }
private void UndoButton_Click(object sender, RoutedEventArgs e) { if (MoveHistory.Count < 1) { return; } Untrack(); Move lastMove = MoveHistory.Last(); Cell target = BoardGrid.GetCellAt(lastMove.Target); target.Filled = false; Cell source = BoardGrid.GetCellAt(lastMove.Source); Cell middle = BoardGrid.GetMiddleCell(source, target); middle.Selected = false; middle.Filled = true; source.Selected = false; source.Filled = true; UndoHistory.Add(lastMove); MoveHistory.RemoveAt(MoveHistory.Count - 1); }
public void UndoLastMove() { TicTacToeMove m = MoveHistory.Last() as TicTacToeMove; SetPosition(m.Position, 0); mMoveHistory.RemoveAt(MoveHistory.Count - 1); mValue = 0; IsFinished = false; }
public void UndoLastMove() { TicTacToeMove m = MoveHistory.Last() as TicTacToeMove; SetPosition(m.Position, 0); Value = 0; mWeight += mPlayer * mWeights[m.Position.Row, m.Position.Col]; mPlayer = -mPlayer; MoveHistory.RemoveAt(MoveHistory.Count - 1); }
public void UndoLastMove() { TicTacToeMove m = MoveHistory.Last(); SetPosition(m.Position, 0); mMoveHistory.RemoveAt(MoveHistory.Count - 1); mWeight += mPlayer * mWeights[m.Position.Row, m.Position.Col]; mPlayer = -mPlayer; mValue = 0; IsFinished = false; }
private void RemoveLastMovesFromMoveHistory(int count) { for (int i = 0; i < count; ++i) { Player player = Plies % 2 == 0 ? Player.Black : Player.White; --Plies; if (player == Player.White) { MoveHistory.Rows.RemoveAt(MoveHistory.Rows.Count - 1); } else { MoveHistory.Last().BlackDetailedMove = null; } } }
public void AddToMoveHistory(Square fromSquare, Square toSquare, Piece capturedPiece, bool queensideCastle, bool kingsideCastle, CheckStatus checkStatus) { int turnNumber = 1; if (MoveHistory.Count > 0) { if (MoveHistory.Last().Piece.Color == Color.White) { turnNumber = MoveHistory.Last().TurnNumber; } else { turnNumber = MoveHistory.Last().TurnNumber + 1; } } if (capturedPiece == null) { MoveHistory.Add(new Move(turnNumber, toSquare.Piece, fromSquare, toSquare, queensideCastle, kingsideCastle, checkStatus)); } else { MoveHistory.Add(new Move(turnNumber, toSquare.Piece, capturedPiece, fromSquare, toSquare, queensideCastle, kingsideCastle, checkStatus)); } }
/*public bool IsFinished() * { * * }*/ public bool MakeMove(Square fromSquare, Square toSquare) { if (IsValidMove(fromSquare, toSquare)) { bool kingsideCastle = false; bool queensideCastle = false; Piece capturedPiece = null; Pawn pawn; if (toSquare.Piece != null) { capturedPiece = toSquare.Piece; Board.RemovedPieces.Add(capturedPiece); Board.Pieces.Remove(capturedPiece); if (fromSquare.Piece.Type == PieceType.Pawn && (toSquare.Row == 0 || toSquare.Row == 7)) { // TODO SELECTION pawn = (Pawn)fromSquare.Piece; pawn.IsPromoted = true; pawn.PromotedPiece = new Queen(pawn.Color, pawn.Square); pawn.PromotedPiece.LoadContent(Content); } } else if (fromSquare.Piece.Type == PieceType.Pawn) { pawn = (Pawn)fromSquare.Piece; Square enPassantSquare = FindEnPassant(fromSquare); if (!fromSquare.Piece.HasMoved && (fromSquare.Row - toSquare.Row == 2 || fromSquare.Row - toSquare.Row == -2)) { pawn.UsedTwoSquareMove = true; } else if (enPassantSquare == toSquare) { if (fromSquare.Piece.Color == Color.White) { capturedPiece = Board.Squares[toSquare.Row + 1, toSquare.Column].Piece; } else if (fromSquare.Piece.Color == Color.Black) { capturedPiece = Board.Squares[toSquare.Row - 1, toSquare.Column].Piece; } Board.RemovedPieces.Add(capturedPiece); Board.Pieces.Remove(capturedPiece); } else if (toSquare.Row == 0 || toSquare.Row == 7) { // TODO SELECTION pawn.IsPromoted = true; pawn.PromotedPiece = new Queen(pawn.Color, pawn.Square); pawn.PromotedPiece.LoadContent(Content); } } // Castling else if (fromSquare.Piece.Type == PieceType.King) { Square rookSquare = null; if (fromSquare.Column - toSquare.Column == 2) { rookSquare = Board.Squares[fromSquare.Row, fromSquare.Column - 4]; rookSquare.Piece.HasMoved = true; Board.Squares[fromSquare.Row, fromSquare.Column - 1].Piece = rookSquare.Piece; rookSquare.Piece = null; queensideCastle = true; } else if (fromSquare.Column - toSquare.Column == -2) { rookSquare = Board.Squares[fromSquare.Row, fromSquare.Column + 3]; rookSquare.Piece.HasMoved = true; Board.Squares[fromSquare.Row, fromSquare.Column + 1].Piece = rookSquare.Piece; rookSquare.Piece = null; kingsideCastle = true; } } toSquare.Piece = fromSquare.Piece; toSquare.Piece.HasMoved = true; fromSquare.Piece = null; Square oppositeKingSquare = null; foreach (Piece piece in Board.Pieces) { if (piece.Type == PieceType.King && piece.Color != ActivePlayer.Color) { oppositeKingSquare = piece.Square; } } IsCheck(oppositeKingSquare); AddToMoveHistory(fromSquare, toSquare, capturedPiece, queensideCastle, kingsideCastle, CheckStatus); String history = MoveHistory.Last().ToString(); AdvanceTurn(); return(true); } return(false); }