Hacker News new | past | comments | ask | show | jobs | submit login
JavaScript Code Plays Google Dinosaur/T-Rex Game Automatically (edopedia.com)
26 points by truly_furqan on Aug 14, 2020 | hide | past | favorite | 20 comments



If you've got a photoresistor and a servo, you can make a "robot" play the dinosaur game manually!

https://www.youtube.com/watch?v=L2NtMpQml-A


I don't like the length of their solution, quite the same logic can be shortened to just a few lines of code

setInterval(() => {

  const { currentSpeed, horizon: { obstacles: [{ xPos, width, yPos } = {}] } } = Runner?.instance_;

  if (xPos < 25 * currentSpeed - width && yPos >= 75)
    document.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 32 }));
}, 100);


Thanks for mentioning this code. Actually, I've just tried your solution. But, the dinosaur dies quickly.

So, I think the code I mentioned in the article is more efficient.


May be it is something small as dividing the width by 2 and setting a lower milliseconds value for the setinterval so it runs the checks more often.

Essentially this is the same solution as in the post, just stripped down to the bare minimum of code, but I haven't tested it enough. There must be some edge case that it fails on


I have a t-shirt that features the Google T-Rex Game and I found that a large number of people do not recognisee the dinosaur nor know the game despite using chrome daily!


TIL that pressing "down" makes the dinosaur duck.


Here's a quick deobfuscated version (pretty printed, renamed variables, converted foo && (bar(), baz()) to if(foo) {bar(); baz()}).

https://gist.github.com/Gaelan/a0c5461055437dca9618a12f68949...


Edit: after I did that, I discovered jsnice.org, which managed to do all the deobfuscation I did (including inferring variable names from usage!) automatically. I'm very impressed. I replaced the gist above with the JSNice output.


That's cool. I appreciate that.


Copy-pasting random javascript from the internet is not good security hygene.


Especially when it's minimized like this. Are they trying to hide something? Why couldn't it be formatted in a more readable manner?

(it does look safe though)


Great point!

But actually, I minified this code so that people can quickly try it out. I'll try to explain it in some other article.


I completely agree with your concern.

But, I had to make it as simple as possible for non-programmers.


There's also a relatively old Common Lisp solution.

https://vitovan.com/dino.html


Hmm, nice one. Thanks for mentioning.


I didn’t even know this Dino game existed and suddenly fear that a massive procrastination wave is unfolding.


Simulated paleontology is such an amazing field!


now they just need to make this an offline chrome app so you can open it when you're offline


As long as you have Chrome, you can still play it offline. Just go to chrome://dino


New is edge browsers surfer




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: