minesweeper_4d

Crates.iominesweeper_4d
lib.rsminesweeper_4d
version0.1.17
created_at2025-12-15 20:17:52.521914+00
updated_at2026-01-25 01:49:33.928451+00
descriptionminesweeper but 4d
homepage
repositoryhttps://github.com/itabesamesa/minesweeper_4d_rs
max_upload_size
id1986666
size310,709
laura418 (itabesamesa)

documentation

README

minesweeper_4d

This is a Ratatui app and my 8th minesweeper variant, 7th multidimensional one (assuming all the ones I abandoned where at least supposed to be 4D), 4th public and 2nd (excluding the 3 abandoned ones) 4D one.

An example game

https://github.com/user-attachments/assets/d1e07569-e4ca-4f18-bfa0-eb96f0d7dc50

How to play

You have to find all the mines in a 4 dimensional field. The pink cursor highlights the current field you're on and its value shows the number of bombs that are around it. To help you find which fields are in the area of influence of the cursor, they are highlighted in a less saturated shade of pink. Have fun finding all the mines!

In delta mode, each cell displays the amount of not yet flagged mines and 0, if there are covered cells in its area of influence.

In sweep mode, whenever you flag a mine, it will be removed. Other than that, it is similar to delta mode. When switching to sweep mode, all already flagged mines will be removed. Falsely flagged cells will end the game.

With marks you can visualise how many mines are in the area of influence. This is not meant to be used as a way to cheese the game, but rather to help one learn new tactics or for a beginner to get a better grasp on how 4D minesweeper works. The order in which you place marks is important! It can get a bit visually crowded when too many marks are placed, so remember to clear them. Marks overriding other marks is intended and should only happen if the amount of cells with that mark isn't fully enclosed by the newly placed mark

https://github.com/user-attachments/assets/913b4012-a483-4150-baad-a219c09b202e

When the program is run with --capture_mouse t, the cursor will track the mouse, left clicking will uncover a cell and right clicking will flag a cell. When the program crashes with capture_mouse on, you'll have to reset your terminal (this is why it is off by default)

There is the option of saving your game in a human readable file format. But I haven't tested it extensively. I only added it so that this variant would have every feature of 4d_minesweeper in c. Files are saved to your downloads directory by default (run with -h and you'll see where that is).

In theory, this program should be OS agnostic ( except for seeds https://docs.rs/rand/latest/rand/rngs/struct.StdRng.html ). But I have never tested this on anything other than Linux... (specifically gentoo and arch and void)

Controls

  Quit:                          ctrl+c, q, ESC
  Controls:                      c
  Settings:                      o
  Move left in x:                Leftarrow,  h
  Move right in x:               Rightarrow, l
  Move up in y:                  Uparrow,    k
  Move down in y:                Downarrow,  j
  Move left in z:                a, ctrl+h
  Move right in z:               d, ctrl+l
  Move up in w:                  w, ctrl+k
  Move down in w:                s, ctrl+j
  Move to start in x:            shift+Leftarrow,  H
  Move to end in x:              shift+Rightarrow, L
  Move to top in y:              shift+Uparrow,    K
  Move to bottom in y:           shift+Downarrow,  J
  Move to start in z:            A, alt+h
  Move to end in z:              D, alt+l
  Move to top in w:              W, alt+k
  Move to bottom in w:           S, alt+j
  Retry game:                    r
  New game:                      n
  Find free cell:                f
  Uncover cell:                  SPACE
  Give up/reveal field:          g
  Flag cell:                     m, e
  Flag cell chording:            M, E
  Pause game:                    p
  Toggle info:                   i
  Toggle delta mode:             u
  Toggle sweep mode:             U
  Clear all marks:               ctrl+x
  Flag obvious marked cells:     alt+x
  Mark cell:                     x
  Uncover obvious marked cells:  X
  Save game:                     ctrl+o

Compiling and running

cargo install minesweeper_4d
mkdir -p $HOME/.config/minesweeper_4d
curl https://raw.githubusercontent.com/itabesamesa/minesweeper_4d_rs/refs/heads/main/config.toml -o $HOME/.config/minesweeper_4d/config.toml

or

from source:

cargo install --path .
mkdir -p $HOME/.config/minesweeper_4d
cp ./config.toml $HOME/.config/minesweeper_4d/

Run:

minesweeper_4d

Commandline arguments

  -h,  -?, --help            Show this menu
  -d,  --dim, --dimension    Change field dimensions. An array of integers greater than 0 e.g.: -d 4 4 4 4
  -m,  --mines               Change amount of mines. An integer greater than 0
  -i,  --show_info           Toggle info box. A boolean value t/f or true/false or y/n or yes/no or on/off (any capitalisation)
  -u,  --delta_mode          Toggle delta mode. A boolean value t/f or true/false or y/n or yes/no or on/off (any capitalisation)
  -U,  --sweep_mode          Toggle sweep mode. A boolean value t/f or true/false or y/n or yes/no or on/off (any capitalisation)
  -s,  --seed                Set seed. An unsigned integer
  -r,  --random              Toggle random seed. A boolean value t/f or true/false or y/n or yes/no or on/off (any capitalisation)
  -cm, --capture_mouse       Wether to allow mouse interaction. A boolean value t/f or true/false or y/n or yes/no or on/off (any capitalisation)
  -c,  --config              Path of configuration file to use
  -o,  --dir                 Where to output save files. Default is "~/Downloads"
Default settings as a command

Default settings as a command

minesweeper_4d -d 4 4 4 4 -m 20 -i t -u t -U f -r t -cm f

Classic Minesweeper as a command... Weirdo...

minesweeper_4d -d 16 16 1 1 -m 40 -i t -u f -U f -r t -cm t

Config

[!WARNING] The way the config is implemented, is a bit jank... It is better you don't randomly remove things/leave them unset

keymap

The keymap is split into 3 sections: global (implied rather than explicitly in the config), movement and game. Global keys work in every state (running, settings, controls, too small), movement for movement (i know right?) and game for any functions specific to the running state/you playing the game. They all accept a list of strings or just a single string. The string can be the name of a key

[!NOTE] Supported are: backspace, enter, left, leftarrow, right, rightarrow, up, uparrow, down, downarrow, end, pageup, pagedown, tab, backtab, delete, insert, esc, escape

or a character.

[!NOTE] Characters are case sensitive!

Modifiers are added to the start, separated by "-"

[!NOTE] Supported are: shift, ctrl, control, alt, super, hyper, meta. ( In code, this function is used: https://docs.rs/crossterm/latest/crossterm/event/struct.KeyModifiers.html#method.from_name )

In the settings menu, there are a few hard coded keys. Those are: 0-9, y, t, n, f, -, +, delete

style

Style is separated into game.color and the rest. In theory, game.color is optional (I have not tested this tho...). The values of game.color can be either the name of a color

[!NOTE] In code, this function is used: https://docs.rs/ratatui/latest/ratatui/style/enum.Color.html#method.from_str

or the RGB hexadecimal representation, prefixed with "#"

The rest are the alignment options for the info, controls, settings and the controls for the settings panels. They can be set to: left, right, center

TODO

  • Make swapping to and from delta_mode possible
  • Fix 0 showing around newly flagged mines
  • Add timer idk, kinda too lazy...
  • Fix win condition
  • Make random seedable hehe, i did it anyway :3
  • Add chording
  • Editable settings
  • Make Controls scrollable custom implementation instead of ratatui Scrollbar
  • Make it possible to win when there are 0 mines
  • Make game state message part of game instead of field
  • Config (coming soon tm, currently on a different branch (you'll have to use an earlier commit tho))
  • Create launch option for people who don't have a Unicode font available (for now install smth like noto)
  • Fix "Shift" being displayed next to uppercase letters
  • Make "-" mappable
  • Scrolling happening before the cursor is in the middle

License

Copyright (c) itabesamesa/laura418

This project is licensed under the MIT license (LICENSE or http://opensource.org/licenses/MIT)

Special thanks

To Julian Schlüntz for creating 4D Minesweeper on steam, the original inspiration for this project

To Ratatui for sparing me from implementing a TUI library from scratch again...

Commit count: 102

cargo fmt