minskat if-satser

This commit is contained in:
lov3b 2022-05-15 14:43:46 +02:00
parent 6eea10491b
commit b112c6314b

View File

@ -65,8 +65,8 @@ public abstract class Piece {
* Ger tillbaks alla ställen pjäsen kan attackera * Ger tillbaks alla ställen pjäsen kan attackera
* *
* @param pieces * @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska kolla ifall det är något i möjliga attackrutor * @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska
* ifall * kolla ifall det är något i möjliga attackrutor ifall
* @return Alla lämpliga attackMoves * @return Alla lämpliga attackMoves
*/ */
public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) { public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
@ -123,14 +123,9 @@ public abstract class Piece {
// Detta är en tom plats // Detta är en tom plats
if (pieceToCheck == null) { if (pieceToCheck == null) {
if (!isSelected) { if (!isSelected || !isInSchack(pieces, pos)) {
movable.add(pos); movable.add(pos);
} else {
if (!isInSchack(pieces, pos)) {
movable.add(pos);
}
} }
// Fortsätt att
return false; return false;
} }
@ -139,18 +134,9 @@ public abstract class Piece {
* längre Ifall det är samma färg som oss betyder det att vi inte kan * längre Ifall det är samma färg som oss betyder det att vi inte kan
* lägga till den * lägga till den
*/ */
if (pieceToCheck.isWhite() != this.isWhite()) { if ((pieceToCheck.isWhite() != this.isWhite())
/** && ((isSelected && !isInSchack(pieces, pos)) || !isSelected)) {
* Detta betyder att det är en motsatts pjäs här, vi kan ta men inte movable.add(pos);
* längre
*/
if (!isSelected) {
movable.add(pos);
} else {
if (!isInSchack(pieces, pos)) {
movable.add(pos);
}
}
} }
return true; return true;