mirror of
				https://github.com/lov3b/Schack.git
				synced 2025-11-04 07:00:21 +01:00 
			
		
		
		
	Update King.java
This commit is contained in:
		@@ -29,25 +29,31 @@ public final class King extends PieceKnownIfMoved {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Vänster
 | 
					        // Vänster
 | 
				
			||||||
        boolean nothingInBetween = true;
 | 
					        boolean nothingInBetween = true;
 | 
				
			||||||
        for (int kingX = this.position.x - 1; kingX >= 0; kingX--) {
 | 
					        for (int loopX = this.position.x - 1; loopX >= 0; loopX--) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Kolla ifall vi kollar tornet och inget är emellan
 | 
					            // Kolla ifall vi kollar tornet och inget är emellan
 | 
				
			||||||
            if (kingX == 0 && nothingInBetween) {
 | 
					            if (loopX == 0 && nothingInBetween) {
 | 
				
			||||||
                movable.add(new Point(2, 7));
 | 
					                movable.add(new Point(2, this.position.y));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Kolla ifall det är tomt emellan kung och torn
 | 
					            // Kolla ifall det är tomt emellan kung och torn
 | 
				
			||||||
            if (pieces[kingX][this.position.y] != null) {
 | 
					            if (pieces[loopX][this.position.y] != null) {
 | 
				
			||||||
                nothingInBetween = false;
 | 
					                nothingInBetween = false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Höger
 | 
					        // Höger
 | 
				
			||||||
        for (int kingX = this.position.x + 1; kingX <= 7; kingX++) {
 | 
					        for (int loopX = this.position.x + 1; loopX <= 7; loopX++) {
 | 
				
			||||||
            boolean shouldBreak = addMovesIfCan(new Point(kingX, this.position.y), movable, pieces);
 | 
					
 | 
				
			||||||
            if (shouldBreak) {
 | 
					            // Kolla ifall vi kollar tornet och inget är emellan
 | 
				
			||||||
                break;
 | 
					            if (loopX == 7 && nothingInBetween) {
 | 
				
			||||||
 | 
					                movable.add(new Point(6, this.position.y));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Kolla ifall det är tomt emellan kung och torn
 | 
				
			||||||
 | 
					            if (pieces[loopX][this.position.y] != null) {
 | 
				
			||||||
 | 
					                nothingInBetween = false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -67,7 +73,6 @@ public final class King extends PieceKnownIfMoved {
 | 
				
			|||||||
        // Uppdatera brädet
 | 
					        // Uppdatera brädet
 | 
				
			||||||
        pieces[king.position.x][king.position.y] = king;
 | 
					        pieces[king.position.x][king.position.y] = king;
 | 
				
			||||||
        pieces[rook.position.x][rook.position.y] = rook;
 | 
					        pieces[rook.position.x][rook.position.y] = rook;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user