npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hrm-cpu

v0.2.3

Published

Run Human Resource Machine programs in JavaScript

Downloads

9

Readme

hrm-cpu

Run Human Resource Machine programs in JavaScript

This is a JavaScript runtime for the programs you write in the game Human Resource Machine

Screenshot

Human Resource Machine is a puzzle game. In each level, your boss gives you a job. Automate it by programming your little office worker! If you succeed, you'll be promoted up to the next level for another year of work in the vast office building. Congratulations!

NPM

npm install hrm-cpu

Usage

Requires node 4.x - uses ES6

Basic Usage

const HrmCpu = require( 'hrm-cpu' )

//source is a string in the Human Resource Machine program format
const source = loadSomeSourceFile()

//the initial state of the inbox - treated as FIFO
const inbox = [ 5, 18 ]

//initial memory state - set just slot 9 to 0
const tiles = {
  9: 0
}

const outbox = HrmCpu( source, inbox, tiles ).run()

console.log( outbox )

Some levels don't require any floor tiles, in which case you can do:

const outbox = HrmCpu( source, inbox ).run()

Some levels don't require an inbox, but if this is the case they must have floor tiles:

const outbox = HrmCpu( source, [], tiles ).run()

Advanced Usage

Also see examples directory or try running the tests with mocha

Factory overloads
HrmCpu( state ) 
HrmCpu( options )
HrmCpu( source, inbox )
HrmCpu( source, options )
HrmCpu( source, inbox, tiles )
HrmCpu( source, inbox, floor )

HrmCpu is a factory function that returns an object with some properties and the functions run and step

{
  options: {...},
  state: {...},
  run: ( cb ) => ...,
  step: ( cb ) => ...
}

Regardless of which overloads you choose, the factory requires a source file, and either of, or both of, inbox and floor state

If run is called synchronously it runs the whole program and returns the outbox

If step is called synchronously it executes a single line of the program, and returns the program state

If run is called asynchronously it runs the whole program and then calls the callback with ( err, outbox, state )

If step is called asynchronously it executes a single line and calls with ( err, state )

State

The state object when set to the initial defaults looks like:

{
  program: [], 
  accumulator: null,
  inbox: [],
  outbox: [],
  memory: [],
  counter: 0,  
  steps: 0,
  running: false
}
Options

Passed in options extend the default options, which are:

{
  source: '',
  inbox: [],
  tiles: [],
  columns: Infinity,
  rows: Infinity,
  commands: [ 'INBOX', 'OUTBOX', 'COPYFROM', 'COPYTO', 'ADD', 'SUB', 'BUMPUP', 'BUMPDN', 'JUMP', 'JUMPZ', 'JUMPN' ],
  dereferencing: true,
  maxSteps: 5000,
  maxSize: 255,
  minValue: -999,
  maxValue: 999  
}

These match the constraints of the actual game

source, inbox and tiles are described above

columns and rows describe the floor layout - these determine the valid floor addresses and if set and your program tries to access a tile outside of these, an error will be thrown or sent to your callback, depending on whether you used the sync or async call

commands are the commands allowed for the current program - for example, in the early levels many commands are not yet available

dereferencing is whether or not the program can access memory indirectly eg [12]

maxSteps is the maximum number of steps your program can run

maxSize is the maximum length of a program, not counting labels and comments. A jump only counts as one line

minValue is the minimum value that you can hold in your hand

maxValue is the maximum value that you can hold in your hand

Async example
HrmCpu( source, inbox, tiles ).run( ( err, outbox ) => {
  if( err ){
    console.error( err )
  } else {
    console.log( outbox )
  }
})
Get program state from run
HrmCpu( source, inbox, tiles ).run( ( err, outbox, state ) => {
  if( err ){
    console.error( err )
  } else {
    console.log( state )
  }
})

Related projects

Runtimes

Parsers

Comment/label decoders & encoders

Viewers

Solutions

Utils/data

Please let me know if you know of any others!

License

MIT