Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 77 78 [79] 80 81 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100469 times)

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1170 on: September 01, 2013, 08:11:39 am »

So what is the difference between Node_Base, Node and Seq_Node? Also you can implicitly cast pointers-to-derived-objects to pointers-to-base-objects.
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1171 on: September 01, 2013, 08:31:17 am »

If you don't use too many classes, you could also have a method like isSeqNode() and isBaseNode(), and then static_cast based on what they return?

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1172 on: September 01, 2013, 08:39:41 am »

I think I really took the purpose separation thing too far. :P

Node_Base has the data and operations for making/editing/destroying trees (a Parent pointer, an array of Children pointers, along with helpful operations).
Node holds values for each player (in a sequential game) and functions for finding the Nash equilibrium of a subtree.
Seq_Node is derived from Node and also has a template interface (to the "definition" of the game). It holds a (game) move, as well as an interface to a payoff function, as well as other stuff. It's basically the most complicated class.

If you don't use too many classes, you could also have a method like isSeqNode() and isBaseNode(), and then static_cast based on what they return?
I... don't think so.

I think my best bet is just rewriting them all as one class.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: Programming Help Thread (For Dummies)
« Reply #1173 on: September 01, 2013, 10:49:04 am »

It's my experience that in almost all circumstances, having to use dynamic_cast is just a symptom of a flaw in the overall design. It's a code smell, an indicated that aspects of the design need reconsidering because in all likelihood: There's a cleaner way.
Logged

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1174 on: September 04, 2013, 10:35:49 am »

Putting it all in one class improved performance by ~10%. Whoo! :D
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Help Thread (For Dummies)
« Reply #1175 on: September 04, 2013, 10:58:20 am »

What is the best way to write code in a room with a jackhammer and gasoline fumes?
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

cerapa

  • Bay Watcher
  • It wont bite....unless you are the sun.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1176 on: September 04, 2013, 11:34:18 am »

Drunk.
Somewhere else.
Wearing a gas mask and headphones.
Wearing the skin of the person with the jackhammer.

Don't know any other methods sadly.
Logged

Tick, tick, tick the time goes by,
tick, tick, tick the clock blows up.

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1177 on: September 04, 2013, 11:38:47 am »

Of course, you could ask the jackhammer guy to do it on your keyboard, it would make for some interesting code...

And anyways, a True CoderTM hears only the tap-tappin' of the keyboard and the rotting of food in his keyboard.
« Last Edit: September 04, 2013, 11:40:47 am by TolyK »
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1178 on: September 06, 2013, 02:38:50 pm »

I'm learning LISP while on my honeymoon. Does that count towards my True CoderTM membership?
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1179 on: September 06, 2013, 05:30:48 pm »

What is the best way to write code in a room with a jackhammer and gasoline fumes?

I'm guessing emacs has a mode for that? :)

malimbar04

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1180 on: September 07, 2013, 08:42:41 am »

Fizzbuzz!

I was reading this: http://www.zoharbabin.com/which-fizzbuzz-solution-is-the-most-efficient

2 questions:
how do they determine speed of a function? More importantly, how do I do this? Not sure if it matters, but I'm using C++ and Ubuntu, using command line and a basic text editor only.

How can it be that bulding a string step by step is faster than using else-if solution? It would do lots of checks for every number, where an else-if could skip over a few if it matches the first case.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #1181 on: September 07, 2013, 09:05:23 am »

To determine the speed of a function, you run it over and over and over then divide the elapsed time by the number of times you've ran it.
You can also guess or roughly get a feel by looking at how it does what you're doing.

if/else being slower than building a string step by step probably has to do with processor trickery. >_>

Someone else probably has a better answer.
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

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Programming Help Thread (For Dummies)
« Reply #1182 on: September 07, 2013, 01:13:26 pm »

You might be able to find a "profiler", which essentially tells you how much time your code spends in each function. It's pretty nifty to figure out where you need to optimise.

I didn't read the problem through, but it might be that if you're using Strings as identifiers (i.e., you never ever change them), the compiler might be smart enough to convert them to integer identifiers or  so.

JanusTwoface

  • Bay Watcher
  • murbleblarg
    • View Profile
    • jverkamp.com
Re: Programming Help Thread (For Dummies)
« Reply #1183 on: September 07, 2013, 07:24:29 pm »

how do they determine speed of a function? More importantly, how do I do this? Not sure if it matters, but I'm using C++ and Ubuntu, using command line and a basic text editor only.
If you want very basic timing in Linux, you can use the time command. Basically:

Code: [Select]
$ time ./some-program
./some-program  0.25s user 0.07s system 16% cpu 1.907 total

You're going to get a lot of noise in that, but for basic timing tests, it's good enough. And you don't have to modify your actual program. And and it works on any type of program, not just C++ or whichever.

How can it be that bulding a string step by step is faster than using else-if solution? It would do lots of checks for every number, where an else-if could skip over a few if it matches the first case.
Mostly: Branch prediction. In most cases, avoiding comparisons will speed up computation. You can get the same benefits if the compiler can guess which way it's going to go, which compilers are getting pretty good at these days.
Logged
You may think I'm crazy / And I think you may be right
But life is ever so much more fun / If you are the crazy one

My blog: Photography, Programming, Writing
Novels: A Sea of Stars, Confession

Lost in Nowhere

  • Bay Watcher
  • AHAHAHAHA~!
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #1184 on: September 09, 2013, 09:19:36 am »

OK... I'm trying to load an image from the code directory in Java. Nothing that I have tried so far has worked.
Here is my current code:
Code: [Select]
              //Returns the index of the image in imageStorage
public int addImage(String path) {
int index=imageStorage.size();
BufferedImage img=null;
try {
    img = ImageIO.read(new File(Garden.directory+"\\"+path));
} catch (IOException e)  {
System.out.println(e.toString());
index=-1;
if(Garden.abortOnErrors) {
System.exit(0);
}
}
imageStorage.add(img);
return index;
}
Code: [Select]
private LinkedList<BufferedImage> imageStorage=new LinkedList<BufferedImage>();
Code: [Select]
public static String directory=System.getProperty("user.dir")+"\\bin";So, what is wrong with this?
e - If it matters, I'm using Eclipse.
« Last Edit: September 09, 2013, 09:37:42 am by Lost in Nowhere »
Logged
And so I strike, like an unseen dodge ball in an echoing gymnasium!
Another book entitled Start Your Day with Extinction.
Must be the next book in the series after Start Your Day with Death.
Pages: 1 ... 77 78 [79] 80 81 ... 91