开发者

Calculating the value of a unit in a game

开发者 https://www.devze.com 2023-01-27 11:08 出处:网络
I\'m currently working on a game where each unit has a value for health, shields and agility as well as a certain number of six types of weapon.

I'm currently working on a game where each unit has a value for health, shields and agility as well as a certain number of six types of weapon.

e.g. Unit B has 2 lasers, 2 heavy lasers, and 1 missile launcher, no ion blast开发者_JAVA技巧er, no heavy ion blaster, no nuclear missiles, 5 health, 2 shield, and 40 agility.

I have gone through a good 20 different algorithms trying to get MS Excel to balance these all these factors to give the ship a score. My current algorithm works great for some of the smaller units, but gets very unbalanced with the bigger units

Each ship has a damage value, where each type of weaponry is multiplied by the damage of that weapon and added together.

damage = weapon1*damage1 + weapon2*damage2 + ...

The damage value is multiplied by health + 2*shield + 2*agility. Agility and shield are multiplied to give them weight over health (a unit cant lose health if it can't be hit). I also subtract the cost of the unit. So my current equation for one of my units looks like:

value = damage*(health + 2*shield + 2*agility) - 3*cost

Here are some examples:

  • Unit 1 - 1 laser, 1 health, 93 agility, and costs 1. Total score is 233.
  • Unit 2 - 2 lasers, a missile launcher, and 3 health, but only 76 agility. Score is 200.
  • Unit 3 - 6 lasers, 30 health and 15 shields, 37 agility - scores 585.

I want the scores of unit 3 to be higher, but the scores for units 1 and 2 are pretty good. Can anyone suggest a better equation that will smooth out the values?


I think a genetic programming algorithm is a good approach to solving the issue you describe. Genetic programming evolves an algorithm's computations through iteration to minimize a cost function. This is done by creating a set of "mutations" to apply to the algorithm, for instance your idea of decreasing by the cost of the unit as 3R could be one of the mutations. The cost function would be something that increases/decreases relative to the concept of balance. Mutations would be evaluated in light of this cost function.

See the book Programming Collective Intelligence for Python code to do this type of problem solving.


This problem is similar to my cloud balancing example (open source, java). Just replace Computer by Unit and Process by Weapon.

0

精彩评论

暂无评论...
验证码 换一张
取 消