mirror of
https://github.com/lov3b/Schack.git
synced 2024-11-10 07:00:11 +01:00
Integrera niklaskod
This commit is contained in:
parent
e545ca7902
commit
18dcc24a12
@ -15,44 +15,15 @@ public class Horse extends Piece {
|
||||
public ArrayList<Point> validMoves(Piece[][] pieces, boolean isSelected) {
|
||||
ArrayList<Point> movable = new ArrayList<>();
|
||||
|
||||
// TODO: Integrera
|
||||
/*
|
||||
for (int dx : new int[]{-2, -1, 1, 2}) {
|
||||
for (int y = -1; y <= 1; y += 2) {
|
||||
int dy = y * (3 - abs(dx));
|
||||
|
||||
for (int direction : new int[]{-1, 1}) {
|
||||
int stepLength = (3 - abs(dx));
|
||||
int dy = direction * stepLength;
|
||||
Point potentialMove = new Point(this.position.x + dx, this.position.y + dy);
|
||||
addMovesIfCan(potentialMove, movable, pieces, isSelected);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// Postitioner att checka
|
||||
Point[] positions = {
|
||||
// Snett höger uppåt
|
||||
new Point(this.position.x + 1, this.position.y - 2),
|
||||
// Snett höger neråt
|
||||
new Point(this.position.x + 1, this.position.y + 2),
|
||||
// Långt höger åt sidan uppåt
|
||||
new Point(this.position.x + 2, this.position.y - 1),
|
||||
// Långt höger åt sidan neråt
|
||||
new Point(this.position.x + 2, this.position.y + 1),
|
||||
// Snett vänster uppåt
|
||||
new Point(this.position.x - 1, this.position.y - 2),
|
||||
// Snett vänster neråt
|
||||
new Point(this.position.x - 1, this.position.y + 2),
|
||||
// Långt vänster åt sidan uppåt
|
||||
new Point(this.position.x - 2, this.position.y - 1),
|
||||
// Långt vänster åt sidan neråt
|
||||
new Point(this.position.x - 2, this.position.y + 1)
|
||||
};
|
||||
|
||||
for (Point pos : positions) {
|
||||
// Ifall en är blockerad så ska vi inte sluta kolla
|
||||
addMovesIfCan(pos, movable, pieces, isSelected);
|
||||
}
|
||||
|
||||
return movable;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user