{"id":138553,"student_id":10,"content":"var b1 = new Bar();\nvar b2 = new Bar();\nvar b3 = new Bar();\n\nsetInterval(function () {\n \n \n \n // 先進先出排程演算法\n b2.sort(function (a, b) {\n return a.order - b.order;\n });\n b2.serve(b2[0]);\n \n // 最小工作優先排程演算法\n b1.sort(function (a, b) {\n return a.value - b.value;\n });\n b1.serve(b1[0]);\n\n\n // 優先排程演算法\n // b1.sort(function (a, b) {\n // return a.time - b.time;\n // });\n // b1.serve(b1[0]);\n // 循環排程演算法\n var task = b3.shift();\n b3.push(task);\n b3.serve(b3[0]);\n \n}, 1000);","created_at":"2020-04-07T16:16:25.684+08:00","updated_at":"2020-04-08T14:07:39.470+08:00","name":"酒吧排程演算法_雙師","language":"javascript","screenshot":{"url":"/uploads/project/screenshot/138553/7201dab5fb5a4c6b83a3edfb264bc8f3.jpg"},"parent_id":2,"plugin":"// const COSTUMES = [['b_0.png', 'b_1.png'],['r_0.png', 'r_1.png'],['g_0.png', 'g_1.png'],['y_0.png', 'y_1.png']];\nconst COSTUMES = [['k_0.png', 'k_1.png'],['k_0.png', 'k_1.png'],['k_0.png', 'k_1.png'],['k_0.png', 'k_1.png']];\n\nvar bars = [];\n\nvar peopleSprite = {};\n\nfunction Bar (x, y) {\n this.table = createSprite(\"bg.png\");\n this.table.y = bars.length*160 + 80;\n this.table.layer = 1;\n \n this.arr = [];\n this.seats = {};\n this.idx = 0;\n \n bars.push(this);\n\n \n forever(() =\u003e {\n this.arr.forEach((p)=\u003e {\n var s = this.seats[p.seat];\n print(p.value, s.x, s.y);\n });\n });\n \n this.arr.serve = this.serve.bind(this);\n \n return this.arr;\n}\n\nBar.prototype = {\n addTask: function (sprite, data) {\n this.arr.push(data);\n \n for (var i=0; i\u003c10; i++) {\n if (this.seats[this.idx] == undefined) {\n this.seats[this.idx] = sprite;\n sprite.x = this.idx*64 + 32;\n sprite.y = this.table.y;\n data.seat = this.idx;\n break;\n }\n this.idx++;\n if (this.idx \u003e= 10) this.idx = 0;\n }\n },\n \n removeEmptyTask: function () {\n this.arr.forEach((p) =\u003e {\n if (p \u0026\u0026 p.value \u003c= 0) {\n var idx = this.arr.indexOf(p);\n this.arr.splice(idx, 1);\n this.seats[p.seat].destroy();\n delete this.seats[p.seat];\n }\n });\n },\n \n serve: function (data) {\n data.value--;\n for (var i=0; i\u003c10; i++) {\n var s = this.seats[i]\n if (s) s.costumeId = 0;\n }\n this.seats[data.seat].costumeId = 1;\n }\n}\n\n\nvar clock = 0;\nvar order = 0;\n\nsetInterval(function () {\n \n clock++;\n \n bars.forEach(function (b) {\n b.removeEmptyTask();\n });\n \n if (bars.length == 0 || clock % 2 != 0) return;\n if (bars.some(function (b) { return b.arr.length \u003e= 10 })) return;\n \n order++;\n \n var value = Math.floor(Math.random()*8) + 1;\n var costume = COSTUMES[Math.floor(Math.random()*COSTUMES.length)];\n \n bars.forEach(function (bar) {\n var s = createSprite(costume);\n var data = { value: value, time: 0, order: order }\n bar.addTask(s, data);\n s.on('click', () =\u003e data.value -= 1);\n });\n \n \n \n}, 1000);","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":452,"hashid":"meys8r9m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2386374,"file_name":"b_0.png","project_id":138553,"asset_id":202669,"created_at":"2020-04-07T16:16:45.146+08:00","updated_at":"2020-04-07T16:16:45.146+08:00"},{"id":2386375,"file_name":"b_1.png","project_id":138553,"asset_id":202670,"created_at":"2020-04-07T16:16:45.148+08:00","updated_at":"2020-04-07T16:16:45.148+08:00"},{"id":2386380,"file_name":"r_1.png","project_id":138553,"asset_id":202675,"created_at":"2020-04-07T16:16:46.142+08:00","updated_at":"2020-04-07T16:16:46.142+08:00"},{"id":2386381,"file_name":"y_0.png","project_id":138553,"asset_id":202676,"created_at":"2020-04-07T16:16:46.143+08:00","updated_at":"2020-04-07T16:16:46.143+08:00"},{"id":2386377,"file_name":"g_0.png","project_id":138553,"asset_id":202672,"created_at":"2020-04-07T16:16:45.580+08:00","updated_at":"2020-04-07T16:16:45.580+08:00"},{"id":2386378,"file_name":"g_1.png","project_id":138553,"asset_id":202673,"created_at":"2020-04-07T16:16:45.891+08:00","updated_at":"2020-04-07T16:16:45.891+08:00"},{"id":2386379,"file_name":"r_0.png","project_id":138553,"asset_id":202674,"created_at":"2020-04-07T16:16:45.893+08:00","updated_at":"2020-04-07T16:16:45.893+08:00"},{"id":2386382,"file_name":"y_1.png","project_id":138553,"asset_id":202677,"created_at":"2020-04-07T16:16:46.403+08:00","updated_at":"2020-04-07T16:16:46.403+08:00"},{"id":2388492,"file_name":"bg.png","project_id":138553,"asset_id":203716,"created_at":"2020-04-08T13:50:51.400+08:00","updated_at":"2020-04-08T13:50:51.400+08:00"},{"id":2388493,"file_name":"k_0.png","project_id":138553,"asset_id":203717,"created_at":"2020-04-08T13:51:17.293+08:00","updated_at":"2020-04-08T13:51:17.293+08:00"},{"id":2388494,"file_name":"k_1.png","project_id":138553,"asset_id":203718,"created_at":"2020-04-08T13:51:17.295+08:00","updated_at":"2020-04-08T13:51:17.295+08:00"}]
Orange Apple Learning Platform
My Projects
View Project Page
Export
Remix
Import
Delete
Download Android APP (APK)
Screenshot
繁中
简中
English
日本語
1:1:1
1:1
Full Width
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer
Scan the QRCode below with your phone to install
Or you can
download APK
to this computer