{"id":27752,"student_id":10,"content":"setBackdrop('black');\n\nvar size = 10;\nvar dots = [];\n\nfor (var i=0; i\u003csize; i++) {\n var dot = createSprite('dot.png');\n dot.x = Math.random()*640;\n dot.y = Math.random()*480;\n dots.push(dot);\n}\n\nvar best = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];\nvar current = [];\n\nforever(function(){\n \n for(var i=0; i\u003csize - 1; i++) {\n var dotA = dots[best[i]];\n var dotB = dots[best[i + 1]];\n pen.color = 'red';\n pen.drawLine(dotA.x, dotA.y, dotB.x, dotB.y);\n }\n \n\n current = swap(best);\n if (fitness(best) \u003c fitness(current)) {\n best = current;\n }\n})\n\nfunction fitness (arr) {\n var distance = 0;\n for(var i=0; i\u003csize - 1; i++) {\n var dotA = dots[arr[i]];\n var dotB = dots[arr[i + 1]];\n distance += dotA.distanceTo(dotB);\n }\n return distance;\n}\n\nfunction swap (arr) {\n arr = arr.slice(0);\n var rand1 = Math.floor(Math.random()*size);\n var rand2 = Math.floor(Math.random()*size);\n var temp = arr[rand1];\n arr[rand1] = arr[rand2];\n arr[rand2] = temp;\n return arr;\n}","created_at":"2018-05-02T23:10:24.785+08:00","updated_at":"2019-10-15T11:05:10.669+08:00","name":"TSP","language":"javascript","screenshot":{"url":"https://cdn4.koding.school/uploads/project/screenshot/27752/ab423e4c3bfbedcd8a78c8fc6a80fb1c.jpg"},"parent_id":2,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":289,"hashid":"36ysd6vk","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":511190,"file_name":"dot.png","project_id":27752,"asset_id":62758,"created_at":"2018-05-02T23:12:08.213+08:00","updated_at":"2018-05-02T23:12:08.213+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦