This is a multithreaded Java card game where each player draws and discards cards from decks to their left and right. The goal is to collect four cards of the same value to win.
The game supports concurrent player turns and thread-safe logging of all actions.
- Java 8 or higher
- Pack file (e.g.
pack.txt) containing 8 × N integers (one per line), where N is the number of players.
- Open the project in Eclipse or IntelliJ, or compile via command line.
- Run the
Mainclass in thecardgamepackage. - When prompted:
- Enter the number of players (e.g.,
4). - Enter the file path to the pack file (e.g.,
C:\Users\Ollie\pack.txt).
- Enter the number of players (e.g.,
After the game completes:
-
Each player will have a log file:
player1_output.txtplayer2_output.txt- ...
These contain logs of each player’s actions and final result.
-
Each deck will also have a file:
deck1_output.txtdeck2_output.txt- ...
Showing the final state of each deck.
All files are written to the project root directory (./) by default.
- JUnit 4
- Ensure the test files are in the correct package (
cardgame). - Run the test files from your IDE using the built-in test runner.
- Example test classes:
CardDeckTest.javaPlayerTest.javaTurnConcurrencyTest.javaLoggingTest.javaOnlyFirstWinnerCounts.javaAtomicTurnLocking.java
- Example test classes:
Alternatively, from the command line:
javac -cp .:junit-4.13.2.jar:hamcrest-core-1.3.jar cardgame/*.java
java -cp .:junit-4.13.2.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore cardgame.PlayerTest- Multithreaded player turns with deck locking.
- Turn atomicity guaranteed (draw + discard together).
- Game ends cleanly with all players notified.
- Clean logging for players and decks.
- Error handling for invalid inputs and empty decks.
- Oliver Appleby (680049063)
- Raghavendra Iyer (740074572)