Skip to content

Three Trios Solitaire — GUI + Machine Mode A fully featured Three Trios Solitaire game with both graphical and machine-playable modes. Built with clean, testable game logic and expandable architecture.

Notifications You must be signed in to change notification settings

aviks4897/ThreeTrios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreeTrios Game

A multiplayer card game where players place cards on a grid and battle for control.

Class Invariant

If the cell state of a grid cell is Block, it cannot be modified at any point in the code.

Overview

The ThreeTrios game is a multiplayer card game where players place cards on a grid.
The objective is to control the most cards of your PlayerColor on the board by the end of the game.

  • Grid & cells:
    Each position on the grid is represented by a GridCells object, which has:

    • a cell state (Filled, Unfilled, or Block)
    • a card value, which is initially null

    Based on a grid cell’s state, a player may or may not be allowed to place a card on that cell.

  • Configuration-driven setup:
    The game is loaded from configuration files:

    • a grid configuration (board layout)
    • a deck configuration (cards and their values)

Quick Start

Below is a minimal example of how to construct and run a game using the model and view:

import cs3500.threetrios.model.SoloTTGModel;
import cs3500.threetrios.model.SimpleCard;
import cs3500.threetrios.model.TTGModel;
import cs3500.threetrios.view.SoloTTGView;
import cs3500.threetrios.view.TTGView;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    TTGModel<SimpleCard> ttgModel =
        new SoloTTGModel("src/hardboard.config", "src/largeCardBase.config");
    TTGView ttgView = new SoloTTGView(ttgModel);

    ttgModel.startGame();
    ttgModel.placeCard(0, 0, 0);
    ttgModel.battle();
    ttgModel.placeCard(0, 1, 1);
    ttgModel.battle();

    System.out.println(ttgView.toString());
  }
}

Key Components

  • Grid & cells (GridCells):
    The grid is a 2D array of GridCells.
    Each cell:

    • has a state: Filled, Unfilled, or Block
    • holds an optional card (initially null)
  • Deck & grid creation (DeckCreator, GridCreator):
    These classes read and parse the configuration files to construct:

    • the starting deck
    • the initial grid layout

Key Subcomponents

  • GameState:
    Tracks the current phase of the game, such as:

    • Start
    • Place
    • Battle
    • End
  • Pair:
    Stores a row/column pair used for tracking the coordinates of cards that are flipped during the battle phase. This supports combo battles by remembering which cells were affected.

Source Organization

  • Configuration files:
    Located under src/ (for example, hardboard.config, largeCardBase.config).

  • Model (cs3500.threetrios.model):
    Contains all core interfaces and classes for the game logic, including:

    • grid and cells
    • cards and decks
    • game state and strategies
  • View (cs3500.threetrios.view):
    Contains classes and interfaces to render the game and interact with the user.

UI & View Components

  • GridPanel

    • A JPanel subclass representing the grid.
    • Uses the actual model grid to display:
      • holes
      • filled cells
      • unfilled cells
  • HandPanel

    • Represents both players’ hands.
    • Shows the current cards available to each player.
  • ThreeTriosGUI

    • A JFrame subclass that represents the window of the game.
    • Hosts panels and connects them to the controller.

Controller & Features

  • Features interface

    • Defines the actions that can be triggered from the view (e.g., button clicks in the hand and grid).
    • Implemented by the controller and used by both HandPanel and GridPanel to notify the model of user interactions.
  • ModelFeatures interface

    • Defines methods in the model that interact with both the controller and the view.
    • Includes methods such as:
      • addListeners(...) to subscribe the controller as a listener
      • displayTurn() to announce whose turn it is

Player Abstractions & Strategies

  • Player interface

    • Implemented by:
      • HumanPlayer
      • MachinePlayer
    • Allows the controller to distinguish between human and machine players and request moves or coordinates accordingly.
  • Controller logic

    • The controller supports:
      • human vs. human
      • human vs. machine
      • machine vs. machine
    • The machinePlay() method interacts with the model and applies the appropriate strategy based on the Player type, choosing the coordinates to pass into placeCard(...).

Configurations & Running the Game

  • Player types & strategies

    • In your configuration, specify:
      • human to initialize a human player
      • strategy1 or strategy2 (or other supported names) to initialize a machine player

    If no command-line arguments are provided, the game defaults to a human vs. human game.

  • Entry point (ThreeTrios class)

    • Reads the command-line arguments.
    • Creates the appropriate player types (human or machine) and the strategies associated with them.
    • Initializes the model, view, and controller.

Design & Refactoring Notes

  • View–Features pattern

    • The view’s frame and its panels are separated into distinct classes.
    • Each feature (panel, button group, etc.) is responsible only for UI concerns and delegates logic to the controller via the Features interface.
  • Observer pattern

    • The model uses ModelFeatures to notify subscribed listeners (e.g., the controller) of changes.
    • This yields strong decoupling between model, view, and controller.
  • Future improvements

    • Move further away from concrete classes when possible and increase the use of interfaces and abstractions.
    • Continue refining the MVC design to keep responsibilities well separated and testable.

About

Three Trios Solitaire — GUI + Machine Mode A fully featured Three Trios Solitaire game with both graphical and machine-playable modes. Built with clean, testable game logic and expandable architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages