473,915 Members | 5,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Logic question...

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<un it>& at, vector<unit>& dt,
board * b , terrain * trn ){

vector<fightcla ssfighting;

/* 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.siz e() == 0){
fightclass ft;
ft.addAu(at[atu]);
fighting.push_b ack(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;
ft.addAu(at[atu]);
fighting.push_b ack(ft);
} else {
fighting[lp].addAu(at[atu]);
}
}
}
}
/* 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()){
fighting[lp].addDu(dt[dtu]);
}
}
}

// Combat routine

for(int lp = 0; lp != fighting.size() ; lp++){ //handles combat
if(fighting[lp].canfight()){
int df = b->GetSpace(fight ing[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();
void addAu(unit au); //adds an addacking unit
void addDu(unit du); //adds a defending unit
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::fig htclass(){
xl = 0;
yl = 0;
}

void fightclass::add Au(unit u){
at.push_back(u) ;
xl = u.getXloc();
yl = u.getYloc();

}

void fightclass::add Du(unit u){

dt.push_back(u) ;

}

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

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

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.

Sep 4 '06 #1
73 4351
Hi,

comp.games.deve lopment.program ming is probably more appropiate for this
question.

--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"JoeC" <en*****@yahoo. comwrote in message
news:11******** **************@ p79g2000cwp.goo glegroups.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<un it>& at, vector<unit>& dt,
board * b , terrain * trn ){

vector<fightcla ssfighting;

/* 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.siz e() == 0){
fightclass ft;
ft.addAu(at[atu]);
fighting.push_b ack(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;
ft.addAu(at[atu]);
fighting.push_b ack(ft);
} else {
fighting[lp].addAu(at[atu]);
}
}
}
}
/* 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()){
fighting[lp].addDu(dt[dtu]);
}
}
}

// Combat routine

for(int lp = 0; lp != fighting.size() ; lp++){ //handles combat
if(fighting[lp].canfight()){
int df = b->GetSpace(fight ing[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();
void addAu(unit au); //adds an addacking unit
void addDu(unit du); //adds a defending unit
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::fig htclass(){
xl = 0;
yl = 0;
}

void fightclass::add Au(unit u){
at.push_back(u) ;
xl = u.getXloc();
yl = u.getYloc();

}

void fightclass::add Du(unit u){

dt.push_back(u) ;

}

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

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

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.

Sep 4 '06 #2

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.

Sep 4 '06 #3
In article <11************ **********@p79g 2000cwp.googleg roups.com>,
en*****@yahoo.c om says...

[ ... ]
void fight(vector<un it>& at, vector<unit>& dt,
board * b , terrain * trn ){

vector<fightcla ssfighting;

/* 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.siz e() == 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;
ft.addAu(at[atu]);
fighting.push_b ack(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;
ft.addAu(at[atu]);
fighting.push_b ack(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_b ack(fightclass( at[atu]));
} else {
fighting[lp].addAu(at[atu]);
}
}
}
}
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()){
fighting[lp].addDu(dt[dtu]);
}
}
}
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(fight ing[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(doubl e 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
// "outnumbere d".
//
static char *strings[] = {
"Outnumbere d", "1:1", "2:1", "3:1", "4:1", "5:1"};

string output("Fightin g! ");
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::don e). Still, adding things like that shouldn't
be too horrible.

void fight(vector<un it&at, vector<unit&dt, board *b, terrain *trn)
{
vector<fightcla ssfighting;

add_attacking_u nits(at.begin() , at.end(),
std::back_inser ter(fighting));

add_defending_u nits(dt.begin() , dt.end(),
std::back_inser ter(fighting));

std::vector<dou bleodds_values( fighting.size() );

std::transform( fighting.begin( ), fighting.end(),
odds_values.beg in(), bind1st(figure_ odds, trn));

std::for_each(o dd_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_interse ction.

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< unitconst &at, // attacking units
multiset<unitco nst &dt, // defending units
board const *b,
terrain const *trn)
{
vector<fightcla ssfighting;

find_fighting_u nits(at.begin() , at.end(),
dt.begin(), dt.end(),
std::back_inser ter(fighting));

vector<doubleod ds_values(fight ing.size());

transform(fight ing.begin(), fighting.end(),
odds_values.beg in(), bind1st(figure_ odds, trn));

for_each(odd_va lues.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.
Sep 4 '06 #4
Thank...
Jerry Coffin wrote:
In article <11************ **********@p79g 2000cwp.googleg roups.com>,
en*****@yahoo.c om says...

[ ... ]
void fight(vector<un it>& at, vector<unit>& dt,
board * b , terrain * trn ){

vector<fightcla ssfighting;

/* 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.siz e() == 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;
ft.addAu(at[atu]);
fighting.push_b ack(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;
ft.addAu(at[atu]);
fighting.push_b ack(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_b ack(fightclass( at[atu]));
} else {
fighting[lp].addAu(at[atu]);
}
}
}
}
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()){
fighting[lp].addDu(dt[dtu]);
}
}
}

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(fight ing[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
0 ae ae ae ae ae ad ad
1 ae ae ae ae ad ad dd
2 ae ae ae ad ad dd dd
3 ae ae ad ad dd dd de
4 ae ae ad dd dd de de
5 ae dd dd dd ad de de

ae =attacker eliminated
ad = attacker dispersed
dd = defebder dispersed
de = defender eliminated
>
void show_odds(doubl e 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
// "outnumbere d".
//
static char *strings[] = {
"Outnumbere d", "1:1", "2:1", "3:1", "4:1", "5:1"};

string output("Fightin g! ");
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::don e). Still, adding things like that shouldn't
be too horrible.

void fight(vector<un it&at, vector<unit&dt, board *b, terrain *trn)
{
vector<fightcla ssfighting;

add_attacking_u nits(at.begin() , at.end(),
std::back_inser ter(fighting));

add_defending_u nits(dt.begin() , dt.end(),
std::back_inser ter(fighting));

std::vector<dou bleodds_values( fighting.size() );

std::transform( fighting.begin( ), fighting.end(),
odds_values.beg in(), bind1st(figure_ odds, trn));

std::for_each(o dd_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_interse ction.
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
add
Applying those comments, we could end up with a function something like:

void fight(multiset< unitconst &at, // attacking units
multiset<unitco nst &dt, // defending units
board const *b,
terrain const *trn)
{
vector<fightcla ssfighting;

find_fighting_u nits(at.begin() , at.end(),
dt.begin(), dt.end(),
std::back_inser ter(fighting));

vector<doubleod ds_values(fight ing.size());

transform(fight ing.begin(), fighting.end(),
odds_values.beg in(), bind1st(figure_ odds, trn));

for_each(odd_va lues.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.
Sep 5 '06 #5
Moonlit wrote:
comp.games.deve lopment.program ming 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.

Sep 5 '06 #6
Bart wrote:
Moonlit wrote:
>comp.games.dev elopment.progra mming 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!!!
Sep 5 '06 #7
In article <BU************ ****@newssvr25. news.prodigy.ne t>,
Phlip <ph******@yahoo .comwrote:
>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
Sep 5 '06 #8
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!!!
Sep 5 '06 #9
Phlip wrote:
The only topicality criteria relevant to a questioner is what newsgroup
will provide the best question.
answer.

you know...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Sep 5 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

60
7341
by: Fotios | last post by:
Hi guys, I have put together a flexible client-side user agent detector (written in js). I thought that some of you may find it useful. Code is here: http://fotios.cc/software/ua_detect.htm The detector requires javascript 1.0 to work. This translates to netscape 2.0 and IE 3.0 (although maybe IE 2.0 also works with it)
6
1574
by: Ted Singh | last post by:
(I apologize in advance if this is an obvious question, my experience is more with console or client-only apps) I am trying to build an web-based HTML UI, which will work with a web-server on the same machine (i.e., http://localhost/...). However, I do not want the logic source to be visible to the user to prevent customer support problems, intellectual property issues, etc. The requirements strictly call for a web-based UI running...
0
1911
by: Tony Johansson | last post by:
Hello Experts! I reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that sound strange. "Exception are divided into logic errors and runtime errors. Logic errors represent static errors that can be prevented and detected at compile time. Runtime errors represent dynamic errors that can be detected only at runtime."
2
1512
by: Simon Harvey | last post by:
Hi all, I was wondering how most developers handle the initial startup of their Windows Forms applications? When you make an application in Visual Studio, the IDE places Main in the form that VS makes for you. When I make my applications I sometimes feel uneasy about leaving the startup logic in the Form - it sort of seems the wrong place for it. I'm by no means an expert on such things (which is why I'm writing this post), but it...
3
1532
by: mca | last post by:
Hi everyone, I'm new to asp.net and i have a question about separating the html code from the programming code. i have an unknown numbers of entries in my table. I want to make a hyperlink for every entry in my table. So i query the database and get for example 3 entries back. So in a while loop i can make 3 hyperlinks with response.write(.......) etc.
24
14429
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate phone numbers, and emails and addresses even person names. I need to sift through all this data (roughly 300,000+ records and use fuzzy logic to break it down, so that i have only unique records.
6
2015
by: Simon Harvey | last post by:
Hi everyone, We have a need to make a Windows Forms (2.0) client application that will be installed on our clients site. The data that the application uses needs to be centrally available to a potentially large number of other sites, which would seem to leave us with our traditional approach, or having a central database server on a dedicated server someplace.
14
3584
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an internal intranet application rewrite. This approach will definitely stir up hot debate from hardcore server-side Java folks who wants to do UI stuff even on the server!. Since I am pretty much known as the JS or UI Guy of the group, my Boss...
29
2244
by: Brad Pears | last post by:
Here is a simple OO design question... I have a Contract class. The user can either save an existing contract or they start off fresh with a blank contract, fill in the data and then save a "new" contract. I have a method in my contract class called "Save" which is called like this... dim oContract as new Contract
15
2453
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic, not to remove logic from presentation (which just couldn't work). Templating systems are for presentation logic. Whether they work by embedding an existing complete programmation language or by providing they're own specialised mini-language (or...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9881
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11354
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4778
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.