RISC-V Bit-Golf Game

RISC-V Bit-Golf Game

Code Golf is a challenge where the goal is to write code for a task while minimizing some metric of the code - usually tring to write code using as few characters as possible. This Bit-Golf game is a variant I created exclusively for the 32-bit RISC-V assembly language where the goal is to minimize the number of bits with value 1 in the machine code. Try it out at bitgolf.dfrost.net.

Features

This project uses the same RISC-V assembler and VM from this project (rather, I created them for Bit-Golf before making them available as a standalone project). The VM supports the RV32I ISA. It allows the program to be run step-by-step, until a breakpoint, or until completion. It also implements a custom ECALL, allowing the user to easily input and output values for the challenges. The assembler recognizes common pseudoinstructions, such as "li" and "j". It supports labels in jump/branch instructions and comments for more readable code.
The homepage has a list of all available challenges, ranked by difficulty, with your best score for each one displayed.
The main page has 7 sections, which can be resized by dragging the gray dividers. The top left has the challenge statement and the public testcases, with the option to use your own custom testcase. Below that is your current score (number of bits). Below that is a panel which shows whether your code passes the serverside testcase validation. In the bottom left there is a leaderboard of the best scores. In the center, there is the code editor and the display of assembled machine code. On the right, the values of the register file and PC are displayed.

How it Works

The clientside RISC-V engine is written in vanilla JavaScript. The backend is PHP, with mySQL used for the databases. Serverside validation of the challenges is done using Node JS, with the same assembler & VM code as clientside, for simplicity and to ensure there are not any discrepencies between the two versions.