@@ -51,13 +51,15 @@ protected void onCreate(Bundle savedInstanceState) {
5151 super .onCreate (savedInstanceState );
5252 setContentView (R .layout .activity_analysis );
5353
54+ // Initialize views
5455 scrollView = findViewById (R .id .scroll_view_analysis );
5556 chessBoardImage = findViewById (R .id .chess_board );
5657 analysisText = findViewById (R .id .analysis_text );
5758 pawnText = findViewById (R .id .pawn_structure_text );
5859 developmentText = findViewById (R .id .piece_development_text );
5960 kingSafetyText = findViewById (R .id .king_safety_text );
6061
62+ // Initialize buttons
6163 Button addPieceButton = findViewById (R .id .add_piece_button );
6264 Button lockButton = findViewById (R .id .lock_button );
6365 Button analyzeButton = findViewById (R .id .analyze_button );
@@ -141,6 +143,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
141143 }
142144 }
143145
146+ // Show dialog to delete a piece
144147 private void showDeletePieceDialog () {
145148 AlertDialog .Builder builder = new AlertDialog .Builder (this );
146149 builder .setTitle ("Delete Piece" );
@@ -173,6 +176,7 @@ private void showDeletePieceDialog() {
173176 builder .show ();
174177 }
175178
179+ // Show dialog to select which piece to add
176180 private void showPieceSelectionDialog () {
177181 AlertDialog .Builder builder = new AlertDialog .Builder (this );
178182 builder .setTitle ("Select a Piece to Place" );
@@ -195,6 +199,7 @@ private void showPieceSelectionDialog() {
195199 builder .show ();
196200 }
197201
202+ // Show dialog to input square for placing piece
198203 private void showSquareSelectionDialog (String piece ) {
199204 AlertDialog .Builder builder = new AlertDialog .Builder (this );
200205 builder .setTitle ("Enter Square (e.g., e4)" );
@@ -216,6 +221,7 @@ private void showSquareSelectionDialog(String piece) {
216221 builder .show ();
217222 }
218223
224+ // Show dialog to select color for the new piece
219225 private void showColorSelectionDialog (String piece , String square ) {
220226 AlertDialog .Builder builder = new AlertDialog .Builder (this );
221227 builder .setTitle ("Select Piece Color" );
@@ -230,6 +236,7 @@ private void showColorSelectionDialog(String piece, String square) {
230236 builder .show ();
231237 }
232238
239+ // Add selected piece to board
233240 private void addPieceToBoard (String square , String piece ) {
234241 try {
235242 PyObject result = chessLogic1 .callAttr ("add_piece" , currentFEN , square , piece );
@@ -253,9 +260,7 @@ private void addPieceToBoard(String square, String piece) {
253260 }
254261 }
255262
256-
257-
258-
263+ // Show instructions about using analysis page
259264 private void showInstructionsDialog () {
260265 AlertDialog .Builder builder = new AlertDialog .Builder (this );
261266 builder .setTitle ("Instructions" );
@@ -278,6 +283,7 @@ private void showInstructionsDialog() {
278283 builder .show ();
279284 }
280285
286+ // Handles touch interactions on the chessboard
281287 private void handleTouch (MotionEvent event ) {
282288 if (isLocked ) {
283289 Toast .makeText (this , "Board is locked" , Toast .LENGTH_SHORT ).show ();
@@ -373,6 +379,7 @@ private void handleTouch(MotionEvent event) {
373379 }
374380 }
375381
382+ // Converts touch screen coordinates into a chessboard square nam
376383 private String getSquareFromTouch (float x , float y ) {
377384 int boardSize = chessBoardImage .getWidth ();
378385 int squareSize = boardSize / 8 ;
@@ -394,6 +401,7 @@ private String getSquareFromTouch(float x, float y) {
394401 return "" + file + rank ;
395402 }
396403
404+ // Updates the displayed chessboard based on the current FEN and theme settings
397405 private void updateBoard () {
398406 new Thread (() -> {
399407 try {
@@ -421,6 +429,7 @@ private void updateBoard() {
421429 }).start ();
422430 }
423431
432+ // Prompts user to select whose turn it is to move, then analyzes the current board position
424433 private void analyzePosition () {
425434 AlertDialog .Builder builder = new AlertDialog .Builder (this );
426435 builder .setTitle ("Select Turn" );
@@ -467,6 +476,7 @@ private void analyzePosition() {
467476 builder .show ();
468477 }
469478
479+ // Sends the current board position (FEN)
470480 private void getBestMoveFromAPI (String fen ) {
471481 new Thread (() -> {
472482 try {
@@ -529,6 +539,8 @@ private void getBestMoveFromAPI(String fen) {
529539 }
530540 }).start ();
531541 }
542+
543+ // Returns the drawable resource ID
532544 private int getPieceResource (String piece ) {
533545 switch (piece ) {
534546 case "P" : return R .drawable .wpawn ;
@@ -546,6 +558,8 @@ private int getPieceResource(String piece) {
546558 default : return 0 ;
547559 }
548560 }
561+
562+ // Moves a piece from one square to another
549563 private void movePiece (String fromSquare , String toSquare ) {
550564 try {
551565 if (isFreeMoveMode ) {
0 commit comments