Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 562 563 [564] 565 566 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8445 on: November 20, 2015, 03:55:22 am »

I can't think of many applications where XML would be strictly better than JSON. The ease of use and parsing for JSON is just so good, PLUS it has a looot less boilerplate for simple data.
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

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8446 on: November 20, 2015, 09:39:08 am »

look at the little nerdy car go

http://rednuht.org/genetic_cars_2/

this need to become  game, somehow

I had best result with 30% / 30%
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8447 on: November 20, 2015, 02:40:41 pm »

That's pretty awesome.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8448 on: November 20, 2015, 08:11:12 pm »

Got a problem with a small question. It's asking me to print two strings in alphabetical order. I can get the following resulets:

 [Imagine a checkmark here] Testing input rabbits capes
Your output:  capes rabbits
✖   Testing input capes rabbits
Expected output:  capes rabbits
Your output:  rabbits capes
 Tests aborted.

by inputting this piece of code: cout << secondString << " " << firstString << endl;

I'm confused why my code goes from capes rabbits to rabbits capes when they change the input. I don't know how to proceed from here.




Spoiler (click to show/hide)
« Last Edit: November 20, 2015, 08:56:33 pm by 3man75 »
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8449 on: November 20, 2015, 08:38:11 pm »

How are they even giving input? You've written a main function that appears hard coded to print two particular strings in a particular order - no sorting at all. It sounds like they want you to write a function that takes an arbitrary pair of strings as arguments, and then prints them in the correct order.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8450 on: November 20, 2015, 08:44:41 pm »

Surely C++ has a generic sorting function that could be used?
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8451 on: November 20, 2015, 08:46:50 pm »

well no, you can use the stl::sort functionality, but this assignment is clearly about how to write the sorting code so that you learn about string handling. If everyone just learned by using black-box library functions we end up running out of people who are smart enough to actually write the underlying code. C++ is for writing underlying code, and knowing how to do that in the minimal amount of memory or fastest possible time, not quick hacks that just get the job done without you needing to know what's going on.

EDIT: btw STL is pretty powerful, but if you start doing sizeof checks you realize that they're all hideously bloated memory hogs compared to writing your own light-weight classes. An empty STL string takes 28 bytes of pure bloat. You can get that down to maybe 4-8 bytes by writing your own light-weight wrapper around a char* and a "int size". With just that, you can implement most of the stuff from std::string that's actually useful.

3man75: your code seems to be just swapping the position of the strings, it's not sorting them alphabetically. You have to sort them into correct order, no matter what order they come in the input.
« Last Edit: November 20, 2015, 08:58:45 pm by Reelya »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8452 on: November 20, 2015, 08:52:39 pm »

well no, you can use the stl::sort functionality, but this assignment is clearly about how to write the sorting code so that you learn about string handling. If everyone just learned by using black-box library functions we end up running out of people who are smart enough to actually write the underlying code. C++ is for writing underlying code, and knowing how to do that in the minimal amount of memory or fastest possible time, not quick hacks that just get the job done without you needing to know what's going on.
Right, that makes sense. I use Python too much.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8453 on: November 20, 2015, 08:55:41 pm »

Ah Python, the language that will keep the C/C++ programmers who write all of the actual fast libraries for it employed for years to come. :P
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8454 on: November 20, 2015, 08:57:27 pm »

well no, you can use the stl::sort functionality, but this assignment is clearly about how to split strings up and write sorting code. Sure, he could grab some premade libraries that already do everything, but that would sort of defeat the purpose of learning how to write the underlying code. C++ is for optimized low-level programming such as games. And you're an idiot if your final version of a game is riddled with STL calls.

STL is pretty powerful, but if you start doing sizeof checks you realize that they're all hideously bloated memory hogs compared to writing your own light-weight classes.

3man75: your code seems to be just swapping the position of the strings, it's not sorting them alphabetically. You have to sort them into correct order, no matter what order they come in the input.

How do you sort? I'm a little lost when you guys talked about this because I've never seen anything that involves sorting in the chapter.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8455 on: November 20, 2015, 09:10:43 pm »

To sort something, you need two basic bits of code:

- a method to compare two values
- a method to swap two values

then, with only two inputs, you only need to do two things:

- check if the first value is higher than the second value
- if the check was true, swap the values

So you need to find or create a string comparison function. to do that you need to go through letter by letter until you find one that's lower alphabetically than the other. The basic outline is like this:

Spoiler (click to show/hide)

Once you have a working comparison function you need to sometimes swap two strings so that they are in the right order. and you swap two things by making a "temp" variable, then backing up one of the values in that:
Spoiler (click to show/hide)
« Last Edit: November 20, 2015, 09:16:38 pm by Reelya »
Logged

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8456 on: November 20, 2015, 09:22:33 pm »

Given the setup, they're probably easing you into the idea of sorting, which may be why they haven't used the word. You don't need to do a full-blown sort (that is, you don't need to swap anything). All you need to do is compare the strings until you can determine which to print first.

In this case, you will need to define a string comparison like Reelya just said, then something like

Code: [Select]
if isGreaterThan
    print String2, then String1
else
    print String1, then String2

What I just wrote is what's called pseudocode, if that's not a concept you're familiar with. I laid out a vague structure, but since I'm not really familiar with C++ syntax I didn't bother writing the correct version.

What Reelya suggested or what I just did should both work, it's just a matter of what you're more comfortable with and what you think your class expects.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Uristides

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8457 on: November 20, 2015, 09:42:02 pm »

look at the little nerdy car go

http://rednuht.org/genetic_cars_2/

this need to become  game, somehow

I had best result with 30% / 30%
Oh my god it's just like boxcar2d but with even more pretty graphs to look at. Shame it's only 2 wheels max.
« Last Edit: November 20, 2015, 09:44:48 pm by Uristides »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8458 on: November 20, 2015, 10:37:07 pm »

We have a thread about this game already:
http://www.bay12forums.com/smf/index.php?topic=152831

Magnumcannon

  • Bay Watcher
  • Deep waters don't run still
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8459 on: November 21, 2015, 06:05:54 pm »

I'm trying to do some kind of questionnaire or something in Python 2.7 that will display the user's answers at the end. I'm not even done with it but i encountered some problems with loops.
Spoiler (click to show/hide)
Everytime i reach the first loop, it doesn't break. Ever. Like, it will keep asking the age even if the age is valid. I tried adding a variable before the loop, making it something like this.
Spoiler (click to show/hide)
It didn't work either. It just keeps looping forever. I know this is likely a very basic problem, so basic i can't find an answer online. My objective is to get that "Sandwich" printed, so i know the loop is dead and i can insert the next question.
« Last Edit: November 21, 2015, 06:11:43 pm by Magnumcannon »
Logged
Pages: 1 ... 562 563 [564] 565 566 ... 796