Minesweeper

Minesweeper preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

game 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 778 times • Downloaded 82 times • Run 1 time
Download the 'Minesweeper' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This is game of strategy. There are land mines hidden beneath the green landscape. Your job is to locate all of the mines without exploding any of them.

HOW IT WORKS

If you click on a patch of grass without a mine, a number appears. The number tells you how many adjacent mines there are.

If you click on a mine, the mine explodes, and you lose the game.

You win the game by uncovering every square that doesn't have a mine.

If you lose, the land turns red. If you win, it turns blue.

HOW TO USE IT

Press SETUP to set up the board, then press GO to play the game.

While GO is pressed, click on green squares to check them for mines.

To help you remember where where you think the mines are, you can mark a square by pointing at it and pressing the M key. (Note the M in the corner of the MARK/UNMARK button. If the M is grayed out, hide the command center.)

You can make the game easier or harder by adjusting the MINE-COUNT slider before pressing SETUP.

THINGS TO NOTICE

Use the numbers to deduce where it is safe to click and where it isn't.

Can you always know where it is safe to click, or do you have to guess sometimes?

Note that when you click in an empty region, the model saves you time by automatically clearing all the surrounding empty cells for you. This keeps the game from being tedious.

THINGS TO TRY

Try to win the game as fast as possible. Your time appears in the CLOCK monitor.

Try playing with a bigger or smaller board by editing the view and adjusting min-p(x/y)cor and max-p(x/y)cor.

EXTENDING THE MODEL

Write out a file to disk containing the best times players have achieved so far for a given board size. Update the file when someone beats a previous time.

Write a computer player that can play the game automatically. What strategy should it use?

Modify the game to use a hexagonal grid instead of a square one. (See Hex Cells Example, in Code Examples, to see how to make a hexagonal grid.)

NETLOGO FEATURES

The neighbors primitive is used to find neighboring squares.

RELATED MODELS

Some of the models in Cellular Automata section, under Computer Science, also have rules based on how many neighboring cells are occupied.

CREDITS AND REFERENCES

According to http://en.wikipedia.org/wiki/Minesweeper%28computergame%29, Minesweeper was invented by Robert Donner in 1989. A version of the game is included with the Windows operating system.

Landmines are a real problem that kills people every day. To learn more about the campaign to ban landmines, see http://www.icbl.org.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Wilensky, U. (2005). NetLogo Minesweeper model. http://ccl.northwestern.edu/netlogo/models/Minesweeper. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2005 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [
  clock             ;; how many seconds the game has lasted so far
  game-started?     ;; initially false, becomes true when player first presses GO
  game-over?        ;; initially false, becomes true if the player loses
]

breed [ grass-squares grass-square ]    ;; these are the green squares the player hasn't tested yet
breed [ mines mine ]             ;; the mines (initially invisible)
breed [ markers marker ]          ;; show where the player thinks mines are

to setup
  clear-all
  set clock 0
  set game-started? false
  set game-over? false
  set-default-shape grass-squares "grass patch"
  set-default-shape mines "bomb"
  set-default-shape markers "bomb"
  ask patches [
    sprout-grass-squares 1 [ set color green ]
    set pcolor gray
  ]
  ;; make the number of mines determined by the mine-count slider
  ask n-of mine-count patches [
    sprout-mines 1 [
      set color black
      hide-turtle
    ]
  ]
  reset-ticks
end 

to go
  if game-over? [
    ask markers with [any? mines-here] [ die ]
    ask markers [ set color gray  - 2 ]
    ask mines [ show-turtle ]
    set game-over? true
    ask patches [ set pcolor red ]
    stop
  ]
  if not game-started? [
    ;; this must be the first time through GO, so start the clock
    reset-timer
    set game-started? true
  ]
  set clock timer
  if all? grass-squares [any? mines-here] [
    ;; you win!!!
    ask mines [ show-turtle ]
    ask patches [ set pcolor blue ]
    stop
  ]
  if mouse-down? [
    ask patch (round mouse-xcor) (round mouse-ycor) [
      ifelse any? mines-here
        [ set game-over? true ]   ;; aiggghhhh!
        [ clear ]                 ;; whew!
    ]
  ]
  tick
end 

to clear  ;; patch procedure
  ask grass-squares-here [ die ]
  ask markers-here [ die ]
  let total count neighbors with [any? mines-here]
  ifelse total > 0
    [ set plabel total ]
    ;; if none of our neighbors have mines on them, then they can
    ;; be cleared too, to save the user from extra clicking
    [ ask neighbors with [any? grass-squares-here]
      [ clear ] ]
end 

to mark/unmark
  if not mouse-inside? [ stop ]
  ask patch round mouse-xcor round mouse-ycor [
    if any? grass-squares-here [
      ifelse any? markers-here
        [ ask markers-here [ die ] ]
        [ sprout-markers 1 [ set color black ] ]
    ]
  ]
end 


; Copyright 2005 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Minesweeper Download this version

Attached files

File Type Description Last updated
Minesweeper.png preview Preview for 'Minesweeper' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.