Logic question...

J

JoeC

Nathan said:
Managing "who's where" is best separated from the "combat routine."
Most games have some code (and data structures) dedicated to keeping
track of units on the map. This means that units know where they are,
and the map manager also knows which units are where. If your map is
just a 2D array of a fixed, "reasonable" size (under a million
entries), you can just make a 2D array of entries, and each entry is
just a linked list of all units in that cell. If you're working on
PCs, just burn some memory upfront, and work on optimizing it later--
plenty of data structures exist to manage sparse datasets.

You should also separate out code to to map manager so that you can
say "find all units within radius R of point X,Y" and it'll go do that
for you. That's code for the map manager, not a "combat routine," as
you'll probably want your UI code to be able to do the same thing--
clicking on a square selects all units in that square, or shift-drag
selects all units in a user-specified rectangle. If you're going to
use the same kinds of functionality in multiple places, then break it
out to a common place.

Nathan Mates

--

Thanks for the advice. I am not realy sure how to implement that into
my program. I would have to seem some kind of example of how to do
that. I hope my program is not too far along to impleent a map handler.
 
P

Phlip

[Please trim irrelevant quotes from your posts!]
...What my problem is is that I
program in a vaccuum, I don't have people with more experience letting
me know that there are better ways to do what I am trying to do.

Do you have any Users Groups near you? (or maybe a college?)
 
N

Nathan Mates

Thanks for the advice. I am not realy sure how to implement that
into my program. I would have to seem some kind of example of how
to do that. I hope my program is not too far along to impleent a
map handler.

My description above is more or less what you need to do, written
out in English. Just turn it into code -- you need a 2D array of all
possible map locations (if the map is laid out like a chessboard of
discrete locations), and for each location, a list of what's in it.
When a unit moves, it removes itself from its old location, and adds
itself at the new location. Each of these things I've mentioned is a
short bit of code.

Think about how you'd do this for a chessboard (i.e. 8x8, but allow
multiple pieces per square), and extend that for your program.

Nathan Mates
 
J

JoeC

Phlip said:
[Please trim irrelevant quotes from your posts!]
...What my problem is is that I
program in a vaccuum, I don't have people with more experience letting
me know that there are better ways to do what I am trying to do.

Do you have any Users Groups near you? (or maybe a college?)
Not that I am awaire of. I do live in a large city and I am sure there
are some here but I don't know how to find them.
 
J

JoeC

Jerry said:
[ ... ]
I didn't see anyone say in this thread "your question is off topic here go
away"
I merely suggested a better newsgroup.

I'm not even sure that's true -- at least to me, it seems that most of
the discussion has centered primarily around how to express his ideas in
C++, not so much about the fundamental design of the game itself. That
being the case, I think the questions are really more topical here --
though it may be that enough game programming is done in C++ that it
would also fit well there.


I have posted this question on several pages and I have gotten some
advice. The problem is that I am not sure how to implement that
advice. I used my knowlege of programming to write this program. If I
could have done better I would have. I han't seen examples of games to
study and get ideas. Most of what I see is how to create better and
better graphics. I started this by asking how to do a map game. I got
some ideas and wrote my game. I created all the libraries I could then
made the game. I think I would have to re-do the whole game if I want
to change the design. I try to include lessons I have learned to my
projects but my experience is limited.

My ultimate goal is to get a job that involves programming so I can be
around people who program. The challenge is getting my skills up so
that I can get a job. I am also debating taking programming classes
but I am often told that I have the knowlege that is taught. when I do
searches for class I see C++ part 1 and 2 and may be 3. How much can
you learn in three classes. I would like to find classes in design
patterns and how to design a program. Learn some rules and methods for
problem solving.
 
N

Nathan Mates

I have posted this question on several pages and I have gotten some
advice. The problem is that I am not sure how to implement that
advice. I used my knowlege of programming to write this program. If I
could have done better I would have. I han't seen examples of games to
study and get ideas.

A bit of poking online would find you LOTS of source code to study
and get ideas. http://www.sourceforge.net/ has lots (12292!) of games
listed, of varying quality. http://www.liberatedgames.com/ has a lot
of games that used to be under commercial licenses, and are now opened
up for download (sometimes completely, sometimes source code only).
Find a game similar to what you're trying to do (I'm guessing
turnbased strategy), and look at it. In short, if you're asking "how
was this done," then there's a million resources online that google or
the like will find for you.

Most of what I see is how to create better and better graphics. I
started this by asking how to do a map game. I got some ideas and
wrote my game. I created all the libraries I could then made the
game. I think I would have to re-do the whole game if I want to
change the design. I try to include lessons I have learned to my
projects but my experience is limited.

Everyone's second project is better than their first. That's
natural in programming. And, don't worry about reinventing the wheel.
Commercial games do that all the time as game engines are written and
discarded quite often. (I think a lot of the rewrites are just
ego-stroking, but some are necessary.) Once you get better, you'll be
able to crank out the support code on autopilot.

You can also learn a bit by cleaning up your code as you go along.
Adding in a map manager (which I've suggested) can be done without
tossing out lots of code. This is called 'refactoring', which you can
look up online to get references and resources.

My ultimate goal is to get a job that involves programming so I can be
around people who program. The challenge is getting my skills up so
that I can get a job. I am also debating taking programming classes
but I am often told that I have the knowlege that is taught. when I do
searches for class I see C++ part 1 and 2 and may be 3. How much can
you learn in three classes. I would like to find classes in design
patterns and how to design a program. Learn some rules and methods for
problem solving.

Don't knock courses until you've taken them. And, while familiarity
with design patterns is good, a just as critical tool for professional
programmers is how to turn an idea or outline from others into
code. Professional games are done with LARGE teams these days, and
that includes programmers. As the new guy on a team, you'll probably
initially do a lot of "here's an idea, go write it." Teams need to see
what one's skills are in writing code, following directions, before
you can really go up the ladder. Design patterns can be learned from
books or online; ability to write code to a spec comes from lots of
practice.

When I've described a map manager in previous postings, I described
what it needed to do-- store who's where on the map. I didn't spell
out every last function, or even write out a header file for you to
fill in the implementation. It's up to you to see how useful such a
thing would be (or not useful), and implement it on your own.

Nathan Mates
 
N

Nathan Mates

Ill give that a try. I often don't find sarch engines very helpful.
It often takes a while to find what I am looking for.

Like coding, the more practice you have in using search engines,
the better the results. Perhaps if you post what you're searching for,
people can suggest some more useful search terms. Perhaps if you'd be
willing to disclose what city you live in in your posts here, you
might just get some more useful suggestions from people. As long as
you stay in a shell where you don't say much, don't want to try to do
any searches, and expect others to read your mind, it'll be a LOT
harder to get quality help. The online world works a certain way, and
the more you work with the system, the more you get out of it.

Nathan Mates
 
J

JoeC

Nathan said:
A bit of poking online would find you LOTS of source code to study
and get ideas. http://www.sourceforge.net/ has lots (12292!) of games
listed, of varying quality. http://www.liberatedgames.com/ has a lot
of games that used to be under commercial licenses, and are now opened
up for download (sometimes completely, sometimes source code only).
Find a game similar to what you're trying to do (I'm guessing
turnbased strategy), and look at it. In short, if you're asking "how
was this done," then there's a million resources online that google or
the like will find for you.



Everyone's second project is better than their first. That's
natural in programming. And, don't worry about reinventing the wheel.
Commercial games do that all the time as game engines are written and
discarded quite often. (I think a lot of the rewrites are just
ego-stroking, but some are necessary.) Once you get better, you'll be
able to crank out the support code on autopilot.

You can also learn a bit by cleaning up your code as you go along.
Adding in a map manager (which I've suggested) can be done without
tossing out lots of code. This is called 'refactoring', which you can
look up online to get references and resources.



Don't knock courses until you've taken them. And, while familiarity
with design patterns is good, a just as critical tool for professional
programmers is how to turn an idea or outline from others into
code. Professional games are done with LARGE teams these days, and
that includes programmers. As the new guy on a team, you'll probably
initially do a lot of "here's an idea, go write it." Teams need to see
what one's skills are in writing code, following directions, before
you can really go up the ladder. Design patterns can be learned from
books or online; ability to write code to a spec comes from lots of
practice.

When I've described a map manager in previous postings, I described
what it needed to do-- store who's where on the map. I didn't spell
out every last function, or even write out a header file for you to
fill in the implementation. It's up to you to see how useful such a
thing would be (or not useful), and implement it on your own.

Nathan Mates


I have done search in the past and have been disapointed with the
result. I did find one site, www.planetsourceceode.com where I have
posted my work. It has taken a great deal of work to get to the point
I am now. I am trying to keep my game as simple as possible. In a
previous work I created a grid of space objects where the pieces
resided but it became buggy trying to put in and take out the pieces as
they moved. I have each piece keep track of its own location and draw
themselvs.

Still there is a great deal of advice in this post and I will get back
to it and study it furter. I am proud of my programming skills, I did
this game in win32 the graphic interface I know best and have the
resource for. A map manager is an intersting idea, I will have to take
a while and see if I can create one. One thing I know I need to do is
create a coord struct. I have one written, it is very simple. I have
several ideas to make the program better and I have to get to writing
them.

I know that games are huge projects and I could never hope to create a
prefetional game myself. I do think I can create the basics of one. I
do have a large idea for a complete game but I am far from being able
to create it. Right now I am working on the basics. The best I can do
is write what I can then ask for help when I run into problems. I am
also awaire of my shortcommings and I do what I can to work on my
weaknesses.

I would be very happy if I can learn the skills necessary to just get a
job at the lowest level. As with any profetion you learn as you go.
There is no subsitute for experience.
 
N

Nathan Mates

I have done search in the past and have been disapointed with the
result. I did find one site, www.planetsourceceode.com where I have
posted my work. It has taken a great deal of work to get to the point
I am now. I am trying to keep my game as simple as possible. In a
previous work I created a grid of space objects where the pieces
resided but it became buggy trying to put in and take out the pieces as
they moved. I have each piece keep track of its own location and draw
themselvs.

All games are a lot of work. This is why the usual advice given on
game development newsgroups is to work on simple games, like pong,
breakout, Tetris, or the like as your first title, just to get a feel
for game development, the language(s) you're using, and understanding
just how much time/work is involved in simple games. Now that you've
bitten off a large project, the question becomes: how to get it on
track, runnable, etc.

I do recommend that you try and resurrect that old code for where
objects resided, and get it debugged and functional. That's your basic
map manager, and it's certainly cleaner to get it working than make
all your attack code duplicate the same work. As to the bugs in moving
pieces, the usual logic is to remove the piece from its old location,
do the move, and then add the piece at its new location. (Or, tell the
map manager the old & new locations). If you haven't already, start
throwing in a lot of assert/_ASSERTE/whatevers into the code, so that
if things aren't as "expected," then you can get the opportunity to
drop into the debugger then and there. Additionally, if you write
things cleanly, you can take your map manager and put it into a short
workout program that tests its functionality. Personally, I'm in favor
of lots of assert bombs in the code to stop ASAP on issues.

Nathan Mates
 
J

JoeC

Nathan said:
All games are a lot of work. This is why the usual advice given on
game development newsgroups is to work on simple games, like pong,
breakout, Tetris, or the like as your first title, just to get a feel
for game development, the language(s) you're using, and understanding
just how much time/work is involved in simple games. Now that you've
bitten off a large project, the question becomes: how to get it on
track, runnable, etc.

I know that games are difficult. This is not my first project, I have
written others in perl and C++. I have done some work with moving
graphics and directX. This program was not difficult until I came to
the combat routine. I actually finished the routine but it doesn't
work. I need to do alot of work on it. I have create other fighting
functions for one of my perl games and it wasn't too dificult. I do
realize that I have limits to my programming skills and it looks like I
have reached those limits.

My goal for writing games is simply to learn to program better. I also
like the creativity of programming. Programming is all about solving
problems and I am at a problem that is not working as I had planned. I
have written many demo programs to test and learn syntax. I recently
wrote a simple handle that managed dynamic binding. Still I doing
smaller programs that increase my programming skills.

I have seen how to create arcade type games and I think I could
probibly write one but I don't have any desire to be a graphic artist.
I do recommend that you try and resurrect that old code for where
objects resided, and get it debugged and functional. That's your basic
map manager, and it's certainly cleaner to get it working than make
all your attack code duplicate the same work. As to the bugs in moving
pieces, the usual logic is to remove the piece from its old location,
do the move, and then add the piece at its new location. (Or, tell the
map manager the old & new locations). If you haven't already, start
throwing in a lot of assert/_ASSERTE/whatevers into the code, so that
if things aren't as "expected," then you can get the opportunity to
drop into the debugger then and there. Additionally, if you write
things cleanly, you can take your map manager and put it into a short
workout program that tests its functionality. Personally, I'm in favor
of lots of assert bombs in the code to stop ASAP on issues.

That is my problem I don't have a map manager. My map is an array of
int which each number represents a kind of terrain. My pieces store
their own location. I did write another game where the map was a grid
of space objects. That became overly cumbersom and buggy. I have been
experimenting with several designs of map games. It is all a learning
proscess and I do have ideas and have gotten advice on how I can make
the game better. It is a matter of just doing those improvments. They
won't change the design of my program much or solve my current problem
but I am always looking for ways to make the program better.
 
J

JoeC

Phlip said:
Can you run the combat routine alone, in isolation from the other modules?
No, I need the unit objects arrays and terrain data.

I take this as a hint and as a good programming lesson. If I can read
between the lines, my functions need to be independent of other objects.
 
M

Miss Elaine Eos

No, I need the unit objects arrays and terrain data.

I take this as a hint and as a good programming lesson. If I can read
between the lines, my functions need to be independent of other objects.

Well, there're certainly a lot of positives, there.

As a minimum, see if you can break out the combat to work on a mock-up
terrain (say, all flat world) with mock-up objects (say, 2 combatants
from each team and 2 trees, or whatever.)

It's very useful to isolate a sub-system as much as possible, and then
observe it under VERY controlled conditions. It may be useful to have a
combatTest app (as described above) and a terrainTest app (no features,
just terrain), and similar type sub-system test apps where the
sub-system tested is there, but everything else is as bare-bones as
possible. This lets you isolate problems to one system, before
combining them in complicated ways.

Having those sub-system-test apps around will be nice for AFTER you've
combined them, too, when you have some weird bug and want to figure out
which sub-system(s) it's in.

Luck!
 
P

Phlip

Miss said:
As a minimum, see if you can break out the combat to work on a mock-up
terrain (say, all flat world) with mock-up objects (say, 2 combatants
from each team and 2 trees, or whatever.)

This parallels the technique, in high-end games, of developing a bunch of
in-house levels, with nothing but a few spawn points, weapons, and barriers.
Then you can manually test a few activities without interference from
nuisances, like the game's plot.

The distinction would seem to be that not only don't you put textures on all
the surfaces, you don't even pull in the texturing system.
 
J

JoeC

Miss said:
Well, there're certainly a lot of positives, there.

As a minimum, see if you can break out the combat to work on a mock-up
terrain (say, all flat world) with mock-up objects (say, 2 combatants
from each team and 2 trees, or whatever.)

It's very useful to isolate a sub-system as much as possible, and then
observe it under VERY controlled conditions. It may be useful to have a
combatTest app (as described above) and a terrainTest app (no features,
just terrain), and similar type sub-system test apps where the
sub-system tested is there, but everything else is as bare-bones as
possible. This lets you isolate problems to one system, before
combining them in complicated ways.

Having those sub-system-test apps around will be nice for AFTER you've
combined them, too, when you have some weird bug and want to figure out
which sub-system(s) it's in.

Luck!
I thought my concept was very simple. It take the arrays of units and
then checks to see if they are in the same space if they are put into
the fightclass which has a defender array and attacker array. If they
can fight that is units in the same space the get the attacking factors
and defending factors then compute odds. I still have bugs like I
can't eliminate units.
I am trying to do simple things. That is see if units are in the same
space if they are add up factors caculate odds and resolve combat. It
is simple for me but putting all that so a computer can understand is
not so easy.
 
J

JoeC

Phlip said:
This parallels the technique, in high-end games, of developing a bunch of
in-house levels, with nothing but a few spawn points, weapons, and barriers.
Then you can manually test a few activities without interference from
nuisances, like the game's plot.

The distinction would seem to be that not only don't you put textures on all
the surfaces, you don't even pull in the texturing system.

My game is very simple, as simple as I can make it. I could get rid of
terrain but all I want to do is move pieces on a board and if they are
in the same space have them fight. I have done several map games and
each one has its problems. This worked great until I wanted to have
the units fight.
 
L

LR

JoeC said:
I thought my concept was very simple. It take the arrays of units and
then checks to see if they are in the same space if they are put into
the fightclass which has a defender array and attacker array. If they
can fight that is units in the same space the get the attacking factors
and defending factors then compute odds. I still have bugs like I
can't eliminate units.

How are you storing the units? Why can't you eliminate them?

I am trying to do simple things. That is see if units are in the same
space if they are add up factors caculate odds and resolve combat. It
is simple for me but putting all that so a computer can understand is
not so easy.

Sounds like you need some functions.

ReturnType? SeeIfUnitsAreInTheSameSpace( paramters ?)
AddUpFactors
CalculateOdds
ResolveCombat

Try to break the problem apart into simple things that you can do a
little at a time.
 
J

JoeC

LR said:
How are you storing the units? Why can't you eliminate them?



Sounds like you need some functions.

ReturnType? SeeIfUnitsAreInTheSameSpace( paramters ?)
AddUpFactors
CalculateOdds
ResolveCombat

Try to break the problem apart into simple things that you can do a
little at a time.

I can send you my current code if you are intersted. It is a challenge
to work with the arrays of units. They are not on my map they hold
their own values and then they draw themselvs. The challenge is that I
have to find units in the same space then to see if the other side has
units in that space. There is a posibility that several spaces have
both side in it and therefor elegible for combat.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top