public Piece ToMove(Position origin, Position destiny) { Piece p = Board.ToRemovePiece(origin); p.UpdateAmtMoviments(); //update amount moviments of this piece Piece capturedPiece = Board.ToRemovePiece(destiny); //to controll the capitured Board.ToSetPiece(p, destiny); if (capturedPiece != null) { Captureds.Add(capturedPiece); } //#Special Moviment Small Rock if (p is King && destiny.Column == origin.Column + 2) { Position originTower = new Position(origin.Row, origin.Column + 3); Position destinyTower = new Position(origin.Row, origin.Column + 1); Piece T = Board.ToRemovePiece(originTower); T.UpdateAmtMoviments(); Board.ToSetPiece(T, destinyTower); } //#Special Moviment Small Rock if (p is King && destiny.Column == origin.Column - 2) { Position originTower = new Position(origin.Row, origin.Column - 4); Position destinyTower = new Position(origin.Row, origin.Column - 1); Piece T = Board.ToRemovePiece(originTower); T.UpdateAmtMoviments(); Board.ToSetPiece(T, destinyTower); } //#Special Moviment En Passant if (p is Pawn) { if (origin.Column != destiny.Column && capturedPiece == null) { Position posP; if (p.Color == Color.White) { posP = new Position(destiny.Row + 1, destiny.Column); } else { posP = new Position(destiny.Row - 1, destiny.Column); } capturedPiece = Board.ToRemovePiece(posP); Captureds.Add(capturedPiece); } } return(capturedPiece); }
public void ToPlay(Position origin, Position destiny) { ToMove(origin, destiny); if (IsInCheck(CurrentPlayer)) { UndoMoviment(origin, destiny); throw new BoardException("Você não pode se colocar em xeque"); } Piece p = Board.GetPiece(destiny); //#Special Moviment: promotion if (p is Pawn) { if ((p.Color == Color.White && destiny.Row == 0) || (p.Color == Color.Black && destiny.Row == 7)) { p = Board.ToRemovePiece(destiny); Pieces.Remove(p); Piece queen = new Queen(Board, p.Color); Board.ToSetPiece(queen, destiny); Pieces.Add(queen); } } if (IsInCheck(Adversary(CurrentPlayer))) { Check = true; } else { Check = false; } if (IsInCheck(Adversary(CurrentPlayer))) { Finished = true; } else { Turn++; ChangePlyaer(); } //#special moviment en passant if (p is Pawn && (destiny.Row == origin.Row - 2) || (destiny.Row == origin.Row + 2)) { CanPassant = p; } else { CanPassant = null; } }
public void UndoMoviment(Position origin, Position destiny, Piece capturedPiece = null) { Piece p = Board.ToRemovePiece(destiny); p.UpdateDecrementAmtMoviments(); if (capturedPiece != null) { Board.ToSetPiece(capturedPiece, destiny); Captureds.Remove(capturedPiece); } Board.ToSetPiece(p, origin); //#Special Moviment Small Rock if (p is King && destiny.Column == origin.Column + 2) { Position originTower = new Position(origin.Row, origin.Column + 3); Position destinyTower = new Position(origin.Row, origin.Column + 1); Piece T = Board.ToRemovePiece(destinyTower); T.UpdateDecrementAmtMoviments(); Board.ToSetPiece(T, originTower); } //#Special Moviment Small Rock if (p is King && destiny.Column == origin.Column - 2) { Position originTower = new Position(origin.Row, origin.Column - 4); Position destinyTower = new Position(origin.Row, origin.Column - 1); Piece T = Board.ToRemovePiece(destinyTower); T.UpdateAmtMoviments(); Board.ToSetPiece(T, originTower); } //#Special Moviment En Passant if (p is Pawn) { if (origin.Column != destiny.Column && capturedPiece == CanPassant) { Piece pawn = Board.ToRemovePiece(destiny); Position posP; if (p.Color == Color.White) { posP = new Position(3, destiny.Column); } else { posP = new Position(4, destiny.Column); } Board.ToSetPiece(pawn, posP); } } }
public void ToSetNewPiece(char column, int row, Piece piece) { Board.ToSetPiece(piece, new ChessPosition(column, row).ToPosition()); Pieces.Add(piece); }