{"id":31539,"student_id":10,"content":"\n\nforever(function () {\n\n});\n\nfunction getStatus (bird, target) {\n\n}\n\nfunction reward (S, A, R, _S) {\n \n}","created_at":"2018-06-12T14:35:59.256+08:00","updated_at":"2019-11-11T18:29:23.454+08:00","name":"flappy bird Q-learning(S)","language":"javascript","screenshot":{"url":null},"parent_id":30960,"plugin":"setBackdrop('bg.png');\n\n// Brain\nfunction Brain () {\n var w = 16;\n var h = 32;\n var obj = {};\n obj['undefined'] = [0, 0];\n for (var x = -1; x \u003c w + 1; x++) {\n for (var y=-h; y \u003c h; y++) {\n obj[x + ':' + y] = [0, 0];\n }\n }\n return obj;\n}\n\nvar game = (() =\u003e {\n\n let points = 0; // 分數\n let speed = 3; // 速度\n let space = 720/3; // 720/3 為三組水管之間的間隔\n let targetApple; // 鳥前面最近的蘋果\n let gravity = 0.25; // 引力\n let gameStatus = 'playing'; // 遊戲狀態 playing: 進行中 stop: 死亡\n \n let apple1 = createSprite('apple.png');\n let apple2 = createSprite('apple.png');\n let apple3 = createSprite('apple.png');\n let apples = [apple1, apple2, apple3];\n\n let pipe1 = createSprite('pipe.png');\n let pipe2 = createSprite('pipe.png');\n let pipe3 = createSprite('pipe.png');\n let pipe4 = createSprite('pipe.png');\n let pipe5 = createSprite('pipe.png');\n let pipe6 = createSprite('pipe.png');\n pipe2.direction = -90;\n pipe4.direction = -90;\n pipe6.direction = -90;\n\n let ground1 = createSprite('ground.png');\n let ground2 = createSprite('ground.png');\n ground1.y = 450;\n ground2.y = 450;\n\n let bird = createSprite('bird.png');\n bird.x = 200;\n bird.vy = 0;\n bird.scale = 0.8;\n \n bird.jump = function () {\n bird.vy = -4.5;\n }\n\n bird.on('touch', [pipe1, pipe2, pipe3, pipe4, pipe5, pipe6, ground1, ground2], () =\u003e gameStatus = 'stop');\n\n forever(()=\u003e{\n\n // Sprite.x -\u003e Sprite.x\n [bird, apple1, apple2, apple3].forEach(function(s) {\n s.X = Math.floor(s.x/15);\n s.Y = Math.floor(s.y/15);\n });\n\n game.gameStatus = gameStatus; // suck\n\n pipe1.moveTo(apple1);\n pipe1.y -= 270;\n pipe1.x -= 25;\n pipe2.moveTo(apple1);\n pipe2.y += 270;\n pipe2.x -= 25;\n\n pipe3.moveTo(apple2);\n pipe3.y -= 270;\n pipe3.x -= 25;\n pipe4.moveTo(apple2);\n pipe4.y += 270;\n pipe4.x -= 25;\n \n pipe5.moveTo(apple3);\n pipe5.y -= 270;\n pipe5.x -= 25;\n pipe6.moveTo(apple3);\n pipe6.y += 270;\n pipe6.x -= 20;\n\n if (gameStatus === 'playing') {\n\n bird.vy += gravity;\n bird.y += bird.vy;\n \n ground1.x -= speed;\n ground2.x -= speed;\n if (ground1.x \u003c -320) ground1.x += 1280;\n if (ground2.x \u003c -320) ground2.x += 1280;\n\n apples.forEach((apple) =\u003e {\n apple.x -= speed;\n apple.opacity = .3;\n \n if (apple.x \u003c -30) {\n apple.x += space*3;\n apple.y = Math.random() * 150 + 110;\n apple.hidden = false;\n };\n });\n }\n \n // 取的眼前最近的蘋果\n targetApple = apples\n .filter((a) =\u003e { return a.x \u003e bird.x })\n .sort((a1, a2) =\u003e { return a1.x - a2.x })[0];\n \n targetApple.opacity = 1;\n \n if (targetApple.x \u003e bird.x \u0026\u0026 targetApple.x - bird.x \u003c speed*2) {\n points++;\n }\n \n if (game.displayApple == false) {\n apple1.opacity = 0;\n apple2.opacity = 0;\n apple3.opacity = 0;\n }\n\n print(points, 10, 10, 'white', 45);\n });\n\n function restart() {\n bird.y = 240;\n bird.vy = 0;\n apple1.x = space*1 + 200;\n apple1.y = Math.random() * 150 + 110\n apple2.x = space*2 + 200;\n apple2.y = Math.random() * 150 + 110\n apple3.x = space*3 + 200;\n apple3.y = Math.random() * 150 + 110\n points = 0;\n apple1.hidden = false;\n apple2.hidden = false;\n apple3.hidden = false;\n ground1.x = 320;\n ground2.x = 320 + 640;\n gameStatus = 'playing';\n }\n\n function getApple () {\n return targetApple;\n }\n\n return {\n restart: restart,\n bird: bird,\n getApple: getApple,\n displayApple: false,\n }\n})();\n\nvar bird = game.bird;\ngame.restart();","description":null,"note":null,"status":"public","like_student_ids":[],"is_featured":false,"views":375,"hashid":"p93srwng","is_content_changed":false,"review_status":"unsubmitted","submitted_at":null,"reviewed_at":null,"advise":null,"is_deleted":false}
[{"id":589935,"file_name":"apple.png","project_id":31539,"asset_id":70035,"created_at":"2018-06-12T14:35:59.265+08:00","updated_at":"2018-06-12T14:35:59.265+08:00"},{"id":589936,"file_name":"pipe.png","project_id":31539,"asset_id":70034,"created_at":"2018-06-12T14:35:59.267+08:00","updated_at":"2018-06-12T14:35:59.267+08:00"},{"id":589937,"file_name":"ground.png","project_id":31539,"asset_id":70033,"created_at":"2018-06-12T14:35:59.269+08:00","updated_at":"2018-06-12T14:35:59.269+08:00"},{"id":589938,"file_name":"bird.png","project_id":31539,"asset_id":70032,"created_at":"2018-06-12T14:35:59.270+08:00","updated_at":"2018-06-12T14:35:59.270+08:00"},{"id":589939,"file_name":"bg.png","project_id":31539,"asset_id":70031,"created_at":"2018-06-12T14:35:59.272+08:00","updated_at":"2018-06-12T14:35:59.272+08:00"}]
橘蘋學習平台
橘蘋學習平台
我的作品
檢視專案頁
匯出
複製
匯入
刪除
下載 Android APP (APK)
截圖
1:1:1
1:1
full
幫助
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦
用手機掃描下方 QRCode 進行安裝
或您也可以
下載 APK
到這台電腦