This project is a Scala implementation of a simplified poker game. It demonstrates various aspects of Scala programming through the development of a functional poker game, covering both the game domain and persistence features.
- Poker Game Mechanics: Simulates poker rules and gameplay, including card dealing, hand evaluation, and determining winners.
- Domain Model: Implements essential components such as cards, hands, decks, and players.
- Persistence Layer: Uses MongoDB to persist game data.
- Scala: A functional programming language that runs on the JVM.
- MongoDB: A NoSQL database used for storing game data.
- SBT: A build tool for Scala projects.
- Game Rules: Simplified Poker for one player and one dealer.
- Game Flow:
- Deal 2 cards face down for the dealer.
- Deal 2 cards face up for the player.
- Ask the player for a bet amount.
- Deal 3 community cards face up.
- Determine the winner based on the hand types: High Card, One Pair, Two Pairs, Three of a Kind, Straight, Flush.
- Ask if the player would like to play another round.
- Persistence: Stores game rounds data using MongoDB.
build.sbt: SBT build configuration file for project dependencies and settings.project/build.properties: File for specifying the SBT version used in the project.src/main/scala/: Contains the main source code.models/: Includes the game models and domain logic.repositories/: Contains MongoDB repository and document models.services/: Game service with core functionality.
src/main/resources/: Contains configuration files for MongoDB.src/test/scala/: Contains test code.services/: Includes tests for game service.models/: Includes tests for game models.
The project dependencies are managed via build.sbt and will be automatically resolved by SBT when you run the build commands. Here are the main dependencies:
- MongoDB Scala Driver:
"org.mongodb.scala" %% "mongo-scala-driver" % "5.1.2"
- SL4J Logging:
"org.slf4j" % "slf4j-api" % "2.0.12" "org.slf4j" % "slf4j-simple" % "2.0.13"
- ScalaTest:
"org.scalatest" %% "scalatest" % "3.2.19" % Test
- Mockito:
"org.mockito" %% "mockito-scala" % "1.17.37" % Test
- Configuration Management:
"com.typesafe" % "config" % "1.4.3"
To set up and run the project, follow these steps:
First, clone the repository to your local machine:
git clone https://github.com/SebastianoFazzino/poker-game.git
cd poker-gameTo get started with the project, you need to install the following dependencies:
-
SBT - The Scala Build Tool is used for managing the project dependencies and building the project.
-
MongoDB - A NoSQL database used for persisting game data.
- Alternative (Using Docker):
- You can run MongoDB on Docker with the following command:
docker pull mongo docker run -d -p 27017:27017 --name poker-mongo mongo
- You can run MongoDB on Docker with the following command:
- Alternative (Using Docker):
Please note that the MongoDB Scala driver does not support Scala 3.
By default, the application connects to MongoDB running on localhost:27017.
If you need to change the connection settings, update the application.conf file in the src/main/resources directory.
Note that you can also run the application without MongoDB.
In this case, you will see a few error messages related to the database connection, and the games will not be persisted.
Once you have cloned the repository and installed the dependencies, build the project with:
sbt compileTo run the project, execute:
sbt runThis will start the application, connect to the MongoDB instance and ask you to enter your name to start a new game round.
To run the tests, execute:
sbt test| Step | Command |
|---|---|
| Clone the Repository | git clone https://github.com/SebastianoFazzino/poker-game.gitcd poker-game |
| Install SBT | SBT Installation |
| Install MongoDB | MongoDB Installation |
| Run MongoDB on Docker | docker pull mongodocker run -d -p 27017:27017 --name poker-mongo mongo |
| Build the Project | sbt compile |
| Run the Project | sbt run |
| Run Tests | sbt test |
| Clean the Project | sbt clean |
| Update Dependencies | sbt update |
| Package the Project | sbt package |