Coder Social home page Coder Social logo

danielmahadi / minesweeper-go-csp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ebarlas/minesweeper-go-csp

0.0 0.0 0.0 28 KB

Minesweeper implemented in Go using Goroutines and communicating sequential processes

License: MIT License

Go 100.00%

minesweeper-go-csp's Introduction

Minesweeper

Minesweeper is a Go implementation of Microsoft Minesweeper using communicating sequential processes (CSP).

Each game tile is an independent, anonymous process and all communication occurs via channels. No explicit synchronization primitives are used beyond channels.

Channels

Goroutines

Minesweeper Goroutines:

  • T[R,C] - Tile in row R, column C: handles cell input events and notifies neighbors
  • G - The game engine: main game loop with win-loss logic
  • W - The window GUI component: presents game state in
  • C - The game clock: emits tick event periodically

Goroutines communicate via channels as follows:

  • T[R][C] -> T[R-1][C-1], T[R-1][C], ... - Cell tells neighbors about state change
  • T[R][C] -> G - Cell tells game about state change
  • G -> T[R][C] - Game tells cell about user input
  • G -> W - Game tells window about game state change
  • W -> G - Window tells game about mouse click
  • C -> G - Clock tells game about clock tick

Build

Minesweeper Go depends on go-sdl2, a Go wrapper for SDL2.

As noted in the go-sdl2 documentation, the SDL2 system library must be installed.

Docker

Docker can be used with X Window System to build and run Minesweeper without installing libraries directly.

The following command launches a bash shell in a Golang Docker container.

docker run -it --rm --name go -v "$PWD":/usr/src/golang -w /usr/src/golang golang:bookworm bash

The command below installs SDL2 and SDL2-image within the container:

apt-get install -y libsdl2-dev libsdl2-image-dev

Configure X11 display:

export DISPLAY=host.docker.internal:0

On my system running MacOS, I did the following to establish a suitable X11 server:

  • Install XQuartz (version 2.8.5) brew install xquartz
  • Edit XQuartz settings to "Allow connections from network clients"
  • Run command defaults write org.xquartz.X11 enable_iglx -bool true to allow OpenGL drawing
  • Run XQuartz
  • Run command xhost + 127.0.0.1 to ensure localhost is allowed X11 forwarding

Command Line Arguments

Include Beginner, Intermediate, or Advanced command-line argument to select a difficulty.

Difficulty Rows Columns Mines Mine Density
Beginner 9 9 10 12%
Intermediate 16 16 40 16%
Advanced 16 30 99 21%

Assets

All game assets were created from scratch in Inkscape and rasterized to PNG images.

minesweeper-go-csp's People

Contributors

ebarlas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.