Bay 12 Games Forum

Please login or register.

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

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

monkey

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8205 on: October 16, 2015, 04:02:29 pm »

To me the point of JSON is that is human readable, whatever language you use you are going to load it with an function/api.
But for some kind of data seeing the individual values is useless. Say you have 1000 floats that make up a curve, how do you figure out its shape ? or modify it ?
In that case (maybe with bigger files) I would move to binary files, so that leaves you designing your own format(waste of time) or using a persistence library and binary JSON is as simple as it gets, and you can go back to using text files real easy.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8206 on: October 17, 2015, 06:48:21 am »

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.
Another point of json is having a standardized format you can use in multiple places, just like xml!

And, unlike xml, it is very simple to understand and parse.
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

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8207 on: October 18, 2015, 01:34:32 pm »

Can someone remind me of the syntax for printing a variable number of characters with Python? I can never remember how to format strings, and I couldn't find the answer after a little browsing through the documentation.

I'm just trying to make a simple progress bar.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

Arx

  • Bay Watcher
  • Iron within, iron without.
    • View Profile
    • Art!
Re: if self.isCoder(): post() #Programming Thread
« Reply #8208 on: October 18, 2015, 01:44:25 pm »

If it's the same character, you can multiply it.

Code: [Select]
n = 5
print ("-"*n)
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.

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8209 on: October 18, 2015, 02:00:42 pm »

I thought there was a way to do it in between other text like "Blah blah blah: ***** 50%" or something.

Well, that still works, I just have to use multiple lines of code. Thanks.
Logged
Life is, in a word, volcanoes.
                        - Random human lord

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8210 on: October 18, 2015, 02:02:20 pm »

I thought there was a way to do it in between other text like "Blah blah blah: ***** 50%" or something.

Well, that still works, I just have to use multiple lines of code. Thanks.
Just concatenate the string before printing?
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.

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8211 on: October 18, 2015, 02:08:26 pm »

Yeah, I was using sys.stdout, but got it working with one print statement.

Code: [Select]
print("{}% completed:".format(percentDone), "*"*(percentDone//10), "\r", end="", flush = True)
Logged
Life is, in a word, volcanoes.
                        - Random human lord

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8212 on: October 18, 2015, 02:43:31 pm »

Hey is here someone who knows SFML well? The task is to write a program for solving the linear programming problem using the graphical method. I want to know if it's possible to draw something like this

Spoiler (click to show/hide)

with the help of SFML? Basically it's a sort of rectangular coordinate system with a set of lines on it to be drawn. It's also welcome that polygon determined by points A, B, C, D, E be filled with a colour.
« Last Edit: October 18, 2015, 02:52:35 pm by RoguelikeRazuka »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8213 on: October 18, 2015, 04:08:19 pm »

So I've got a code that works but it repeats itself in the middle.

Spoiler (click to show/hide)

Logged

nogoodnames

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8214 on: October 18, 2015, 04:23:47 pm »

Nothing immediately jumps out. Care showing the output for clarification?
Logged
Life is, in a word, volcanoes.
                        - Random human lord

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8215 on: October 18, 2015, 04:25:37 pm »

You should stop using spoilers for your code. Also, code is a mass noun :P
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8216 on: October 18, 2015, 04:44:19 pm »

There's also an error where you check for "userChoice < 0" meaning that 0 is treated like a valid input, as well as 1,2,3. That wouldn't be so bad if you rewrote the program to tell the player that "0 == end program" and the game keeps playing until you enter a zero for your move. But right now, entering a zero causes the game to just say "you picked 0" and do nothing else. So I guess that "0" is an "undocumented feature" not a bug meaning "I didn't want to play anyway!"

you also set it to loop while there's a tie. It's right in your code, here:

Spoiler (click to show/hide)

If you don't want it to repeated, don't use a while loop, us some sort of "if" statement.

Here's a compacted version of your code, that doesn't have the looping behaviour and doesn't have repeated sections of code. Also, i added a lookup value for the name of the move, so that you don't have to print out just a number:

Spoiler (click to show/hide)
« Last Edit: October 18, 2015, 05:01:22 pm by Reelya »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8217 on: October 18, 2015, 06:03:00 pm »

Nothing immediately jumps out. Care showing the output for clarification?

Spoiler (click to show/hide)

I put an input validation twice in the code which I think counts as "reusing code" which is something my teacher looks unkindly too apparently. To me their was just no other way to shuffle or merge the code around without having crashes, breaks, or other errors.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8218 on: October 18, 2015, 06:19:47 pm »

There's always a way. My sample version shows one way.

if you want to get rid of the looping, you have to stop using the "while" loop in the code you showed.

BTW, you were asked for clarification, but you shows ALL THREE while loops there. Which one is it? It gets annoying to have to keep asking you to tell us WTF you're even asking for. Exactly what is being printed out that you're not happy with? Showing us all the code doesn't tell us what you want / what you're getting.
« Last Edit: October 18, 2015, 06:29:18 pm by Reelya »
Logged

TheBiggerFish

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

@3man75: ...Reusing code is the bread and butter of programmers.  Seriously, your teacher either doesn't get it or doesn't get it.
@Reelya: I was WONDERING if you could simplify the RPS stuff.  Nice.
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.
Pages: 1 ... 546 547 [548] 549 550 ... 796