Compare commits
2 Commits
ee4b64f6e1
...
bc16333d88
| Author | SHA1 | Date |
|---|---|---|
|
|
bc16333d88 | |
|
|
debffdd8b5 |
BIN
exterminate.wav
BIN
exterminate.wav
Binary file not shown.
|
|
@ -570,7 +570,6 @@ public class Board {
|
|||
public boolean isKingInCheck(boolean isWhite) {
|
||||
// First, find the king's position
|
||||
Piece king = findKing(isWhite);
|
||||
soudEffect soundPlayer = new soudEffect();
|
||||
|
||||
if (king == null) {
|
||||
// If king not found (shouldn't happen in a valid chess game)
|
||||
|
|
@ -596,7 +595,6 @@ public class Board {
|
|||
// Check if any move can capture the king
|
||||
for (Move move : moves) {
|
||||
if (move.getToX() == kingX && move.getToY() == kingY) {
|
||||
soundPlayer.playCheckSound();
|
||||
return true; // King is in check
|
||||
}
|
||||
}
|
||||
|
|
@ -718,5 +716,32 @@ public class Board {
|
|||
// Replace highlights with filtered version
|
||||
highlightedSquares = newHighlights;
|
||||
}
|
||||
|
||||
public boolean isCheckmate(boolean isWhite) {
|
||||
if (!isKingInCheck(isWhite)) {
|
||||
return false; // Not in check, so not checkmate
|
||||
}
|
||||
|
||||
// Check if ANY legal move can get the king out of check
|
||||
for (Piece piece : getPieces()) {
|
||||
if (piece.isWhite() == isWhite) {
|
||||
ArrayList<Move> legalMoves = getLegalMoves(piece);
|
||||
|
||||
for (Move move : legalMoves) {
|
||||
// Simulate move
|
||||
Board simulatedBoard = new Board(this.toFileRep());
|
||||
simulatedBoard.playMove(move);
|
||||
|
||||
// If king is not in check after this move, it's not checkmate
|
||||
if (!simulatedBoard.isKingInCheck(isWhite)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true; // No legal move prevents check => checkmate
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
package backend;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class soudEffect {
|
||||
public void playCheckSound() {
|
||||
try {
|
||||
// Replace "check.wav" with the path to your check sound file
|
||||
File soundFile = new File("exterminate.wav");
|
||||
AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile);
|
||||
Clip clip = AudioSystem.getClip();
|
||||
clip.open(audioStream);
|
||||
clip.start();
|
||||
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue