#minesweeper #game #restful #server #flags #reveal

yanked mineswpttd

A RESTful Minesweeper server

0.1.0 Jul 9, 2021

#8 in #reveal

GPL-3.0 license

28KB
402 lines

Mineswepttd

A RESTful Minesweeper server.

Install

git clone https://github.com/pard68/mineswepttd && \
cd mineswepttd && \
cargo run

or

git clone https://github.com/pard68/mineswepttd && \
cd mineswepttd && \
cargo build --release && \
./target/release/mineswepttd

Usage

Get a new random state:

GET /new/<width>/<height>/<difficulty>

State

The board state has the following format (newlines are optional)

10 10 10
currently-lately-sound-coral
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00

The first line is made up of three integers; width, height, and difficulty (difficulty refers to the number of mines on the board). The second line is the seed for the board, a request to /new will return a human-friendly string, however any unicode string is an acceptable seed. The remaining lines are a series of two integer pairs, comprised of 1's and 0's. The first integer in the each pair refers to the reveal state for the cell. The second integere in each pair refers to the flag state for that cell.

Flag or unflag a cell:

POST /flag/<x>/<y>?send_state=<true|false>, passing the aforementioned state as the body

Reveal a cell:

POST /reveal/<x>/<y>?send_state=<true|false>, passing the aforementioned state as the body

Flag and Reveal Responses

The /flag and /reveal endpoints reponses can be comprised of between one and three parts. The first part, which will always be returned is what the board looks like following a flagging or reveal. It looks like this:

0000011100
000001F100
0000011100
0000000000
0000000000
0000111000
01122F1000
02....3100
14.....100
.......100

An integer refers to the number of neighboring mines for a revealed cell. This integer can be anything between 0 and 8. An . refers to an unrevealed, unflaaged cell. An F refers to a flagged cell. An M (not shown above) refers to a revealed cell which contains a mine -- if an M is on the board, than the game is over. Which brings us to the next potential part of the response; the win/lose state.

0000011100
000001F100
0000011100
0000000000
0000000000
0000111000
01122F1000
02..M.3100
14.....100
.......100
Lose!

If the line following the board is populated the game is over. The line will contain one of two strings; Win! or Lose!. In the event that the third part of the response is requested than this line can also be blank -- \n. The third potential part of a response is the board's state. Developers implementing a frontend for mineswepttd can choose to either keep track of the game's state in their own application or can request an updated state with each request. To request a state, send the paramete ?send_state=true with the /flag or /reveal request.

Development

A postman config can be found in the root of this project. It contains a request for each of the endpoints currently available.

Dependencies

~17–50MB
~801K SLoC