{"id":40197,"student_id":119,"content":"var group1 = createGroup(vendor1);\nvar group2 = createGroup(vendor2);\nvar group3 = createGroup(vendor3);\nvar count = 0;\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// Shortest Job First\nforever(function () {\n arr = group2;\n arr.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 1) {\n group2.shift();\n }\n }\n});\n// Round Robin\nforever(function () {\n if (group3.length \u003e 0) {\n group3[count].number -= 1\n if (group3[count].number \u003c 1) {\n group3.splice(count, 1);\n }\n count++;\n if (count \u003e group3.length-1) {\n count = 0;\n }\n }\n});","created_at":"2018-08-31T16:32:48.854+08:00","updated_at":"2019-11-11T08:15:09.199+08:00","name":"Schedule 排程 副本","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/40197/73c64adddf96b86984c44ee1b3e70b9e.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":66,"hashid":"6rpsr3qq","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":708989,"file_name":"P-10.png","project_id":40197,"asset_id":71811,"created_at":"2018-08-31T16:32:48.863+08:00","updated_at":"2018-08-31T16:32:48.863+08:00"},{"id":708990,"file_name":"P-09.png","project_id":40197,"asset_id":71810,"created_at":"2018-08-31T16:32:48.865+08:00","updated_at":"2018-08-31T16:32:48.865+08:00"},{"id":708991,"file_name":"P-08.png","project_id":40197,"asset_id":71809,"created_at":"2018-08-31T16:32:48.867+08:00","updated_at":"2018-08-31T16:32:48.867+08:00"},{"id":708992,"file_name":"P-07.png","project_id":40197,"asset_id":71808,"created_at":"2018-08-31T16:32:48.868+08:00","updated_at":"2018-08-31T16:32:48.868+08:00"},{"id":708993,"file_name":"P-06.png","project_id":40197,"asset_id":71807,"created_at":"2018-08-31T16:32:48.870+08:00","updated_at":"2018-08-31T16:32:48.870+08:00"},{"id":708994,"file_name":"P-05.png","project_id":40197,"asset_id":71806,"created_at":"2018-08-31T16:32:48.871+08:00","updated_at":"2018-08-31T16:32:48.871+08:00"},{"id":708995,"file_name":"P-04.png","project_id":40197,"asset_id":71805,"created_at":"2018-08-31T16:32:48.873+08:00","updated_at":"2018-08-31T16:32:48.873+08:00"},{"id":708996,"file_name":"P-03.png","project_id":40197,"asset_id":71804,"created_at":"2018-08-31T16:32:48.874+08:00","updated_at":"2018-08-31T16:32:48.874+08:00"},{"id":708997,"file_name":"P-02.png","project_id":40197,"asset_id":71803,"created_at":"2018-08-31T16:32:48.876+08:00","updated_at":"2018-08-31T16:32:48.876+08:00"},{"id":708998,"file_name":"P-01.png","project_id":40197,"asset_id":71802,"created_at":"2018-08-31T16:32:48.877+08:00","updated_at":"2018-08-31T16:32:48.877+08:00"},{"id":708999,"file_name":"vendor_1.png","project_id":40197,"asset_id":71801,"created_at":"2018-08-31T16:32:48.879+08:00","updated_at":"2018-08-31T16:32:48.879+08:00"},{"id":709000,"file_name":"vendor_2.png","project_id":40197,"asset_id":71800,"created_at":"2018-08-31T16:32:48.880+08:00","updated_at":"2018-08-31T16:32:48.880+08:00"},{"id":709001,"file_name":"vendor_3.png","project_id":40197,"asset_id":71799,"created_at":"2018-08-31T16:32:48.882+08:00","updated_at":"2018-08-31T16:32:48.882+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦