---minority game.nlogo
来自「NETLOGO」· NLOGO 代码 · 共 1,430 行 · 第 1/3 页
NLOGO
1,430 行
end;; view the next item in the quickstart monitorto view-next set qs-item qs-item + 1 if qs-item >= length qs-items [ set qs-item length qs-items - 1 ] set quick-start (item qs-item qs-items)end;; view the previous item in the quickstart monitorto view-previous set qs-item qs-item - 1 if qs-item < 0 [ set qs-item 0 ] set quick-start (item qs-item qs-items)end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Code for interacting with the clients ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; listen for hubnet client activityto listen-clients while [hubnet-message-waiting?] [ hubnet-fetch-message ifelse hubnet-enter-message? [ execute-create ] [ ifelse hubnet-exit-message? [ ask players with [user-id = hubnet-message-source] [ die ] ] [ if hubnet-message-tag = "0" [ choose-value 0 ] if hubnet-message-tag = "1" [ choose-value 1 ] ] ] ]end;; create a client player upon loginto execute-create create-custom-players 1 [ set heading 90 set user-id hubnet-message-source set size 3 set-unique-shape-and-color clear-my-data ]endto set-unique-shape-and-color ;; turtle procedure let max-possible-codes (length colors * length shape-names) let code random max-possible-codes while [member? code used-shape-colors and count turtles < max-possible-codes] [ set code random max-possible-codes ] set used-shape-colors (lput code used-shape-colors) set shape item (code mod length shape-names) shape-names set color item (code / length shape-names) colorsend;; to tell the clients what they look liketo send-identity-to-clients ;; player procedure hubnet-send user-id "You are a:" identityend;; report the string version of the turtle's identity (color + shape)to-report identity ;; turtle procedure report (color-string color) + " " + shapeend;; report the string version of the turtle's colorto-report color-string [color-value] report item (position color-value colors) color-namesend;; turtle/client procedure to reset the client interfaceto clear-my-client ;; player procedure hubnet-send user-id "Status:" "Please make your selection." hubnet-send user-id "Your last choice:" "N/A" hubnet-send user-id "The past history:" full-history player-history player-memory hubnet-send user-id "Total score:" "0" hubnet-send user-id "Success rate:" "N/A"end;; the client chooses 0 or 1to choose-value [ value-chosen ] ask players with [user-id = hubnet-message-source] [ if (not chosen-sides?) [ set choice value-chosen set chosen-sides? true set choices-made choices-made + 1 hubnet-send user-id "Current choice:" value-chosen hubnet-send user-id "Status:" "Waiting for other players..." ] ]end; *** NetLogo Model Copyright Notice ***;; This activity and associated models and materials were created as part of the projects:; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and ; INTEGRATED SIMULATION AND MODELING ENVIRONMENT.; These projects gratefully acknowledge the support of the ; National Science Foundation (REPP & ROLE programs) -- grant numbers ; REC #9814682 and REC-0126227.;; Copyright 2004 by Uri Wilensky. Updated 2004. All rights reserved.;; Permission to use, modify or redistribute this model is hereby granted,; provided that both of the following requirements are followed:; a) this copyright notice is included.; b) this model will not be redistributed for profit without permission; from the copyright holders.; Contact the copyright holders for appropriate licenses for redistribution ; for profit.;; To refer to this model in academic publications, please use:; Wilensky, U. (2004). NetLogo HubNet Minority Game model.; http://ccl.northwestern.edu/netlogo/models/HubNetMinorityGame.; Center for Connected Learning and Computer-Based Modeling,; Northwestern University, Evanston, IL.;; In other publications, please use:; Copyright 2004 Uri Wilensky. All rights reserved.; See http://ccl.northwestern.edu/netlogo/models/HubNetMinorityGame; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW41596803505171710.81101110CC-WINDOW5599812694Command CenterBUTTON361010543setupsetupNIL1TOBSERVERNILNILBUTTON3141037743gogoT1TOBSERVERNILNILSLIDER2087198120number-of-androidsnumber-of-androids010015511NILSLIDER205119884player-memoryplayer-memory112611NILSLIDER20123198156android-memoryandroid-memory112311NILPLOT224435404585Success ratetimesuccess rate0.01.00.00.05truetruePENS"max" 1.0 0 -65536 true"min" 1.0 0 -16776961 true"avg" 1.0 0 -11352576 truePLOT13435219585Number Picking Zerotimenumber0.01.00.025.0truefalsePENS"number" 1.0 0 -11352576 trueMONITOR21756390105Historyfull-history player-history player-memory31PLOT13283219433Scorestimescore0.01.00.01.0truetruePENS"max" 1.0 0 -65536 true"min" 1.0 0 -16776961 true"avg" 1.0 0 -11352576 trueCHOOSER255112347157color-bycolor-by"choice" "success"1PLOT224283404433Success Ratesscorenumber0.01.00.010.0truetruePENS"default" 0.02 1 -16777216 falseBUTTON1131018843re-runclear-all-dataNIL1TOBSERVERTNILSLIDER210176302209wait-timewait-time015411NILSLIDER20159199192strategies-per-androidstrategies-per-android115511NILMONITOR4151080359Quick Start Instructions-More in Info Windowquick-start31BUTTON4156156394Reset Instructionssetup-quick-startNIL1TOBSERVERTNILBUTTON7206180394NEXT>>>view-nextNIL1TOBSERVERTNILBUTTON6356171994<<<PREVview-previousNIL1TOBSERVERTNILMONITOR19223190272Winnerwinner31MONITOR194223365272Loserloser31BUTTON2301030143log-inlog-inT1TOBSERVERTNILMONITOR309163408212Time to Chooseclock31@#$#@#$#@WHAT IS IT?-----------Minority Game is a simplified model of an economic market. In each round agents choose to join one of two sides, 0 or 1. Those on the minority side at the end of a round earn a point. This game is inspired by the "El Farol" bar problem. Each round, the live participants must choose 0 or 1. They can view their choice history for a specified number of previous turns, and may employ a finite set of strategies to make their decision. The record available to them shows which side, 0 or 1, was in the minority in previous rounds.This HubNet version of the model allows players to play against each other and a set of androids. The androids' intelligence (and thus the difficulty of the game) can be increased through the ANDROID-MEMORY slider.HOW IT WORKS------------Each player begins with a score of 0 and must choose a side, 0 or 1, during each round. If their choice is in the minority they earn a point. If they do not make their decision in WAIT-TIME seconds, they are randomly assigned to a side.Each computer agent begins with a score of 0 and STRATEGIES-PER-AGENT strategies. Each of these strategies is a string of 0 and 1 choices, such as [0 1 1 1 0 0 1] that together represent the agents' possible plan of action (first choose 0, next time choose 1, next time choose 1, etc.). Initially, they choose a random one of these strategies to use. If their current strategy correctly predicted whether 0 or 1 would be the minority, they add one point to their score. Each strategy also earns virtual points according to whether it would have been correct or not. From then on, the agents will use their strategy with the highest virtual point total to predict whether they should select 0 or 1. Thus, for each android, the "fittest" strategies survive.This strategy consists of a list of 1's and 0's that is 2^ANDROID-MEMORY long. The choice the computer agent then makes is based off of the history of past choices. This history is also a list of 1's and 0's that is ANDROID-MEMORY long, but it is encoded into a binary number. The binary number is then used as an index into the strategy list to determine the choice.This means that if there are only computer agents and no human participants, once the number of computer agents, the number of strategies, and the length of the historical record are chosen, all parameters are fixed and the behavior of the system is of interest.HOW TO USE IT-------------QUICKSTART INSTRUCTIONS:------------------------Teacher: Follow these directions to run the HubNet activity.Optional: Zoom In (see Tools in the Menu Bar)Optional: Change any of the settings. If you did change settings, press the SETUP button.Teacher: Press the LOG-IN button.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?