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
*
* @param pieces
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska kolla ifall det är något i möjliga attackrutor
* ifall
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot För bönder ifall den ska
* kolla ifall det är något i möjliga attackrutor ifall
* @return Alla lämpliga attackMoves
*/
public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
@ -123,14 +123,9 @@ public abstract class Piece {
// Detta är en tom plats
if (pieceToCheck == null) {
if (!isSelected) {
movable.add(pos);
} else {
if (!isInSchack(pieces, pos)) {
if (!isSelected || !isInSchack(pieces, pos)) {
movable.add(pos);
}
}
// Fortsätt att
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ägga till den
*/
if (pieceToCheck.isWhite() != this.isWhite()) {
/**
* Detta betyder att det är en motsatts pjäs här, vi kan ta men inte
* längre
*/
if (!isSelected) {
if ((pieceToCheck.isWhite() != this.isWhite())
&& ((isSelected && !isInSchack(pieces, pos)) || !isSelected)) {
movable.add(pos);
} else {
if (!isInSchack(pieces, pos)) {
movable.add(pos);
}
}
}
return true;