Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 331 332 [333] 334 335 ... 796

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

gogis

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4980 on: September 20, 2013, 01:00:40 pm »

I went 15 minutes to explaining my junior collegaues why-and-how I want them to keep certain flags in a one-number-bit-mask approach. Nobody cares about saving space optimizations nowadays. I suddenly feel ancient right now.
Logged
In Soviet Russia cigarette smokes you

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4981 on: September 20, 2013, 01:49:18 pm »

You are trying to make them write stuff to streams, right? I guess it depends on the kind of stream they're using, and how important transfer speed is.
Logged

gogis

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4982 on: September 20, 2013, 01:53:44 pm »

You are trying to make them write stuff to streams, right? I guess it depends on the kind of stream they're using, and how important transfer speed is.

Ugh, who you asking?  :D
Logged
In Soviet Russia cigarette smokes you

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4983 on: September 20, 2013, 03:32:04 pm »

Okay so I think I get how to break up streams based on white space, but would I use if statements to identify the individual words, or is there a better method?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4984 on: September 20, 2013, 03:45:05 pm »

You can save specific actions in a map<string, Action>, and then use actionMap[command].run(this), but that would require lots of code, and you need to know a bit more about object-oriented programming first. So I say you go with what you can already do until it works; you can still change it later.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4985 on: September 20, 2013, 04:56:04 pm »

It's 1155PM, I've had a few glasses of wine and got a sudden urge to fix some stuff I didn't have time for at work today. I am however not sure if I'm at or beyond Ballmers Peak. How should I proceed?
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #4986 on: September 20, 2013, 05:00:40 pm »

It's 1155PM, I've had a few glasses of wine and got a sudden urge to fix some stuff I didn't have time for at work today. I am however not sure if I'm at or beyond Ballmers Peak. How should I proceed?

Do the Bowling Kata with tests. It's not a complex one, but it's deceitfully simple and I find completely impossible when beyond the Ballmers Peak.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4987 on: September 20, 2013, 05:00:57 pm »

It's 1155PM, I've had a few glasses of wine and got a sudden urge to fix some stuff I didn't have time for at work today. I am however not sure if I'm at or beyond Ballmers Peak. How should I proceed?
Just start writing code right now and review it tomorrow morning.

EDIT:
Bowling Kata with tests
Wow that site is cool.
« Last Edit: September 20, 2013, 05:23:33 pm by MagmaMcFry »
Logged

olemars

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4988 on: September 20, 2013, 06:10:57 pm »

It's 1155PM, I've had a few glasses of wine and got a sudden urge to fix some stuff I didn't have time for at work today. I am however not sure if I'm at or beyond Ballmers Peak. How should I proceed?

Do the Bowling Kata with tests. It's not a complex one, but it's deceitfully simple and I find completely impossible when beyond the Ballmers Peak.

For some reason, realtime oil well integrity control seems less complicated than bowling right now.
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4989 on: September 20, 2013, 06:50:56 pm »

For some reason my program gets stuck in this loop forever

Code: [Select]
int getHoldings(string strEndRead)
{
ifstream fin("EmpireHoldings.dat");
        istringstream is;
//needs to go to startread
        while (true)
{
string key;
            int value;
            string line;
            getline(fin, line);
            is.str(line);
            is >> key;
            if (key == strEndRead) break;
            is >> value;
            data[key] = value;
}
fin.close();
return 0;
}

E: I fixed it by making the condition for the break be (line == strEndRead).
« Last Edit: September 20, 2013, 06:52:54 pm by MrWillsauce »
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4990 on: September 21, 2013, 12:13:15 am »

For the function that takes inputs from the input text file, I wrote a thing that breaks up the lines from the file into individual strings within a vector, then a loop that goes through every string in that vector in order to identify commands. How would I take integers that I wrote in the file, such as the 4 in "4 coal mines" and use it?

Here's what I've written so far.
Code: [Select]
int getInputs(string strStartRead, string strEndRead)
{
ifstream inf("HFC Input.dat");

while(true)
{
string strFindStart;
getline(inf, strFindStart);
if (strFindStart == strStartRead) break;
}

while(true)
{
string strCommand;
getline(inf, strCommand);
if (strCommand == strEndRead) break;
istringstream iss(strCommand);
vector<string> tokens;
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));

for (int nX = 0; nX < tokens.size(); nX++)
{
if (tokens[nX] == "build")
{
data["Population:"] - tokens[nX + 1];
}

}

}
return 0;
}
If there's anything else I'm doing strangely here please tell me. I really don't know what I'm doing.
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4991 on: September 21, 2013, 09:16:14 am »

Code: [Select]
int strToInt(string s) {
  istringstream is;
  is.str(s);
  int i;
  is >> i;
  return i;
}
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4992 on: September 21, 2013, 04:59:26 pm »

I am having trouble with writing a function that prints all of data's keys and values.
Logged

Dutchling

  • Bay Watcher
  • Ridin' with Biden
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4993 on: September 21, 2013, 05:01:25 pm »

Assuming data is a dictionary can't you just do: (python code, but that's basically pseudo-code so you'll understand :P)
Code: [Select]
for key in data:
    print(key, data[key])
Logged

MrWillsauce

  • Bay Watcher
  • Has an ass that won't quit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4994 on: September 21, 2013, 05:04:05 pm »

Data is c++ <string, int> map.
Logged
Pages: 1 ... 331 332 [333] 334 335 ... 796