{"id":79927,"student_id":37,"content":"var group1 = createGroup(vendor1);\nvar group2 = createGroup(vendor2);\nvar group3 = createGroup(vendor3);\n\n// First-Come First-Served\nforever(function () {\n if (group1.length \u003e 0) {\n group1[0].number -= 1\n if (group1[0].number \u003c 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.length \u003e 0) {\n group2[0].number -= 1\n if (group2[0].number \u003c 0) {\n group2.shift();\n }\n }\n});\n\nvar count = 0\n// Round Robin\nforever(function () {\n if (group3.length \u003e 0) {\n group3[count].number -=1 \n if(group3[count].number \u003c 0 ){\n group3.splice(count,1)\n }\n }\n count ++\n if (count \u003e= group3.length) {\n count = 0\n }\n\n});","created_at":"2019-07-14T10:08:03.424+08:00","updated_at":"2019-10-08T05:42:11.840+08:00","name":"Schedule 排程 副本","language":"javascript","screenshot":{"url":"https://cdn1.koding.school/uploads/project/screenshot/79927/798f25d5732df00c51ea4f7e2182d075.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":49,"hashid":"36ysz95m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1370586,"file_name":"P-10.png","project_id":79927,"asset_id":71811,"created_at":"2019-07-14T10:08:03.429+08:00","updated_at":"2019-07-14T10:08:03.429+08:00"},{"id":1370587,"file_name":"P-09.png","project_id":79927,"asset_id":71810,"created_at":"2019-07-14T10:08:03.430+08:00","updated_at":"2019-07-14T10:08:03.430+08:00"},{"id":1370588,"file_name":"P-08.png","project_id":79927,"asset_id":71809,"created_at":"2019-07-14T10:08:03.430+08:00","updated_at":"2019-07-14T10:08:03.430+08:00"},{"id":1370589,"file_name":"P-07.png","project_id":79927,"asset_id":71808,"created_at":"2019-07-14T10:08:03.431+08:00","updated_at":"2019-07-14T10:08:03.431+08:00"},{"id":1370590,"file_name":"P-06.png","project_id":79927,"asset_id":71807,"created_at":"2019-07-14T10:08:03.432+08:00","updated_at":"2019-07-14T10:08:03.432+08:00"},{"id":1370591,"file_name":"P-05.png","project_id":79927,"asset_id":71806,"created_at":"2019-07-14T10:08:03.433+08:00","updated_at":"2019-07-14T10:08:03.433+08:00"},{"id":1370592,"file_name":"P-04.png","project_id":79927,"asset_id":71805,"created_at":"2019-07-14T10:08:03.434+08:00","updated_at":"2019-07-14T10:08:03.434+08:00"},{"id":1370593,"file_name":"P-03.png","project_id":79927,"asset_id":71804,"created_at":"2019-07-14T10:08:03.434+08:00","updated_at":"2019-07-14T10:08:03.434+08:00"},{"id":1370594,"file_name":"P-02.png","project_id":79927,"asset_id":71803,"created_at":"2019-07-14T10:08:03.435+08:00","updated_at":"2019-07-14T10:08:03.435+08:00"},{"id":1370595,"file_name":"P-01.png","project_id":79927,"asset_id":71802,"created_at":"2019-07-14T10:08:03.436+08:00","updated_at":"2019-07-14T10:08:03.436+08:00"},{"id":1370596,"file_name":"vendor_1.png","project_id":79927,"asset_id":71801,"created_at":"2019-07-14T10:08:03.437+08:00","updated_at":"2019-07-14T10:08:03.437+08:00"},{"id":1370597,"file_name":"vendor_2.png","project_id":79927,"asset_id":71800,"created_at":"2019-07-14T10:08:03.437+08:00","updated_at":"2019-07-14T10:08:03.437+08:00"},{"id":1370598,"file_name":"vendor_3.png","project_id":79927,"asset_id":71799,"created_at":"2019-07-14T10:08:03.438+08:00","updated_at":"2019-07-14T10:08:03.438+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦