PA3 is to implement a multi-threaded text version of the game in PA1. There are a few changes in the rules.
Closed Issues
for questions asked by others which have been resolved.Add TAs as cooperators to your private GitHub repository.
When it is the human player's round, actions can be specified using the console.
A critical region has been introduced. A critical region are M number of rows centered by the center place. Within which, no more than N pieces can enter the critical region. N, M are parameters that can be customized.
The same as PA1 and PA2, using the following environments:
>= 14
>= 2020.2
Each piece (both Knight
and Archer
) on the computer player's side should run in a separate thread, which can be paused, resumed and terminated.
run
method should be overwritten to handle the following situations:Note:
The pieces belonging to human player follow the same rules as in PA1.
There are two strategies of computer player: RANDOM
and SMART
. , both implementing interface Player
as we did in
PA1.
Note: The ConsolePlayer
extends HumanPlayer
. There can be other kinds of Human Players in TA-only tests. So if you
want to check the kind of player, use instanceof HumanPlayer
to check whether a player is a human player.
There are two strategies of computer player, one is RANDOM
, the other isSMART
.
For test smart behavior, the test will let Random Computer Player vs Smart Computer Player 5 times with the following configuration, if Smart Computer Player wins 3 or more times, the test is passed.
In PA1, console player receives only Move
as input, while in PA3, more actions can be handled.
WithinConsolePlayer
class, the input string should be parsed and decide whether it is valid (either a move, or an action).
If the input is a valid move, then make the move.
If the input is a valid action, then make the corresponding actions (see below) .
The Behavior
specifies the behavioral preference of a piece (including Knight
and Archer
).
The piece takes a random available move as the next move.
The piece prefers to move towards the central place.
The piece prefers to blocking enemy's knight piece.
See how to block a knight here: https://en.wikipedia.org/wiki/Xiangqi (see Horse
)
The piece prefers to capture enemy's piece.
NOTE:
Behavior
is only useful for pieces belonging to a computer player. For pieces belonging to human players, it is the human player makes the decision.
The strategy
includes RANDOM and SMART. It specifies which strategy a computer player adopts.
Among all the candidate next move proposed by pieces, a computer player with SMART strategy randomly pick one move from all the proposed moves.
Among all the candidate next move proposed by pieces, students need to design how SMART strategy works. It can be implemented based on a smart heuristic or an objective function.
NOTE
Besides, since each piece has it's own behavioral preference, so when designing the SMART strategy, a configurable class textversion/SmartPlayerFactory
is also provided so that students can customize Behavior
for each piece.
Description: undo till the human player's last move
Usage:
[White] Make a Move/Action: undo
Example:
Round 1 (Human Player):
- input: move1
- result: make move1
Round 2 (Computer Player):
- result: make move2
Round 3 (Human Player):
- input: undo
- result: roll back to Round 1 and wait for Human player's input
- input: move3
- result: make move3
This action will call undo
method in Game
class and should consider the following situations:
UndoException
when exception happensDescription: pause the piece thread at the given place. The piece should belong to computer player, and the place should have a piece. Once paused, the piece cannot propose moves until it has been resumed.
Usage
[White] Make a Move/Action: pause a1
This action will call pause
method in Piece
class. The following situations should be considered:
Description: resume a paused piece thread at the given place. The piece should belong to computer player, and the place should have a piece. Once resumed, the piece can propose moves afterwards.
Usage
[White] Make a Move/Action: resume a1
This action will call resume
method in Piece
class. The following situations should be considered:
Description: Terminate a piece thread at the given place. The piece should belong to computer player, and the place should have a piece. Once terminated, the piece cannot propose moves (thus cannot move) any more, and cannot be resumed.
Usage
[White] Make a Move/Action: terminate a1
This action will call terminate
method in Piece
class. The following situations should be considered:
In Configuration
class, since each piece is run by a thread, the thread should start running when the piece is added to the chess board.
Besides, a map from piece to the corresponding thread should be recorded.
A critical region is added into configuration. It is prescribed by criticalRegionSize
and criticalRegionCapacity
.
criticalRegionSize
: the size of critical region. The requirement is specified in JavaDoc.criticalRegionCapacity
: the maximum number of Knights
of each player inside the critical region.Example:
In a 5 * 5 board, which center place lies in the center of the 3rd row. Suppose criticalRegionSize = 3
and criticalRegionCapacity = 2
, then for the critical region row 2-4 (in total row 1-5), there are at most 2 kngiths of each player in it (row 2-4).
Remaining functions are the same as in PA1.
This rule checks whether the number of pieces within the critical region is smaller or equal to the capacity of critical region.
When getting available moves, the role of current player should be distinguished:
Undo the last human player's move.
Example:
Round 1 (Human Player):
- input: move 1
- result: make move 1
Round 2 (Computer Player):
- result: make move 2
Round 3 (Human Player):
- input: undo
- result: roll back to Round 1 and wait for Human player's input
- input: move 3
- result: make move 3
At most 3 times of undos can be executed.
If there are not enough steps that can be executed, an UndoException
should be thrown.
Complete all the TODOs in the entire project.
A detailed description of each task is provided in the Javadoc above each method.
In IntelliJ IDEA, go to View > Tool Windows > TODO
to jump to each TODO in the project. You may replace the placeholder implementation in the methods marked as TODO.
Note:
We provide an obfuscated demo of PA3, which can be found at artifacts/PA3_obfuscated.jar
.
java -jar artifacts/PA3_obfuscated.jar <size> <numMovesProtection> <criticalRegionSize> <criticalRegionCapacity>
For example,
java -jar artifacts/PA3_obfuscated.jar 9 1 1 1
where 9
represents board size, the first 1
stands for the number of protection steps, the second 1
stands for the size of critical region, the last 1
stands for the capacity of critical region.
You can use Ctrl-C/Command-C
to interrupt/terminate the program.
Default:
If no parameters are given, the default values for these parameters will be 5 1 1 1
.
We provide code skeleton with detailed JavaDoc for you to complete this assignemnt. // TODO
indicates that you should write your own code there. There are in total 24 TODO
s (1 optional + 23 compulsory) for you to implement.
Note:
Do not modify other parts of the Java code unless hints in JavaDoc tell you to do that, otherwise many tests will fail unexpectedly.
Code of this assignment depends on several libraries, including JUnit5
and Jetbrains Annotations
. Jar package of these dependencies are provided in folder lib
, you need to add lib
folder as the library of your IntelliJ Project. Typically, this is already done, if you download use the prepared code in this repository.
The main method is at castle.comp3021.assignment.textversion.Main
class.
Maintaining a good code style in Java program is good practice for a developer. To help you practise good code style in Java programs, we provide a jar application to check the code style of your code.
Usage:
java -jar artifacts/checkstyle-8.36-all.jar -c artifacts/style_checks.xml com.puppycrawl.tools.checkstyle.gui.GUIMain src
If your code contains any bad code style, errors will show up with detailed information.
Note that good code style is also a part of your grade in this assignment.
Your submission is a zip file including:
github_url.txt
file containing the url of your private repository. We will ask you to add TAs' accounts as collaborators.You need to submit your zip file in CASS (not CANVAS). Please also push on your github repository before the deadline!
The deadline of assignment 3 is 10 Dec. 2020, 23:55
.
Do remember not to violate the following rules, otherwise it would be considered as an act of plagiarism.
We will conduct code plagiarism tests on your submission, and handle it according to the Honor Code if any extent of code plagiarism is found.
Percentage | Remark | |
---|---|---|
Keep your Github repository private | 0% | You must keep your repository private all the time; otherwise deduct 5%. |
At least 3 commits in different days | 5% | You must commit in three different days in your repository. |
Pass all regression tests | 5% | (# of passed tests / # of regression tests ) * 5% |
Pass all TA-only tests | 80% | (# of passed tests / # of TA-only tests ) * 80% |
Code Style | 10% | Get 10% if no error in code style checking. Deduct 1% for each 5 errors. |
No bonus tasks are provided in PA3.