The Thread for Programming
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
You have to connect and confirm your email address. I can't confirm it until they fix their website.
-
devil†zukin
Re: The Thread for Programming
i accidentally made something really cool
http://cat.rena.so/projects/planning/noiseredux.zip (win32)
(it keeps going forever but sometimes it'll just be blank)
http://cat.rena.so/projects/planning/noiseredux.zip (win32)
(it keeps going forever but sometimes it'll just be blank)
Re: The Thread for Programming
I also like that definition a lot, I actually chuckled a bit when I saw itRenaBeach wrote:i like this definition in vc++'s math.h
Code: Select all
#define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
dA
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
Oh man, that's pretty neat.
I decided to try my hand at making a Rubik's Cube scramble generator.
For those that don't know, cubing notation is generally spoken with 18 types of moves, 3 for each face of the cube. With the cube facing you the whole time, you'll have the front face (F), left face (L), downward face (D), right face (R), upper face (U), and back face (B). Each of those letters indicate a clockwise move of said face. So U would mean rotate the upper face of the cube 90 degrees clockwise. For counterclockwise, it's the same idea but with a ' symbol, spoken as "prime". So R' (R prime) is a counterclockwise rotation of the right face 90 degrees. The final type of move is the 180 degree movement of a face, and for that you just put a 2 before the letter. 2B = the back face being moved 180 degrees.
When I originally had the idea I assumed it would be super simple, and it was for the most part, but as I was writing it, I realized it's not as simple as just "print out a list of moves". With a Rubik's cube, you can easily have redundant moves right next to each other. So if the program were to generate an R and then an R' right next to each other, the cube would remain in the same state as if you were to not do those moves at all. Another thing is if you were to have R and R next to each other, you might as well have just printed 2R and now you're short one extra move that could have been in that scramble. There are a few cases like this where you don't want 2 similar moves right next to each other. I did my best to avoid this, but my workaround still isn't perfect. My whole code is here:
http://pastebin.com/fFYWcXiJ
The way I avoided some redundant moves was with the loop:
I'm not sure if there's a more elegant way of doing this but it's the best I could come up with in the few minutes I was working on it.
The other issue is that by the logic of the code, it could still theoretically generate something like
R L R' L' R L R' L' R L R' 2L 2R L 2R
which wouldn't scramble the cube at all. So I mean, I can probably counteract this by doing another check with another variable that keeps track of what the move 2 moves ago was, but I don't know how far you would have to go to make a foolproof scramble generator, or even if it's possible at all. You could probably do a scramble partway through, and then undo it in another way partway through.
I'm just mindvomiting right now. I don't have a conclusion. Hope you enjoyed my post.
I decided to try my hand at making a Rubik's Cube scramble generator.
For those that don't know, cubing notation is generally spoken with 18 types of moves, 3 for each face of the cube. With the cube facing you the whole time, you'll have the front face (F), left face (L), downward face (D), right face (R), upper face (U), and back face (B). Each of those letters indicate a clockwise move of said face. So U would mean rotate the upper face of the cube 90 degrees clockwise. For counterclockwise, it's the same idea but with a ' symbol, spoken as "prime". So R' (R prime) is a counterclockwise rotation of the right face 90 degrees. The final type of move is the 180 degree movement of a face, and for that you just put a 2 before the letter. 2B = the back face being moved 180 degrees.
When I originally had the idea I assumed it would be super simple, and it was for the most part, but as I was writing it, I realized it's not as simple as just "print out a list of moves". With a Rubik's cube, you can easily have redundant moves right next to each other. So if the program were to generate an R and then an R' right next to each other, the cube would remain in the same state as if you were to not do those moves at all. Another thing is if you were to have R and R next to each other, you might as well have just printed 2R and now you're short one extra move that could have been in that scramble. There are a few cases like this where you don't want 2 similar moves right next to each other. I did my best to avoid this, but my workaround still isn't perfect. My whole code is here:
http://pastebin.com/fFYWcXiJ
The way I avoided some redundant moves was with the loop:
Code: Select all
while(moveArray[i] == lastMove || moveArray[i] == lastMove - 6 || moveArray[i] == lastMove + 6){
moveArray[i] = rand()%18; //reroll for a new move
}The other issue is that by the logic of the code, it could still theoretically generate something like
R L R' L' R L R' L' R L R' 2L 2R L 2R
which wouldn't scramble the cube at all. So I mean, I can probably counteract this by doing another check with another variable that keeps track of what the move 2 moves ago was, but I don't know how far you would have to go to make a foolproof scramble generator, or even if it's possible at all. You could probably do a scramble partway through, and then undo it in another way partway through.
I'm just mindvomiting right now. I don't have a conclusion. Hope you enjoyed my post.
-
devil†zukin
Re: The Thread for Programming
i did a simple path tracing and it looks a lot better already

and for fun, here's what happens when i make the walls a little reflective


and for fun, here's what happens when i make the walls a little reflective

- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
Update oh my thing: That thing might not work properly because one time I ran it it gave me 2 R moves next to each other. Gonna have to figure out what's wrong.
edit: oh, I also need to add + or - 12 to the check my while loop to make it even ridiculously longer. I feel like while loops should not have that long of arguments but I don't know what the proper thing to do in this case is so I'll just leave it as is for now. Updated version:
http://pastebin.com/G4nqVZe5
In the meantime I have a question:
When I wrote that in Xcode on my laptop, everything ran fine and it was all good and dandy, but when I copy-pasted it into Visual Studio on my PC it gave me an issue with the time() function.
I ended up having to #include <time.h> in my header. Any idea why my laptop didn't need that but my PC did? Does Xcode's compiler just not need that for some reason?
edit: oh, I also need to add + or - 12 to the check my while loop to make it even ridiculously longer. I feel like while loops should not have that long of arguments but I don't know what the proper thing to do in this case is so I'll just leave it as is for now. Updated version:
http://pastebin.com/G4nqVZe5
In the meantime I have a question:
When I wrote that in Xcode on my laptop, everything ran fine and it was all good and dandy, but when I copy-pasted it into Visual Studio on my PC it gave me an issue with the time() function.
I ended up having to #include <time.h> in my header. Any idea why my laptop didn't need that but my PC did? Does Xcode's compiler just not need that for some reason?
Last edited by Ashan 8 years ago, edited 1 time in total.
-
devil†zukin
Re: The Thread for Programming
this is mildly interesting:
allocating memory with glTexImage2D but not initialising it and then rendering it:


allocating memory with glTexImage2D but not initialising it and then rendering it:


- docopoper
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla non pharetra enim, nec maximus odio.
- Posts: 78
- Joined: 11 years ago
- First name: Shane Farrell
- Pronouns: they/he
- Location: Ireland
Re: The Thread for Programming
That should be the new forum design.
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.
<- Go team Yeah Doctor Shemp.!
<- That's everyone being nice to me. ^^
I made a game called Utter Confusion! Play it! :D
It's a lot of fun and has been incredibly popular at every indie game dev party I've brought it to.
<- Go team Yeah Doctor Shemp.!
<- That's everyone being nice to me. ^^I made a game called Utter Confusion! Play it! :D
It's a lot of fun and has been incredibly popular at every indie game dev party I've brought it to.
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
Wrote my first CS exam today.
It was pretty simple, something like "get third character on the third line of a .txt file and output x to a file if the third character is A and y if it's B and z if it's neither of those things".
I'm not sure if they dock points for making things less efficient, but the way I got the third character of the third line was pretty dumb and I realized that after.
I made a for loop that cycled twice, and it would basically go through one character at a time until it reached a \n, and that's completely unnecessary cause I could have just like, used the extraction operator twice cause that takes in a line until it hits a \n but whatever.
Hopefully they don't take off marks for not being as efficient.
It was pretty simple, something like "get third character on the third line of a .txt file and output x to a file if the third character is A and y if it's B and z if it's neither of those things".
I'm not sure if they dock points for making things less efficient, but the way I got the third character of the third line was pretty dumb and I realized that after.
I made a for loop that cycled twice, and it would basically go through one character at a time until it reached a \n, and that's completely unnecessary cause I could have just like, used the extraction operator twice cause that takes in a line until it hits a \n but whatever.
Hopefully they don't take off marks for not being as efficient.
Re: The Thread for Programming
So, I'm realizing just how useful it is to have multiple header files to put your stuff in. SPOILER:
Also I think I'm gonna try to make a platformer again. Or at least try to get collision and proper jumping mechanics working. The jumping is what screwed me over last time I tried to make one, but I think I have a relatively solid strategy planned out.
it's really useful
Also I think I'm gonna try to make a platformer again. Or at least try to get collision and proper jumping mechanics working. The jumping is what screwed me over last time I tried to make one, but I think I have a relatively solid strategy planned out.
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
So I did my best to replicate the code I wrote yesterday and I totally realized I messed up!!
http://pastebin.com/HJ3H6WuJ
(as you can see it was kind of a dumb solution since I could have just used the extraction operator twice to get to the third line but fart fart fart)
I put a comment beside the line I forgot. Without the line it would only go through the loop once since the theChar != '\n' test would be false once it went through the loop once, so in the code I wrote it would get the third character on the second line rather than the third line.
Maybe I'll get lucky and the marker won't notice.
Oh also yeah I used using namespace std on it cause that's still what they want us to do I guess. I'm not using outside of class though I'll have you know!!
http://pastebin.com/HJ3H6WuJ
(as you can see it was kind of a dumb solution since I could have just used the extraction operator twice to get to the third line but fart fart fart)
I put a comment beside the line I forgot. Without the line it would only go through the loop once since the theChar != '\n' test would be false once it went through the loop once, so in the code I wrote it would get the third character on the second line rather than the third line.
Maybe I'll get lucky and the marker won't notice.
Oh also yeah I used using namespace std on it cause that's still what they want us to do I guess. I'm not using outside of class though I'll have you know!!
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
YesRenaBeach wrote:what do you mean they might not notice...
were you writing this on paper or something?
So far they haven't cared about stuff like that, you're just supposed to assume that if you're checking the third character on the third line of a file that you have a file where that exists.RenaBeach wrote:also what happens if there are no linebreaks in the file
We haven't even covered arrays in the class yet so I'm not going to bother using them yet.RenaBeach wrote:really you should just have read three lines and then grabbed the third character with the array operator
(after checking that there actually were 3 lines and there is a third character of course)
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
No I get it's not going to work all the time but I don't think they care about clearing it of bugs like that cause most of the people in this class are doing it as an elective so we just assume the files have the things they're checking for.
If I were actually writing a program to do this I'd check for that stuff but for the exam when you're writing on a piece of paper they don't expect that extra stuff as far as I know.
Even the example programs the prof does in class don't check for that stuff.
If I were actually writing a program to do this I'd check for that stuff but for the exam when you're writing on a piece of paper they don't expect that extra stuff as far as I know.
Even the example programs the prof does in class don't check for that stuff.
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
I'll do my best.
Like I said, I'm less cautious about that stuff with pen + paper since if you make a mistake it's way more annoying to fix on paper. When you're programming, you don't typically write everything completely chronologically, chances are you'll go back to fix stuff, maybe add more lines, correct spacing, etc. On paper you can't do any of that so you kind of want to do the bare minimum of what you have to write so mistakes aren't as big of a deal.
Hell, I forgot to air check (by the way, not sure if it's actually called that cause I Googled it and nothing came up, but we were told checking if i/o files exist and giving an error if they don't is called air checking) and realized it after I wrote everything else out so I had to draw a big bubble and write the code in there and draw a big line pointing between 2 other lines of code to show "this code codes here".
Programming on paper sucks.
Like I said, I'm less cautious about that stuff with pen + paper since if you make a mistake it's way more annoying to fix on paper. When you're programming, you don't typically write everything completely chronologically, chances are you'll go back to fix stuff, maybe add more lines, correct spacing, etc. On paper you can't do any of that so you kind of want to do the bare minimum of what you have to write so mistakes aren't as big of a deal.
Hell, I forgot to air check (by the way, not sure if it's actually called that cause I Googled it and nothing came up, but we were told checking if i/o files exist and giving an error if they don't is called air checking) and realized it after I wrote everything else out so I had to draw a big bubble and write the code in there and draw a big line pointing between 2 other lines of code to show "this code codes here".
Programming on paper sucks.
- WhattayaBrian
- Posts: 239
- Joined: 8 years ago
Re: The Thread for Programming
"Error checking" :)Ashan wrote:air checking
To expound a bit on what Rena said:
Only rarely do you want to interact with a file's contents through the file interface. The general idea is thus:
1. You've got a billion pre-built utilities for interacting with strings.
2. You do not for files.
So usually what file i/o consists of is opening a file, reading all of its contents into a string, and then parsing that string.
This isn't about efficiency, but ease of use. If you open your file and put it into a string, you suddenly have tons of ways to solve your problem. Sometimes you can use a find() function to find a specific character, or you can use split() in something like python to split your string into many strings that were once separated by the character of your choice.
Or you could do a ridiculous regex (assuming it supports multiline).
And the same goes true for writing to files. Generally you collect your info into a buffer, and flush it all at once into a file. If your file is really big, you may want to break this up into chunks, but that's not normally necessary.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.
Current Game: Distorted Travesty 3
Current Game: Distorted Travesty 3
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
Waitwaitwait I swear I didn't just mishear him. Gonna go through my notes, I swear he's written "air checking" in powerpoint slides. hold on
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
This was taken verbatim from the notes. I type all my notes from exactly what it says on the slide.
And yeah I know assumptions and things and stuff but they also taught us file I/O before booleans so they clearly aren't teaching this traditionally.
- WhattayaBrian
- Posts: 239
- Joined: 8 years ago
Re: The Thread for Programming
I'm afraid your lecturer made a typo then.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.
Current Game: Distorted Travesty 3
Current Game: Distorted Travesty 3
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
But he reads off his slides! I'm pretty sure he actually calls it air checking!
Maybe he learned it off of his lecturer and my university has just been passing on this misinformation since the first CS prof made the typo years ago.
Maybe he learned it off of his lecturer and my university has just been passing on this misinformation since the first CS prof made the typo years ago.
Re: The Thread for Programming
I like to draw my programs, much nicer to understand
d̀͢͏̷͢ȩ̢͡͞͠-̸̢͟҉g̶̡͟͞҉e͞͏͞͞͠n͢҉e̸̛͠͞r͟á̡͠͡ţ̛́͜i̧̛o̵̢ń̴͠͝͝
dA
dA
Re: The Thread for Programming
Okay, I've spent a majority of my day today, and a good chunk of time yesterday, trying to figure this out, and I just don't seem to be able to Sherlock my way out of it.
I've tried to make this as simple and understandable as possible:
So, two questions:
1) Is this a good way to organize my code? Or are there way too many files?
2) I'm getting a bunch of errors involving how things are being included multiple times. I'm completely stumped as to how this can be the case because I've put #pragma once at the top of every header. Note that at first, I was using this approach:
and I was still getting errors of things being included/defined/etc. multiple times.
I'd really love some assistance, but I also don't want y'all to spend all day trying to figure my problems out for me. I really hope this isn't an unreasonable question or anything, haha.
I've tried to make this as simple and understandable as possible:
1) Is this a good way to organize my code? Or are there way too many files?
2) I'm getting a bunch of errors involving how things are being included multiple times. I'm completely stumped as to how this can be the case because I've put #pragma once at the top of every header. Note that at first, I was using this approach:
Code: Select all
#ifndef PLAYER_H
#define PLAYER_H
...
#endifI'd really love some assistance, but I also don't want y'all to spend all day trying to figure my problems out for me. I really hope this isn't an unreasonable question or anything, haha.
- WhattayaBrian
- Posts: 239
- Joined: 8 years ago
Re: The Thread for Programming
Rena's way faster at posting than I am. :(
OH WELL
1. As with most things in programming, there is no one true answer. It will depend heavily on your situation. However, in general, you would not want to do things this way. In larger projects, a system like this would could your compile times to exponentially compound (n^2) with each new header added. This is because each file is including each header. This is related to the handshakes problem.
Including files is work. Not a huge amount, but it can be easy to forget that a lot of what the compilation process does is parse text. The more text the compiler has to parse, the worse off your times will be. Remember, #include is not a smart command. Literally the only thing it does is replace itself with the text of the file you give it, wholesale.
But there's perhaps a more important reason. This will be difficult to grasp at the level you're programming, and that's okay. In bigger projects, we try to minimize dependencies. The word is pretty self-evident. If Circle needs to know about Shape in order to compile, then Circle is dependent on Shape.
The more dependencies your project has, the harder it is to maintain your project. This can be difficult to wrap your head around, since it would seem like having code know about more things would make code easier to write, not harder. That's the slippery slope.
However, this doesn't really hold for standard headers, because you're not maintaining them. In this case, what many projects use is what's called a procompiled header. It is almost exactly what you've done manually: create a header file that contains a bunch of things and have everyone include them. Because it's a compiler feature, it can do cool things to dramatically speed up compilation times (like only parsing all of those files once instead of for every translation unit).
2. Hard to say without seeing some more details. There is actually no error for including a header multiple times, so you must be seeing something else. Multiply defined symbols? Do you have global variables defined in a header? That will bite regardless of how many header guards you have.
OH WELL
1. As with most things in programming, there is no one true answer. It will depend heavily on your situation. However, in general, you would not want to do things this way. In larger projects, a system like this would could your compile times to exponentially compound (n^2) with each new header added. This is because each file is including each header. This is related to the handshakes problem.
Including files is work. Not a huge amount, but it can be easy to forget that a lot of what the compilation process does is parse text. The more text the compiler has to parse, the worse off your times will be. Remember, #include is not a smart command. Literally the only thing it does is replace itself with the text of the file you give it, wholesale.
But there's perhaps a more important reason. This will be difficult to grasp at the level you're programming, and that's okay. In bigger projects, we try to minimize dependencies. The word is pretty self-evident. If Circle needs to know about Shape in order to compile, then Circle is dependent on Shape.
The more dependencies your project has, the harder it is to maintain your project. This can be difficult to wrap your head around, since it would seem like having code know about more things would make code easier to write, not harder. That's the slippery slope.
However, this doesn't really hold for standard headers, because you're not maintaining them. In this case, what many projects use is what's called a procompiled header. It is almost exactly what you've done manually: create a header file that contains a bunch of things and have everyone include them. Because it's a compiler feature, it can do cool things to dramatically speed up compilation times (like only parsing all of those files once instead of for every translation unit).
2. Hard to say without seeing some more details. There is actually no error for including a header multiple times, so you must be seeing something else. Multiply defined symbols? Do you have global variables defined in a header? That will bite regardless of how many header guards you have.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.
Current Game: Distorted Travesty 3
Current Game: Distorted Travesty 3
- WhattayaBrian
- Posts: 239
- Joined: 8 years ago
Re: The Thread for Programming
Code: Select all
if ( DoStop >= ( GGFxEngine->GameHasRendered > 1 ? 1 : 2 ) )1. Stop
2. Drop
3. Set yourself on fire
This has been a public service announcement. Have a nice day.
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.
Current Game: Distorted Travesty 3
Current Game: Distorted Travesty 3
- WhattayaBrian
- Posts: 239
- Joined: 8 years ago
Re: The Thread for Programming
whoa you work for adobe
If you read this post and thought "Wow, what a swell guy, I sure would like to hear his voice and also watch videogames?" then do I have a link for you.
Current Game: Distorted Travesty 3
Current Game: Distorted Travesty 3
- Ashan
- The world has become a place
- Posts: 2660
- Joined: 12 years ago
- Location: Canada
- https://ashan.talkhaus.com/
Re: The Thread for Programming
Wait...WhattayaBrian wrote:If you realize you've written code like this:Code: Select all
if ( DoStop >= ( GGFxEngine->GameHasRendered > 1 ? 1 : 2 ) )
1. Stop
2. Drop
3. Set yourself on fire
This has been a public service announcement. Have a nice day.
That's like... They made an if statement a condition for an if statement?










