{"id":99850,"student_id":37,"content":"// 可以修改預設密碼來測試\n// setPassword('password');\n\nvar chars = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ \";\nvar pops = [];\n// 不斷嘗試密碼並將分數高的排在前面,產生下一代的密碼\nwhile (pops.length \u003c 20) {\n var gens = \"\";\n for (var i = 0; i \u003c 23; i++) {\n gens += chars[Math.floor(Math.random()*53)];\n }\n pops.push(gens);\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 genes = crossover(pops[0], pops[1]);\n children.push(genes);\n }\n pops = children;\n});\n\n// 將兩組密碼進行組合\nfunction crossover (a, b) {\n var gens = \"\";\n for (var i = 0; i \u003c 23; i++) {\n if (Math.random() \u003c 0.05) {\n gens += chars[Math.floor(Math.random()*53)];\n } else if (Math.random() \u003c 0.5) {\n gens += a[i];\n } else {\n gens += b[i]\n }\n }\n return gens;\n}","created_at":"2019-10-06T10:13:22.878+08:00","updated_at":"2019-11-11T19:19:23.423+08:00","name":"遺傳演算法 副本","language":"javascript","screenshot":{"url":"https://cdn2.koding.school/uploads/project/screenshot/99850/23fd8cb6e743128e440fb4f677b30db6.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":46,"hashid":"kdmsd292","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1684514,"file_name":"hacker2.jpg","project_id":99850,"asset_id":74924,"created_at":"2019-10-06T10:13:22.882+08:00","updated_at":"2019-10-06T10:13:22.882+08:00"},{"id":1684515,"file_name":"hacker3.jpg","project_id":99850,"asset_id":74923,"created_at":"2019-10-06T10:13:22.884+08:00","updated_at":"2019-10-06T10:13:22.884+08:00"},{"id":1684516,"file_name":"hacker1.jpg","project_id":99850,"asset_id":74922,"created_at":"2019-10-06T10:13:22.885+08:00","updated_at":"2019-10-06T10:13:22.885+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦