![]() Wrap up your code into a if _name_ = "_main_": guard. This point is interwoven with dividing the code into functions/classes, see this link as to WHY working in the global namespace is considered bad. Using a structure like this will improve the code alot, and adding an AI (or other improvements will be easier after this) Movement_keys: list of Keys used to move the player """ĭef _init_(self, name, paddle_x, paddle_y, score, movement_keys): Paddle_y: an int of the players paddle y position Paddle_x: an int of the players paddle x position What functions/classes should a game of pong have?Ī Player (class) <- This player class can be used by both Players. Thonny is a beginner-friendly Python IDE, developed in University of Tartu, Estonia, which takes a different approach as its debugger is designed specifically for learning and teaching programming. ![]() But if you would have divided your code into more functions, the AI can reuse a lot of the functions you created for a single player game, and thus making your code easier to maintain, or add functionality. as is, your code would require a heck of a rewrite. You say you want to make it run by an AI. Good code should be readable at first glance, the below variables have no meaning for me. Step 1 Start by installing a few Python 3.9 packages. But, there are alt-variants of Thonny that use Python 3.9 instead of 3.7, which you’ll use instead. However, py5 requires Python 3.8 or higher. With the turtle module you can draw cartoons, shapes and some cool designs. Turtle is a python graphics (GUI) library. I would have been able to give a better review if your code was more readable. At the time of writing, Thonny (at version 3.3.10) comes bundled with Python 3.7.9. Looking for some awesome python turtle codes or programs then you are at the right place today in this article I will share with you the best awesome python turtle codes so read this article till the end. Would you still understand this code after a hiatus of a few months? I have a hard time understanding the code as is. Magic 8 Ball Am I dating myself by saying I loved Magic 8 Balls as a kid Well, if you no longer have yours (maybe because, like me, you smashed it to see what that murky liquid was inside), you can recreate the 8 Ball logic with this classic Python script example It uses elif to generate responses to your burning questions. It has been mentioned in the comments by naming is a very important part of coding. I'd like to know what the common best practices are when working on a project _caption('Snake ML v.1.0.0')ĭrawpaddle(p1x, p1y, paddle_width, paddle_height)ĭrawpaddle(p2x, p2y, paddle_width, paddle_height) It is easy for students to use, features a module installer, and contains its own internal version of Python 3, making it very. Score = comic.render(str(p1score) + " - " + str(p2score), False, WHITE) I personally have very little experience with Python and coding in general, so any feedback would really help! If possible, I'd like to know what the common best practices are when working on a project like this and to what degree I am complying with those practices.Ĭomic = ('Comic Sans MS', 30) So far, all I have is the game without any AI. ![]() I'm trying to code a machine learning version of pong in python.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |