Skip to content

About

This repository contains code for the Python-Java Integration for the Game of Amazons Project in UBC's COSC 322 Course.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Game of Amazons: Python-Java Integration for COSC 322

This project extends the COSC 322 Game of Amazons client so students can write AI logic in Python while continuing to use the course's existing Java and SmartFoxServer infrastructure.

User: students building Game of Amazons agents in an undergraduate AI course.
Input: game state from the Java client and Python-based agent logic.
Output: a legal game action returned through the Java client and sent to the SmartFoxServer game server.

Watch the Python-Java integration demo

Why this project exists

The COSC 322 Game of Amazons environment is built around a Java client and SmartFoxServer APIs. That works well with the course infrastructure, but it makes it harder for students to use Python-first AI and machine-learning libraries.

This integration adds a bridge rather than replacing the course stack. Python can compute an action, Py4J carries that result across the language boundary, and the existing Java client remains responsible for game-server communication.

That lets students experiment with Python AI tooling without rewriting the networking and game infrastructure around it.

Architecture

flowchart LR
    State[Game state] --> Java[Java Game of Amazons client]
    Java --> Bridge[Py4J JVM gateway]
    Bridge --> Python[Python AI / search logic]
    Python --> Action[Selected move]
    Action --> Bridge
    Bridge --> Java
    Java --> Validate[Java action validation]
    Validate --> SmartFox[SmartFoxServer client API]
    SmartFox --> Server[COSC 322 game server]
    Server --> Java
Loading

The language boundary is intentionally narrow: Python is used for AI computation, while Java keeps ownership of the existing client lifecycle, action representation and server protocol.

How the integration works

  1. The Java client receives the current Game of Amazons state.
  2. The client exposes the state across a Py4J JVM gateway.
  3. Python code evaluates the state and selects a move.
  4. The selected move is returned to Java.
  5. Java converts and validates the action using the existing game structures.
  6. The SmartFoxServer client API sends the move to the course game server.
  7. The next server update returns through the same Java client.

The repository includes both Java and Python implementations around this boundary so the integration can be inspected end to end.

AI code in the repository

The Java side includes Game of Amazons action utilities, game-player logic and Monte Carlo Tree Search components. The Python side includes a Python MCTS implementation that can participate through the language bridge.

This makes the repository useful for more than demonstrating Py4J syntax: it shows how a Python decision-making component can be inserted into a Java game client without changing the server contract.

Validation

The integration is validated through the linked working demo and repository-side test code.

Validation focuses on the boundary that matters most:

  • game state can move from Java to Python;
  • Python can compute and return an action;
  • Java can translate the returned action into the existing game structures;
  • the course client can continue communicating through SmartFoxServer;
  • action-validation logic remains on the Java side before the move is sent.

The repository also contains Java test code under src/main/java/ubc/cosc322/test/.

Design tradeoffs

  • Bridge the existing Java client instead of replacing it: this preserves compatibility with the course server and avoids reimplementing the networking stack, while introducing a cross-language boundary.
  • Python for AI logic, Java for protocol ownership: students gain access to Python's ML/AI ecosystem while the established Java client remains the source of truth for server communication.
  • Py4J over file-based or subprocess-only exchange: object-level JVM access gives tighter integration than serializing every move through files, while requiring the Python and Java runtimes to stay coordinated.
  • Keep action validation in Java: Python can focus on search or learning logic, while the existing client continues enforcing the action structures expected by the server.
  • Reuse the course architecture: the project demonstrates integration inside a real teaching system rather than creating a separate standalone game that would not exercise the same client-server constraints.

Repository structure

src/main/
├── java/ubc/cosc322/
│   ├── actionutil/        # action representation and construction
│   ├── mcts/              # Java MCTS components
│   ├── run/               # game-player entrypoints
│   └── test/              # integration/test code
└── python/
    └── mcts_amazons.py    # Python MCTS logic

pom.xml                    # Java/Maven configuration
PROJECT_DETAILS.md         # course/project context

Technology

Java · Python · Py4J · SmartFoxServer APIs · Maven · Monte Carlo Tree Search

Java provides the existing course client and server-facing protocol. Python provides an alternate environment for AI logic. Py4J connects both runtimes through a JVM gateway, while Maven manages the Java project dependencies.

Key files

Related work

The integration grew out of the broader PNRL honors-thesis work on reinforcement-learning development for undergraduate AI education:

PNRL: Reinforcement Learning Development for an Undergraduate AI Course

About

This repository contains code for the Python-Java Integration for the Game of Amazons Project in UBC's COSC 322 Course.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages