{"id":39499,"student_id":1976,"content":"var group1 = createGroup(vendor1);\nvar group2 = createGroup(vendor2);\nvar group3 = createGroup(vendor3);\n\n\n\n// First-Come First-Served\nforever(function () {\n if (group1[0]) {\n group1[0].number -= 1\n console.log(group1[0].number)\n if (group1[0].number == 0) {\n group1.shift()\n }\n }\n});\n\n// Shortest Job First\nforever(function () {\n group2.sort(function(a, b) {\n return a.number-b.number\n })\n if (group2[0]) {\n group2[0].number -= 1\n console.log(group2[0].number)\n if (group2[0].number == 0) {\n group2.shift()\n }\n }\n\n});\n\n\n// Round Robin\nvar count = 0\nforever(function () {\n if(group3.length \u003e 0 ) {\n group3[count].number -= 1\n if(group3[count].number == 0) {\n group3.splice(count,1)\n }\n }\n \n count++\n \n if(count \u003e= group3.length) {\n count = 0\n }\n \n});","created_at":"2018-08-24T19:11:34.168+08:00","updated_at":"2019-10-27T06:00:47.061+08:00","name":"Schedule 排程 副本","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/39499/2c6b3424e8ef6678d4124f471c459633.jpg"},"parent_id":31715,"plugin":"var vendor1 = createSprite('vendor_1.png');\nvendor1.scale = 0.2;\nvendor1.x -= 150;\nvendor1.y -= 120;\nvar vendor2 = createSprite('vendor_2.png');\nvendor2.scale = 0.2;\nvendor2.x -= 150;\nvendor2.y += 10;\nvar vendor3 = createSprite('vendor_3.png');\nvendor3.scale = 0.2;\nvendor3.x -= 150;\nvendor3.y += 140;\n\nvar groups = []; // 存放攤販對應的客人群\n\n// 攤販對應的客人群\nfunction createGroup (vendor) {\n var arr = [];\n arr.vendor = vendor;\n arr.count = 0; // 總客人數量\n arr.time = 0; // 所有的客人累積的等待時間\n setInterval(()=\u003e { arr.time += arr.length*100 }, 100);\n forever(()=\u003e {\n var t = Math.floor(arr.time/arr.count/10)/100\n print(`平均等待時間 ${t} 秒`, vendor.x - 50, vendor.y + 50, 'black');\n });\n groups.push(arr);\n return arr;\n}\n\n// 產生一個客人\nfunction createUnit (value, group) {\n\n var unit = createSprite([\"P-01.png\", \"P-02.png\", \"P-03.png\", \"P-04.png\", \"P-05.png\", \"P-06.png\", \"P-07.png\", \"P-08.png\", \"P-09.png\", \"P-10.png\"]);\n unit.x = 600;\n unit.y = group.vendor.y + 25;\n unit.scale = 0.15;\n unit.costumeId = Math.floor(Math.random() * 10);\n unit.number = value;\n\n unit.forever(function () {\n var idx = group.indexOf(unit);\n // 如果被移除的客人則將移動目標設為 -100\n if (idx == -1) {\n var target = -50;\n } else {\n var target = group.vendor.x + 80 + idx*30;\n }\n if (target \u003e unit.x) unit.x++;\n if (target \u003c unit.x) unit.x--;\n if (unit.x \u003c -50) unit.destroy();\n });\n\n group.push(unit);\n}\n\nforever(function () {\n\n //總人數上限為攤販車的個數乘上 10\n var total = 0;\n for (var i=0; i\u003cgroups.length; i++) total += groups[i].length;\n \n // 每秒鐘隨機產生一個客人\n if (Math.random()*60 \u003c 1 \u0026\u0026 total \u003c groups.length*10) {\n var value = Math.floor(Math.random()*150);\n groups.forEach((g) =\u003e {\n createUnit(value, g);\n g.count++;\n });\n }\n \n // 印出陣列內所有數值\n groups.forEach((g, idx) =\u003e {\n var arr = [];\n g.forEach((s)=\u003earr.push(s.number));\n print(`[ ${arr} ]`, 10, 10 + idx*20);\n });\n});\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":339,"hashid":"yeys4538","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":697589,"file_name":"P-10.png","project_id":39499,"asset_id":71811,"created_at":"2018-08-24T19:11:34.178+08:00","updated_at":"2018-08-24T19:11:34.178+08:00"},{"id":697590,"file_name":"P-09.png","project_id":39499,"asset_id":71810,"created_at":"2018-08-24T19:11:34.181+08:00","updated_at":"2018-08-24T19:11:34.181+08:00"},{"id":697591,"file_name":"P-08.png","project_id":39499,"asset_id":71809,"created_at":"2018-08-24T19:11:34.182+08:00","updated_at":"2018-08-24T19:11:34.182+08:00"},{"id":697592,"file_name":"P-07.png","project_id":39499,"asset_id":71808,"created_at":"2018-08-24T19:11:34.184+08:00","updated_at":"2018-08-24T19:11:34.184+08:00"},{"id":697593,"file_name":"P-06.png","project_id":39499,"asset_id":71807,"created_at":"2018-08-24T19:11:34.185+08:00","updated_at":"2018-08-24T19:11:34.185+08:00"},{"id":697594,"file_name":"P-05.png","project_id":39499,"asset_id":71806,"created_at":"2018-08-24T19:11:34.187+08:00","updated_at":"2018-08-24T19:11:34.187+08:00"},{"id":697595,"file_name":"P-04.png","project_id":39499,"asset_id":71805,"created_at":"2018-08-24T19:11:34.188+08:00","updated_at":"2018-08-24T19:11:34.188+08:00"},{"id":697596,"file_name":"P-03.png","project_id":39499,"asset_id":71804,"created_at":"2018-08-24T19:11:34.190+08:00","updated_at":"2018-08-24T19:11:34.190+08:00"},{"id":697597,"file_name":"P-02.png","project_id":39499,"asset_id":71803,"created_at":"2018-08-24T19:11:34.191+08:00","updated_at":"2018-08-24T19:11:34.191+08:00"},{"id":697598,"file_name":"P-01.png","project_id":39499,"asset_id":71802,"created_at":"2018-08-24T19:11:34.193+08:00","updated_at":"2018-08-24T19:11:34.193+08:00"},{"id":697599,"file_name":"vendor_1.png","project_id":39499,"asset_id":71801,"created_at":"2018-08-24T19:11:34.195+08:00","updated_at":"2018-08-24T19:11:34.195+08:00"},{"id":697600,"file_name":"vendor_2.png","project_id":39499,"asset_id":71800,"created_at":"2018-08-24T19:11:34.197+08:00","updated_at":"2018-08-24T19:11:34.197+08:00"},{"id":697601,"file_name":"vendor_3.png","project_id":39499,"asset_id":71799,"created_at":"2018-08-24T19:11:34.198+08:00","updated_at":"2018-08-24T19:11:34.198+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦