// Returns all the legal moves for the given cell public ArrayList GetLegalMoves(Cell source) { ArrayList LegalMoves; LegalMoves = GetPossibleMoves(source); // Get the legal moves ArrayList ToRemove = new ArrayList(); // contains a list of all the moves to remove // Now check and mark all the moves which moves user under check foreach (Cell target in LegalMoves) { // if the move place or leave the user under check if (CauseCheck(new Move(source, target))) { ToRemove.Add(target); } } // When checking the moves for the king, don't allow tower/caslting, if // the king is under check if (source.piece.Type == Piece.PieceType.King && IsUnderCheck(source.piece.Side.type)) { foreach (Cell target in LegalMoves) { //if the move place or leave the user under check if (Math.Abs(target.col - source.col) > 1) { ToRemove.Add(target); } } } // remove all the illegal moves foreach (Cell cell in ToRemove) { LegalMoves.Remove(cell); // remove the illegal move } return(LegalMoves); }
// Returns all the legal moves for the given cell public ArrayList GetLegalMoves(Cell source) { ArrayList LegalMoves; LegalMoves = GetPossibleMoves(source); // Get the legal moves ArrayList ToRemove = new ArrayList(); // contains a list of all the moves to remove // Now check and mark all the moves which moves user under check foreach (Cell target in LegalMoves) { // if the move place or leave the user under check if (CauseCheck(new Move(source, target))) { ToRemove.Add(target); } } // remove all the illegal moves foreach (Cell cell in ToRemove) { LegalMoves.Remove(cell); // remove the illegal move } return(LegalMoves); }