⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 !!!---investments.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 2 页
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable and Breed declarations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;globals [   quick-start  ;; current quickstart instruction displayed in the quickstart monitor  qs-item      ;; index of the current quickstart instruction  qs-items     ;; list of quickstart instructions  rounds ]breeds [ students ]students-own[  user-id    ;; the name selected by each user  fraction   ;; the fraction of current money the user has selected to invest  investment ;; the amount the user has invested  my-money   ;; the money that the user currently has to use  return-investment ;; the interest plus the principle returned on the investment  cars        ;; the number of cars purchased  invested?    ;; boolean variable indicating whether the user has invested this round];;;;;;;;;;;;;;;;;;;;;;; Setup Functions ;;;;;;;;;;;;;;;;;;;;;;;to startup  setup  hubnet-set-client-interface "COMPUTER" [ "clients/Investments client.nlogo" ]  hubnet-resetend;; initialize the displayto setup  ca  ask patches [ set pcolor gray ]  setup-quick-startend;; reset all the clients to begin the activity againto start-over  set rounds 1    ask students     [       reset-client      send-info-to-clients     ]end;;;;;;;;;;;;;;;;;;;;;;;;; Runtime Functions ;;;;;;;;;;;;;;;;;;;;;;;;;to go  every .1  [ listen-clients ] ;; get commands and data from the clientsend;; move on the the next round, calculate interest and update the variables on the clientsto next-round  set rounds rounds + 1   ask students [ update-student ]end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Code for interacting with the clients ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; standard hubnet procedure to collect data sent by clientsto listen-clients  while [ hubnet-message-waiting? ]  [    hubnet-fetch-message    ifelse hubnet-enter-message?    [ create-new-student ]    [      ifelse hubnet-exit-message?      [ remove-student ]      [ execute-command hubnet-message-tag ]    ]  ]end;; interpret each hubnet message as a commandto execute-command [command]   if command = "fraction-to-invest" ;; every time a student adjusts their fraction to invest button update the turtle variable  [     ask students with [user-id = hubnet-message-source]     [        if (invested? = false)         [ set fraction hubnet-message ]     ]      ]     if command = "invest"    [      ask students with [user-id = hubnet-message-source] ;; when the student press the INVEST button move the money from My Money into investment         [             if (invested? = false) ;; students may only invest once per round             [               set investment my-money * fraction               set my-money my-money - investment               set return-investment 0               hubnet-send user-id "investment" precision investment 2               hubnet-send user-id "My Money" precision my-money 2               hubnet-send user-id "investment-return" precision return-investment 2               set invested? true             ]         ]     ]     if command = "buy-car"  [     ask students with [user-id = hubnet-message-source]      [        if (my-money >= car-cost)        [          set cars cars + 1          set my-money my-money - car-cost          hubnet-send user-id "cars" cars          hubnet-send user-id "My Money" precision my-money 2        ]     ]  ]end;; manage the turtles as clients enter and exitto create-new-student  create-custom-students 1  [    setup-student-vars    reset-client    send-info-to-clients  ]endto remove-student  ask students with [user-id = hubnet-message-source] [ die ]end;; sets the turtle variables to appropriate initial values;;;;;;;;;;;;;;;;;;;;;;;;; Turtle Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;; setup the visual components of each turtleto setup-student-vars  set user-id hubnet-message-source  set shape "circle"   set color red  set label-color black  setxy ( random ( screen-edge-x * 2 ) - screen-edge-x )  ( random ( screen-edge-y * 2 ) - screen-edge-y )  setxy round xcor round ycor  set label word user-id ", "end;; initialize the turtle variablesto reset-client  set my-money 100   set invested? false  set return-investment 0  set cars 0  set label ( word  user-id ", " precision my-money 2 )end;; calculate investments and send the results to the clientsto update-student  set return-investment ( investment * ( interest-rate + 1 ) )  set my-money ( my-money + return-investment )  set label ( word  user-id ", " precision my-money 2 ", " cars)   set invested? false  set investment 0  send-info-to-clientsend;; send the appropriate monitor information back to the clientto send-info-to-clients  hubnet-send user-id "I am:" user-id    hubnet-send user-id "Round" rounds  hubnet-send user-id "My Money" precision my-money 2  hubnet-send user-id "investment" precision investment 2  hubnet-send user-id "investment-return" precision return-investment 2  hubnet-send user-id "cars" carsend;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Quick Start functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; instructions to quickly setup the model, and clients to run this activityto setup-quick-start  set qs-item 0  set qs-items  [      "Teacher: Follow these directions to run the HubNet activity."      "Optional: Zoom In (see Tools in the Menu Bar)"      "Teacher: Open up the HubNet Control Center (see Tools in the Menu Bar)."        "This will show you the IP Address of this computer."      "Everyone: Open up a HubNet Client on your machine and..."      "type your user name, select this activity and press ENTER."      "Teacher: Setup the activity by selecting a cost for cars and an interest rate using the sliders."       "Teacher: Press the GO button."      "Everyone: Decide how to use your money by either investing, or buying a car."       "Teacher: Press the NEXT-ROUND button."          "Teacher: To rerun the activity with the same group, press the RESET button."  ]    set quick-start (item qs-item qs-items)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-prev  set qs-item qs-item - 1  if qs-item < 0  [ set qs-item 0 ]  set quick-start (item qs-item qs-items)end; *** NetLogo Model Copyright Notice ***;; This activity and associated models and materials was 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 Investments model.; http://ccl.northwestern.edu/netlogo/models/HubNetInvestments.; 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/HubNetInvestments; for terms of use.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW2961226665134440.01161110CC-WINDOW5527675622Command CenterBUTTON143190238223NILgoT1TOBSERVERNILNILSLIDER54312222345interest-rateinterest-rate01.00.150.011NILBUTTON90230194263NILnext-roundNIL1TOBSERVERTNILMONITOR112356170405roundrounds01BUTTON40190135223resetstart-overNIL1TOBSERVERTNILSLIDER55270222303car-costcar-cost01005011NILMONITOR911462763Quick Start Instructionsquick-start01BUTTON9068233101Reset Instructions

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -