From 68d1136ff16d9f462f7bf4f9e7b300be2464ba5d Mon Sep 17 00:00:00 2001 From: Jerome Bedier Date: Fri, 23 May 2025 08:09:42 +0200 Subject: [PATCH] add comment --- src/backend/AutoPlayer.java | 25 +++++++++++++++++++++++++ src/backend/Board.java | 7 ++++--- src/backend/SpecialMoves.java | 29 +++++++++++++++++++++++++++++ src/backend/soudEffect.java | 19 +++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/backend/AutoPlayer.java b/src/backend/AutoPlayer.java index ae1e91b..3b6c32e 100644 --- a/src/backend/AutoPlayer.java +++ b/src/backend/AutoPlayer.java @@ -4,6 +4,31 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +/* +Task: Chess Autoplayer Implementation + +Class name: AutoPlayer + +Methods name: +- computeBestMove(Board board) - Computes and returns the best move for the current player according to a simple priority heuristic; returns null if no legal move or if a king would be captured. +- resetLastMovedPiece() - Resets the tracking of the last moved piece; to be called after a human move. + +Methods output: +- The best possible move for the AI player given the current board state, or null if no legal move exists. +- Resets internal state for move tracking after a human move. + +Methods works: +- Analyzes all possible moves for the current player. +- Avoids repeating the previous piece moved by the autoplayer. +- Prevents illegal moves that would result in capturing the king. +- Prioritizes moves that put the opposing king in check or bring pieces closer to the opposing king. +- Randomly selects among equal-priority moves. +- Tracks the last moved piece to avoid repetitive AI behavior. + +Authors: Bédier Jérôme jerome.bedier@ecam.fr, Gardern Florian florian.gardner@ecam.fr, Leng Sidden sidden.leng@ecam.fr +Date: 05/21/2025 +*/ + public class AutoPlayer { private Integer lastMovedPieceHash = null; // Track the last moved piece diff --git a/src/backend/Board.java b/src/backend/Board.java index 036af0d..271a309 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -5,9 +5,10 @@ import java.util.Stack; import javax.swing.JLabel; import javax.swing.JPanel; -/*Task: Chess Game Board Implementation +/* +Task: Chess Game Board Implementation -Class name: Board.java +Class name: Board Methods name: - getWidth() - Returns the width of the board as an integer @@ -72,7 +73,7 @@ Methods works: - User interaction handling - Visual board representation -Authors: Bédier Jérôme jerome.bedier@ecam.fr Gardern Florian florian.gardner@ecam.fr Leng Sidden sidden.leng@ecam.fr +Authors: Bédier Jérôme jerome.bedier@ecam.fr, Gardern Florian florian.gardner@ecam.fr, Leng Sidden sidden.leng@ecam.fr Date: 05/21/2025 */ diff --git a/src/backend/SpecialMoves.java b/src/backend/SpecialMoves.java index 9018c32..63955b8 100644 --- a/src/backend/SpecialMoves.java +++ b/src/backend/SpecialMoves.java @@ -1,5 +1,34 @@ package backend; +/* +Task: Chess Special Moves Implementation + +Class name: SpecialMoves + +Methods name: +- promotePawn(boolean isWhite, int x, int y) - Returns a new Queen piece to replace a pawn upon reaching the promotion rank. +- isEnPassant(Board board, Move move) - Returns true if the specified move is an en passant capture. +- handleEnPassant(Board board, Move move) - Handles the en passant capture by removing the captured pawn from the board. +- updateEnPassantTracking(Board board, Move move, Piece piece) - Updates en passant square tracking after a pawn's double move. +- canCastle(Board board, Piece king, boolean isKingside) - Returns true if castling is possible (placeholder, always false). +- handleCastling(Board board, Move move, boolean isKingside) - Handles king and rook movement for castling (placeholder, no implementation). + +Methods output: +- Promoted queen piece on pawn promotion. +- Boolean status for en passant and castling move possibilities. +- Updates to board state for en passant and castling. +- En passant tracking updates after pawn double moves. + +Methods works: +- Pawn promotion to queen on reaching the opponent's back rank. +- Detection and execution of en passant captures. +- Tracking and resetting en passant target squares. +- (Placeholder) Castling logic including detection and execution. + +Authors: Bédier Jérôme jerome.bedier@ecam.fr, Gardern Florian florian.gardner@ecam.fr, Leng Sidden sidden.leng@ecam.fr +Date: 05/21/2025 +*/ + public class SpecialMoves { // Pawn promotion: always promotes to Queen for simplicity diff --git a/src/backend/soudEffect.java b/src/backend/soudEffect.java index d829ea4..380ce97 100644 --- a/src/backend/soudEffect.java +++ b/src/backend/soudEffect.java @@ -4,6 +4,25 @@ import javax.sound.sampled.*; import java.io.File; import java.io.IOException; +/* +Task: Chess Sound Effect Handling + +Class name: soudEffect + +Methods name: +- playCheckSound() - Plays a sound effect when the king is in check. Uses a WAV file and Java's audio system. + +Methods output: +- Plays a check sound effect. + +Methods works: +- Loads and plays a WAV audio file to provide audio feedback (e.g., when the king is in check). +- Handles exceptions for unsupported file formats, unavailable lines, and IO errors. + +Authors: Bédier Jérôme jerome.bedier@ecam.fr, Gardern Florian florian.gardner@ecam.fr, Leng Sidden sidden.leng@ecam.fr +Date: 05/21/2025 +*/ + public class soudEffect { public void playCheckSound() { try {