{"id":52860,"student_id":10,"content":"var Q = {};\nvar S1;\nvar S2;\nvar A;\nvar alpha = 0.8;\nvar beta = 0.5;\n\n\nforever(function () {\n S1 = player.X + ':' + player.Y;\n if (Q[S1] == undefined) Q[S1] = [0, 0, 0, 0]; \n \n var max = Math.max(...Q[S1]);\n var A = Q[S1].indexOf(max);\n if (A == 0) player.Y--;\n if (A == 1) player.X++;\n if (A == 2) player.Y++;\n if (A == 3) player.X--;\n \n S2 = player.X + ':' + player.Y;\n if (Q[S2] == undefined) Q[S2] = [0, 0, 0, 0];\n \n if (map[player.Y][player.X] == ' ') {\n reword(Q, S1, A, S2, -100);\n player.reset(1, 1);\n }\n \n if (map[player.Y][player.X] == 'T') {\n reword(Q, S1, A, S2, 10);\n player.reset(1, 1);\n }\n \n reword(Q, S1, A, S2, -1);\n});\n\nfunction reword (Q, S1, A, S2, score) {\n Q[S1][A] = alpha*Q[S1][A] + (1 - alpha)*(score + beta*Math.max(...Q[S2]));\n}\n\n","created_at":"2019-01-02T11:35:42.975+08:00","updated_at":"2019-11-08T14:46:38.698+08:00","name":"Q-learning","language":"javascript","screenshot":{"url":"https://cdn5.koding.school/uploads/project/screenshot/52860/720fa500e9577b1fa8ccbf80ebd3f8cb.jpg"},"parent_id":2,"plugin":"var player = createSprite(['0.png','1.png','2.png','3.png','4.png','5.png','6.png','7.png','8.png','9.png','10.png','11.png','12.png','13.png','14.png','15.png'])\nplayer.layer = 1;\nplayer.rotationStyle = 'fixed';\nplayer.X = 1;\nplayer.Y = 1;\n\nplayer.reset = function (x, y) {\n player.X = x;\n player.Y = y;\n}\n\nplayer.moveUp = function () {\n this.target = this.target.top;\n}\nplayer.moveRight = function () {\n this.target = this.target.right;\n}\nplayer.moveDown = function () {\n this.target = this.target.bottom;\n}\nplayer.moveLeft = function () {\n this.target = this.target.left;\n}\n\n// player.decision = function () {\n// var target = player.target;\n// if (key.up \u0026\u0026 target.top) player.target = target.top;\n// if (key.right \u0026\u0026 target.right) player.target = target.right;\n// if (key.down \u0026\u0026 target.bottom) player.target = target.bottom;\n// if (key.left \u0026\u0026 target.left) player.target = target.left;\n// player.nextDirection = undefined;\n// }\n\nforever(function(){\n player.toward(player.target);\n if (player.distanceTo(player.target) \u003c 3) {\n player.moveTo(player.target);\n // player.decision();\n // AI();\n } else {\n player.stepForward(3);\n }\n})\n\nfunction createMap (map) {\n \n var W;\n var H;\n \n for (var i=0; i\u003cmap.length; i++) {\n map[i] = ' ' + map[i] + ' ';\n }\n var W = map[0].length;\n map.push(Array(W).fill(' '));\n map.unshift(Array(W).fill(' '));\n \n var H = map.length;\n \n var grid = Array();\n for (var i=0; i\u003cW; i++) {\n grid.push([]);\n }\n\n // 創造岩漿背景\n for (var x = 0; x \u003c 13; x++) {\n for (var y = 0; y \u003c 10; y++) {\n var laval = createSprite('lava.png');\n laval.y = y*50 + 25;\n laval.x = x*50 + 25;\n }\n }\n\n // 創造石頭地板\n for (var x = 0; x \u003c W; x++) {\n for (var y = 0; y \u003c H; y++) {\n var rock = createSprite('rock.png');\n rock.x = x*50;\n rock.y = y*50;\n \n if (map[y][x] == ' ') rock.hidden = true;\n \n if (map[y][x] == 'P') player.target = rock;\n \n grid[x][y] = rock;\n\n }\n }\n \n // connect\n for (var x=0; x\u003cW; x++) {\n for (var y=0; y\u003cH; y++) {\n if (y \u003e 0) grid[x][y].top = grid[x][y-1];\n if (y \u003c H-1) grid[x][y].bottom = grid[x][y+1];\n if (x \u003e 0) grid[x][y].left = grid[x-1][y];\n if (x \u003c W-1) grid[x][y].right = grid[x+1][y];\n }\n }\n \n forever(function () {\n player.moveTo(grid[player.X][player.Y]); \n });\n \n return map;\n}\n\n\nvar map = createMap([\n 'PXXX',\n 'X X',\n 'X TX',\n 'XXXX',\n]);\n\n\n\n\n// });","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":290,"hashid":"6rpsdwpq","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":941702,"file_name":"lava.png","project_id":52860,"asset_id":105548,"created_at":"2019-01-02T11:36:56.307+08:00","updated_at":"2019-01-02T11:37:00.298+08:00"},{"id":941704,"file_name":"rock.png","project_id":52860,"asset_id":105550,"created_at":"2019-01-02T12:00:03.838+08:00","updated_at":"2019-01-02T12:00:03.838+08:00"},{"id":941705,"file_name":"0.png","project_id":52860,"asset_id":105551,"created_at":"2019-01-02T12:04:47.597+08:00","updated_at":"2019-01-02T12:04:59.296+08:00"},{"id":941706,"file_name":"1.png","project_id":52860,"asset_id":105552,"created_at":"2019-01-02T12:04:47.599+08:00","updated_at":"2019-01-02T12:05:01.271+08:00"},{"id":941708,"file_name":"3.png","project_id":52860,"asset_id":105553,"created_at":"2019-01-02T12:04:47.992+08:00","updated_at":"2019-01-02T12:05:05.606+08:00"},{"id":941707,"file_name":"2.png","project_id":52860,"asset_id":105551,"created_at":"2019-01-02T12:04:47.989+08:00","updated_at":"2019-01-02T12:05:08.121+08:00"},{"id":941709,"file_name":"4.png","project_id":52860,"asset_id":105554,"created_at":"2019-01-02T12:04:48.552+08:00","updated_at":"2019-01-02T12:05:10.399+08:00"},{"id":941710,"file_name":"5.png","project_id":52860,"asset_id":105555,"created_at":"2019-01-02T12:04:48.555+08:00","updated_at":"2019-01-02T12:05:12.601+08:00"},{"id":941711,"file_name":"6.png","project_id":52860,"asset_id":105554,"created_at":"2019-01-02T12:04:48.971+08:00","updated_at":"2019-01-02T12:05:16.124+08:00"},{"id":941712,"file_name":"7.png","project_id":52860,"asset_id":105556,"created_at":"2019-01-02T12:04:48.974+08:00","updated_at":"2019-01-02T12:05:18.630+08:00"},{"id":941713,"file_name":"8.png","project_id":52860,"asset_id":105557,"created_at":"2019-01-02T12:04:49.370+08:00","updated_at":"2019-01-02T12:05:20.114+08:00"},{"id":941714,"file_name":"9.png","project_id":52860,"asset_id":105558,"created_at":"2019-01-02T12:04:49.373+08:00","updated_at":"2019-01-02T12:05:22.570+08:00"},{"id":941715,"file_name":"10.png","project_id":52860,"asset_id":105557,"created_at":"2019-01-02T12:04:49.760+08:00","updated_at":"2019-01-02T12:05:24.311+08:00"},{"id":941716,"file_name":"11.png","project_id":52860,"asset_id":105559,"created_at":"2019-01-02T12:04:49.762+08:00","updated_at":"2019-01-02T12:05:26.893+08:00"},{"id":941717,"file_name":"12.png","project_id":52860,"asset_id":105560,"created_at":"2019-01-02T12:04:50.159+08:00","updated_at":"2019-01-02T12:05:29.558+08:00"},{"id":941718,"file_name":"13.png","project_id":52860,"asset_id":105561,"created_at":"2019-01-02T12:04:50.161+08:00","updated_at":"2019-01-02T12:05:31.051+08:00"},{"id":941719,"file_name":"14.png","project_id":52860,"asset_id":105560,"created_at":"2019-01-02T12:04:50.810+08:00","updated_at":"2019-01-02T12:05:33.439+08:00"},{"id":941720,"file_name":"15.png","project_id":52860,"asset_id":105562,"created_at":"2019-01-02T12:04:50.812+08:00","updated_at":"2019-01-02T12:05:35.747+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦