Minesweeper

Minesweeper

Hard

Introduction

Minesweeper is a popular game where the user has to find the mines using numeric hints that indicate how many mines are directly adjacent (horizontally, vertically, diagonally) to a square.

Instructions

Your task is to add the mine counts to empty squares in a completed Minesweeper board. The board itself is a rectangle composed of squares that are either empty (' ') or a mine ('*').

For each empty square, count the number of mines adjacent to it (horizontally, vertically, diagonally). If the empty square has no adjacent mines, leave it empty. Otherwise replace it with the adjacent mines count.

For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '路' character for display on screen):

路*路*路
路路*路路
路路*路路
路路路路路

Which your code should transform into this:

1*3*1
13*31
路2*2路
路111路

Minefield format

The minefield is represented as a null-terminated string, with a newline character at the end of each row.

An example would be " \n * \n \n"

Registers

Register Usage Type Description
$a0 input address null-terminated input string
$a1 input/output address null-terminated output string
$t0-9 temporary any for temporary storage
Edit via GitHub The link opens in a new window or tab
MIPS Assembly Exercism

Ready to start Minesweeper?

Sign up to Exercism to learn and master MIPS Assembly with 54 exercises, and real human mentoring, all for free.

Deep Dive into Minesweeper!

We explore nested for loops, clever use of min/max to simplify bounds checking, functional pipelines and using two-dimensional matrices.