mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Ingen mer wrap med arraylist
This commit is contained in:
parent
11302d00a2
commit
15ad9de99a
@ -75,7 +75,10 @@ public class Pawn extends PieceKnownIfMoved {
|
|||||||
Piece piece = pieces[pos.x][pos.y];
|
Piece piece = pieces[pos.x][pos.y];
|
||||||
// Ifall det är tomt här, gör ingenting
|
// Ifall det är tomt här, gör ingenting
|
||||||
if (piece != null && piece.isWhite() != this.isWhite()) {
|
if (piece != null && piece.isWhite() != this.isWhite()) {
|
||||||
movable.addAll(tryToMoveAndCheckIfCheck(pieces, pos));
|
boolean isSchack = isInSchack(pos, pieces);
|
||||||
|
if (isSchack) {
|
||||||
|
movable.add(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return movable;
|
return movable;
|
||||||
}
|
}
|
||||||
@ -88,7 +91,10 @@ public class Pawn extends PieceKnownIfMoved {
|
|||||||
|
|
||||||
Piece pieceToCheck = pieces[pos.x][pos.y];
|
Piece pieceToCheck = pieces[pos.x][pos.y];
|
||||||
if (pieceToCheck == null) {
|
if (pieceToCheck == null) {
|
||||||
movable.addAll(tryToMoveAndCheckIfCheck(pieces, pos));
|
boolean isSchack = isInSchack(pos, pieces);
|
||||||
|
if (isSchack) {
|
||||||
|
movable.add(pos);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -69,7 +69,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 Ifall man inte ska bry sig ifall
|
* @param shouldNotCareIfAttackSpaceIsEmptyOrNot Ifall man inte ska bry sig
|
||||||
|
* ifall
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
|
public ArrayList<Point> validAttacks(Piece[][] pieces, boolean shouldNotCareIfAttackSpaceIsEmptyOrNot) {
|
||||||
@ -131,7 +132,11 @@ public abstract class Piece {
|
|||||||
if (!isSelected) {
|
if (!isSelected) {
|
||||||
movable.add(pos);
|
movable.add(pos);
|
||||||
} else {
|
} else {
|
||||||
movable.addAll(tryToMoveAndCheckIfCheck(pieces, pos));
|
boolean isSchack = isInSchack(pos, pieces);
|
||||||
|
if (isSchack) {
|
||||||
|
movable.add(pos);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// Fortsätt att gå
|
// Fortsätt att gå
|
||||||
return false;
|
return false;
|
||||||
@ -150,7 +155,10 @@ public abstract class Piece {
|
|||||||
if (!isSelected) {
|
if (!isSelected) {
|
||||||
movable.add(pos);
|
movable.add(pos);
|
||||||
} else {
|
} else {
|
||||||
movable.addAll(tryToMoveAndCheckIfCheck(pieces, pos));
|
boolean isSchack = isInSchack(pos, pieces);
|
||||||
|
if (isSchack) {
|
||||||
|
movable.add(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -165,8 +173,7 @@ public abstract class Piece {
|
|||||||
* @param pos
|
* @param pos
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
ArrayList<Point> tryToMoveAndCheckIfCheck(Piece[][] pieces, Point pos) {
|
boolean isSchackHere(Piece[][] pieces, Point pos) {
|
||||||
ArrayList<Point> movable = new ArrayList<>();
|
|
||||||
// Kom ihåg vart vi var
|
// Kom ihåg vart vi var
|
||||||
Point previousPosition = new Point(this.position);
|
Point previousPosition = new Point(this.position);
|
||||||
|
|
||||||
@ -184,11 +191,8 @@ public abstract class Piece {
|
|||||||
pieces[previousPosition.x][previousPosition.y] = this;
|
pieces[previousPosition.x][previousPosition.y] = this;
|
||||||
pieces[pos.x][pos.y] = opponentPiece;
|
pieces[pos.x][pos.y] = opponentPiece;
|
||||||
this.position = new Point(previousPosition);
|
this.position = new Point(previousPosition);
|
||||||
|
return inSchack;
|
||||||
|
|
||||||
if (!inSchack) {
|
|
||||||
movable.add(pos);
|
|
||||||
}
|
|
||||||
return movable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user