How mic-hb/proyek_ai_backend works
Project Type and Purpose
• This is a backend AI service for the traditional Indonesian game “Macan-Macanan.”
• It exposes a Socket.IO API (real-time events) and houses both the game rule engine and multiple AI algorithms (Minimax with alpha-beta pruning).
a. Client
• Any front-end or UI (web/mobile) that uses Socket.IO to interact with the server.
b. Socket.IO Server Layer (src/app/api.py)
• Listens for connection, room-join, move requests, AI-suggestion requests.
• Emits game state updates and AI moves back to clients.
c. Game Engine (src/game/…)
• Domain model: Board, Cell, Piece, Player, Room.
• Game rules and state transitions (game.py, move_request.py, suggested_move.py).
d. AI Service Layer (src/app/ai.py)
• Orchestrates calls to specific algorithms based on game state.
e. Algorithm Modules (src/ai/…)
• algorithm_1.py, algorithm_2.py implement Minimax / alpha-beta.
• AI.py defines common interfaces for algorithms.
f. (Optional) Persistence / Configuration
• Even if no database is used, show configuration (pyproject.toml, requirements.txt, .env, if any) and test harness (tests/).
Relationships and Data Flows
• Client → Socket.IO Server: emits events like “join_room,” “make_move,” “request_suggestion.”
• Socket.IO Server → Game Engine: invokes game logic to validate/apply moves.
• Socket.IO Server → AI Service → Algorithm Modules: for “suggest_move” events.
• Game Engine / AI → Socket.IO Server → Client: emits updated game state or AI-chosen move.
Architectural Patterns & Design Principles
• Separation of Concerns:
• API layer handles connectivity & protocol.
• Game engine encapsulates pure domain logic.
• AI layer wraps algorithms.
• Modularity/Plug-in Architecture: new AI algorithms can be dropped into src/ai/ and wired in src/app/ai.py.
• Event-Driven: Socket.IO events drive the flow.
Technologies & Frameworks to Annotate
• Python 3.12 (interpreter)
• python-socketio (server implementation)
• Minimax & Alpha-Beta Pruning techniques (in algorithm modules)
• pytest (tests suite)
• Sphinx (in docs/)