Skip to content

Max851010/CSE_535_Project_2

Repository files navigation


Tic Tac Toe Game

CSE_535_Project_2

View Demo Video

Table of Contents
  1. About The Project
  2. Getting Started
  3. File Structure

About The Project

Product Name Screen Shot

This project presents a mobile Tic-Tac-Toe game featuring both AI-vs-human and player-vs-player (PvP) modes, developed for Android platform. The AI opponent uses the Minimax algorithm with alpha-beta pruning, allowing efficient decision-making even on resource-limited devices. The game includes adjustable AI difficulty levels, a PvP mode on one device and with Bluetooth multiplayer, and logs game history locally, storing outcomes and difficulty levels.

Introduction

Mobile gaming offers unique challenges, particularly in implementing efficient AI algorithms under constrained system resources. This project focuses on building a mobile Tic-Tac-Toe game for Android, supporting both AI-vs-human and player-vs-player (PvP) modes.

In the AI mode, a human player can challenge a computer opponent driven by the Minimax algorithm with alpha-beta pruning, which allows the AI to make optimal moves while minimizing unnecessary calculations. With three difficulty levels (Easy, Medium, Hard), the game can accommodate players of different skill levels.

In addition to the AI mode, the game offers a PvP mode, where two players can compete on a single device or over Bluetooth, enabling multiplayer interaction across two devices. The app also stores game results (game time and the winner) and difficulty levels locally, allowing players to review their history and assess their performance.

(back to top)

Built With

This section briefly describe what techenologies are used to build the project.

  • Kotlin
  • Android
  • RoomDB

(back to top)

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

Users must install the application mentioned below to set up the local environment.

  • Android Studio (Android SDK 34)

Installation

This section gives an instruction of how to run the project on local machine with Android Studio emulator.

  1. Clone the repo

    git clone https://github.com/Max851010/CSE_535_Project_2.git
  2. Activate an emulator

    • Open Android Studio
    • Click "Device Manager" at the right side bar
    • Create or activate a device
  3. Sync Project with Gradle Files

  4. Run the app

(back to top)

File Structure

This project follows the Model-View-Controller (MVC) architecture using the Jetpack Compose framework for a modular, maintainable, and responsive UI design.

  • Model: All data-related operations are managed within the database/ and viewModels/ folders, where Room entities (Entities.kt) and DAOs (HistoryDao.kt, SettingsDao.kt) represent the data layer, while DataBaseViewModel.kt and TicTacToeViewModel.kt handle data interactions and business logic.

  • View: The UI components, layouts, and themes are organized in the ui/ folder. Screens like GameScreen.kt, PastGameScreen.kt, and SettingsScreen.kt present data to the user, with styling managed in the theme/ subfolder.

  • Controller: Navigation and user flow are controlled by NavGraph.kt, which defines the routes between screens and manages transitions within the app.

The project files are organized within /app/src/main/java/com/example/cse_535_project_2_jet as follows:

.
├── MainActivity.kt
├── components
│   └── DateConverters.kt
├── database
│   ├── Entities.kt          # Defines the Settings and Histories database entities
│   ├── GameDatabase.kt      # Configures Room Database and provides instance
│   ├── HistoryDao.kt        # Data Access Object (DAO) for history table operations
│   ├── MyAutoMigrationSpec.kt # Manages database migrations
│   └── SettingsDao.kt       # DAO for settings table operations
├── navigation
│   └── NavGraph.kt          # Handles app navigation with Jetpack Navigation Component
├── ui
│   ├── components
│   │   └── TicTacToeViewFactory.kt  # Factory for rendering Tic-Tac-Toe board
│   ├── screens
│   │   ├── GameScreen.kt     # Main game screen
│   │   ├── MainScreen.kt     # Home screen, entry point
│   │   ├── PastGameScreen.kt # Displays a list of past games
│   │   └── SettingsScreen.kt # User settings and configurations screen
│   └── theme
│       ├── Color.kt          # App color scheme
│       ├── Theme.kt          # Theme configurations
│       └── Type.kt           # Text styles and font configurations
└── viewModels
    ├── DataBaseViewModel.kt  # ViewModel for database interactions
    └── TicTacToeViewModel.kt # ViewModel containing all game logic for Tic-Tac-Toe

Screens

This project is built using the Jetpack Compose framework. The main entry point is MainActivity.kt, which loads MainScreen.kt as the home screen. From there, the app is structured into three primary screens:

  • GameScreen.kt: The main gameplay interface for Tic-Tac-Toe.
  • PastGameScreen.kt: Displays a history of past games with details.
  • SettingsScreen.kt: Provides configuration options for users.

Navigation between these screens is managed by NavGraph.kt, ensuring smooth transitions.

RoomDB

The Room database setup is located in the database/ folder, with all CRUD operations facilitated through DAOs and managed via DataBaseViewModel.kt. The database includes two primary tables, defined in Entities.kt:

  • settings: Stores user configuration settings.
  • histories: Logs past games with relevant game details.

Data access is handled by SettingsDao.kt and HistoryDao.kt, which provide methods for interacting with the database in a structured, efficient manner.

Game Logic

All the game logic for Tic-Tac-Toe is implemented in TicTacToeViewModel.kt. This includes game state management, turn-based logic, win-checking algorithms, and any updates required during gameplay.

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages