Skip to content

Commit c8e4ef4

Browse files
committed
comments for classes
1 parent 71e23b7 commit c8e4ef4

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

app/src/main/java/com/example/chaiss/AnalysisActivity.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

app/src/main/java/com/example/chaiss/MainMenu.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ protected void onCreate(Bundle savedInstanceState) {
1717
analysisButton.setOnClickListener(new View.OnClickListener() {
1818
@Override
1919
public void onClick(View v) {
20+
// Start the AnalysisActivity when the button is clicked
2021
Intent intent = new Intent(MainMenu.this, AnalysisActivity.class);
2122
startActivity(intent);
2223
}
@@ -26,11 +27,12 @@ public void onClick(View v) {
2627
playButton.setOnClickListener(new View.OnClickListener() {
2728
@Override
2829
public void onClick(View v) {
30+
// Start the SelectDifficultyActivity when the button is clicked
2931
Intent intent = new Intent(MainMenu.this, SelectDifficultyActivity.class);
3032
startActivity(intent);
3133
}
3234
});
33-
35+
// Setup the Settings button to navigate to SettingsActivity
3436
Button settingsButton = findViewById(R.id.button7);
3537
settingsButton.setOnClickListener(new View.OnClickListener() {
3638
@Override

0 commit comments

Comments
 (0)