Skip to content

KunYing-Lee/HumanResourceMachine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Human Resource Machine (SFML/ImGui Edition)

A desktop reimagining of Human Resource Machine powered by C++17, SFML 3, and ImGui-SFML. Write assembly‑style commands in a comfy GUI, watch your little office worker execute them, and progress through handcrafted (or user-defined) levels.

Gameplay Screenshot


Table of Contents


Features

  • Polished UI with warm ImGui styling, animated conveyors, and a lively robot.
  • Command pad:
    • Real-time warnings for unavailable commands (after you press Enter on a line).
    • Clear, Upload
  • Execution controls for Parse, Run, Step, Reset, Menu, Quit — each with custom icons.
  • Mission briefing card showing steps executed and allowed commands.
  • Persistent progress across sessions with a one-click Restart Progress.
  • Custom level loader so players can add levels from data files without touching source.

Project Layout

HumanResourceMachine/
├── report.pdf                # Project report
├── video/
│   └── demo1.mp4             # Gameplay demo video
├── code/
│   ├── main.cpp              # Online Judge Version
│   ├── CMakeLists.txt        # Top-level CMake config
│   ├── CLI/                  # CLI edition code
│   │   ├── CMakeLists.txt    # CMake config for CLI edition
│   │   ├── src/              # CLI edition source files
│   │   │   ├── Display.cpp   
│   │   │   ├── GameData.h    
│   │   │   ├── GameEngine.{h,cpp}
│   │   │   ├── GameManager.{h,cpp}
│   │   │   └── main.cpp
│   │   ├── scripts/
│   │   │   ├── level1.txt
│   │   │   ├── level2.txt
│   │   │   ├── level3.txt
│   │   │   └── level4.txt  
│   ├── GUI/                  # GUI edition code
│   │   ├── CMakeLists.txt    # CMake config for GUI edition
│   │   ├── src/              # GUI edition source files
│   │   │   ├── main.cpp
│   │   │   ├── GameData.h
│   │   │   ├── GameEngine.{h,cpp}
│   │   │   └── GameManager.{h,cpp}
│   │   ├── scripts/
│   │   │   ├── level1.txt
│   │   │   ├── level2.txt
│   │   │   ├── level3.txt
│   │   │   ├── level4.txt
│   │   │   └── custom1.txt          
│   │   └── vendor/           # GUI edition dependencies
│   ├── figures/              # Screenshots used in this README
│   └── README.md             # This README
└── tex /                     # LaTeX source for the report

structure


Getting Started

Prerequisites

  • CMake ≥ 3.10
  • C++17-capable compiler
    • macOS: Apple Clang (Command Line Tools) or brew install llvm
    • Linux: sudo apt install build-essential
    • Windows: Visual Studio 2019/2022, MSYS2, or WSL with GCC/Clang
  • SFML 3.0.2 (or newer) with its CMake configs (SFML_DIR)
  • OpenGL runtime (present by default on most platforms)

Homebrew Setup (macOS)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
xcode-select --install
brew install cmake ninja llvm

Installing SFML

macOS (Homebrew)

brew install sfml

Make sure SFML_DIR in CMakeLists.txt matches Homebrew’s path, e.g.

set(SFML_DIR "/opt/homebrew/Cellar/sfml/3.0.2/lib/cmake/SFML")

Linux (APT)

sudo apt install libsfml-dev

Custom build (any platform)

git clone https://github.com/SFML/SFML.git
cd SFML
cmake -S . -B build
cmake --build build --target install
export SFML_DIR=/usr/local/lib/cmake/SFML   # adjust as needed

Building

cmake -S . -B build
cmake --build build

CLion users can simply open the folder; it defaults to cmake-build-debug/.

Running

./cmake-build-debug/bin/cli/CLI       # for CLI edition
./cmake-build-debug/bin/gui/GUI       # for GUI edition

CLion Example

Click on the "Run/Debug Configurations" dropdown in the top-right, then select either CLI or GUI and press the green play button. run

If you run the executable from somewhere else, remember that uploads, custom levels, and progress files resolve relative to the current working directory.


Gameplay Guide

  1. Main Menu
    • Level tiles show pass/lock state. Custom levels display a [Custom] badge.
    • Bottom-right buttons let you Add Custom Level or Restart Progress. menu 2Mission Briefing
    • Displays description, steps executed, and allowed commands for the current level. briefing 3Command Pad
    • Type instructions (inbox, outbox, copyto, etc.).
    • After you press Enter on a line, the pad warns if that command isn’t available in the current level. command 4Execution Controls
    • Parse validates syntax and available commands.
    • Run animates the entire program.
    • Step executes one instruction at a time.
    • Reset clears state, Menu returns to level select, Quit closes the app. execution 5World Renderer
    • Inbox/outbox belts scroll with subtle motion, and the worker bobs/sways to keep the scene alive.

Uploading/Saving Programs

  • Upload (next to Clear) opens a popup:
    1. Enter a relative or absolute path (e.g., ../scripts/level1.txt when executing from cmake-build-debug/).
    2. Click Load to populate the command pad.
    3. The file must fit within the 16 KiB command buffer. upload

Custom Levels

The main menu now features Add Custom Level, letting players append new levels without editing source code.

  1. Click Add Custom Level (bottom-right).
  2. Enter the path to a data file and press Load.
  3. On success, the level appears in the list with a [Custom] badge (always unlocked). custom1 custom2

File Format

The loader accepts simple key=value lines (comments starting with # are ignored):

level_id=10
description=Sum positives and stop at zero
inputs=5, 3, -2, 0
outputs=6
floor_size=3
commands=inbox,outbox,copyto,copyfrom,add,sub,jump,jumpifzero

Required keys

Key Description
level_id (Optional) Integer ID. If omitted, one is auto-assigned.
description Text shown in the mission briefing.
inputs Comma-separated integers for the inbox sequence.
outputs Expected outbox sequence for success.
floor_size Number of floor tiles available.
commands Allowed instruction names separated by commas.

Invalid lines (missing = or malformed numbers) will produce an error in the popup so you can fix the file quickly.


Core Design & Module Details

Shared Data Structures (GameData.h)

  • enum class GameStatus models states such as RUNNING, FINISHED, SUCCESS, FAIL, and ERROR_STATE.
  • struct Instruction stores the opcode, optional operand, and original line number.
  • struct Level bundles narrative text, inputs, expected outputs, floor size, available commands, and completion flags.
  • struct GameState snapshots inbox/outbox contents, floor tiles, the worker's hand, and the program counter.

Game Engine (GameEngine)

  • loadLevel(const Level&) resets GameState, seeds the inbox, and clears prior programs.
  • parseProgram(const std::vector<std::string>&) tokenizes each line, validates syntax, and enforces each level's command whitelist.
  • run() advances through step() on a timer, renders intermediate state, and compares the outbox against expectations when finished.
  • step() emulates the virtual CPU with strict runtime checks before executing each instruction.
  • handleError(const std::string&) records descriptive failures with line numbers and moves the engine into ERROR_STATE.

Game Manager (GameManager)

  • run() drives the level-select menu, routes user choices, and enforces unlock conditions.
  • playLevel(int) orchestrates the full attempt lifecycle: load level, show details, collect input mode, gather program text, parse, execute, update progress, and persist results.
  • getProgramFromKeyboard() and getProgramFromFile() wrap the two input paths, including path checks and comment/blank-line filtering.
  • saveProgress() and loadProgress() keep progress in progress.txt so unlocks survive restarts.

Display Module (Display.cpp)

The display layer stays decoupled from logic. printGameState(...) clears the terminal, aligns columns with stringstream/setw(), and marks the active instruction with arrow highlighting to keep the CLI readable.

GUI Extension (SFML/ImGui Edition)

Design Goals & Tech Stack

To provide a richer experience, the GUI edition uses SFML 3.0.2 and ImGui-SFML so players can edit programs and watch the simulation in a single window.

Architecture Integration

  • GameEngine and GameManager are reused unchanged, guaranteeing identical instruction semantics and save formats.
  • The new src/main.cpp drives the SFML window loop, wires ImGui panels to engine calls (loadLevel, parseProgram, step, run), and tracks UI state.
  • Rendering helpers such as renderProgramView() and RenderGameWorld() handle code highlighting, conveyor animations, and worker motion.

Interaction & Visual Design

  • Level Menu: Tile-based layout shows lock status, tags custom levels with [Custom], and exposes a one-click progress reset (figures/menu.png).
  • Mission Briefing: Displays objectives, allowed commands, and execution counters to guide planning (figures/briefing.png).
  • Command Editor: Adds line numbers, highlights the currently executing line, and surfaces invalid instructions alongside the Parse button (figures/ExecutionControls.png and figures/CommandPad.png).
  • Animations: Conveyor belts scroll gently, the worker idles with subtle motions, and the overall view reinforces feedback (figures/WholeView.png).

License

Licensed under the MIT License. See the snippet below.

MIT License

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Enjoy automating the office! 🧾🤖 Contributions, new level packs, and feature ideas are always welcome.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published