The Thread for Programming

here's a good place for FRIENDLY, ENJOYABLE, and otherwise very GENERAL discussion!
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Rénà wrote:neat

http://www.codingame.com/games

ppl keep linking me to this

it seems fun
Oh wow this is cool.

I need to find time to play it.
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
User avatar
lukaramu
not lukaramu
Posts: 0
Joined: 10 years ago
First name: not lukaramu
Location: the place where i live

Re: The Thread for Programming

Post by lukaramu »

WhattayaBrian wrote:
Rénà wrote:neat

http://www.codingame.com/games

ppl keep linking me to this

it seems fun
Oh wow this is cool.

I need to find time to play it.
Yep this is cool!!!
User avatar
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

Post by docopoper »

lukaramu wrote:
WhattayaBrian wrote:
Rénà wrote:neat

http://www.codingame.com/games

ppl keep linking me to this

it seems fun
Oh wow this is cool.

I need to find time to play it.
Yep this is cool!!!
This is indeed cool.
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.

Image <- Go team Yeah Doctor Shemp.!
Image <- 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.
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Without looking at it too deeply, you effectively need to solve this problem:

O = optional goal
R = required goal

O + R > R

In order to do this in an interesting way, you might need more constraints in your system, perhaps things that have negative weights: O + R is better, but it takes more time, and longer times affect your "score" negatively. Or the lumberjack can work during the rain, but then he gets sick and that makes him work at a slower rate.

Once you have your list of goals, you would A* through all the permutations of the goals (R only, O then R, R then O) and see which one grants you the highest score at the end. You then need to determine how often you update your logic--every frame? Only when certain events happen?

Or something like that.
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
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »


Image
Image
Image
Image
Image
Image
User avatar
lukaramu
not lukaramu
Posts: 0
Joined: 10 years ago
First name: not lukaramu
Location: the place where i live

Re: The Thread for Programming

Post by lukaramu »

Ashan wrote:
I think that's the kind of thing that's only really cool if you're the one doing it, and if you're not just watching a video of someone doing it1

1those little movements most likely caused by natural head movements are driving me insane and making my headache a little bit worse tbh
User avatar
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

Post by docopoper »

That looks quite fun.
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.

Image <- Go team Yeah Doctor Shemp.!
Image <- 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.
devil†zukin

Re: The Thread for Programming

Post by devil†zukin »

A* search pretties - here's a debug screen showing the order it searched the graph, fading from green to red

Image

here's what happens when you forget to terminate the search, it walks immediately to the end and then decides to search the whole graph anyway (and I didn't even notice until it got slow since it still worked)

Image

(here's what it's meant to look like for comparison)
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

My computer labs are so weird.

So, the lab has like 20 people in it, and the lab instructed explains some stuff, demos some things on the projector, and then you go to the university website and you can find the assignments with the instructions on there. The assignments have been pretty easy so far, but when you finish them the instructor refuses to let you just show him your code and run it for him. You have to make a screenshot of the code and the output, and then show him the screenshot. It just wastes time for no reason.
Image
Image
Image
Image
Image
Image
User avatar
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

Post by docopoper »

Ashan wrote:It just wastes time for no reason.
Sounds like college to me. xP I've had to do that screenshot thing too.

In fact if we are doing these sorts of horror stories then in first year we had a really crappy web development lecturer (according to the year before us she forgot how to do a line break in class and honestly I wouldn't put it past her). But yeah - for our assignment she made us code a website and then print out all the HTML and hand it in to her as well as submitting it online. Like seriously - that was like 45 pages of HTML!
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.

Image <- Go team Yeah Doctor Shemp.!
Image <- 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.
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

We get marked in them so I don't really have the option to not go.
Image
Image
Image
Image
Image
Image
User avatar
ntfwc
Posts: 2
Joined: 9 years ago

Re: The Thread for Programming

Post by ntfwc »

I just finished a decompression cache compatible with Linux systems:

https://github.com/ntfwc/decompression_cache

I designed it so I could increase the efficiency of decompressing games in archives on-the-fly. But it is general and could be applied to other things. Someone might find it useful.
>>> 0.1 + 0.2
0.30000000000000004
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

I was thinking back to an old video I saw on sorting algorithms a while back that I found super satisfying to watch:



And I did my best to do a sort thing like that in C++.
http://pastebin.com/RxVpwTEr

So yeah. I made it limited to numbers between 0 and 99 for the sake of formatting in the printArray function. I don't know if there's a better way to format with simple console output but whatever.

I wanted to make a swap() function as well but I didn't know how. I managed to do it with a function swap(int x, int y) that just took variables by using pointers, but I didn't know how to do it with members of an array cause pointers work differently with arrays or something.
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Well, there are two basic ways you could implement a swap.

Code: Select all

void swap(int & a, int & b)
{
	int temp = a;
	a = b;
	b = temp;
}
You could use this very simply:

Code: Select all

swap(array[index], array[index + 1]);
You could also do:

Code: Select all

void swap(int * a, int * b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}
Which would be used like:

Code: Select all

swap(&array[index], &array[index + 1]);
or

Code: Select all

swap(array + index, array + index + 1);
using pointer arithmetic (technically all of these examples use pointer arithmetic, some just hide it better than others).
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
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Oh, it worked.
I could have sworn I did the exact same thing yesterday (with the first one) and it would work when I put 2 int variables in, but not when I put 2 ints that were part of an array.

Thanks!

edit: oh, also, my IDE was king of throwing a fit that I had

Code: Select all

srand(time(0));
From what I could tell from the caution message, time(0) gives a long value, and srand() wants an int so it was coercing the value, so I casted it

Code: Select all

srand(int(time(0)));
and that seemed to fix it.
Is there a better way I should be fixing it?
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

After waiting 2+ weeks for my first assignment to get marked, I finally asked my prof about it and he said they were supposed to be marked already. So he told met to email him my name and student number and he'd figure out what's going on, and I guess nobody was assigned to be marking me or something so nobody did.

I finally did get it marked though, and I lost 10 marks out of 80 because:
the marker wrote:(-10) - Doesn't use constants. Conversion factors should be as const
And I looked back in the assignment, and it does say
Declare all variables and constants as data type double.
so... I guess I made a mistake? It didn't really say I had to use constants, it just said make sure constants are doubles.

After the deadline, the prof posted an example solution on the website, and he basically did all of the math in the main function, but the way I did it was I created functions that converted to different units (you can see my submitted code here so I didn't really have a reason to declare constants.
Unless, they would have rather I made functions like

Code: Select all

double tonsToPounds(double x){
    const double TONS_TO_POUNDS = x * 2000;
    return TONS_TO_POUNDS;
}
Is that safer than what I did? I can kind of see it in the context of "if someone else was modifying your code, you want to make sure they don't mess it up, so they won't if it's a constant" but I don't know.
Last edited by Ashan 8 years ago, edited 1 time in total.
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Oops, I meant to have const double in that bit of code there. That was my mistake. Edited now.
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Don't judge me
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

Well, there's this concept called a "magic number" in programming. A magic number is, more or less, a number without a name. Magic numbers are bad for maintainability, because no matter how clear they are to you as the person who originally wrote them, someone, somewhere down the line, will be confused.

It's true that putting them in a function makes it clearer, but it's still really good practice to name all your magic numbers. And, if you're going to give them a name anyway, you might as well make it const.
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
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

RenaBeach wrote:no im being sincere that was good
Ahhh, sorry. I read your post in a sarcastic tone. (Relevant)
I wouldn't have been surprised if I did something silly. If you recall a while back, I did that "4 is the magic number" program in Java, and in my original draft I made an object in another class just for storing number to word conversions. I didn't really understand objects; I knew how to use them, but not so much what they're typically used for. I understand them a bit more now, but I still don't really know what point I'm at in understanding when you should do certain things, or when it's just wasting time and making simple things more awkward.
Obviously, learning this stuff comes with time and I'm already learning some of this stuff, but you could convince me at any point in any code I write that there's a better way to do it, so I'm all ears!
RenaBeach wrote:you should program something more interesting though

sign up to that thing i posted on the last page and get ue4 and put your c++ to use
Yeah, that's why outside of my class I've been working on some basics, like, more recently, that sorting algorithm for an array. I'm still kind of intimidated with stuff like UE because I've never done anything like it before. I suppose you just gotta jump in at some point, but the whole thing still feels kind of daunting from my perspective. I'll give it a shot sometime soon though!
WhattayaBrian wrote:stuff and things
Yeah, your explanation is kind of what I had in mind. I suppose writing out things in plain English will pretty much always make things easier for other people in the long run. I'll keep that in mind, thanks!
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

I'm not sure how much of the fundamentals I know is the thing.
When I started off learning C++, I was watching TheNewBoston's tutorials and I still haven't finished that, so I'll probably continue from that series before going on.

Or you know, I could try reading from the $60 beat up book I got for this class and haven't touched once but WHO READS? NERDS, THATS WHO
Image
Image
Image
Image
Image
Image
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

RenaBeach wrote:lol textbooks for classes i never bothered buying any of them and i'm glad i didn't
Yeah, this might be my last time doing so.

So far I've had:
English:
  • Some kind of handbook for formatting essays and MLA guidelines and whatnot. Used it once for an essay but it contained nothing that I couldn't have just found by Googling.
  • A book called "The Wascana Anthology" which is a collection of poems and short stories and whatnot. We've had in-class discussion on one story which I've never read, but we've had so much discussion on it at this point that I know basically everything that happens in it.
  • A book by Jonathan Franzen, "The Discomfort Zone". This one was just a $20 book by Franzen, and apparently we actually are going to have to be familiar with this book by the end of the year, so I'm actually reading through it in my spare time. I actually don't mind it so far, so there's that.
Calculus:
  • A little ringed booklet made specifically for the course (my prof worked on it) that was around $20 I think? Never used it once.
Philosophy:
  • The Art of Reasoning. Never read anything from it even once.
CompSci:
  • A C++ book which like a mentioned, haven't even opened for anything other than to shove my syllabus into it. I actually don't mind having it around though, cause I might keep it anyway since I'm majoring in CompSci and all.
RenaBeach wrote:typing std:: before the few std functions you call is not a big deal when you get used to it and "using namespace" is really not used much in practice for good reason

the bizarre "using namespace std;" habit that introductory courses hammer into people is really not a good one
I've seen people online (stack overflow and whatnot) tend to use std:: so yeah, I was kind of wondering about that. Is there a reason it's "bad practise", other than I'm guessing you just don't use cout and whatnot in day-to-day C++ programming?
I assumed it was kind of like in Java where rather than writing

Code: Select all

java.util.Scanner sc = new java.util.Scanner(System.in);
you could just import it at the beginning

Code: Select all

import java.util.Scanner;
and the later you wouldn't have to manually type it out every time.

Code: Select all

Scanner sc = new Scanner(System.in);
Image
Image
Image
Image
Image
Image
User avatar
WhattayaBrian
Posts: 239
Joined: 8 years ago

Re: The Thread for Programming

Post by WhattayaBrian »

It's true, it's something to be wary of.

On a whim, I saw how many instances of "using namespace" there are in my UE3 project at work right now. Turns out there are exactly 300, which is not a large amount, and many of them are in CLR code (so who cares about quality amirite).

Still, convenience is valuable, and "JsonPrimitive" is easier to read than, say, "System.Json.JsonPrimitive" (to pull a random example from C#), especially if you're using a lot of these objects in a block of code. In that sense, I would probably find myself using a local using statement, which is confined to a scope.

Code: Select all

#include <iostream>

int main()
{
	{
		using namespace std;
		cout << "Yay";
	}
	cout << "This is a compile error!";
}
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
User avatar
Ashan
The world has become a place
Posts: 2660
Joined: 12 years ago
Location: Canada
https://ashan.talkhaus.com/

Re: The Thread for Programming

Post by Ashan »

Wow, I'd really like to try out UE if my university would fix their website!!!
Image
Image
Image
Image
Image
Image
User avatar
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

Post by docopoper »

I'm pretty sure all you need is a valid student email address. That's all I needed.
The first thing I would do with infinite power would be to make myself a cave where I could look at my shadow forever.

Image <- Go team Yeah Doctor Shemp.!
Image <- 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.
Post Reply