Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CS2113-T18-1] ChessMaster #19

Open
wants to merge 634 commits into
base: master
Choose a base branch
from

Conversation

ken-ruster
Copy link

ChessMasterCLI is a command-line interface (CLI) chess game designed to make learning and training accessible for beginners while offering an engaging experience for all skill levels. This sleek and user-friendly chess simulator provides a platform for novice players to build their skills and understanding of the game.

@ken-ruster ken-ruster changed the title [T18-1] ChessMaster [CS2113-T18-1] ChessMaster Oct 5, 2023
Brian030601 pushed a commit to Brian030601/tp that referenced this pull request Oct 19, 2023
Copy link

@maanyos maanyos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good organisation of packages, use of exceptions, and documentations!


import java.util.ArrayList;

public abstract class Player {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good choice of abstract class for player!

row = 0;
}

for (int tempRow = row; row < tempRow + 2; row++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would make more sense if tempRow was changed instead of row

Comment on lines 102 to 116
public Move getNextMove(ChessBoard board) throws InvalidMoveException, NullPieceException, ParseCoordinateException{
String input = TextUI.getUserInput(); // Get user input
try {
Parser parser = new Parser();
Command command = parser.parseCommand(input, board);
if (command instanceof AbortCommand) {
return null;
}
return command.getMove();

} catch (ParseCoordinateException | NullPieceException e) {
TextUI.printErrorMessage(e);
}
return new Move();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the catch clause intended to throw the same exception again after printing error message?

int colour = promoteFrom.getColour();
Coordinate position = promoteFrom.getPosition();

switch (promoteTo.toLowerCase()){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good versatility


import java.util.ArrayList;

public abstract class ChessPiece {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good use of abstract class for chess piece!

public static void saveBoard(ChessBoard board) throws SaveBoardException {

try (FileWriter fileWriter = new FileWriter(filePath)){
for (int row = 0; row < 8; row++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try do define constants as final variables on top

Copy link

@maanyos maanyos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good that you've added help messages
Good use of documentation and comments in some parts to explain code
Try to keep the way of printing messages consistent, some use const final strings, others put the string directly in the methods
Keep the way of printing output consistent also, some classes are directly calling system.out.print

Comment on lines +86 to +88
public static void main(String[] args) {
new ChessMaster().run();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good abstraction of main

Comment on lines +39 to +41
if (move == null) {
throw new InvalidMoveException();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be more informative if you add a message argument to the exception or use a different exception
can also consider using assertion if this is intended to ensure code correctness

import chessmaster.pieces.Pawn;
import chessmaster.ui.TextUI;

public class ChessBoard {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class is doing a lot!
consider extracting parts that deal with pieces and moves

//gets all the moves for the current player
ChessBoard board = tuple.getBoard();
Move[] moves = board.getAllMoves(color);
assert moves.length > 0 : "No moves available for " + color + " at depth " + depth;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can moves.length = 0 ever happen during use?

Comment on lines 18 to 19
assert from != null && to != null : "Coordinates in Move should not be null!";
assert piece != null && !piece.isEmptyPiece() : "Chess piece in Move should not be null or empty!";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these happen during run time?

Comment on lines +42 to +50
private int[][] boardWeight =
{{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0}};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to initialise here right

Comment on lines 76 to 83
ArrayList<Coordinate> flattenedCoordinates = new ArrayList<>();

for (Coordinate[] direction : availableCoordinates) {
for (Coordinate possibleCoord : direction) {
if (this.isMoveValid(possibleCoord, board)) {
flattenedCoordinates.add(possibleCoord);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider refactoring this part if its used in many methods

@@ -23,16 +137,29 @@
|Version| As a ... | I want to ... | So that I can ...|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it supposed to be formatted this way?

**API:**

Below is a class diagram representing the Storage class.
The Storage component is responsible for handling the storage and retrieval of chess game state.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the StorageClass diagram be shown at the next line instead?


![](StorageSequence.png)

* Creates the necessary parent directories for the file and the file itself if they don't exist

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to provide more detailed explanations alongside the diagrams to offer readers a better understanding of creating parent directories, saving the ChessBoard state, resetting the game, and loading the state.

In order to handle user input into the program during the game, the `Parser` class was implemented.
Below is a sequence diagram describing the process of handling user input passed from `Game`:

![](images/ParseCommandSequence.png)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on the diagram and explanation of how the Parser class works! The visual representation along with the detailed step-by-step breakdown makes it easy to understand the process.

Copy link

@DextheChik3n DextheChik3n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added review comments for DG

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sequence diagram seems too big, perhaps break down into the different method calls

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
is there a way to prevent the red cross from overlapping with the String return arrow? I feel that this could be misinterpreted

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
is there supposed to be a method call here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Perhaps colon was forgotten before the class name 😅

Copy link

@ziyi105 ziyi105 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall clean and neat!


chessMaster -> ui : shouldStartNewGame()
activate ui
user -> ui : "yes/no"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be the condition? Because its meaning kinda overlaps with Previous Board Exist, so maybe you should just use one of them

Command -> ChessBoard ++: showAvailableCoordinates
ChessBoard --
Command -> ChessBoard ++: getAvailableCoordinatesString
ChessBoard --> Command --: String
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps using coordinateString: String is clearer?
image



create Storage
User -> Storage++ : new Storage(): String
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
I am not sure how your code is implemented, but it seems a bit strange to me to have user calling the command to create a new Storage() object. Did you mean user will input a command which is received by a class and the class triggers the creation of storage object? If yes, what is the class that triggers the creation of storage object? Perhaps in your uml you should have an arrow pointing from the class to storage class instead?

Storage -> Storage++ : createChessMasterFile()
Storage --> Storage--
create FileWriter
Storage -> FileWriter++ : new FileWriter(): File
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Is there supposed to be a lifeline for FileWriter?

TongZhengHong and others added 30 commits November 14, 2023 11:13
Ignore empty spaces in each `nextLine` method in `Storage` class
Fix bug with current turn in save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants