Array control and examination

Started by
2 comments, last by leggyguy 22 years, 5 months ago
Hi. I am building a card game, and have a little question. the hands of the players will be an array of integers, each integer representing a different card. So, 1 is a punch card, for example. Each card is set into different catagories of sorts, and I need to be able to search this array for the first, say, strength card (where strength is one of my catogory of cards), or first tactic card, or whatever. Strength cards, for example, are all cards with numbers from 1 to 70, tactic cards from 200 to 260. I need to be able to sort through that array, - typically an array of between 10 to 80 integers - and not resort the array into another order, just simply tell me in which array index the first integer between say 1 and 30 is. Now, I could make my own functions which do this fairly easily, I think, but I just wanted to know if there was anything out there that could do this sort of thing for me without me having to do too much work on it. Thanks for any input.
Advertisement
After having looked at my problem, I am thinking a linked list may work better here.

But anyway, any input guys about the array searching? Any source code I can use for this, or am I gonna have to make my own little functions?
The STL ''find'' algorithm might help you here. But that will require a little understanding of how it works, along with understanding of writing predicates when you want to do anything more complex.
If you are simply trying to find the first card that falls within a certan feild, try using a while loop. If you used you strength example:

int index = 0;
while( array[index] > 70 )
{
index++;
}
//index now = the first strength card in the array

Something like that might be what you are looking for. With a little work you could write a function for that.
"cogito, ergo sum" -Descartes

This topic is closed to new replies.

Advertisement