mineswepttd 0.2.0

A RESTful Minesweeper server.
mineswepttd-0.2.0 is not a library.

Mineswepttd

A RESTful Minesweeper server.

I am hosting this service on my domain @ https://mineswepttd.0x44.pw/

Install

If you're looking to run this off of localhost, and you want the port to be something other than 8000 I recommend you use the Docker image:

docker run -p 80:8000 pard68/mineswepttd

If you just want to run it locally -- for fun or with a frontend, you can also make use of the published package on Crates.io:

cargo install mineswepttd && mineswepttd

Or if copying the src and running it from that is more you speed try:

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 integer 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 endpoint responses 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.

A special note, on a call to /flag the line following the board will contain an integer which refers to the total number of used flags. Your game can use this field to determine how many flags the user has left (total available flags is equal to the difficulty). If all flags have been used, /flag will merely return the state it was given, plus the total used flag count.

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 parameter ?send_state=true with the /flag or /reveal request.

Front-ends

None exist. Go make one. Or what until I do...

Development

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

TODO

[ ] - Testing [X] - Max flags? [X] - Create front-end to showcase usage [ ] - Break into a library and a server [X] - Get docker actions working