Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 545 546 [547] 548 549 ... 795

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 817615 times)

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #8190 on: October 15, 2015, 02:37:30 pm »

You won't believe guys but some say programming languages are simply a form of representation of algorithms, and in order to become a programmer I should focus on learning algorithms rather than on learning a programming language. Are they completely right? Whether they are or not, where do I start from? What books (or another resources) on algorithms would you guys particularly suggest and what algorithms is it necessary to know for every programmer?

They're right that programming languages are just a way to represent algorithms, but I suggest learning a language anyway. It's one of the easiest and most hands-on ways to get practice with algorithms and algorithm development.

By and large, you should work on being able to find an algorithm for a given problem rather than memorising them. Most must-have algorithms will be a standard library in most languages, so I wouldn't worry overmuch about that.
Logged

I am on Discord as Arx#2415.
Hail to the mind of man! / Fire in the sky
I've been waiting for you / On this day we die.

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8191 on: October 15, 2015, 03:02:47 pm »

Spoiler (click to show/hide)

Found a problem that after a tie it won't check for incorect responces (Because it's already been done). Something else happens when I swtich them around.

Another one is that if I switch the two loops around then something happens that after I've tied and then input wrong statements that my program will accept a wrong statement before it simply just dosen't declare a winner. This is C++ btw.

Try this:

   cin >> userChoice;
   compChoice = ((rand() % 3) + 1);

   while (true)
   {
      if (userChoice < 1 || userChoice > 3)
      {
         cout << "Have you no shame! You didn't pick 1-3. Try again." << endl << endl << endl;
         cin >> userChoice;
      }
      else if (userChoice == compChoice)
      {
         cout << "You have tied with your opponent. Try again. \t" << endl << endl << endl;
         cin >> userChoice;
         compChoice = ((rand() % 3) + 1);
      }
      else
      {
         break;
      }
   }

Hope it helps!
« Last Edit: October 15, 2015, 03:19:37 pm by RoguelikeRazuka »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8192 on: October 15, 2015, 03:19:58 pm »

what does the else part work? I've never seen break as a piece of code.
Logged

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8193 on: October 15, 2015, 03:22:38 pm »

what does the else part work? I've never seen break as a piece of code.
It just escapes the while statement if the correct (i.e not below 1 or above 3 and not equal to the computer's choice) number has been got and proceeds towards the next statement.
« Last Edit: October 15, 2015, 03:29:20 pm by RoguelikeRazuka »
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8194 on: October 15, 2015, 03:25:15 pm »

break;
will remove you from a looping construct regardless of the continuation condition.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8195 on: October 15, 2015, 04:42:58 pm »

I just solved a programming problem with a combination of template metaprogramming, polymorphism, and bound function objects. I suddenly feel so vindicated.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8196 on: October 15, 2015, 04:49:26 pm »

I just solved a programming problem with a combination of template metaprogramming, polymorphism, and bound function objects. I suddenly feel so vindicated.
I have no idea what any of this means.  Nonetheless, congratulations!
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

TheDarkStar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8197 on: October 15, 2015, 05:11:51 pm »

I just solved a programming problem with a combination of template metaprogramming, polymorphism, and bound function objects. I suddenly feel so vindicated.

Out of curiosity, what was the problem?
Logged
Don't die; it's bad for your health!

it happened it happened it happen im so hyped to actually get attacked now

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8198 on: October 15, 2015, 05:38:37 pm »

I just solved a programming problem with a combination of template metaprogramming, polymorphism, and bound function objects. I suddenly feel so vindicated.

Out of curiosity, what was the problem?

I was trying to find a way to elegantly represent animations for graphical primitives, an animation being broadly defined as "a property changing over time". So a single object representing something like a square being drawn on the screen could have individual animations affecting its position, rotation, scale, color, etc. without having to create a huge mountain of classes to do it.

My solution was to define three classes, derived from a base Animator class. The first is called anim::Scalar, and it is constructed using a function object that takes a single float value as a parameter. There are two more, anim::Vector and anim::Color, which take coordinate and color arguments, respectively. Then I pump the Animators full of KeyFrame objects (templated with the type of value they animate), and cycle through those while interpolating the values (float, float vector, and color).

That probably only made like 40% sense, but you get the basic idea. Honestly I'm surprised it worked out as well as it did.



Which reminds me, I have a question: does anyone here have opinions on data serialization formats? I'm planning on storing and loading those animation objects I described as files, and I've been trying to find a compact, non-flat data representation format to use. Is there something compact and not necessarily human-readable that has a hierarchical format like XML or JSON?

Though I get the feeling human-readability is still a good idea even if it's just for program input and output.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8199 on: October 15, 2015, 08:31:08 pm »

So...Graphics, the bane of my existence?  (I seriously seriously hate rendering things.  Java.)  Yup.  You, sir, have done Great Things today.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8200 on: October 15, 2015, 10:24:49 pm »

I very much like JSON because even if it is human-readable, printing it with no spaces might as well not be human-readable :P It is fairly compact, too, and you could compress it for further space-saving. And the rules are super simple and terse. XML has a toooon of tag (and flexibility) but in almost all cases you don't actually need XML's RADICAL INFINITE CHOICE, and JSON suffices, with its brief syntax of []{},":.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8201 on: October 16, 2015, 01:23:49 am »

Really? I love the Java graphics primitives, very simple to use for a lot of things. Just doesn't scale to animations very well, no tweening, difficult clipping, etc. Also Java is just too pedantic for that IMHO.

That solution for representing animations though... I'm not sure about the need for bound function objects, that seems a bit less efficient to me, but I've never read the documents in the standard(I'd assume c++), but despite the efficiency of your templates, bound functions aren't necessarily optimized very well.

I might very well be wrong, especially if the template parameters include the bound function, that would be very nice.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8202 on: October 16, 2015, 03:11:58 am »

I might very well be wrong, especially if the template parameters include the bound function, that would be very nice.

No, you're right. It does use more cycles, since it needs to lookup a function pointer whenever it updates. It just makes such a tiny difference in the processor load that the convenience was worth it. It was either that or define individual classes for animating position, scale, rotation, origin, fill color, outline color, not to mention different types of objects, some of which don't have setter functions. The way I did it, just a few Animator classes handle everything.

I was worried about the loss in speed at first, then I noticed I could update about 30000 animations per frame while still running at 60fps.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8203 on: October 16, 2015, 09:39:30 am »

http://msgpack.org/ is a nice lib for binary JSON, someone made a nifty tool to convert from text to binary and back, look in the Shell implementation.
And animation data is kind of hard to edit by hand, so you are not losing much by using binary files.
« Last Edit: October 16, 2015, 09:43:49 am by monkey »
Logged

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8204 on: October 16, 2015, 01:34:54 pm »

Why would you use binary json? The whole point is that it can be loaded easily by either javascript or python.

Besides, if performance matters, but you can't have a large json file, then I'd use zlib to compress it with a deflate stream, which works fairly well and won't slow your modern machine down too much.
Pages: 1 ... 545 546 [547] 548 549 ... 795