public List <ChessCommand> Moved(List <GameObject> board, int from, int to) { if (startingPosition) { startingPosition = false; } List <ChessCommand> moves = new List <ChessCommand>(); if (board[to].GetComponent <Square>().Piece != null) { audioPlayer.SE_Capture(); moves.Add(new CaptureCommand(to)); } else if (to == passantBoardIndex) { audioPlayer.SE_Capture(); moves.Add(new CaptureCommand(passantBoardIndex - 4 * direction)); } moves.Add(new MoveCommand(this, from, to)); int ystart = from / 4; int yend = to / 4; // En Passant logic if (Mathf.Abs(yend - ystart) == 2) { int x = to % 4; if (x != 0) { IChessPiece p = board[Library.GetBoardIndex(x - 1, yend)].GetComponent <Square>().Piece; if (p != null && p.Team != team && p.gameObject.GetComponent <Pawn>() != null) { p.gameObject.GetComponent <Pawn>().EnPassantPossible(Library.GetBoardIndex(x, yend - direction)); } } if (x != 3) { IChessPiece p = board[Library.GetBoardIndex(x + 1, yend)].GetComponent <Square>().Piece; if (p != null && p.Team != team && p.gameObject.GetComponent <Pawn>() != null) { p.gameObject.GetComponent <Pawn>().EnPassantPossible(Library.GetBoardIndex(x, yend - direction)); } } } // Promotion logic if (yend == 0 || yend == 7) { moves.Add(new PromoteCommand(to, (team == Affiliation.White? "White" : "Black") + "Pawn")); } return(moves); }
public List <ChessCommand> Moved(List <GameObject> board, int from, int to) { List <ChessCommand> moves = new List <ChessCommand>(); if (board[to].GetComponent <Square>().Piece != null) { moves.Add(new CaptureCommand(to)); audioPlayer.SE_Capture(); } moves.Add(new MoveCommand(this, from, to)); return(moves); }