Need help with apple placement for snake game (no pygame) learn programming |
- Need help with apple placement for snake game (no pygame)
- I am (not) a beginner. Is there any advice for me?
- robust-first vs resilient vs defensive programming, what are the differences?
- Creating .exe on VS Code, using Mac?
- MariaDB, I can't figure out what's wrong with my foreign keys?
- Absolute beginner wanting to learn programming to create a bot that generates sonnets.
- At 40 should I quit my job to finish learning to code and find a dev role?
- Are bunders that minify and uglify JS such as terser reliably applicable to most CMS's?
- Data science as a career
- How do Games make Reaction time Buttons?
Need help with apple placement for snake game (no pygame) Posted: 13 Dec 2021 01:46 AM PST Hi guys, so I need help with the snake game. I am using Snakeinterface and not pygame, so I have to implement it using ui.random(nrFreespots). My snake moves and eats apple, but that is not enough as I need to implement a specific way to spawn the apple at random places. This is how the apple should be placed: Apple placementTo ensure reproducible behavior, we specify exactly how a random number generator must be used to place the food. For this, we provide the method ui.random(max) This gives a random integer in the range [0 − max ) (exclusive). During testing, the result of this method will not be random, but will be the number specified as apple_spot in the test files. You can't use this method to randomly place apple:
This method has the downside that it might take a lot of tries before you find a free spot, especially if the board is almost full. Moreover, it requires an arbitrary amount of numbers for placing a single apple, which complicates testing. Instead of the above method, we opt for a method that always succeeds at placing an apple, using only a single number. To see how this works, suppose we have a 5x3 board and the current position of the snake is as follows: To determine the position of the apple, we want to pick a random free spot on the board (the apple should not be placed on the snake). We number the free spots on the board from left to right, top to bottom, skipping any spot occupied by the snake. In our example, this means the following numbering: To pick a random spot, first compute the number of free spots and then call ui.random(nrFreeSpots)(in our case nrFreeSpots=12 ). Then place the apple at the position corresponding to the number you got. This is what I have: class Coordinate(): def __init__(self,x,y): self.x = x self.y = y def return_x(self): return self.x def return_y(self): return self.y class Apple(): def __init__(self): self.apple_coord="" def place_apple_random(self): self.apple_coord=Coordinate(ui.random(width),ui.random(height)) return self.apple_coord def place_apple(self,snakelength): self.place_apple_random() while snakelength.count(self.apple_coord) > 0: self.place_apple_random() ui.place(self.apple_coord.x,self.apple_coord.y,ui.FOOD) ui.show() so instead of ui.random(width) for x and ui.random(height) for y (what I have now) I need to call ui.random(nrFreespots) which will place the apple at the x and y coordinate of one of the free spots. I know that nrFreespots = width * height - snake_length. But I don't know how I can implement this in my code. If apple_spot is 3, the apple should be placed in the 4th free spot, if apple_spot is 5 the 6th free spot etc. This is an example of a test that I need to pass for apple placement: The snake should begin in the top left, heading east, and be two cells long. When ui.random gives 5, the apple should be placed on 6th free position, counting from left-to-right, top-to-bottom. Width 5 Height 2 apple_spot 5 --- XX... ..A.. So how do I place the apple at apple_spot 5 in this case? Your help would be greatly appreciated [link] [comments] |
I am (not) a beginner. Is there any advice for me? Posted: 13 Dec 2021 12:12 AM PST I am working as an "IT Analyst" which was purely accidental because my degree is in Biotechnology. At the beginning I thought 'meh whatever' as I was doing this job for selfish reasons (money, visa). This week will be one year working here and suddenly, out of nowhere I am interested! I started The Odin Project last week, watched the Scratch seminar from CS50 and am looking into all the definitions that the internet is throwing at me like "programmer", "coder", "web developer", "software engineer". Which is honestly confusing but google has always been my friend. At my current job I use a few linux commands and do other stuff. After I got interested I started learning the basics of python. I know the basics of HTML and CSS (ongoing TOP) and Scratch... But this does not change the fact that I am like any other beginner, but with a job. A low paying one obviously, so I am currently looking for better jobs with my one year of experience (which I am ashamed to flaunt), but I am getting recruiters who ask me for my CV.. There are SO many things that can be learnt! I am having fun with python and HTML, CSS seemed a bit difficult but I am going by. And you guys are way smarter and experienced than me. So, is there any suggestion for someone like me? Where I should be heading, on what I should be focussing? because I will put my heart and soul into this once I understand what should be done.. Thank you and sorry if these kind of posts are not allowed. First time poster here. [link] [comments] |
robust-first vs resilient vs defensive programming, what are the differences? Posted: 13 Dec 2021 12:59 AM PST I've seen these terms used recently and I want to know the details that make them different, because they seem very similar. AFAIK this is what they are: [link] [comments] |
Creating .exe on VS Code, using Mac? Posted: 13 Dec 2021 02:42 AM PST Okay so I'm on Mac coding with VS Code for a school assignment. I need to make my file work as a .exe file. Is this possible? I need to make my file a shareable program that people can install and run. It's just a simple game I made that runs through the terminal, but I can't figure out on vs code how to do that. Is that even a thing? If not is there a way to do that with windows someone can tell me how? I'm stressing out over this but I think it probably has an easy solution. It's just a simple game that runs in the terminal, it runs in the built in terminal for VS Code so I just need to make it an actual file I can share in class for others to download and play themselves [link] [comments] |
MariaDB, I can't figure out what's wrong with my foreign keys? Posted: 13 Dec 2021 01:52 AM PST I have three tables: users, groups, and user_group which should contain the pksof users and groups as fks. I have already created the three tables and made sure fks are of the same type as pks, and successfully run this query:
The query is accepted, no errors. But upon deleteing/adding users/groups from the users/groups tables, no updates happen on user_group table. It remains empty. I even made sure the engine of all three tables is set to InnoDB. I'm using XAMPP on my laptop to run my php and mysql. I run my sql queries through phpmyadmin and the type of DB is MariaDB. [link] [comments] |
Absolute beginner wanting to learn programming to create a bot that generates sonnets. Posted: 13 Dec 2021 01:42 AM PST Hello, everybody. I have a passion for writing, literature and natural languages in general. I'd like to learn programming specifically to create a bot that generates sonnets. You know what sonnets are: a 14 verse poetic composition that follows a precise rhyming scheme. The sonnets must be in my native language which is Spanish. The sonnets do not need to make sense. They only need to be grammatically correct, i.e., comply with the syntactical and morphological rules of the natural language, and, of course, the sonnet rhythm and rhyme scheme . For this, the program would need to be able to tell apart different parts of speech (noun, verb, etc.) and determine where the stress is on each word is, among other things needed to write metric poetry. What suggestions do you have in regards to programming language I should learn, resources I should use, or any other specific learning advice? I'm 32 and I have the rest of my life to get this project done. Trust me. I'll look into every suggestion. Thanks, guys. [link] [comments] |
At 40 should I quit my job to finish learning to code and find a dev role? Posted: 13 Dec 2021 01:02 AM PST Hi all, I need some objective advice and maybe experiences from others who have done it. I'm 40 and have been coding on and off for a few years. For example, I finished the Helsinki Java Mooc and built some toy projects, and I know VBA and have built some fairly decent excel apps for my work, but I've never built a big project or learned any frameworks that could get me hired as a dev. So for the last 6 mths I've been working through The Odin Project part time and am hoping that when I finish, and have built something, I can hopefully make the switch to a dev role (I'm past the foundations, on the full stack javascript track). The problem is, my work is so busy and I have so many other responsibilities that I worry I wont be finished with it before 2022 at this rate. I should note that I'm incredibly sick of my current role and becoming increasingly resentful at the fact it leaves me with so little time to learn. How bad of an idea would it be to quit my job with the aim of finishing the Odin Project in under 6months and finding a dev role? I realise it would be a bad 'financial' decision, but I feel that if I get to the end of 2022 and haven't made any progress I'll regret not taking a shot at it (and will be in the same situation only 1 year older). Also worth noting, I have a family, no debt, some savings, and my current job pays above average. Has anyone else found themselves in a similar situation? [link] [comments] |
Are bunders that minify and uglify JS such as terser reliably applicable to most CMS's? Posted: 13 Dec 2021 12:46 AM PST I'm aware that bundlers such as terser & uglify js can drastically reduce js file size. I am hoping to apply said bundlers to speed up my clients bloated site since no resources are allocated to actually change the codes itself (under time constraint too). My curiosity is, are these bundlers the wonder plug-ins they make themselves out to be or do they only perform correctly under very strict circumstances and environments? Im asking if I can readily recommend bundling as a solution that wont involve the same amount of dev time it would take to just adjust the code itself. (That would defeat the point) If the answer is yes, is it cms agnostic? How can i practice implementing it myself before i brief the devs? (practice resources) Thank you very much! [link] [comments] |
Posted: 13 Dec 2021 12:08 AM PST Hi all, I was an engineering major and I recently switched to Mathematics I want data science as a career, I am really interested in it. I began learning to code in summer but I started with C#, since the start of the semester I became interested in learning more in R and python (I have basics in them but never went deep always did C# mostly in summer) I have a math degree, I took statistics courses, probability, calculus 1,2,3 you name it. I got really high grades in these courses too. Where do I start in data science, what book do I need, what language do I rely on? I have good basic knowledge in R I can use the packages but nothing special just yet. Pandas and Numpy I have been learning too! What machine learning concept do I need to tackle? I am really interested in this field, I also heard its fairly rewarding too in terms of decent money. But I really like it I'd love to develop some sort of analysis models that people can use, that is my vision Thank you all I hope to hear from you soon, I'd love if someone recommends a book or some online course (Coursera, udemy, youtube whatever) Im willing to put in a lot of effort in the winter semester break its only a month, but not a month to be wasted thats for sure [link] [comments] |
How do Games make Reaction time Buttons? Posted: 12 Dec 2021 08:05 PM PST I have seen a lot of games have this feature where if you don't press a button in x amount of seconds (While doing something like running as the button goes smaller every second until its gone if you don't click it) you get punished. I don't get how they can make this and would appreciate if someone explain. [link] [comments] |
You are subscribed to email updates from learn programming. To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google, 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States |
No comments:
Post a Comment