Question

Im in the process of trying to create a simple pokemon battle simulator in C++. The problem Ive ran into now is how to implement the Element system (water beats fire, fire beats grass, grass beats water, and including all the other element types).

I dont know how I would create such a system without having to use a ton of If statements. Is there a better way to do this?

I have a good amount of general programming knowledge, and I know the basics of C++, like classes, loops, and various other basic things.

I would provide code, but there is nothing to provide as I have no idea how to make such a system. I guess i'm asking for what kind of technique, data structure, etc I could use to accomplish this

Was it helpful?

Solution

Consider a lookup table or decision matrix.

Imagine this table, for Rock-Paper-Scissors

   R  P  S
R  -  L  W
P  W  -  L
S  L  W  -

And where it is interpreted as so, reading ROW then COL

ROW(R) at COL(R) -> R *ties* R
ROW(S) at COL(P) -> S *wins* P

(The two diagonal halves of the matrix are inverted mirrors in this case.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top