title: Dino Run
tags: tip—
强化学习训练把dino run玩到4000分,教程链接,需要云服务器,所以放弃了。
在网上找到了外挂的方法:https://blog.csdn.net/weixin_41474364/article/details/85613923
根据判断X轴方向小恐龙和前面物品距离进行自动跳跃,添加了代码避免小恐龙跳过蛋糕、避而不吃,调整了对障碍物需要跳跃的高度判断,防止小恐龙看到低飞的鸟儿迎面而上,还有能够在代码执行后,自动开始游戏。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| function TrexRunnerBot() {
const makeKeyArgs = (keyCode) => { const preventDefault = () => void 0; return {keyCode, preventDefault}; };
const upKeyArgs = makeKeyArgs(38); const downKeyArgs = makeKeyArgs(40); const startArgs = makeKeyArgs(32);
if (!Runner().playing) { Runner().onKeyDown(startArgs); setTimeout(() => { Runner().onKeyUp(startArgs); }, 500); }
function conquerTheGame() { if (!Runner || !Runner().horizon.obstacles[0]) return;
const obstacle = Runner().horizon.obstacles[0];
if (obstacle.typeConfig && obstacle.typeConfig.type === 'SNACK') return;
if (needsToTackle(obstacle) && closeEnoughToTackle(obstacle)) tackle(obstacle); }
function needsToTackle(obstacle) { return obstacle.yPos !== 50; }
function closeEnoughToTackle(obstacle) { return obstacle.xPos <= Runner().currentSpeed * 18; }
function tackle(obstacle) { if (isDuckable(obstacle)) { duck(); } else { jumpOver(obstacle); } }
function isDuckable(obstacle) { return obstacle.yPos === 50; }
function duck() { Runner().onKeyDown(downKeyArgs);
setTimeout(() => { Runner().onKeyUp(downKeyArgs); }, 500); }
function jumpOver(obstacle) { if (isNextObstacleCloseTo(obstacle)) jumpFast(); else Runner().onKeyDown(upKeyArgs); }
function isNextObstacleCloseTo(currentObstacle) { const nextObstacle = Runner().horizon.obstacles[1];
return nextObstacle && nextObstacle.xPos - currentObstacle.xPos <= Runner().currentSpeed * 42; }
function jumpFast() { Runner().onKeyDown(upKeyArgs); Runner().onKeyUp(upKeyArgs); }
return {conquerTheGame: conquerTheGame}; }
let bot = TrexRunnerBot(); let botInterval = setInterval(bot.conquerTheGame, 2);
|
将代码复制到console,回车,会自动进行跳跃,获取分数的速度依然和正常游玩的玩家是一样的,小恐龙走一步记一分。
下面的方法,可以在短时间内迅速加分:
1 2 3
| Runner.instance_.setSpeed(99999); 试试 瞬间 满分 window.tempGameOver = Runner.instance_.gameOver; Runner.instance_.gameOver = function(){}
|