{"id":66269,"student_id":10,"content":"var grid = [\n '******',\n '* *',\n '* ** *',\n '* *C *',\n '* *',\n '******',\n];\ninit(grid);\n\nplayer.reset(1, 1); //初始化老鼠位置\n\nvar Q = {}; //老鼠的大腦\nvar S1; //上一次的狀態(位置)\nvar S2; //當前的狀態(位置)\nvar A; //上一次的動作(移動方向)\nvar alpha = 0.8;\nvar beta = 0.5;\n\nforever(function(){\n S1 = player.x + ':' + player.y; // x,y座標組合成唯一字串表示狀態\n if (Q[S1] == undefined) Q[S1] = [0, 0, 0, 0];\n \n // var max = Math.max(Q[S1][0], Q[S1][1], Q[S1][2], Q[S1][3]);\n var max = Math.max(...Q[S1]); // 同上\n var A = Q[S1].indexOf(max);\n if (A == 0) player.x--;\n if (A == 1) player.x++;\n if (A == 2) player.y--;\n if (A == 3) player.y++;\n \n S2 = player.x + ':' + player.y; // x,y座標組合成唯一字串表示狀態\n if (Q[S2] == undefined) Q[S2] = [0, 0, 0, 0];\n \n if (grid[player.y][player.x] == '*') { //撞到牆壁懲罰 -100\n reword(Q, S1, A, S2, -100);\n player.reset(1, 1);\n }\n if (grid[player.y][player.x] == 'C') { //找到起司獎勵 +10\n reword(Q, S1, A, S2, 10);\n player.reset(1, 1);\n }\n if (grid[player.y][player.x] == ' ') { //浪費步數懲罰 -1\n reword(Q, S1, A, S2, -1);\n }\n});\n\nfunction reword (Q, S1, A, S2, score) {\n // var re = Math.max(Q[S2][0], Q[S2][1], Q[S2][2], Q[S2][3]);\n var re = Math.max(...Q[S2]); // 同上\n Q[S1][A] = alpha*Q[S1][A] + (1 - alpha)*(score + beta*re);\n}","created_at":"2019-05-05T10:01:54.593+08:00","updated_at":"2020-02-19T18:06:30.056+08:00","name":"老鼠找起司(1) 副本","language":"javascript","screenshot":{"url":"/uploads/project/screenshot/66269/7c4fa5b4a1c49cf78a285b02e94a9193.jpg"},"parent_id":65016,"plugin":"var rat = createSprite('mouse.png');;\nvar cheese = createSprite('cheese.png');\nvar W;\nvar H;\nvar width = 40;\n\nfunction init (grid) {\n\n H = grid.length;\n W = grid[0].length;\n\n for (var y = 0; y \u003c H; y++) {\n for (var x = 0; x \u003c W; x++) {\n if (grid[y][x] == 'C') {\n cheese.moveTo(x*width + width/2, y*width + width/2);\n }\n }\n }\n\n forever(function() {\n for (var y = 0; y \u003c H; y++) {\n for (var x = 0; x \u003c W; x++) {\n pen.fillColor = (grid[y][x] == '*' ? 'black' : 'white')\n pen.drawRect(x*width, y*width, width, width);\n }\n }\n });\n}\n\nfunction randomGrid (col, row, rate) {\n var col = col \u003c 16 ? col : 16;\n var row = row \u003c 12 ? row : 12;\n var grid = [];\n for (var y = 0; y \u003c row - 2; y++) {\n grid[y] = '';\n for (var x = 0; x \u003c col - 2 ; x++) {\n if (x == col - 3 \u0026\u0026 y == row - 3) grid[y] += 'C';\n else grid[y] += Math.random() \u003c rate ? '*' : ' ';\n }\n grid[y] = '*' + grid[y] + '*';\n }\n var s = Array(col).fill('*').join('');\n grid.push(s);\n grid.unshift(s);\n return grid;\n}\n\nvar player = {\n x: 1,\n y: 1,\n reset: function (x, y) {\n this.x = x;\n this.y = y;\n }\n}\n\nforever(function () {\n rat.moveTo(player.x*width + width/2, player.y*width + width/2);\n})\n\n","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":506,"hashid":"npms54ev","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":1158504,"file_name":"cheese.png","project_id":66269,"asset_id":117129,"created_at":"2019-05-05T10:01:54.599+08:00","updated_at":"2019-05-05T10:01:54.599+08:00"},{"id":1158505,"file_name":"mouse.png","project_id":66269,"asset_id":117128,"created_at":"2019-05-05T10:01:54.600+08:00","updated_at":"2019-05-05T10:01:54.600+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