Motive There are different types of modules in python which not everyone knows so we thought of introducing them to you guys. Let's start! Note: This is not a tutorial of how to use these but is to show that these modules also exist and if you want to know more you can visit there own page and if you want us to explain leave a comment below. Links to there page are also given below. Hope you found something useful. 1.Wikipedia Yes, there is a module called Wikipedia in python, you can easily install Wikipedia by pip install wikipedia . We cannot rely on this module for advanced use. It was designed for ease of use and simplicity. Learn More Here . Here is a simple example: import wikipedia wikiPython = wikipedia.summary("Python", sentences=2) print(wikiPython) One big disadvantage is that it works only if the internet is connected to your device. You can even control the number of sentences that you
Motive
now you have to make sure that the rectangle doesn't touch the ground and
is as tall as the cactus. try again and again until you get something like
that picture
I saw a video on YouTube that made a python
program to automate the chrome dino game at the end he shows a clip of the
program playing the game. But there was a problem with the code I do
not work when it's dark so I thought of turning the dark mode in the
laptop
so that it stays dark all the time but that did not work after reaching a score
of 700 it becomes day again so I have to think of an alternative see how I did
it.
The Project
- First Import the necessary modules in your IDE
- PyAutoGUI lets Python control the mouse and keyboard, and other GUI automation tasks.
- Pillow helps us to take screenshots
Like Pyautogui we have to install it so run
pip install Pillow
2.Play till you reach a cactus which is as tall as the dino
Note: If your screen is dark instead of the light
background
1. Go to settings
2. Then
personalization
3. Colors
4. Scroll down and
check the 'light' box
5. Back to your
browser and reload your page
3. Go back to the idle and paste this code
run the code and quickly go back to the browser after about
2 sec a screenshot will appear that has a black rectangle in front of the
cactus, you have to mess with the x-axis and the y-axis of the rectangle
to make it look somewhat like this:
The code will wait for two sec and then takes a screenshot and convert it
into grayscale then store that image in a variable called image. Then makes
a rectangle with the given values.
4. After getting the right values, let's make a function
to make the dino jump when it reaches the
cactus:
change the values of x and y to the values that you got, this function
presses the up button when there is is a dark pixel(here < 100 is
considered as black) in the rectangle we made
5. Now edit the if __name__ == "__main__":
part like this:
Now run the code and go back to the browser, you will see the dino
jumping automatically when it reaches the cactus, if not try changing the
rectangle values this might work, if the dino is jumping continuously
check if the rectangle is touching the ground or the stone if so reducing
the y-axis second value a little more and try again. Still, if it does not
work comment down below and it will solve your problem.
Note: To stop the while loop go to the ide and press ctrl+c
6. The dino will run till it becomes dark or if a bird comes so now we will
fix them:
for the bird make another rectangle:
So again edit the if __name__ == "__main__": part like this:
And you will get something like this,
let the x-axis for the bird be as the x-axis of the cactus
and the y-axis of about 20 pixels long
it may differ according to your screen.
This also works as the cactus instead of jumping it crouches.
Try running this by commending out the draw rectangle like this:
Note: To stop the while loop go to the ide and press ctrl+c
8. Now this will also work till it becomes night so we need to find when it
is day and when it is night.
For that, we create another rectangle in a corner and get its value.
again edit the if __name__ == "__main__": part like this:
you will get a small rectangle at the corner of the screen like this(you
might have to change the x-axis and y-axis to get it at a corner):
9. Now we need to find whether it's day or night by looking at the pixel
value if >200 we consider it as day and < 201 we consider it and
night
Again try changing its value to take the program to perfection.
Now change the if __name__ == "__main__": part like this:
Here in the while loop, we set the value of Time to day/night according to the pixel value.
Then we change the def cactus (data): like
this:
Here we find whether it's day or night form the Time variable and then if its day, it jumps or crouches for black pixel(<100) and if it's night it jumps or crouches for the white pixel(>100)
Note: Experiment with those values to take the program to perfection.
And we are done.
The Full code:
The code for drawing the rectangle:
If you have any doubts or errors in the program feel free to comment down below and I will respond as early as possible. And if I have made any mistake please correct me in the comment box below. Don't forget to follow us for such python related content.
✌️👌✌️🙏
ReplyDeleteThank you
DeleteChrome dinosaur game Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.
ReplyDeleteThank You
Delete