Memory HubNet

Memory HubNet preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)



Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0beta1 • Viewed 321 times • Downloaded 33 times • Run 0 times
Download the 'Memory HubNet' modelDownload this modelEmbed this model

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


This is a HubNet version of the classic card game Memory. The game tests players' short term memory of where they last saw an image appear. Players can test different mental strategies for remembering.

A deck of cards made up of card pairs of matching images are dealt face down. Each player takes turns flipping over two cards. If they match, the player keeps the cards and goes again. If the two cards don't match they are put face down again.

At first, the players have no information about the cards. The more cards that are turned over, the more information the players have -- if they can only remember it!


Buttons: SETUP initializes the world but does not remove any of the players DEAL starts a new game GO allows the players who have joined to play the game. Each player plays the game in a sequential order, but all players can see the cards that other player flip over when they are face up. SHOW-ALL-CARDS turns over all the cards so all the faces are revealed and all the matches are visible. HIDE-ALL-CARDS turns all the cards face down so the matches are no longer visible.

Sliders: PAIRS-IN-DECK determines how many shapes are used (up to 52, though you could add more if you were to resize the world and add more shapes). PAIR-UP-DELAY indicates how long you want the turned over cards to display before hiding them again.

Monitors: CARDS REMAINING - the number of cards that have not yet been matched. CURRENT-PLAYER - the name of the player who is taking his or her turn. NUMBER-OF-PLAYERS - the number of people currently logged in and playing the game.


Press SETUP. Ask the players to login using the HubNet client. When everyone has successfully logged in press the GO button. The name of the current player will appear in the CURRENT-PLAYER monitor on the server and the WHOSE TURN monitor on the clients. Only that client will be allowed to select two cards to turn over by clicking on them with the mouse. If the cards match the cards will be removed and that player will receive a point and another turn, if not the CURRENT-PLAYER will be incremented to the next player. The game ends when all pairs of cards are matched and removed from the board.


Try to remember where all the cards you see are located. The game tests your ability to memorize where you last saw an image.


Try different mental strategies for choosing cards and for remembering cards. You can't remember everything, so how will you choose which cards to remember? How many can you remember perfectly? How many can you remember well enough to at least make good guesses?

Adjust the PAIR-UP-DELAY to a higher number to give players a longer or shorter time to study where the flipped up cards are located.

Smaller decks are easier. Adjust the PAIRS-IN-DECK slider to set the difficulty level.

The game is most fun if it's neither too easy nor too hard. What's the best deck size for two players? Three players? Four players? Etc.


Change the shapes used or add more using the Turtle Shapes Editor.

Change the number of cards in each set, have three or four cards of each shape.


The use of invisible turtles to represent players is a little unusual. The location of these turtles in the world is irrelevant; they are used just to store information.

We use the DISPLAY primitive to control what the players see when, and for how long.


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


Copyright 2009 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit 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

Comments and Questions

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

Click to Run Model

;; We represent each card using two turtles, one for the front and one for the
;; back.  The card-back turtles are on top of the card-front turtles, covering
;; them up.  To reveal a card-front, we hide the card-back turtle on top of it.
breed [card-backs card-back]
breed [cards card]

;; Players are invisible turtles that we use to store information about
;; the participants in the game.
breed [players player]
players-own [
  user-name   ;; a string
  matches     ;; a number, how many successful matches so far
  attempts    ;; a number, how may total tries so far

globals [
  current-player  ;; holds a player turtle

;; Setup Procedures

to startup

to setup
  ask patches [ set pcolor gray + 3 ]  ;; light gray

to deal
  ask cards [ die ]
  ask card-backs [ die ]
  ask players
    set attempts 0
    set matches 0
  set current-player 0

  let card-shapes remove "default" shapes
  let y-max floor (pairs-in-deck * 2 / world-width)
  let x-max pairs-in-deck * 2 mod world-width
  let bounded-patches (patch-set patches with [pycor < y-max]
                                 patches with [pycor = y-max and pxcor < x-max])
  ask n-of pairs-in-deck bounded-patches
    sprout-cards 1
      set shape one-of card-shapes
      set card-shapes remove shape card-shapes
      set size 0.5
  ask cards
  [ hatch 1 [ move-to one-of bounded-patches with [not any? cards-here] ] ]
  ask cards
    hatch-card-backs 1
      set color white
      set size 0.8
  if any? players
  [ hubnet-broadcast "Whose turn?" [user-name] of item current-player sort players ]
  hubnet-broadcast "Your matches" 0
  hubnet-broadcast "Your turns" 0
  hubnet-broadcast "Success %" 0
  hubnet-broadcast "Cards remaining" 0
  hubnet-broadcast "Leader" ""
  hubnet-broadcast "Leader's matches" 0

;; Runtime Procedures

to go
  if not any? cards [
    __hubnet-broadcast-user-message winner-message
    user-message winner-message

to-report winner-message
  let winners players with-max [matches]
  ifelse count winners > 1
  [ report (word "It's a " count winners "-way tie." ) ]
  [ report (word [user-name] of one-of winners " wins!") ]

;; HubNet Procedures

to listen-clients
  while [hubnet-message-waiting?]
    ifelse hubnet-enter-message?
    [ add-player hubnet-message-source ][
      ifelse hubnet-exit-message?
      [ remove-player hubnet-message-source ]
        let p item current-player sort players
        if hubnet-message-tag = "View" and [user-name] of p = hubnet-message-source
        [ ask p [ select-card first hubnet-message last hubnet-message ] ]

to add-player [name]
  create-players 1
    set user-name name
    set matches 0
    set attempts 0
    hubnet-send user-name "Your name" user-name
    hubnet-send user-name "Whose turn?" [user-name] of item current-player sort players
    hubnet-send user-name "Your matches" matches
    hubnet-send user-name "Your turns" attempts
    hubnet-send user-name "Success %" 0

to remove-player [name]
  let p one-of players with [user-name = name]
  if p != nobody
    ifelse position p sort players <= current-player
      ask p [ die ]
    [ ask p [ die ] ]

to select-card [x y]
  if count cards with [not hidden?] < 2
    let my-card one-of [cards-here] of patch x y
    if my-card != nobody
      ask my-card [ show-turtle ]
      let selected-cards cards with [not hidden?]
      if count selected-cards = 2
        set attempts attempts + 1
        hubnet-send user-name "Your turns" attempts
        wait pair-up-delay
        ifelse 1 = length (remove-duplicates [shape] of selected-cards)
          ask selected-cards [ ask card-backs-here [ die ] die ]
          set matches matches + 1
          hubnet-send user-name "Your matches" matches
          hubnet-broadcast "Cards remaining" count cards
          hubnet-broadcast "Leader" leader
          hubnet-broadcast "Leader's matches" max [matches] of players
          ask selected-cards [ hide-turtle ]
        hubnet-send user-name "Success %" precision (matches / attempts) 3

to increment-current-player
  ifelse count players = 0
  [ set current-player 0
    hubnet-broadcast "Whose turn?" "" ]
  [ set current-player (current-player + 1) mod count players
    hubnet-broadcast "Whose turn?" [user-name] of item current-player sort players ]

to-report leader
  let leaders players with-max [matches]
  ifelse any? leaders
    ifelse count leaders = 1
    [ report [user-name] of one-of leaders ]
    [ report (word count leaders "-way tie") ]
  [ report "nobody" ]

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

There are 7 versions of this model.

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

Attached files

File Type Description Last updated
Memory HubNet.png preview Preview for 'Memory HubNet' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.