Velocity Reviews > C++ > Logic question...

# Logic question...

JoeC
Guest
Posts: n/a

 09-04-2006
I am writing a game and I am having a challenge with my combat
function. All I want to do is find out how to group pieces that are in
the same space. There are two sides and all the units that are in the
same space fight. I want to add up the attack factors and defending
factors in the same space then figure out the odds so I can roll
against an odds table. Basically each piece holds its own x and y loc.

Here is what I have right now:

void fight(vector<unit>& at, vector<unit>& dt,
board * b , terrain * trn ){

vector<fightclass> fighting;

/* adds attacking units to the fightclass vector if units are in the
same space they are to grouped in the same fight class elemet of
the
vector. */

for(int atu = 0; atu != at.size(); atu++){
if(fighting.size() == 0){
fightclass ft;
fighting.push_back(ft);
} else {
for(int lp = 0; lp != fighting.size(); lp++){
if(at[atu].getXloc() != fighting[lp].getX() &&
at[atu].getYloc() != fighting[lp].getY()){
fightclass ft;
fighting.push_back(ft);
} else {
}
}
}
}
/* Adds defending units to the fightclass array. If x and y locs are
the same as attacking locations (are in the same space) they are
added to array for combat */

for(int dtu = 0; dtu != dt.size(); dtu++){
for(int lp = 0; lp != fighting.size(); lp++){
if(dt[dtu].getXloc() == fighting[lp].getX() &&
dt[dtu].getYloc() == fighting[lp].getY()){
}
}
}

// Combat routine

for(int lp = 0; lp != fighting.size(); lp++){ //handles combat
if(fighting[lp].canfight()){
int df = b->GetSpace(fighting[lp].getX(), fighting[lp].getY());
float odds =
fighting[lp].getAtk()/fighting[lp].getDef();
//gets the defense bonus for the terrain in the space where
//combat takes place
int roll = rand() - trn[df].defend();
//get the die roll modified for terrain
odds = fighting[lp].getAtk() / fighting[lp].getDef();
//gets the attack to defence ratio.
if(odds < .5){
MessageBox(NULL, "Fighting! 1:3", "Info!", MB_OK);
return;
}
if(odds < 1){
MessageBox(NULL, "Fighting! 1:2", "Info!", MB_OK);
return;
}
if(odds < 2){
MessageBox(NULL, "Fighting! 1:1", "Info!", MB_OK);
return;
}
if(odds < 3){
MessageBox(NULL, "Fighting! 2:1", "Info!", MB_OK);
return;
}
if(odds < 4){
MessageBox(NULL, "Fighting! 3:1", "Info!", MB_OK);
return;
}
if(odds < 5){
MessageBox(NULL, "Fighting! 4:1", "Info!", MB_OK);
return;
}
if(odds < 6){
MessageBox(NULL, "Fighting! 5:1", "Info!", MB_OK);
return;
}

}
}
for(int lp = 0; lp != fighting.size(); lp++){
fighting[lp].done();
}
fighting.clear();
}

class fightclass{
/* Fightclass holds two arrays of units. The two arrays represent
units
in the same space elgible for combat. Array at represents the
attacking
forces and dt represents the defending units */

int xl;
int yl;

bool sides2; /* indicates if there are units in both attack and
defend
if there are units in both attack and defend then
combat
is to take place between the opposing sides. */

vector<unit>at; //attack units
vector<unit>dt; //defending units

public:
fightclass();
int getX(){return xl;} //return the x coord
int getY(){return yl;} //returns the y coord
float getAtk(); //returns the total attack factors for one space
float getDef(); //returns the total defending factors for one space
bool canfight(); //if there are both attacking and defending units
void done(); //clears vectores after the turn

};

fightclass::fightclass(){
xl = 0;
yl = 0;
}

at.push_back(u);
xl = u.getXloc();
yl = u.getYloc();

}

dt.push_back(u);

}

bool fightclass::canfight(){
if(at.size() && dt.size()){
return true;
}else {return false;}
}

float fightclass::getAtk(){
float total;
for(int lp = 0; lp != at.size(); lp++){
total +=at[lp].getAttack();
}
}

I know the logic is not the best but it is the best I can do. This is
tricky and I am pretty confused. I would like to find some way of
making the logic steps easier. There may be some simple error that I
overlooked or it can be totally screwed up.

Moonlit
Guest
Posts: n/a

 09-04-2006
Hi,

comp.games.development.programming is probably more appropiate for this
question.

--

Regards, Ron AF Greve

http://moonlit.xs4all.nl

"JoeC" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I am writing a game and I am having a challenge with my combat
> function. All I want to do is find out how to group pieces that are in
> the same space. There are two sides and all the units that are in the
> same space fight. I want to add up the attack factors and defending
> factors in the same space then figure out the odds so I can roll
> against an odds table. Basically each piece holds its own x and y loc.
>
>
> Here is what I have right now:
>
> void fight(vector<unit>& at, vector<unit>& dt,
> board * b , terrain * trn ){
>
> vector<fightclass> fighting;
>
> /* adds attacking units to the fightclass vector if units are in the
> same space they are to grouped in the same fight class elemet of
> the
> vector. */
>
> for(int atu = 0; atu != at.size(); atu++){
> if(fighting.size() == 0){
> fightclass ft;
> fighting.push_back(ft);
> } else {
> for(int lp = 0; lp != fighting.size(); lp++){
> if(at[atu].getXloc() != fighting[lp].getX() &&
> at[atu].getYloc() != fighting[lp].getY()){
> fightclass ft;
> fighting.push_back(ft);
> } else {
> }
> }
> }
> }
> /* Adds defending units to the fightclass array. If x and y locs are
> the same as attacking locations (are in the same space) they are
> added to array for combat */
>
> for(int dtu = 0; dtu != dt.size(); dtu++){
> for(int lp = 0; lp != fighting.size(); lp++){
> if(dt[dtu].getXloc() == fighting[lp].getX() &&
> dt[dtu].getYloc() == fighting[lp].getY()){
> }
> }
> }
>
> // Combat routine
>
> for(int lp = 0; lp != fighting.size(); lp++){ //handles combat
> if(fighting[lp].canfight()){
> int df = b->GetSpace(fighting[lp].getX(), fighting[lp].getY());
> float odds =
> fighting[lp].getAtk()/fighting[lp].getDef();
> //gets the defense bonus for the terrain in the space where
> //combat takes place
> int roll = rand() - trn[df].defend();
> //get the die roll modified for terrain
> odds = fighting[lp].getAtk() / fighting[lp].getDef();
> //gets the attack to defence ratio.
> if(odds < .5){
> MessageBox(NULL, "Fighting! 1:3", "Info!", MB_OK);
> return;
> }
> if(odds < 1){
> MessageBox(NULL, "Fighting! 1:2", "Info!", MB_OK);
> return;
> }
> if(odds < 2){
> MessageBox(NULL, "Fighting! 1:1", "Info!", MB_OK);
> return;
> }
> if(odds < 3){
> MessageBox(NULL, "Fighting! 2:1", "Info!", MB_OK);
> return;
> }
> if(odds < 4){
> MessageBox(NULL, "Fighting! 3:1", "Info!", MB_OK);
> return;
> }
> if(odds < 5){
> MessageBox(NULL, "Fighting! 4:1", "Info!", MB_OK);
> return;
> }
> if(odds < 6){
> MessageBox(NULL, "Fighting! 5:1", "Info!", MB_OK);
> return;
> }
>
> }
> }
> for(int lp = 0; lp != fighting.size(); lp++){
> fighting[lp].done();
> }
> fighting.clear();
> }
>
> class fightclass{
> /* Fightclass holds two arrays of units. The two arrays represent
> units
> in the same space elgible for combat. Array at represents the
> attacking
> forces and dt represents the defending units */
>
>
> int xl;
> int yl;
>
> bool sides2; /* indicates if there are units in both attack and
> defend
> if there are units in both attack and defend then
> combat
> is to take place between the opposing sides. */
>
> vector<unit>at; //attack units
> vector<unit>dt; //defending units
>
> public:
> fightclass();
> int getX(){return xl;} //return the x coord
> int getY(){return yl;} //returns the y coord
> float getAtk(); //returns the total attack factors for one space
> float getDef(); //returns the total defending factors for one space
> bool canfight(); //if there are both attacking and defending units
> void done(); //clears vectores after the turn
>
> };
>
> fightclass::fightclass(){
> xl = 0;
> yl = 0;
> }
>
> at.push_back(u);
> xl = u.getXloc();
> yl = u.getYloc();
>
> }
>
>
> dt.push_back(u);
>
> }
>
> bool fightclass::canfight(){
> if(at.size() && dt.size()){
> return true;
> }else {return false;}
> }
>
> float fightclass::getAtk(){
> float total;
> for(int lp = 0; lp != at.size(); lp++){
> total +=at[lp].getAttack();
> }
> }
>
> I know the logic is not the best but it is the best I can do. This is
> tricky and I am pretty confused. I would like to find some way of
> making the logic steps easier. There may be some simple error that I
> overlooked or it can be totally screwed up.
>

JoeC
Guest
Posts: n/a

 09-04-2006

Thanks, I didn't know about that group. I will ask the question there.
Still it is programming and I am trying to learn programming by
programming games.

Jerry Coffin
Guest
Posts: n/a

 09-04-2006
In article <(E-Mail Removed) .com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) says...

[ ... ]

> void fight(vector<unit>& at, vector<unit>& dt,
> board * b , terrain * trn ){
>
> vector<fightclass> fighting;
>
> /* adds attacking units to the fightclass vector if units are in the
> same space they are to grouped in the same fight class elemet of
> the
> vector. */
>
> for(int atu = 0; atu != at.size(); atu++){
> if(fighting.size() == 0){

A minor detail, but this is better written as:
if (fighting.empty()) {
Given that this is a vector, it probably doesn't make any difference,
but IMO, it's still worth doing.

> fightclass ft;
> fighting.push_back(ft);
> } else {
> for(int lp = 0; lp != fighting.size(); lp++){

Looking just at the tiny bit starting here:

> if(at[atu].getXloc() != fighting[lp].getX() &&
> at[atu].getYloc() != fighting[lp].getY()){

I see what looks like an opportunity for a bit of improvement: create a
class (or struct) to represent a position, and then use it wherever you
have positions. In that case, this would become:
if (at[atu].pos == fighting[lp].pos)
// do whatever

I'd also attempt to use consistent naming -- whether you decide on
'pos' or 'position' or 'location' or 'coordinate' or whatever, attempt
to use the same name everywhere you have to deal with that kind of
thing. In the code above, you've got getXloc and getX, both apparently
doing the same kind of thing. While it's obvious after the fact that
both do the same kinds of things, when you're writing code, it's nice if
you can guess ahead of time what the name of a member is going to be
instead of having to check every time whether it's location, position,
etc. in this particular case.

> fightclass ft;
> fighting.push_back(ft);

In this case, the 'whatever' part can be simplified a bit as well. I'd
create a fightclass ctor that takes a unit as its argument, so it
creates a fightclass object with a single attacking unit, and then use
it here:
fighting.push_back(fightclass(at[atu]));

> } else {
> }
> }
> }
> }

At least if I'm reading the intent correctly, I'd consider this much
enough for one function, though the function might include the following
chunk as well:

> /* Adds defending units to the fightclass array. If x and y locs are
> the same as attacking locations (are in the same space) they are
> added to array for combat */
>
> for(int dtu = 0; dtu != dt.size(); dtu++){
> for(int lp = 0; lp != fighting.size(); lp++){
> if(dt[dtu].getXloc() == fighting[lp].getX() &&
> dt[dtu].getYloc() == fighting[lp].getY()){
> }
> }
> }

Down to here. To implement the logic as I understand it, I'd make it two
functions, but to implement the logic I think you really want, I'd make
it one. See comments below for more on that.

> // Combat routine
>
> for(int lp = 0; lp != fighting.size(); lp++){ //handles combat

Starting from here:

> if(fighting[lp].canfight()){
> int df = b->GetSpace(fighting[lp].getX(), fighting[lp].getY());
> float odds =
> fighting[lp].getAtk()/fighting[lp].getDef();
> //gets the defense bonus for the terrain in the space where
> //combat takes place
> int roll = rand() - trn[df].defend();
> //get the die roll modified for terrain
> odds = fighting[lp].getAtk() / fighting[lp].getDef();
> //gets the attack to defence ratio.

.... and going down to here probably deserves to be yet another function.

> if(odds < .5){
> MessageBox(NULL, "Fighting! 1:3", "Info!", MB_OK);
> return;
> }
> if(odds < 1){
> MessageBox(NULL, "Fighting! 1:2", "Info!", MB_OK);
> return;
> }
> if(odds < 2){
> MessageBox(NULL, "Fighting! 1:1", "Info!", MB_OK);
> return;
> }
> if(odds < 3){
> MessageBox(NULL, "Fighting! 2:1", "Info!", MB_OK);
> return;
> }
> if(odds < 4){
> MessageBox(NULL, "Fighting! 3:1", "Info!", MB_OK);
> return;
> }
> if(odds < 5){
> MessageBox(NULL, "Fighting! 4:1", "Info!", MB_OK);
> return;
> }
> if(odds < 6){
> MessageBox(NULL, "Fighting! 5:1", "Info!", MB_OK);
> return;
> }

This chunk probably also deserves to be a function -- but I'd write it a
bit differently, something like:

void show_odds(double odds) {
//
// For the moment I'm assuming that odds is always in the range 0..6.
// For the moment, I've cheated, and conflated 1:3 and 1:2 together into
// "outnumbered".
//
static char *strings[] = {
"Outnumbered", "1:1", "2:1", "3:1", "4:1", "5:1"};

string output("Fighting! ");
output += strings[(int)odds];
MessageBox(NULL, output, "Info!", MB_OK);
}

The following is meant primarily as pseudo-code, not really C++. Chances
are that I've left out a few things that really need to be there (like
the calls to fightclass::done). Still, adding things like that shouldn't
be too horrible.

void fight(vector<unit> &at, vector<unit> &dt, board *b, terrain *trn)
{
vector<fightclass> fighting;

std::back_inserter(fighting));

std::back_inserter(fighting));

std::vector<double> odds_values(fighting.size());

std::transform(fighting.begin(), fighting.end(),
odds_values.begin(), bind1st(figure_odds, trn));

std::for_each(odd_values.begin(), odds_values.end(), show_odds);
}

For the moment, I've used your function signature, but chances are
pretty good that (for example) all the parameters should refer to const
values. Perhaps the attacking/defending forces can be killed so those
vectors can be modified, but it's almost certain that the board and
probably terrain as well shouldn't be changed -- unless you're getting a
lot more sophisticated than most, and taking into account things like
artillery changing the terrain slightly.

At least as I undertand the idea here, I'd probably also change the
basic algorithm a bit. Unless I'm misreadin it, right now you're adding
a fightclass object to the fighting vector for every attacking unit,
whether there's a defending unit at the same position or not. Then
you're adding defending units everywhere there are attacking units. I
believe your real intent is that units only fight each other where
they're at the same location, so you really want an intersection of the
two -- i.e. a set of fight objects representing those places there's
both an attacker and a defender in the same place.

If that's the case, I'd consider doing things a bit differently. One
possibility would be to keep each force in a multiset, with the units
sorted by position. To move a unit, you remove it from the multiset, and
then insert it back in at the new position. In this case, finding the
intersection between two forces (i.e. the units they have in the same
positions) might be as simple as a single call to std:set_intersection.

I'm not at all sure why board and/or terrain is a pointer either -- it
appears these could be references to vectors, or something on that
order. For the moment, I'm leaving the alone, but I suspect some
reexamination of this point might be worthwhile.

Applying those comments, we could end up with a function something like:

void fight(multiset<unit> const &at, // attacking units
multiset<unit> const &dt, // defending units
board const *b,
terrain const *trn)
{
vector<fightclass> fighting;

find_fighting_units(at.begin(), at.end(),
dt.begin(), dt.end(),
std::back_inserter(fighting));

vector<double> odds_values(fighting.size());

transform(fighting.begin(), fighting.end(),
odds_values.begin(), bind1st(figure_odds, trn));

for_each(odd_values.begin(), odds_values.end(), show_odds);
}

Though it's more or less off-topic, it also seems like using MessageBox
for showing the odds is a poor idea -- if there are many intersections
between the forces, the user is going to have to click through a lot of
boxes, and as soon as he clicks OK on one, he loses that information, so
it's hard for him to any kind of overall picture.

--
Later,
Jerry.

The universe is a figment of its own imagination.

JoeC
Guest
Posts: n/a

 09-05-2006
Thank...

Jerry Coffin wrote:
> In article <(E-Mail Removed) .com>,
> (E-Mail Removed) says...
>
> [ ... ]
>
> > void fight(vector<unit>& at, vector<unit>& dt,
> > board * b , terrain * trn ){
> >
> > vector<fightclass> fighting;
> >
> > /* adds attacking units to the fightclass vector if units are in the
> > same space they are to grouped in the same fight class elemet of
> > the
> > vector. */
> >
> > for(int atu = 0; atu != at.size(); atu++){
> > if(fighting.size() == 0){

>
> A minor detail, but this is better written as:
> if (fighting.empty()) {
> Given that this is a vector, it probably doesn't make any difference,
> but IMO, it's still worth doing.

Thanks fixed that one.

>
> > fightclass ft;
> > fighting.push_back(ft);
> > } else {
> > for(int lp = 0; lp != fighting.size(); lp++){

>
> Looking just at the tiny bit starting here:
>
> > if(at[atu].getXloc() != fighting[lp].getX() &&
> > at[atu].getYloc() != fighting[lp].getY()){

>
> I see what looks like an opportunity for a bit of improvement: create a
> class (or struct) to represent a position, and then use it wherever you
> have positions. In that case, this would become:
> if (at[atu].pos == fighting[lp].pos)
> // do whatever
>

I have been considering that.

> I'd also attempt to use consistent naming -- whether you decide on
> 'pos' or 'position' or 'location' or 'coordinate' or whatever, attempt
> to use the same name everywhere you have to deal with that kind of
> thing. In the code above, you've got getXloc and getX, both apparently
> doing the same kind of thing. While it's obvious after the fact that
> both do the same kinds of things, when you're writing code, it's nice if
> you can guess ahead of time what the name of a member is going to be
> instead of having to check every time whether it's location, position,
> etc. in this particular case.

That is true. Naming conventions are important. I just wrote this
program at different times where some objects left over from older
projects.
>
> > fightclass ft;
> > fighting.push_back(ft);

>
> In this case, the 'whatever' part can be simplified a bit as well. I'd
> create a fightclass ctor that takes a unit as its argument, so it
> creates a fightclass object with a single attacking unit, and then use
> it here:
> fighting.push_back(fightclass(at[atu]));
>
> > } else {
> > }
> > }
> > }
> > }

Intersting, I will have to look into that one. There are times I don't
do that because it is easier for me to read. But yes, it is a good
idea.
>
> At least if I'm reading the intent correctly, I'd consider this much
> enough for one function, though the function might include the following
> chunk as well:
>
> > /* Adds defending units to the fightclass array. If x and y locs are
> > the same as attacking locations (are in the same space) they are
> > added to array for combat */
> >
> > for(int dtu = 0; dtu != dt.size(); dtu++){
> > for(int lp = 0; lp != fighting.size(); lp++){
> > if(dt[dtu].getXloc() == fighting[lp].getX() &&
> > dt[dtu].getYloc() == fighting[lp].getY()){
> > }
> > }
> > }

>
> Down to here. To implement the logic as I understand it, I'd make it two
> functions, but to implement the logic I think you really want, I'd make
> it one. See comments below for more on that.

OK that was the intent of writing this. I couldn't figure out how to
condense this to functions.

>
> > // Combat routine
> >
> > for(int lp = 0; lp != fighting.size(); lp++){ //handles combat

>
> Starting from here:
>
> > if(fighting[lp].canfight()){
> > int df = b->GetSpace(fighting[lp].getX(), fighting[lp].getY());
> > float odds =
> > fighting[lp].getAtk()/fighting[lp].getDef();
> > //gets the defense bonus for the terrain in the space where
> > //combat takes place
> > int roll = rand() - trn[df].defend();
> > //get the die roll modified for terrain
> > odds = fighting[lp].getAtk() / fighting[lp].getDef();
> > //gets the attack to defence ratio.

>
> ... and going down to here probably deserves to be yet another function.
>
> > if(odds < .5){
> > MessageBox(NULL, "Fighting! 1:3", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 1){
> > MessageBox(NULL, "Fighting! 1:2", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 2){
> > MessageBox(NULL, "Fighting! 1:1", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 3){
> > MessageBox(NULL, "Fighting! 2:1", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 4){
> > MessageBox(NULL, "Fighting! 3:1", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 5){
> > MessageBox(NULL, "Fighting! 4:1", "Info!", MB_OK);
> > return;
> > }
> > if(odds < 6){
> > MessageBox(NULL, "Fighting! 5:1", "Info!", MB_OK);
> > return;
> > }

>
> This chunk probably also deserves to be a function -- but I'd write it a
> bit differently, something like:

This is all experiemtal. I am not sure how to implenmt an odds table.
All this is just test to see if the prvious code worked. What I want
to do is implemnt an odds table

1:3 1:2 1:1 2:1 3:1 4:1 5:1
4 ae ae ad dd dd de de
5 ae dd dd dd ad de de

ae =attacker eliminated
dd = defebder dispersed
de = defender eliminated
>
> void show_odds(double odds) {
> //
> // For the moment I'm assuming that odds is always in the range 0..6.
> // For the moment, I've cheated, and conflated 1:3 and 1:2 together into
> // "outnumbered".
> //
> static char *strings[] = {
> "Outnumbered", "1:1", "2:1", "3:1", "4:1", "5:1"};
>
> string output("Fighting! ");
> output += strings[(int)odds];
> MessageBox(NULL, output, "Info!", MB_OK);
> }

I have to lower odds for when I expand the game.

>
> The following is meant primarily as pseudo-code, not really C++. Chances
> are that I've left out a few things that really need to be there (like
> the calls to fightclass::done). Still, adding things like that shouldn't
> be too horrible.
>
> void fight(vector<unit> &at, vector<unit> &dt, board *b, terrain *trn)
> {
> vector<fightclass> fighting;
>
> std::back_inserter(fighting));
>
> std::back_inserter(fighting));
>
> std::vector<double> odds_values(fighting.size());
>
> std::transform(fighting.begin(), fighting.end(),
> odds_values.begin(), bind1st(figure_odds, trn));
>
> std::for_each(odd_values.begin(), odds_values.end(), show_odds);
> }
>
> For the moment, I've used your function signature, but chances are
> pretty good that (for example) all the parameters should refer to const
> values. Perhaps the attacking/defending forces can be killed so those
> vectors can be modified, but it's almost certain that the board and
> probably terrain as well shouldn't be changed -- unless you're getting a
> lot more sophisticated than most, and taking into account things like
> artillery changing the terrain slightly.

I can see the differences from my code and can see the weakness of my
programming. I am not fimilliar with this kind of programming. Are
these algorithms? I am a bit confused and would have not come up with
this. Are there smaller experiment programs I can write to better
understand how to do things like that?
>
> At least as I undertand the idea here, I'd probably also change the
> basic algorithm a bit. Unless I'm misreadin it, right now you're adding
> a fightclass object to the fighting vector for every attacking unit,
> whether there's a defending unit at the same position or not. Then
> you're adding defending units everywhere there are attacking units. I
> believe your real intent is that units only fight each other where
> they're at the same location, so you really want an intersection of the
> two -- i.e. a set of fight objects representing those places there's
> both an attacker and a defender in the same place.

Yes, I just couldn't figure out how to do that. I simply want units in
the same space to add up attack factors then add up defedning factors
then have them fight. I put each attaking unit in some vector. Then
see it they were in the same locations as other units. Then I went to
the defending units and compared them with the other array and if they
are in the same location, put them together int he fightclass.
>
> If that's the case, I'd consider doing things a bit differently. One
> possibility would be to keep each force in a multiset, with the units
> sorted by position. To move a unit, you remove it from the multiset, and
> then insert it back in at the new position. In this case, finding the
> intersection between two forces (i.e. the units they have in the same
> positions) might be as simple as a single call to std:set_intersection.

Again, I am not a very good programmer and not awaire of many of these
techniques. I wrote a dungeon program where my map was an array of
spaces that could hole the graphic for the space, the character then
potentially other things. That became overly complex and difficult to
remove the player from one space then putting it in aother. Just
having the units hold its own location then have them display themselvs
is much simpler but grouping them togert for fighting is a real
challenge.
>
> I'm not at all sure why board and/or terrain is a pointer either -- it
> appears these could be references to vectors, or something on that
> order. For the moment, I'm leaving the alone, but I suspect some
> reexamination of this point might be worthwhile.
>

I don't need vectors because they don't change in size. I made them
pointers because I want to create them in one file then use them in
another. It is ieasier to pass them to functions than regular arrays.

Still I am going to save this post in hopes that I can improve how I

> Applying those comments, we could end up with a function something like:
>
> void fight(multiset<unit> const &at, // attacking units
> multiset<unit> const &dt, // defending units
> board const *b,
> terrain const *trn)
> {
> vector<fightclass> fighting;
>
> find_fighting_units(at.begin(), at.end(),
> dt.begin(), dt.end(),
> std::back_inserter(fighting));
>
> vector<double> odds_values(fighting.size());
>
> transform(fighting.begin(), fighting.end(),
> odds_values.begin(), bind1st(figure_odds, trn));
>
> for_each(odd_values.begin(), odds_values.end(), show_odds);
> }
>
> Though it's more or less off-topic, it also seems like using MessageBox
> for showing the odds is a poor idea -- if there are many intersections
> between the forces, the user is going to have to click through a lot of
> boxes, and as soon as he clicks OK on one, he loses that information, so
> it's hard for him to any kind of overall picture.
>
> --
> Later,
> Jerry.
>
> The universe is a figment of its own imagination.

Bart
Guest
Posts: n/a

 09-05-2006
Moonlit wrote:
> comp.games.development.programming is probably more appropiate for this
> question.

Why? His question was more or less about program logic, using mostly
standard C++ (save for one function). That's more on-topic than many
other posts here.

Regards,
Bart.

Phlip
Guest
Posts: n/a

 09-05-2006
Bart wrote:

> Moonlit wrote:

>> comp.games.development.programming is probably more appropiate for this
>> question.

>
> Why? His question was more or less about program logic, using mostly
> standard C++ (save for one function). That's more on-topic than many
> other posts here.

Only the OP should guess which group will provide the best answer.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

Nathan Mates
Guest
Posts: n/a

 09-05-2006
In article <BUkLg.1693\$(E-Mail Removed)>,
Phlip <(E-Mail Removed)> wrote:
>Only the OP should guess which group will provide the best answer.

Posters are entitled to guess, true. But, correcting guesses is the
job of newsgroup regulars, and prefectly reasonable.

Nathan Mates
--
<*> Nathan Mates - personal webpage http://www.visi.com/~nathan/
# Programmer at Pandemic Studios -- http://www.pandemicstudios.com/
# NOT speaking for Pandemic Studios. "Care not what the neighbors
# think. What are the facts, and to how many decimal places?" -R.A. Heinlein

Phlip
Guest
Posts: n/a

 09-05-2006
Nathan Mates wrote:

>>Only the OP should guess which group will provide the best answer.

>
> Posters are entitled to guess, true. But, correcting guesses is the
> job of newsgroup regulars, and prefectly reasonable.

The only topicality criteria relevant to a questioner is what newsgroup will
provide the best question. Once we suggestion one, we can no longer declare
whether an equally topical question belongs here or there. That was the
context.

When you offer another newsgroup, always reinforce that topicality is in the
poster's best interests. The answer "your question is off topic here go
away" doesn't increase the odds of useful participation.

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

Phlip
Guest
Posts: n/a

 09-05-2006
Phlip wrote:

> The only topicality criteria relevant to a questioner is what newsgroup
> will provide the best question.

you know...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!