mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-03 22:50:24 +01:00 
			
		
		
		
	Mer beskrivande namn
This commit is contained in:
		@@ -17,7 +17,7 @@ public class Bishop extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Upp vänster
 | 
					        // Upp vänster
 | 
				
			||||||
        for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
 | 
					        for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -26,7 +26,7 @@ public class Bishop extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Upp höger 
 | 
					        // Upp höger 
 | 
				
			||||||
        for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
 | 
					        for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -34,7 +34,7 @@ public class Bishop extends Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        // Ner höger
 | 
					        // Ner höger
 | 
				
			||||||
        for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
 | 
					        for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -42,7 +42,7 @@ public class Bishop extends Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        // Ner vänster
 | 
					        // Ner vänster
 | 
				
			||||||
        for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
 | 
					        for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -37,7 +37,7 @@ public class Horse extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        for (Point pos : positions) {
 | 
					        for (Point pos : positions) {
 | 
				
			||||||
            // Ifall en är blockerad så ska vi inte sluta kolla
 | 
					            // Ifall en är blockerad så ska vi inte sluta kolla
 | 
				
			||||||
            checkMove(pos, movable, pieces);
 | 
					            addMovesIfCan(pos, movable, pieces);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return movable;
 | 
					        return movable;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ public class Pawn extends PieceKnownIfMoved {
 | 
				
			|||||||
            System.out.println("this.position.x: " + this.position.x);
 | 
					            System.out.println("this.position.x: " + this.position.x);
 | 
				
			||||||
            System.out.println("calced y: " + (this.position.y + (this.isWhite ? -pawnDY : pawnDY)));
 | 
					            System.out.println("calced y: " + (this.position.y + (this.isWhite ? -pawnDY : pawnDY)));
 | 
				
			||||||
            Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnDY : pawnDY));
 | 
					            Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnDY : pawnDY));
 | 
				
			||||||
            boolean shouldBreak = checkMove(pos, movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(pos, movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                System.out.println("should brkje!");
 | 
					                System.out.println("should brkje!");
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
@@ -34,14 +34,14 @@ public class Pawn extends PieceKnownIfMoved {
 | 
				
			|||||||
        for (int pawnX : new int[]{-1, 1}) {
 | 
					        for (int pawnX : new int[]{-1, 1}) {
 | 
				
			||||||
            // Position vi kollar just nu, snett upp åt höger & vänster
 | 
					            // Position vi kollar just nu, snett upp åt höger & vänster
 | 
				
			||||||
            Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
 | 
					            Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
 | 
				
			||||||
            checkAttack(pos, movable, pieces);
 | 
					            addAttackMovesIfCan(pos, movable, pieces);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        System.out.println("len of movable: " + movable.size());
 | 
					        System.out.println("len of movable: " + movable.size());
 | 
				
			||||||
        return movable;
 | 
					        return movable;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Känns som det här skulle kunnat vara i validMoves, men nu är det såhär
 | 
					    // Känns som det här skulle kunnat vara i validMoves, men nu är det såhär
 | 
				
			||||||
    private void checkAttack(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
					    private void addAttackMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
 | 
					        // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
@@ -54,7 +54,7 @@ public class Pawn extends PieceKnownIfMoved {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
					    protected boolean addMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
				
			||||||
        if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) {
 | 
					        if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,7 +59,7 @@ public abstract class Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
					    protected boolean addMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) {
 | 
				
			||||||
        // Instead of checking index and null, try-catch
 | 
					        // Instead of checking index and null, try-catch
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // Ifall vi kollar utanför brädet kommer detta att faila
 | 
					            // Ifall vi kollar utanför brädet kommer detta att faila
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Vänster
 | 
					        // Vänster
 | 
				
			||||||
        for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
 | 
					        for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -25,7 +25,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Höger
 | 
					        // Höger
 | 
				
			||||||
        for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
 | 
					        for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -33,7 +33,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Ner
 | 
					        // Ner
 | 
				
			||||||
        for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
 | 
					        for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -41,14 +41,14 @@ public class Queen extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Upp
 | 
					        // Upp
 | 
				
			||||||
        for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
 | 
					        for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Upp vänster
 | 
					        // Upp vänster
 | 
				
			||||||
        for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
 | 
					        for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -57,7 +57,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Upp höger 
 | 
					        // Upp höger 
 | 
				
			||||||
        for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
 | 
					        for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -65,7 +65,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        // Ner höger
 | 
					        // Ner höger
 | 
				
			||||||
        for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
 | 
					        for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -73,7 +73,7 @@ public class Queen extends Piece {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        // Ner vänster
 | 
					        // Ner vänster
 | 
				
			||||||
        for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
 | 
					        for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,7 +20,7 @@ public class Rook extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Vänster
 | 
					        // Vänster
 | 
				
			||||||
        for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
 | 
					        for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -28,7 +28,7 @@ public class Rook extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Höger
 | 
					        // Höger
 | 
				
			||||||
        for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
 | 
					        for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -36,7 +36,7 @@ public class Rook extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Ner
 | 
					        // Ner
 | 
				
			||||||
        for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
 | 
					        for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -44,7 +44,7 @@ public class Rook extends Piece {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Upp
 | 
					        // Upp
 | 
				
			||||||
        for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
 | 
					        for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
 | 
				
			||||||
            boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
 | 
					            boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            if (shouldBreak) {
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user