private void OnPieceMoved(Board board, Move move) { var correctMove = move.Color == PieceColor.White ? NextMoveEntry.WhiteMove : NextMoveEntry.BlackMove; if (correctMove == move) { // we just made blacks move. Time to grab next pair; if (move.Color == PieceColor.Black) { this.movesEnumerator.MoveNext(); } this.MakeNextMove(move.Color); } else { // revert last move this.Board.MakeMove(move.TargetSquare, move.OriginalSquare, false); if (this.PuzzleFailed != null) { this.PuzzleFailed(this.Board, this.movesEnumerator.Current.WhiteMove); } messenger.Send(new PuzzleCompletedMessage(false)); } }
private void FirePieceMoved(Square oldPosition, Piece piece) { if (this.PieceMoved != null) { var move = new Move() { Color = piece.Color, OriginalSquare = oldPosition, TargetSquare = piece.Position, Piece = piece.Type }; this.PieceMoved(this, move); } }
public bool Equals(Move p) { if ((object)p == null) { return false; } return (TargetSquare == p.TargetSquare) && (Piece == p.Piece); }
internal void MakeMove(Move nextMove) { var pieceToMove = this.Pieces.FirstOrDefault(x => x.Type == nextMove.Piece && x.Color == (this.IsWhiteMove ? PieceColor.White : PieceColor.Black) && x.PossibleMoves().Contains(nextMove.TargetSquare)); this.PutPiece(nextMove.TargetSquare, pieceToMove, false); }