-
Notifications
You must be signed in to change notification settings - Fork 89
[CS2113-T18-1] ChessMaster #19
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
base: master
Are you sure you want to change the base?
Changes from 250 commits
9fc8c13
70b7003
e0159f0
f2e8235
10847a1
37cbf93
3268804
98331c4
c0b3577
0fe8b95
80e109a
f17486a
dc3668c
f7838f2
7eb0f9e
f8a7b35
714d012
d82392e
1f3e7f7
498fbea
08420ba
7324ef4
a052e85
9bffca4
1710195
32cf804
99a3ee4
18d37b1
f684dee
acdd930
5406e62
3762f79
19fb966
42eef1a
fa0fa79
4525066
7bf7c54
8e0a8f1
802582d
717b358
7d870ef
59c2d5e
a10c349
67619dc
ef6bac8
ff6b86b
9b339c0
8268c7b
26725a4
7469500
4e50d84
eb87848
d3fa18b
e9e5923
1941801
65c8c86
52086ff
d7ec2a8
5770b3d
e5300d3
5a1f957
c836b13
50b6d2e
2ff19bf
41f3b5f
809e5e4
f1b2b4e
30aa1e6
b3012f1
d2dd897
2a8bb70
4fad3f2
491c930
87717d8
0870bc7
eb795e1
ad02abf
8763f34
f7accc3
21806a5
eb1b788
30c659f
5f078f2
c2e3ec8
56dbf14
bd4d5f6
4de3a98
c6e77af
eedd6ec
dd63b30
8017314
6f9c306
ef82d23
9b39705
69fd191
f0b364c
de5ae95
01be1dd
6e02e4b
12a84ad
1dc655a
caeabca
381d557
e4f0cc4
2fb6596
1e276c1
b2ad4f9
e0c3716
201303c
c1788f6
5cb0482
2e445ee
efa9398
a57b464
ab71546
b464629
8c5aacb
9efb1cb
651a844
5d1d3b6
4dd5747
a0110a6
17a7572
742b2e3
665087e
94b21a2
c246dab
0ca6bc5
b0900e3
f7431ce
02478a1
1b58255
74c3649
d8f7b1e
2ab92d3
9e8ad64
0d55d2a
8f86bab
a6067ed
69d0824
96178ee
b7099fd
90522ef
d7bb8c9
d1ce2ce
7e3e10e
bbfe1ed
8a4de19
f676892
32e4d12
c88fea3
413a98e
25acc31
964da00
fcae0e3
23b2736
cecc663
429ea9f
23dd131
edb977b
0993b31
b20897b
0fb5a55
c34338f
f46af11
3c38813
49caca9
311ff0d
862dda0
62e4ee3
fc2e9c0
06c2aad
2061176
d33f630
9df3942
579fcfb
c662f9d
6bb4d9d
98c510d
acd7a81
6f3df81
d7da223
abb1446
6efa74c
e22f171
de6b09a
1c1dde6
2680650
c829a78
466b9bb
b9d5726
18b17ae
26dc224
25f0c0a
2e85987
ce1009c
8b590fe
a0f0648
4d663ae
fe98b6f
d9332ac
33dea45
74d3956
fc333cd
8d5ba9a
2259860
c0c17a5
c750b5c
360a1fd
1c8da78
2bd7357
56b8aba
8c7342e
f457f9b
0de748b
8d75c39
3af0b23
3e31de5
e28809a
2ed2f11
640f78c
6afb108
67be4cc
aae3ad2
04e18cb
50c96b0
a7aa3a1
9fa6733
59f5d20
ad9de0c
aa788a2
d7bb443
8ffe6a4
5cae662
460dc3b
3d190c1
6f75922
c9dc296
65fccd0
e630390
0fe9f19
f895863
21b3717
d74d6d3
bf7e53a
7a30a43
92a817f
640bcaf
1259479
a4245f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: chessmaster.ChessMaster | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<project name="ChessMaster" basedir="." default="main"> | ||
|
||
<property name="src.dir" value="src/main/java"/> | ||
<property name="build.dir" value="build"/> | ||
<property name="classes.dir" value="${build.dir}/classes"/> | ||
<property name="jar.dir" value="${build.dir}/jar"/> | ||
<property name="main-class" value="chessmaster.ChessMaster"/> | ||
|
||
<target name="clean"> | ||
<delete dir="${build.dir}"/> | ||
</target> | ||
|
||
<target name="compile"> | ||
<mkdir dir="${classes.dir}"/> | ||
<javac includeantruntime="false" target="11" source="11" encoding="utf8" srcdir="${src.dir}" destdir="${classes.dir}"/> | ||
</target> | ||
|
||
<target name="jar" depends="compile"> | ||
<mkdir dir="${jar.dir}"/> | ||
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}"> | ||
<manifest> | ||
<attribute name="Main-Class" value="${main-class}"/> | ||
</manifest> | ||
</jar> | ||
</target> | ||
|
||
<target name="run" depends="jar"> | ||
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/> | ||
</target> | ||
|
||
<target name="clean-build" depends="clean,jar"/> | ||
|
||
<target name="main" depends="clean,run"/> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
# About us | ||
|
||
Display | Name | Github Profile | Portfolio | ||
--------|:----:|:--------------:|:---------: | ||
 | John Doe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
 | Don Joe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
 | Ron John | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
 | John Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
 | Don Roe | [Github](https://github.com/) | [Portfolio](docs/team/johndoe.md) | ||
| Name | ID | Github | | ||
|-----------------|-----------|---------------| | ||
| Antriksh Dhand | A0278458J | antrikshdhand | | ||
| Oh Ken Wei | A0251850J | ken-ruster | | ||
| Ou Ningxiang | A0249445W | onx001 | | ||
| Tong Zheng Hong | A0251819Y | TongZhengHong | | ||
| Tricia Boo Koh | A0264665U | TriciaBK | |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,110 @@ | |
|
||
## Design & implementation | ||
|
||
{Describe the design and implementation of the product. Use UML diagrams and short code snippets where applicable.} | ||
 | ||
|
||
### Architecture | ||
|
||
The Architecture Diagram given above explains the high-level design of the application. Given below is a quick overview of main components and how they interact with each other. | ||
|
||
#### Main components of the architecture | ||
|
||
`ChessMaster` is the main invocation of the application. It handles the loading of previous chess games from the storage file and running of the chess `Game` instance. | ||
|
||
The remaining logic is handled by the following components: | ||
- **UI**: The User Interface of the application | ||
- **Game**: Executes user commands in game and CPU moves | ||
- **Storage**: Reads and write chess game information to the hard disk | ||
- **ChessBoard**: Holds the current chess board state in memory | ||
- **Parser**: Parses string representations into relevant classes (`Command`, `Move`, `ChessPiece`, etc) | ||
|
||
Our application also uses other classes to store information about the chess game and provide utility functions for the main components to function. This include: `Command`, `Move`, `Coordinate`, `Color`, `Player`, `ChessTile` and `ChessPiece(s).` | ||
|
||
### ChessMaster component | ||
|
||
<!-- Here is a partial class diagram of ChessMaster. --> | ||
|
||
The sequence diagram below illustrates the interactions within the ChessMaster component, when they launch the program. | ||
|
||
 | ||
|
||
How does ChessMaster component work: | ||
|
||
1. Attempts to load previously stored game in storage | ||
2. If previous game exists, asks the user if a new game or the previous game should be loaded. | ||
3. If a new game is selected, the user will be prompted for the color to start. | ||
4. Start running the new or previous game instance. | ||
|
||
### Game component | ||
|
||
The sequence diagram below illustrates the interactions within the Game component, taking a move of "a2 a3" as example. | ||
|
||
 | ||
|
||
How does the Game component work: | ||
1. Solicits input from user. Users can provide game commands, if not recognised, it will parsed as a `MoveCommand`. | ||
2. The returned command will be executed. | ||
3. If user entered a game command (not MoveCommand), the next user input will be solicited. | ||
4. If a MoveCommand is identified, the user's input will be parsed as a Move object with checks to ensure it is a valid move on the chessboard. | ||
5. The user's validated Move will be executed on the chess board. This move will then be saved in the storage file. | ||
6. Next, it will be the CPU's turn to play. The best move will be calculated by the CPU object and it will be executed on the chess board. This move will also be saved in the storage file. | ||
7. Once both the user and CPU has made their moves, the game state will be checked where the number of kings on the board and the winner will be determined. | ||
|
||
### Architecture | ||
|
||
### User Input Handling - `Parser` and `Command` | ||
Below is a class diagram representing the Command and Parser classes. | ||
 | ||
|
||
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`: | ||
|
||
 | ||
|
||
`Parser` works to resolve a player's input in the following manner: | ||
|
||
1. When `Parser` is called to parse a command, it returns the relevant `Command` object (More precisely, | ||
one of its subclasses e.g. `MoveCommand`), which is then executed by `Game`. | ||
2. Depending on the type of `Command` returned, the following may occur: | ||
1. If it is a `MoveCommand`, the Command calls `parseMove` to instantiate the `Move`, | ||
which is passed back to `Game` to be executed in the main logic. | ||
2. If it is a `ShowMovesCommand`, `parseAlgebraicCoor` is called to obtain the position of the piece as a | ||
`Coordinate` object. The available coordinates are printed using `showAvailableCoordinates`, then stored as a String | ||
by `getAvailableCoordinatesString()`. | ||
3. The result is then encapsulated in a `CommandResult` and returned to `Game` to be handled. | ||
4. If the player made a move resulting in a promotion, `parsePromote` is called. | ||
5. `Parser` calls `getColor` and `getPosition` to retrieve relevant data from the `ChessPiece` | ||
the player wants to promote. | ||
6. The user's input is parsed and a new `ChessPiece` is returned. | ||
|
||
`Parser` also contains methods to fulfil parsing needs in other parts of the program, for instance `parseChessPiece`, | ||
which is called while loading the .txt file containing save data, called for each character representing a | ||
singular chess piece. Using a Case statement, it returns the relevant `ChessPiece` object depending on the character | ||
(representing the type of piece), and whether it is capitalised (representing colour). | ||
|
||
How the parsing works: | ||
- When called upon to parse a user command, the `Parser` class returns a relevant subclass of the `Command` class | ||
(i.e. entering a valid command "XYZ" will cause `Parser` to return an `XYZCommand` object) | ||
- Each `Command` subclass contains the relevant methods to execute the specified command | ||
(AbortCommand, ShowCommand, etc.) and inherit from the abstract `Command` class. | ||
|
||
### Minimax algorithm | ||
|
||
The minimax algorithm is used to determine the best move for the AI to make. It is a recursive algorithm that works by alternatingly minimising opponent scores and maximising CPU scores. The algorithm is implemented in the `Minimax` class. | ||
|
||
### Storage Component | ||
**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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the StorageClass diagram be shown at the next line instead? |
||
 | ||
|
||
 | ||
|
||
* Creates the necessary parent directories for the file and the file itself if they don't exist | ||
|
||
* Saves the current state of the ChessBoard to the file. It includes the player's color information and current player's turn as the first line and the state of the chessboard in an 8x8 format. | ||
* Allows resetting the game by clearing the contents of the file. | ||
* Loads the state of the chessboard from the file by constructing a 2D array of ChessTile objects. | ||
|
||
|
||
## Product scope | ||
|
@@ -23,16 +126,29 @@ | |
|Version| As a ... | I want to ... | So that I can ...| | ||
|
||
|--------|----------|---------------|------------------| | ||
|v1.0|new user|see usage instructions|refer to them when I forget how to use the application| | ||
|v1.0|player|only move valid moves|play chess properly| | ||
|v1.0|new user|start a new game|play chess multiple times| | ||
|v1.0|player|see the current state of the chess board on every turn|think about what move to play| | ||
|v1.0|player|tell which symbol represents which piece|know what is where| | ||
|v1.0|player|specify move coordinates|move the piece I want how I want it| | ||
|v1.0|player|promote pieces when the option is available|play extended games properly| | ||
|v1.0|player|have the option to abort the game|leave the game when I no longer want to play| | ||
|v2.0|user|find a to-do item by name|locate a to-do without having to go through the entire list| | ||
{more to be added} | ||
|
||
|
||
## Non-Functional Requirements | ||
|
||
{Give non-functional requirements} | ||
1. Should work on any mainstream OS as long as it has Java 11 or above installed. | ||
2. A user with a basic understanding of chess should be able to navigate the game without difficulty. | ||
{More to be added} | ||
|
||
|
||
## Glossary | ||
|
||
* *glossary item* - Definition | ||
|
||
## Instructions for manual testing | ||
|
||
|
||
{Give instructions on how to do a manual product testing e.g., how to load sample data to be used for testing} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Duke | ||
# ChessMaster | ||
|
||
{Give product intro here} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@startuml | ||
class Storage { | ||
- filePathString: String | ||
|
||
+ Storage(filePath: String) | ||
+ saveBoard(board: ChessBoard, playerColor: Color): void | ||
+ resetBoard(): void | ||
+ loadBoard(): ChessTile[][] | ||
+ loadPlayerColor(): Color | ||
|
||
- createChessMasterFile(): void | ||
} | ||
|
||
class ChessBoard { | ||
- SIZE: int | ||
} | ||
|
||
class ChessTile | ||
|
||
class Color | ||
|
||
Storage --|> File | ||
Storage --|> ChessBoard | ||
Storage --|> ChessTile | ||
Storage --|> Color | ||
@enduml |
|
There was a problem hiding this comment.
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.