Dice

Dice preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Dor Abrahamson (Author)

Tags

mathematics 

Tagged by Reuven M. Lerner over 6 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 322 times • Downloaded 29 times • Run 2 times
Download the 'Dice' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

Click to Run Model

globals [
  instructions                          ; the user instructions that appear in the monitor on the top left
  
  abort-pick-dice?                      ; Boolean to preempt run-time error
  
  count-steps                           ; counts the number of outcomes in the current sample
  #combi-successes-per-sample-list      ; list of outcomes per sample that were exactly like
                                        ; the original combination
  #permis-successes-per-sample-list     ; list of outcomes per sample that are the original combination
                                        ; or its permutation
  samples-counter                       ; how many sample have elapsed in an experiment
  count-combi-successes                 ; counts up hits under the combi condition
  count-permis-successes                ; counts up hits under the permutation condition
  mean-combi-per-sample                 ; mean number of same-order outcomes per sample
  mean-permis-per-sample                ; mean number of either-order outcomes per sample  
]

breed [ user-dice user-die ]            ; dice that the user chooses
breed [ model-dice model-die ]          ; dice that the model chooses

to startup
  initialize
  set instructions "Hi! Please read the Info tab to learn about this model, or just press Setup."
end 

to initialize
  clear-all
  ask patches [ set pcolor green - 2 ]
  set abort-pick-dice? false
  set #combi-successes-per-sample-list []
  set #permis-successes-per-sample-list []
end 

to setup
  initialize
  set-default-shape turtles "1"

  ; distribute the dice evenly along the x axis  
  let spacing ((max-pxcor - min-pxcor) / 3)
  foreach n-values 2 [ min-pxcor + (? + 1) * spacing ] [
    create-user-dice 1 [
      set size spacing
      set ycor max-pycor / 2 ; middle of top half
      set xcor ?
      set color white
      set heading 0
      hatch-model-dice 1 [
        ; for each user die, we create a model dice in the bottom half of the view
        set ycor pycor * -1
        set hidden? true
      ]
    ]
  ]
  
  set instructions "OK. Now press [Pick Values] to set the combination of dice faces."
  reset-ticks
end 

to pick-values
  if abort-pick-dice? [ stop ]
  set instructions (word 
    "Click on the dice to create your combination. "
    "It goes from 1 to 6 and over again. "
    "Next, unpress [Pick Values].")
  display
  assign-face
end 

; Convert any number to a shape from "1" to "6"
; (See info tab for explanations.)

to-report shape-for [ value ]
  let face-value (value - 1) mod 6 + 1
  report (word face-value)
end 

; Every time you click on a die face, the procedure identifies the die's current face value,
; adds 1 to it, and assigns the corresponding new shape to the die.

to assign-face
  if mouse-down? [
    ask min-one-of user-dice [ distancexy mouse-xcor mouse-ycor ] [
      repeat 2 [ rt 45 display ] ; for visual effect!
      set shape shape-for (read-from-string shape + 1)
      repeat 2 [ rt 45 display ] ; for visual effect!
    ]
  ]
end 

; procedure for generating random dice and searching for matches with the dice you picked

to search
  if samples-counter = total-samples [ stop ]
  
  ; managing the user-code interface
  set abort-pick-dice? true
  set instructions (word 
    "The program guesses combinations randomly and tracks "
    "the number of times it discovers the dice you picked.")
  
  ask model-dice [
    set shape shape-for (random 6 + 1)
    show-turtle
  ]
  
  if single-success? [ display ] ; this would slow down the model too much in the global search
  
  ; Make lists of user dice shapes and model dice shapes, ordered from left to right
  let user-dice-shapes  map [ [ shape ] of ? ] sort-on [ xcor ] user-dice
  let model-dice-shapes map [ [ shape ] of ? ] sort-on [ xcor ] model-dice
  
  let combination-found? (model-dice-shapes = user-dice-shapes)
  let permutation-found? (sort model-dice-shapes = sort user-dice-shapes)
  
  set count-steps count-steps + 1
  
  if combination-found? [ set count-combi-successes count-combi-successes + 1 ]  
  if permutation-found? [ set count-permis-successes count-permis-successes + 1 ]
  
  ; for 'single-success?' true, we want the program to stop after matching dice were found
  if single-success? [
    let message ""
    
    if permutation-found? and member? analysis-type ["Permutations" "Both"] [
      set message congratulate-permi
    ]
    if combination-found? and member? analysis-type ["Combination" "Both"] [
      set message congratulate-combi ; overwrites the "permutation" message, which is all right
    ]
    if not empty? message [
      set instructions message
      little-setup
      stop
    ]
  ]
  
  if count-steps = sample-size [ 
    set samples-counter samples-counter + 1
    set #combi-successes-per-sample-list fput count-combi-successes #combi-successes-per-sample-list
    set #permis-successes-per-sample-list fput count-permis-successes #permis-successes-per-sample-list
    tick
  ]
end 

to-report congratulate-combi
  let steps (length #combi-successes-per-sample-list  * sample-size) + count-steps
  report (word 
    "Congratulations! You discovered the hidden combination in " steps " steps. "
    "You can press [Roll Dice] again.")
end 

to-report congratulate-permi
  let steps (length #permis-successes-per-sample-list  * sample-size) + count-steps
  report (word 
    "Congratulations!  You discovered a permutation of the hidden combination in "
    steps " steps. You can press [Roll Dice] again.")
end 

to little-setup
  set count-steps 0
  set count-combi-successes 0
  set #combi-successes-per-sample-list []
  set count-permis-successes 0
  set #permis-successes-per-sample-list []
end 

to-report ratio
  ; we want the ratio to be rounded after two decimal points
  let denominator precision (mean #permis-successes-per-sample-list / mean #combi-successes-per-sample-list) 2
  report word "1 : " denominator
end 


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

There are 15 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 7 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 7 years ago Updated version tag Download this version
Uri Wilensky over 7 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky about 8 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 9 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 9 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 9 years ago Dice Download this version

Attached files

File Type Description Last updated
Dice.png preview Preview for 'Dice' almost 7 years ago, by Uri Wilensky Download
Dice.png preview Preview for 'Dice' almost 7 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.