11package com .example .chaiss ;
22
3+ /**
4+ * Medium Activity handles the medium difficulty using algorithms
5+ * Similar to HardActivity and EasyActivity
6+ * includes premoving, sound effects, and dragging-dropping pieces
7+ *
8+ */
9+
310import android .content .Intent ;
411import android .content .SharedPreferences ;
512import android .graphics .drawable .PictureDrawable ;
@@ -86,7 +93,7 @@ public class MediumActivity extends AppCompatActivity {
8693 PIECE_IMAGES .put ("q" , R .drawable .bqueen );
8794 PIECE_IMAGES .put ("k" , R .drawable .bking );
8895 }
89-
96+ // Initializes board, pieces, settings, and feed
9097 @ Override
9198 protected void onCreate (Bundle savedInstanceState ) {
9299 super .onCreate (savedInstanceState );
@@ -259,6 +266,7 @@ private void startRematch() {
259266 updateCapturedPiecesUI ();
260267 }
261268
269+ // Handles premoving and sensors for touch for all purposes
262270 private void handleTouch (float x , float y ) {
263271 if (gameOver ) return ;
264272 String square = getSquareFromTouch (x , y );
@@ -378,6 +386,7 @@ private void updateCapturedPiecesUI() {
378386 capturedBlackText .setText ("" );
379387 }
380388
389+ // Handles logic behind all legal moves for pieces
381390 private void makeMove (String move ) {
382391 try {
383392 char turnBefore = currentFEN .split (" " )[1 ].charAt (0 );
@@ -428,14 +437,10 @@ private void makeMove(String move) {
428437 @ Override
429438 protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
430439 super .onActivityResult (requestCode , resultCode , data );
431-
432440 if (requestCode == 1 ) {
433441 updateBoard ();
434-
435- // FIX: re-read the sound setting
436442 SharedPreferences prefs = getSharedPreferences ("AppSettings" , MODE_PRIVATE );
437443 isSoundEnabled = prefs .getBoolean ("soundEnabled" , true );
438-
439444 Toast .makeText (this , "Settings updated!" , Toast .LENGTH_SHORT ).show ();
440445 }
441446 }
@@ -445,7 +450,7 @@ private String getSquareFromTouch(float x, float y) {
445450 chessBoardImage .getLocationOnScreen (location );
446451 int boardLeft = location [0 ];
447452 int boardTop = location [1 ];
448- int boardSize = chessBoardImage .getWidth (); // assumes square board
453+ int boardSize = chessBoardImage .getWidth ();
449454 float localX = x ;
450455 float localY = y ;
451456 int squareSize = boardSize / 8 ;
@@ -468,6 +473,7 @@ private String getSquareFromTouch(float x, float y) {
468473 return "" + file + rank ;
469474 }
470475
476+ // Analyzes the FEN of the current position
471477 private void updateBoard () {
472478 new Thread (() -> {
473479 try {
@@ -609,6 +615,7 @@ private void showColorSelectionDialog() {
609615 dialog .show ();
610616 }
611617
618+ // Starts game after color selection. Also handles piece selection and scrolling of board
612619 private void startGame () {
613620 currentFEN = chessLogic .callAttr ("create_board" ).toString ();
614621 updateBoard ();
0 commit comments