ID:1753594
 
Keywords: army, count, design, game
I'm recreating the Game of Thrones Board Game. If you've played it, then this post will be even easier for you to understand.

Simply put, the board is split in to territories.

A player can have as many units as they want, so long as there is only one in each territory.

For simplicity's sake;
A player is only allowed one territory to hold up to three men, and two territories to hold up to two each. (In the actual game these allowances change, but that doesn't affect this problem).

I've programmed the different territories as areas over a bunch of connected turfs, and the 'men' as objs.

How would you cycle through all the men (or territories), and discern whether the allowances have been met?

Furthermore, I'd like to test if a specific Territory can have another unit added and still meet the allowance. This bit seems the trickiest.

Foreseeable problem: the computer sees an army of two, and compares it to the allowance of three, and passes. But then sees an army of three, compares it to the allowance of two (as the three is taken) and then fails, despite the allowance being met.
area
var/mob/controller
var/mob/troops

proc/CheckTroops()
if(troops == 3 && controler.troop3) return
else
controller.troop3 = 1
//continue
if(troops <= 2) //continue


mob
var/troop3 = 0 // 1 when the 3 troop is placed


Loop through area turfs for soldiers, when you're done call checktroops()
Apparently, you have a certain allowance of how many territories can have 2 units, how many can have 3 units, etc., and you can have unlimited territories of 1 unit.
// these lists are all potential amounts associated with something
var
// allowance["[n]"] is the upper limit of how many armies of [n] are allowed to exist
// You might want this to be passed as an argument of the proc instead of a variable inside it.
allowance[] = list("2" = 2, "3" = 1)

// amounts["[n]"] is how many armies of [n] exist
amounts[0]

// territories["[n]"] is a list of territories with [n] of your units
territories[0]

// count units in every territory
for(var/area/territory/territory)

// count units in territory
var amount = 0
for(var/obj/unit/unit in territory)
if(src == unit.owner)
amount++

// convert number to string to make it associable
amount = "[amount]"

// add amount to amounts
amounts[amount]++

// add territory to territory amount
if(!territories[amount])
territories[amount] = list()
territories[amount] += territory

// check excess
var excess[0]
for(var/amount in amounts)
excess[amount] = amounts[amount] - allowance[amount]

if(excess[amount] > 0)
src << "You have [excess[amount]] too many territories with [amount] units."
src << "Territories with [amount] units:"
for(var/area/territory/territory in territories[amount])
src << "- [territory]"

else if(excess[amount] < 0)
src << "You can have [-excess[amount]] more territories with [amount] units."

This is untested code off the top of my head after googling the rulebook. There are probably better ways to do this.