{"id":29741,"student_id":10,"content":"var order1 = createGroup(vendor1);\nvar order2 = createGroup(vendor2);\nvar order3 = createGroup(vendor3);\n\n// First-Come First-Served\nforever(function () {\n if (order1.length \u003e 0) {\n order1[0].number -= 1;\n if (order1[0].number \u003c= 0) {\n order1.shift();\n }\n };\n});\n\n// Shortest Job First\nforever(function () {\n order2.sort(function (a, b) {\n return a.number - b.number;\n });\n if (order2.length \u003e 0) {\n order2[0].number -= 1;\n if (order2[0].number \u003c= 0) {\n order2.shift();\n }\n };\n});\n\n\n// Round Robin\nvar count = 0;\nforever(function () {\n if (order3.length \u003e 0) {\n order3[count].number -= 1;\n if (order3[count].number \u003c= 0) {\n order3.splice(count, 1);\n }\n };\n\n count++;\n if (count \u003e= order3.length) {\n count = 0;\n }\n});","created_at":"2018-05-24T15:43:28.152+08:00","updated_at":"2020-04-07T15:59:12.310+08:00","name":"排程演算法","language":"javascript","screenshot":{"url":"https://cdn0.koding.school/uploads/project/screenshot/29741/c449b87e53b64440950a50b3b418fc68.jpg"},"parent_id":28329,"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":346,"hashid":"882snjme","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":550175,"file_name":"P-10.png","project_id":29741,"asset_id":63976,"created_at":"2018-05-24T15:43:28.159+08:00","updated_at":"2018-05-24T15:43:28.159+08:00"},{"id":550176,"file_name":"P-09.png","project_id":29741,"asset_id":63975,"created_at":"2018-05-24T15:43:28.162+08:00","updated_at":"2018-05-24T15:43:28.162+08:00"},{"id":550177,"file_name":"P-08.png","project_id":29741,"asset_id":63974,"created_at":"2018-05-24T15:43:28.163+08:00","updated_at":"2018-05-24T15:43:28.163+08:00"},{"id":550178,"file_name":"P-07.png","project_id":29741,"asset_id":63973,"created_at":"2018-05-24T15:43:28.164+08:00","updated_at":"2018-05-24T15:43:28.164+08:00"},{"id":550179,"file_name":"P-06.png","project_id":29741,"asset_id":63972,"created_at":"2018-05-24T15:43:28.166+08:00","updated_at":"2018-05-24T15:43:28.166+08:00"},{"id":550180,"file_name":"P-05.png","project_id":29741,"asset_id":63971,"created_at":"2018-05-24T15:43:28.167+08:00","updated_at":"2018-05-24T15:43:28.167+08:00"},{"id":550181,"file_name":"P-04.png","project_id":29741,"asset_id":63970,"created_at":"2018-05-24T15:43:28.169+08:00","updated_at":"2018-05-24T15:43:28.169+08:00"},{"id":550182,"file_name":"P-03.png","project_id":29741,"asset_id":63969,"created_at":"2018-05-24T15:43:28.170+08:00","updated_at":"2018-05-24T15:43:28.170+08:00"},{"id":550183,"file_name":"P-02.png","project_id":29741,"asset_id":63968,"created_at":"2018-05-24T15:43:28.171+08:00","updated_at":"2018-05-24T15:43:28.171+08:00"},{"id":550184,"file_name":"P-01.png","project_id":29741,"asset_id":63967,"created_at":"2018-05-24T15:43:28.173+08:00","updated_at":"2018-05-24T15:43:28.173+08:00"},{"id":550185,"file_name":"vendor_1.png","project_id":29741,"asset_id":63753,"created_at":"2018-05-24T15:43:28.174+08:00","updated_at":"2018-05-24T15:43:28.174+08:00"},{"id":550186,"file_name":"vendor_2.png","project_id":29741,"asset_id":63754,"created_at":"2018-05-24T15:43:28.176+08:00","updated_at":"2018-05-24T15:43:28.176+08:00"},{"id":550187,"file_name":"vendor_3.png","project_id":29741,"asset_id":63755,"created_at":"2018-05-24T15:43:28.177+08:00","updated_at":"2018-05-24T15:43:28.177+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦