public bool Equals(Move other) { return(To == other.To && From == other.From && Player == other.Player); }
public void Undo() { if (GameEnded) { GameEnded = false; Winner = FieldState.Empty; } //LAST MOVE WAS GIVE-UP MOVE if (!GameHistory.PeekLastMove().IsValid()) { GameHistory.PopLastMove(); } GameHistory.RemoveState(GameBoard.ToString()); Move lastMove = GameHistory.PopLastMove(); //LAST MOVE WAS CAPTURE, UNDO ONE MORE MOVE if (lastMove.To < 0) { GameBoard.PlaceAt(lastMove.From, (FieldState)(-(int)lastMove.Player)); Move oneMore = GameHistory.PopLastMove(); if (oneMore.Player != lastMove.Player) { throw new InvalidOperationException(); } if (oneMore.To >= 0) { GameBoard.RemoveFrom(oneMore.To); } if (oneMore.From >= 0) { GameBoard.PlaceAt(oneMore.From, oneMore.Player); } // LAST MOVE WAS PLACEMENT, ADD PAWN TO HAND if (oneMore.From < 0) { if (oneMore.Player == FieldState.White) { _whitesInHand++; } else if (oneMore.Player == FieldState.Black) { _blacksInHand++; } } } // LAST MOVE WAS REGULAR MOVE else { if (lastMove.To >= 0) { GameBoard.RemoveFrom(lastMove.To); } if (lastMove.From >= 0) { GameBoard.PlaceAt(lastMove.From, lastMove.Player); } // IF LAST MOVE WAS PLACEMENT, ADD PAWN TO HAND if (lastMove.From < 0) { if (lastMove.Player == FieldState.White) { _whitesInHand++; } else if (lastMove.Player == FieldState.Black) { _blacksInHand++; } } } NextPlayer = lastMove.Player; NextPlayersTurnEvent?.Invoke(this, NextPlayer); }