Git Product home page Git Product logo

minesweeper's Introduction

Minesweeper

Part A: React.js Implementation

1. Setup

In the project directory, run yarn install then you can run:

yarn start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

yarn test

Launches the test runner in the interactive watch mode.

2. Code Design

Click to see code directly:

React.js Components

Board API

Human Player

Computer Player

Part B: Puzzle Solver

1. How to Run

Launches the run solver script with the given optional arguments.

yarn solve [ n [ numMines [ numTrials ] ] ]

yarn solve

automatically solves the 10 * 10 puzzle with 10 mines 100,000 times (each time is a randomly generated puzzle)

If you want to see a step-by-step solution generated by GameAI:

Go to Solver and set the flag below to true.

  const printSteps = false; // set this to true

2. Algorithm

This solver implements a Double-Set-Single-Point (DSSP) strategy. For more information, check here in Chapter 5.3.

Solving a 10 by 10 puzzle with 10 mines 100,000 times (each time is a different puzzle), the chance of winning is around 72%, which is similar to what's been obtained in the paper. The run time is within 35 seconds.

The pseudo-code is illustrated below:

  firstStep = firstMove()
  S = new Set()   // "safe" cells to explore
  Q = new Set()   // cells that need more information about neighbors
  S.add(firstStep)
  
  while game is not over:
    if S is empty:
      x = selectRandomSquare()
      S.add(x)  
    
    while S is not empty:
      x = S.remove()
      probe(x)    // probe means uncover
      if x is mine:
        return failure
      if AFN(x):   // all-free-neighbor: # neighbor mines - marked cells == 0
        S.add(unmarkedNeighbors(x))
      else:
        Q.add(x)
    
    for q in Q:
      if AMN(q):   // all-mines-neighbor: # neighbor mines - marked cells == # of unmarked cells
        for y in unmarkedNeighbors(q):
          mark(y)   // mark cell y as mine
        Q.remove(q)
     
     for q in Q:
      if AFN(q):
        S.add(unmarkedNeighbors(q))
        Q.remove(q)  
        
   return success

minesweeper's People

Contributors

garydmg avatar

Stargazers

 avatar

Watchers

 avatar  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.