Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 161 162 [163] 164 165 ... 796

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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2430 on: May 19, 2012, 08:21:28 pm »

that's an odd set of bugs. Okay, what does "Juggle the various gene-storing arrays" do? For some extra clarification can you answer the following questions:
* Are the rabbits given attributes (speed, agility) based on their gene information?
* Do the remaining rabbits create new rabbits based on the remaining genes to essentially produce faster and more agile rabbits?
* What purpose does the removed gene list have?

Can you post your hunting code? Im not entirely sure what is going on but I might be able to figure it out if i can look at the code :) (also, what language are you programming this in?)
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2431 on: May 19, 2012, 08:44:10 pm »

If you saw my post in the Dr.Poo thread, I only know C++ :P

The hunting code is so confusing (I suppose) that I don't think it'll help o_o

The attributes are simple pair of numbers, averaged.

I have not coded the new rabbits stuff.

foxhunt.cpp
foxhunt.h

I can post the Genes.cpp and Genes.h code if you want it. The hunting code references a function or two in Genes.cpp.
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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2432 on: May 19, 2012, 09:00:49 pm »

Seeing Genes.cpp/.h might help a little more with getting everything figured out. I'm cool with C++ and it seems to be pretty cool with me as well :) so I should be able to hunt down problems that I see.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2433 on: May 19, 2012, 09:06:50 pm »

I think there is a slight problem with your hunt function. After assigning the index of a prey animal that is alive to the variable 'random', you subsequently assign a random number from 0 to 9999 to random and then use this as an index. I think that your list of prey animals doesn't have 10,000 elements, so you are probably overwriting some random part of your program's memory. I think you might want to try assigning rand()%10000 to another variable.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2434 on: May 19, 2012, 09:14:23 pm »

oh damn I didn't even see that one, good catch RulerOfNothing! Something else that I see is that it looks like when you call your hunt method from within Foxes::mainFunc(...) you are doing a F number calls of it. This I suppose is how you simulate through however many foxes you are using to hunt? Within the hunt function itself you are then doing a for-loop through F number of foxes, which effectively doubles the number of times the foxes are hunting. That right there is probably what is giving you such large numbers of hunting attempts, as well as part of why your rabbit-death-toll is so high.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Blargityblarg

  • Bay Watcher
  • rolypolyrolypolyrolypoly
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2435 on: May 19, 2012, 09:38:02 pm »

Spoiler (click to show/hide)

So there are the relevant methods; populateWorld, the City constructor, the Country constructor, addCity (to a country) and addCountry (to a world) The issue, so nobody has to search for my last post, is that when I add the countries I've instantiated to pWorld, the cities inside those countries are not copied over; it claims that the are no cities in any of the countries.

I have tried manually adding the cities from the pre-added to country to the copy of that country inside a world by editing the addCountry method, but it gives me an array out of bounds exception, which is incredibly confusing; there is space for all the cities in each of the countries; this would imply that there are, during addCountry's runtime, cities in the copied country.
Logged
Blossom of orange
Shit, nothing rhymes with orange
Wait, haikus don't rhyme

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2436 on: May 19, 2012, 09:41:04 pm »

Wow, that fixed part of my problem nicely. I didn't even notice that... Thanks, GE and Ruler!

Of course, the list-shuffling part is still as is.

As for the other two files : Genes.cpp, Genes.h

Updated foxhunt files : foxhunt.h, foxhunt.cpp

The problem is that after the second generation, the lists of genes are randomly shuffled up; gene_1i and gene_1ii are randomly switched up, and the phenotype doesn't match either D:

Ex: One of the elements, genelistA[36] = 3,87,81. First of all, the generation made sure that w/o breeding, 1i and 1ii can't be more than 1 or 2 difference; also, the phenotype should be the average of the first two. T_T

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

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2437 on: May 19, 2012, 10:04:43 pm »

I had another look at foxHunt::mainFunc, and I noticed that it always calls repopulate. It calls repopulate whenever foxes equals zero, but due to the way your loop is constructed, foxes will always equal zero after the loop is finished.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2438 on: May 19, 2012, 10:08:06 pm »

Hmm, that should be rabbits. I must fix that tomorrow.

Huh... wait, since I actualy wrote repop last night, that means that's the trouble.

Thank you so very much with helping me, Ruler. I bet I'd never had found those things without long debugging sessions...
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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2439 on: May 19, 2012, 10:17:58 pm »

@BlargityBlarg: My suggestion, since arrays like to play tricks on me, is to use Collection typed objects such as vector or list to populate your countries with cities and world with countries. Something like below, which will be in pseudocode since I am really lazy right now with making proper code work in this instance.

Code: [Select]
main{
     World w = new World();
     
     w.addCountry(new Country("name",maxCities,etc...));
     w.addCityToCountry("Country name", new City("name", etc));
     // continue to do this for each country and city
}

// World::variables and methods
Vector<Country> countryList;
World::World(){
     countryList = new Vector<Country>();
}
World::void addCountry(Country toAdd){
     // depends on a Vector<Country> variable called countryList
     countryList.add(toAdd);
}
World::void addCityToCountry(String country, City toAdd){
     // iterate through countryList to find a country with name specified
     for (int i = 0; i < countryList.size(); i++){
          if (country == countryList.get(i).getName()){
               countryList.get(i).addCity(toAdd);
          }
     }
}

// Country:: variables and methods
Vector<City> citiesList;

Country::Country(...){
     citiesList = new Vector<City>();
     // and the name assignment stuff
}
Country::String getName(){
     return this.name;
}
Country::void addCity(City toAdd){
     citiesList.add(toAdd); // you can put in extra null-type checking if you want
}



That should work for the most part since you are making the world first, then putting in a country, and then putting in cities from there

@Skyrunner: Glad that part of the problem is fixed :D Which part of the code is it that changes the gene variables before they start getting used? Also, I'm a little rusty with Structs but can't you put in a default value of vartype v = varDefaultValue {0,null,etc} or something like that? I don't see the code within Genes.cpp/.h that would alter the phenotype of the genes so could you provide that code as well?
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2440 on: May 19, 2012, 10:23:00 pm »

Stucts are classes. That's it :P
I read that most modern compilers treat structs and classes as the same.

The code is in class Gene, initializeWholeThing() if memory serves right. Off the computer right now, see.
Sets everything in lists A and temp to 0. Also, initializegenelistA() blanks list A, initializetemp() blanks list temp. The phenotype is calculated in the allelePop class somewhere, and I  think Ruler solved the problem. I have to check tomorrow if it really is so...
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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2441 on: May 19, 2012, 10:34:31 pm »

Okay, that's good. I hope that he did solve the problem. I think that I may have been asking about post-initialization assignments for Ai and Aii (alleles) and then the further assignment of the phenotypes from that. But, if the problem is fixed then you'll have no need to post up the allelePop class ^_^. If structs do act as classes then you could very well just add in some default initial values for the genes and then mostly skip the initializeWholeThing() since it would just be setting default values to default values. Unless it gets called during repopulation, in that case it will probably still be needed :P
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2442 on: May 20, 2012, 12:16:08 am »

The only difference between structs and classes with most modern C++ compilers is that structs have a default access level of public. Therefore, the following two snippets of code are essentially identical:

Code: [Select]
struct foo {
    int bar;
    int getBar() { return bar; }
};

Code: [Select]
class foo {
public:
    int bar;
    int getBar() { return bar; }
};

That's it. Even in warning messages, 'struct' and 'class' are used interchangeably. For example, std::string is a struct according to g++.

Blargityblarg

  • Bay Watcher
  • rolypolyrolypolyrolypoly
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2443 on: May 20, 2012, 01:50:35 am »

Code: [Select]
public boolean addCityToCountry(City newCity, int countryIndex){
if(newCity!= null && countryIndex >= 0 && countryIndex < numCountries){
countries[countryIndex].addCity(newCity);
return true;
} else {
return false;
}
}

Still having the same issue after coding this method and using to to add the cities to the countries after adding the countries to the world.

E:Assignment was overdue anyway, handed it in with a .txt file explaining the issue and asking to be marked on my actual code, rather than whatever the bug or oversight was.
« Last Edit: May 20, 2012, 04:34:27 am by Blargityblarg »
Logged
Blossom of orange
Shit, nothing rhymes with orange
Wait, haikus don't rhyme

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2444 on: May 20, 2012, 04:33:33 am »

Are you using regular ol' arrays to store your data? If so, that's your problem. Use a list or vector or something.

Arrays are pointers, and don't copy well when used as class/struct attributes. Avoid using arrays at all, unless you have good knowledge about pointers and a very good reason to use them over the generic data storage classes.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.
Pages: 1 ... 161 162 [163] 164 165 ... 796