{"id":149619,"student_id":1998,"content":"// 可以修改預設密碼來測試\n// setPassword('password');\n\n// 不斷嘗試密碼並將分數高的排在前面,產生下一代的密碼\nvar pwd = \"gummygummy\";\nsetPassword(pwd);\nvar chars = ' abcdefghijklmnopqrstuwvxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';\nvar pops = [];\nfor (var i = 0; i \u003c 20; i++) {\n var gene = \"\";\n for (var j = 0; j \u003c pwd.length; j++) {\n var char = chars[Math.floor(Math.random()*chars.length)];\n gene += char;\n }\n pops.push(gene);\n}\n\nforever(function() {\n var children = [];\n pops.sort(function(a, b) {\n return password(b) - password(a);\n });\n for (var i = 0; i \u003c 20; i++) {\n var child = crossover(pops[0], pops[1]);\n children.push(child);\n }\n pops = children;\n\n});\n// 將兩組密碼進行組合\nfunction crossover (parentA, parentB) {\n var child = \"\";\n for (var i = 0; i \u003c parentA.length; i++) {\n if (Math.random() \u003c 0.6) {\n child += parentA[i];\n } else {\n\n child += parentA[i];\n }\n }\n return child;\n}\n","created_at":"2020-05-16T16:12:19.559+08:00","updated_at":"2020-05-23T16:25:09.387+08:00","name":"遺傳演算法 副本","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/149619/89edcce60b8890776f43b51e69f48ea4.jpg"},"parent_id":33940,"plugin":"setBackdrop('hacker1.jpg', 0, 0, 640, 480);\n\nvar game = (function () {\n \n var log = [];\n var key = 'I love Koding very much';\n var gameOver = false;\n \n when('click', function () {\n if (prompt('請輸入密碼?') == key) {\n setBackdrop('hacker2.jpg', 0, 0, 640, 480);\n setTimeout(function() {\n setBackdrop('hacker3.jpg', 0, 0, 640, 480);\n stop();\n }, 1000);\n }\n });\n \n function password (passwd) {\n if (gameOver) return;\n if (passwd == key) gameOver = true;\n \n log.unshift(passwd);\n var count = 0;\n for (var i = 0; i \u003c key.length; i++) {\n if (key[i] == passwd[i]) count++;\n }\n return count;\n }\n \n function setPassword (passwd) {\n key = passwd;\n }\n \n forever(function(){\n for (var i=0; i\u003c14 \u0026\u0026 i\u003clog.length; i++) {\n print(log[i], 50, 35 + 20*i, log[i] == key ? 'gold' : 'white');\n }\n });\n\n return {\n password: password,\n setPassword: setPassword\n }\n})();\n\nvar password = game.password;\nvar setPassword = game.setPassword;\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":36,"hashid":"ej9sze5m","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":2595694,"file_name":"hacker2.jpg","project_id":149619,"asset_id":74924,"created_at":"2020-05-16T16:12:19.565+08:00","updated_at":"2020-05-16T16:12:19.565+08:00"},{"id":2595695,"file_name":"hacker3.jpg","project_id":149619,"asset_id":74923,"created_at":"2020-05-16T16:12:19.566+08:00","updated_at":"2020-05-16T16:12:19.566+08:00"},{"id":2595696,"file_name":"hacker1.jpg","project_id":149619,"asset_id":74922,"created_at":"2020-05-16T16:12:19.567+08:00","updated_at":"2020-05-16T16:12:19.567+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦