{"id":49551,"student_id":10,"content":"var Q = {}; \nvar S; \nvar A;\nvar _S; \nvar alpha = 0.3;\nvar beta = 0.7;\n\n\nforever(function () {\n _S = getStatus(dinosaur, tree);\n print(_S, 100, 10, 'white', 30);\n \n if (Q[S] == undefined) Q[S] = [0, 0];\n if (Q[_S] == undefined) Q[_S] = [0, 0];\n \n if (dinosaur.touched(tree)) {\n restart();\n reward(S, A, -100, _S);\n }\n reward(S, A, 1, _S);\n\n\n if (Q[_S][0] \u003c Q[_S][1]) {\n A = 1;\n jump();\n } else {\n A = 0;\n }\n S = _S;\n});\n\nfunction getStatus (dinosaur, tree) {\n // return '' + Math.floor((dinosaur.x - tree.x)/10) + ':' + Math.floor(dinosaur.speed)\n return '' + Math.floor((dinosaur.x - tree.x)/10)\n}\n\nfunction reward (S, A, R, _S) {\n var mr = Math.max(Q[_S][0], Q[_S][1]);\n Q[S][A] = Q[S][A]*(1 - alpha) + alpha*(R + beta*mr);\n}","created_at":"2018-11-22T16:31:50.617+08:00","updated_at":"2019-10-26T03:58:32.278+08:00","name":"Q-learning 小恐龍","language":"javascript","screenshot":{"url":"https://cdn9.koding.school/uploads/project/screenshot/49551/da1b9760265615ac49660742d0bb01b5.jpg"},"parent_id":2,"plugin":"var score = 0;\nvar bestScore = 0;\nvar dinosaur = createSprite('dinosaur.png');\ndinosaur.scale = 0.4;\ndinosaur.x = 100;\ndinosaur.speed = 3;\n\ndinosaur.v = 0;\n\ndinosaur.forever(function(){\n dinosaur.y -= dinosaur.v;\n dinosaur.v -= 0.4;\n if (dinosaur.y \u003e 240) {\n dinosaur.y = 240;\n }\n});\n\nwhen('click', function () {\n dinosaur.v = 9; \n});\n\n\nvar tree = createSprite('tree.png');\ntree.scale = 0.6;\ntree.x = 640;\ntree.forever(function () {\n tree.x -= dinosaur.speed;\n if (tree.x \u003c -10) {\n tree.x += 670;\n tree.scale = Math.random()+0.\n }\n});\n\nforever(function(){\n score++;\n if (score \u003e bestScore) bestScore = score;\n print('score:' + score, 10, 10);\n print('best:' + bestScore, 10, 30);\n print('speed:' + dinosaur.speed, 10, 50);\n // dinosaur.speed = Math.floor(score/1000) + 4\n});\n\nfunction jump () {\n dinosaur.v = 9;\n}\n\nfunction restart () {\n tree.x = 640;\n score = 0;\n dinosaur.speed = 3;\n dinosaur.y = 240;\n dinosaur.v = 0;\n}","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":315,"hashid":"meysg55e","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":888016,"file_name":"dinosaur.png","project_id":49551,"asset_id":28779,"created_at":"2018-11-22T16:32:00.665+08:00","updated_at":"2018-11-22T16:32:00.665+08:00"},{"id":888017,"file_name":"tree.png","project_id":49551,"asset_id":28784,"created_at":"2018-11-22T16:32:01.964+08:00","updated_at":"2018-11-22T16:32:01.964+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦