
JavaScript Code Plays Google Dinosaur/T-Rex Game Automatically - truly_furqan
https://www.edopedia.com/blog/javascript-code-plays-google-dinosaur-t-rex-game-automatically/
======
ravenstine
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](https://www.youtube.com/watch?v=L2NtMpQml-A)

------
jestanoff
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);

~~~
truly_furqan
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.

~~~
jestanoff
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

------
nestorD
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!

------
oplav
TIL that pressing "down" makes the dinosaur duck.

------
Gaelan
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...](https://gist.github.com/Gaelan/a0c5461055437dca9618a12f68949ce6)

~~~
Gaelan
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.

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

~~~
thdc
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)

~~~
truly_furqan
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.

------
9214
There's also a relatively old Common Lisp solution.

[https://vitovan.com/dino.html](https://vitovan.com/dino.html)

~~~
truly_furqan
Hmm, nice one. Thanks for mentioning.

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

------
awesomeideas
Simulated paleontology is such an amazing field!

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

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

------
bobbydreamer
New is edge browsers surfer

