@@ -318,38 +318,46 @@ private void updateCapturedPiecesUI() {
318318
319319 private void makeMove (String move ) {
320320 try {
321+ char turnBefore = currentFEN .split (" " )[1 ].charAt (0 );
321322 PyObject result = chessLogic .callAttr ("make_move" , currentFEN , move );
322323 List <PyObject > tuple = result .asList ();
323324 String newFen = tuple .get (0 ).toString ();
324325 String capturedSymbol = tuple .get (1 ).toString ();
326+ char turnAfter = newFen .split (" " )[1 ].charAt (0 );
327+ if (turnBefore == turnAfter ) {
328+ Toast .makeText (this , "Invalid move: Move did not change the turn" , Toast .LENGTH_SHORT ).show ();
329+ selectedSquare = null ;
330+ legalMoves = null ;
331+ updateBoard ();
332+ return ;
333+ }
325334 currentFEN = newFen ;
326- Log .d ("ChessApp" , "After move, FEN = " + currentFEN
327- + ", next turn = " + currentFEN .split (" " )[1 ]);
335+ Log .d ("ChessApp" , "After move, FEN = " + currentFEN + ", next turn = " + turnAfter );
328336 if (!capturedSymbol .isEmpty ()) {
329337 handleCapturedPiece (capturedSymbol );
330338 }
331339
332- soundPool .play (moveSoundId , 1 , 1 , 0 , 0 , 1 );
340+ if (moveSoundId != 0 ) {
341+ soundPool .play (moveSoundId , 1 , 1 , 0 , 0 , 1 );
342+ }
333343 PyObject gameResult = chessLogic .callAttr ("check_game_result" , currentFEN );
334344 if (!gameResult .toString ().equals ("Game still in progress" )) {
335345 showGameOverDialog (gameResult .toString ());
336346 return ;
337347 }
338- // ADDED FOR MOVE FEED: Add move and auto-scroll
339348 String currentPlayer = (moveCounter % 2 == 1 ) ? "White" : "Black" ;
340349 if (moveFeedAdapter != null ) {
341350 MoveItem moveItem = new MoveItem (moveCounter , currentPlayer , move );
342351 moveFeedAdapter .addMove (moveItem );
343- moveFeedRecyclerView .smoothScrollToPosition (moveFeedAdapter .getItemCount () - 1 ); // AUTO-SCROLL
352+ moveFeedRecyclerView .smoothScrollToPosition (moveFeedAdapter .getItemCount () - 1 );
344353 }
345354 moveCounter ++;
346355 selectedSquare = null ;
347356 legalMoves = null ;
348357 updateBoard ();
349358 if (isBotTurn ()) {
350359 new Handler (Looper .getMainLooper ()).postDelayed (this ::makeMediumAIMove , 2000 );
351- }
352- else {
360+ } else {
353361 checkAndPlayPremove ();
354362 }
355363 } catch (Exception e ) {
0 commit comments