/// <summary> /// Moves a piece. /// </summary> /// <param name="move">A description of the move to be perform.</param> public void MovePiece(BoardMove move) { move.Destination.PutPiece(move.Piece); if (move.IsEating) { RemovePiece(move.PieceEaten); } }
/// <summary> /// Get all possible moves by a given piece. /// </summary> /// <param name="piece">The piece looking to move.</param> /// <returns>Array with the possible moves.</returns> public BoardMove[] GetPossibleMoves(Piece piece) { Piece eatenPiece; BoardSquare holder; BoardMove move; Direction[] directions = GetAvailableDirections(piece.Square.Pos); IList <BoardMove> possibleMoves = new List <BoardMove>(); // For all the available directions for (int i = 0; i < directions.Length; i++) { // Get square in the current direction holder = GetBoardSquareByDirection(piece.Square, directions[i]); if (holder != null) { // If there's no piece there... if (!holder.HasPiece) { // ...this move is possible. move = new BoardMove(piece, holder, null); possibleMoves.Add(move); } // If there is a piece there but it's from the other player else if (holder.Piece.Color != piece.Color) { eatenPiece = holder.Piece; holder = GetBoardSquareByDirection(holder, directions[i]); // A EAT is possible? if (holder != null && !holder.HasPiece) { move = new BoardMove(piece, holder, eatenPiece); possibleMoves.Add(move); } } } } return(possibleMoves.ToArray()); }