{"id":24502,"student_id":10,"content":"let map = [\n [1,1,1,1,1,1],\n [1,0,0,0,0,1],\n [1,0,0,1,0,1],\n [1,0,1,2,0,1],\n [1,0,0,1,0,1],\n [1,1,1,1,1,1],\n];\n\nlet w = 60; // 繪圖的寬度\nlet player = {x: 1, y: 1};\n\nlet Q = [];\nlet S = '1:1';\nlet A;\nlet _S;\n\nlet alpha = 0.7;\nlet beta = 0.8;\n\nlet i=0;\nforever(function () {\n i++;\n if (i%2 == 0) update();\n});\n\nfunction update () {\n \n _S = player.x + ':' + player.y\n\n if (Q[S] == undefined) Q[S] = [0, 0, 0, 0];\n if (Q[_S] == undefined) Q[_S] = [0, 0, 0, 0];\n\n let c = map[player.x][player.y];\n \n if (c == 0) Q = reward(Q, S, A, -1, _S); // 白色\n if (c == 1) Q = reward(Q, S, A, -100, _S); // 黑洞\n if (c == 2) Q = reward(Q, S, A, +300, _S); // 寶藏\n \n // 撞到黑洞或寶藏就重新開始\n if (c == 1 || c == 2) {\n player.x = 1;\n player.y = 1;\n }\n\n S = _S;\n A = Q[S].indexOf(Math.max(...Q[S]));\n if (A == 3) player.y -= 1;\n if (A == 2) player.x += 1;\n if (A == 1) player.y += 1;\n if (A == 0) player.x -= 1;\n}\n\nfunction reward (Q, S, A, R, _S) {\n let mr = Math.max(...Q[_S]);\n Q[S][A] = Q[S][A]*(1 - alpha) + alpha*(R + beta*mr); \n return Q;\n}\n\n// 繪圖\nforever(() =\u003e {\n for(let x=0; x\u003c6; x++) {\n for(let y=0; y\u003c6; y++) {\n if (map[x][y] == 1) pen.fillColor = 'black';\n else if (map[x][y] == 2) pen.fillColor = 'red';\n else pen.fillColor = '#eee';\n pen.drawRect(x*w, y*w, w-5, w-5);\n }\n }\n pen.fillColor = 'orange';\n pen.drawRect(player.x*w, player.y*w, w-5, w-5);\n});","created_at":"2018-03-16T15:01:26.928+08:00","updated_at":"2019-10-30T21:38:15.400+08:00","name":"Q-learning 迷宮","language":"javascript","screenshot":{"url":"/uploads/project/screenshot/24502/5904bed1a401ef7d335f05e7f9772a06.jpg"},"parent_id":24474,"plugin":"","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":535,"hashid":"vngs5d82","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":463362,"file_name":"1.wav","project_id":24502,"asset_id":10,"created_at":"2018-03-16T15:01:26.937+08:00","updated_at":"2018-03-16T15:01:26.937+08:00"},{"id":463363,"file_name":"0.wav","project_id":24502,"asset_id":9,"created_at":"2018-03-16T15:01:26.940+08:00","updated_at":"2018-03-16T15:01:26.940+08:00"},{"id":463364,"file_name":"2.png","project_id":24502,"asset_id":8,"created_at":"2018-03-16T15:01:26.943+08:00","updated_at":"2018-03-16T15:01:26.943+08:00"},{"id":463365,"file_name":"1.svg","project_id":24502,"asset_id":7,"created_at":"2018-03-16T15:01:26.945+08:00","updated_at":"2018-03-16T15:01:26.945+08:00"},{"id":463366,"file_name":"0.png","project_id":24502,"asset_id":6,"created_at":"2018-03-16T15:01:26.948+08:00","updated_at":"2018-03-16T15:01:26.948+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