Skip to content

This is the first project of COMP336 Algorithms course in BZU. Its main aim is to create a coin game where the player who moves first always wins, using a Dynamic Programming approach.

Notifications You must be signed in to change notification settings

MaysHroub/DPCoinsGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Optimal Coin Game Strategy with Dynamic Programming 🪙

Or known as "Optimal strategy for a game using dynamic programming".

Overview

DPCoinsGame is a dynamic programming-based game where players take turns choosing coins (first or last coins only) strategically to maximize their score. This game demonstrates concepts of dynamic programming, user interaction with a GUI built with JavaFX, and game logic implemented using Java.

I used Singleton design pattern in NaviagationManager class to navigate between game panes, and applied Single Responsibility Principle to ensure clean, modular, and maintainable code.

Dynamic Programming Logic

DP Relation Used:

dp relation i is a pointer to the start of the coins array and j is a pointer to the end of the array.

Initial value:

  • If we have one coin, we take it.
  • If we have two coins, we take the maximum one.

Features

  • Dynamic Programming: Implements a dynamic programming solution for coin selection.
  • Real-Time Updates: UI updates as players make their moves, displaying scores and coin selections.
  • Animation: Animates UI components of the screen.
  • Different Input Options: There are three options, manually, randomly generated, and reading from file.
  • Scoreboard: Displays current scores for both players.
  • Game End: Announces the winner once all coins are selected.
  • There are two modes in the game: Two-Player mode and DP-Game mode.
    • Two-Player mode: A classic turn-based game where two players compete.
    • DP-Game Mode: Watch the game play out automatically based on dynamic programming logic. (It's a Computer vs. Computer game)

Screenshots of main screens

Start Screen

Main Screen

Game Rules

Game Rules

Data Input Options

Data Input Options

Manual Data Input

Manual Data Input

DP Game Screen

DP Game Screen

DP Table

DP Table

Demo Video

Click here to see the demo :3

About

This is the first project of COMP336 Algorithms course in BZU. Its main aim is to create a coin game where the player who moves first always wins, using a Dynamic Programming approach.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published