Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 532 533 [534] 535 536 ... 796

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

SaintofWar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7995 on: September 26, 2015, 06:58:33 pm »

Yeah, sure, I guess. But then you might as well just call the EIP an abascus. I dunno, nevermind then. I thought it was a good idea. I guess I'll come back with some interesting code instead.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7996 on: September 26, 2015, 07:02:49 pm »

What the fuck are you talking about now?

Explicit "Goto" instructions have been removed from high-level languages, but the languages are still entirely structured around using them, it's just that their use has been constrained to specific cases.

If we're talking machine code, we can ask whether gotos exist, or whether for loops, while loops exist. For loops and while loops do not exist in machine code. There's only the "jmp" instruction and registers. Which is identical to how you'd write a goto-based loop in a high level language. Basically none of the high-level theoretical structures of execution flow exist in machine language except the function call/return stack, and one-way gotos.
« Last Edit: September 26, 2015, 07:23:49 pm by Reelya »
Logged

SaintofWar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7997 on: September 26, 2015, 07:25:57 pm »

There's a misunderstanding here. I was answering Miauw62's remark that it was mostly GOTOs. I mistakenly thought that was what you said, hence my remark. What I was trying to say is, assembly is not all about jumps. In fact, there's only a few jumps here and there, especially after compiler optimizations.

If it was all jumps, then indeed, you could just call the EIP some counting or calculation helper 'tool'. Like me in 1st grade when I was tracing with my fingers the numbers I was trying to add together... from a different notebook. It's a bad analogy, I get it. But it's not far off the mark.

In hindsight, I suppose what I should have said, had I immediately realized I was replying to someone else was: Specifically, the pointer would jump forward 4 bytes if it was an int array. Would the same be true for a &pointer? The dereference *pointer is less interesting, that would just increase the value at the address the pointer is pointing to.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7998 on: September 26, 2015, 07:32:47 pm »

If you did (&pointer)++, then this would most likely do nothing at all. "&pointer" takes the address that holds "pointer", and puts it into a temporary variable. You then increment that temporary variable. but since it's only a literal expression that temp variable is basically out of scope after this instruction ends, losing any changes. It's similar for basic types:

int i;
(&i)++; // <= this won't break i, because &i takes a copy of i's pointer, it doesn't change the address of i itself.
« Last Edit: September 26, 2015, 07:36:20 pm by Reelya »
Logged

SaintofWar

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7999 on: September 26, 2015, 07:40:18 pm »

Indeed. But I figured it was awesomer to answer that in actual disassembled code, rather than a straight answer. That was the point, right?

Anyway. I guess it wasn't that special of an idea.
Logged

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8000 on: September 27, 2015, 04:32:15 am »

Hey guys I need to write a program for resolving the travelling salesman problem with the use of the greedy algorithm. The program itself is already written in C (as a concole application), but the teacher says it also needs a visualization to be made, that is a complete weighted undirected graph to be drawn on the screen. I know it's impossible to do it in the console window, and I don't possess any knowledge of win32api or anything. I suspect I could draw the graph by the means of the graph unit from Pascal, but in this case I'll have to rewrite the whole program which could be painfully difficult. What do I do?
« Last Edit: September 27, 2015, 04:46:57 am by RoguelikeRazuka »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8001 on: September 27, 2015, 04:36:18 am »

Try learning Opengl. To make things easier you should use a windowing library that builds the OpenGL context for you. GLUT is one I used to use, but I started using SFML recently.

Whatever you do, don't bother with win32api or any of that junk for this. Just use the cross-platform OpenGL stuff and an additional library that handles the windows side of things. Here's the tutorials for SFML. Basically try and hook it up with your compiler of choice, then cut and paste the code from the "open a window" tutorial to get a blank window going. At that point you can look at further SFML stuff, or just do regular OpenGL commands.

http://www.sfml-dev.org/tutorials/2.3/
« Last Edit: September 27, 2015, 04:44:47 am by Reelya »
Logged

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8002 on: September 27, 2015, 02:07:25 pm »

SFML is a library that I'm a bit familiar with, but the one thing that surprises me is that some people on stackoverflow recommend it for typical gui programming. I have to wonder if they don't understand the question, or perhaps are advocating fluid uis coded from scratch out of more primitive SFML primitives. Which has ups and downs, but mostly a lot more code than most people would like to implement for themselves.

I hope that's what they're doing, rather than misunderstanding the question.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8003 on: September 27, 2015, 02:42:55 pm »

If anyone has ever heard of Zybooks then its that. I go toehri for the 'online portion of my class' (In reality the majority) to do sections of chapters. Each section in the end has challenges on the concepts discussed in the chapter. Such as debugging or using a piece of code.


Basically I used the same code but added endl.

 cout << "Press the " << letterToQuit << " key " << numPresses << " times to quit.";

Thinking back it wasn't too hard..except that one bit at the end. Is it normal to 'know' a concept but have some some particle be missing in your code which stops you getting what you want for hours on end? Or am I just bad at being a new programmer?
Perfectly normal, really. Often bugs can be traced back to accidentally typing i++ instead of j++ or using > where you should've used < or =>, stuff like that.
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.

LoSboccacc

  • Bay Watcher
  • Σὺν Ἀθηνᾷ καὶ χεῖρα κίνει
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8004 on: September 27, 2015, 03:20:49 pm »

Perfectly normal, really. Often bugs can be traced back to accidentally typing i++ instead of j++ or using > where you should've used < or =>, stuff like that.

my favorite is

if (something); {


}
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8005 on: September 27, 2015, 03:24:46 pm »

That causes me physical pain.
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.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #8006 on: September 27, 2015, 04:20:13 pm »

* Orange Wizard gags violently.
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.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8007 on: September 27, 2015, 04:24:06 pm »

Error in process rational_thought: uncaught HasGoneStarkRavingMad exception.
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.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8008 on: September 27, 2015, 08:18:46 pm »

Okay, so I wasted about 4 hours of my time on one of Google's foo.bar puzzles today, in the spoiler below. I have given up because I have now become convinced that the solution I arrived at within the first hour is correct, but it keeps failing all tests but one. At this point, I'd just like to know why the code doesn't do what I think it should do. I looked up the solution, and while I take a different approach to implementing it, as far as I can tell they should result in equivalent outcomes, so an illustration of the difference would work for me.

Thanks.

Spoiler: The Problem (click to show/hide)

Spoiler: My Code (click to show/hide)

Spoiler: My Code, Uncommented (click to show/hide)

EDIT: Had pasted a slightly older, less clean version by mistake. Should be logically identical.
« Last Edit: September 27, 2015, 08:27:29 pm by Bauglir »
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.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8009 on: September 27, 2015, 08:32:23 pm »

...Grr why did i look at this thread now I want to solve this problemmmmmmm....
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 ... 532 533 [534] 535 536 ... 796