Risk Style Map - Random Territory

Uszi

New Member
Reaction score
5
Hello!

I'm working on a Risk style map with 42 territories that will randomly (and as equally as possible) be split between 2-6 players.

I'm not really sure how to go about doing it though.

First, I figured I would make an integer variable, and for each player with slot status playing, I would increase the value by one. So 6 players playing means that PlayersPlayingVar = 6, etc.

Then I made a region for each territory, and assigned them to a region array variable (i.e. Territory[1-42]).

Then I figured once the game started I would divide 42 by players playing, and then I would randomly give that quotient of territories to the players out of 42...

I was just beginning to go into that. Maybe another variable that had the value of 42/Players Playing... I'm really not sure.

Also, I was trying to figure out what to do with remainders. When Players Playing = 2,3 or 6 I'm fine. But 4 or 5, then I'm going to have to decide some fair way to divide the remaining territories. I figured I would put the remaining territories into a separate array, and then randomly give those to two lucky players who would start with one more territory than everyone else.


Eh. I don't want to cycle through players and randomly give each a territory until they're all gone. That would mean that players 1 and 2 would always get those extra two territories. :thdown:


Any suggestions? I would post triggers, but I don't have much more than setting variables at this point.
 

UndeadDragon

Super Moderator
Reaction score
447
I made this quickly. I am not sure if it will work or not, but if it does work, then it will be efficient :p

Code:
Random Control
    Events
        Map initialization
    Conditions
    Actions
        Set tmpInt = (42 / (Number of players in (All players))) [COLOR="Green"]//Sets number of building that each player can own.[/COLOR]
        For each (Integer A) from 1 to (Number of players in (All players)), do (Actions) [COLOR="Green"]//Picks all players[/COLOR]
            Loop - Actions
                Unit Group - Pick every unit in (Random tmpInt units from (Units in (Playable map area))) and do (Actions) [COLOR="Green"]//Picks tmpInt units from the whole map.[/COLOR]
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                ((Owner of (Picked unit)) controller) Not equal to User [COLOR="Green"]//Makes sure the unit is not owned by another player.[/COLOR]
                            Then - Actions
                                Unit - Change ownership of (Picked unit) to (Player((Integer A))) and Change color [COLOR="Green"]//Changes ownership of the picked unit.[/COLOR]
                            Else - Actions

I have commented it for understandability. (Does that word exist? :p)
 

Uszi

New Member
Reaction score
5
Yup, working on it.

A few changes I'm considering:

Instead of "All Players" what about, "Matching Control - User?" Does All Players include Neutral Passive (all the barracks are neutral at the start).

There are also circles of power located at each territory. These will be used for defenders. I wasn't sure if I wanted them to change control, but I suppose I could add an extra condition in there that not only is owner not equal to user, but also that the picked unit is of type Barracks.


...

Alright, here's the trigger with changes. Oh, and I should mention, it runs from a trigger where the host selects the game mode, not map initialization. Just to clear up any confusion about why it has no event.

Code:
Randomized Starts
    Events
    Conditions
    Actions
        Set NumTerritoriesPer = (42 / (Number of players in (All players controlled by a User player)))
        For each (Integer A) from 1 to (Number of players in (All players controlled by a User player)), do (Actions)
            Loop - Actions
                Unit Group - Pick every unit in (Random NumTerritoriesPer units from (Units in (Playable map area))) and do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                ((Owner of (Picked unit)) controller) Not equal to User
                                (Unit-type of (Picked unit)) Equal to Barracks
                            Then - Actions
                                Unit - Change ownership of (Picked unit) to (Player((Integer A))) and Change color
                            Else - Actions

Here's what it did:

I started a game with just myself, so it should give me all of the territories.

Instead, I started with 3 territories.
It gave purple (not playing) 4
It gave yellow (not playing) 3
It gave teal (not playing) 2

The rest remained under control of Neutral Passive.



EDIT: Ran it a second time. It gave the same territories to the same players again, which means that it's not randomly giving territories to players.


Hmm.
 

Uszi

New Member
Reaction score
5
I hate to bump my old thread. :eek:

I spent some time searching through the help forums and the tutorials, and I've found several threads about Risk style map related topics.

But I haven't found something like a guide that I could use.

And I'm still in the dark about how to randomly divide the territories equally among the number of players currently playing.

I apologize for thread Necromancy, but does anyone have any suggestions?

Thankyou.
 

UndeadDragon

Super Moderator
Reaction score
447
EDIT: Ran it a second time. It gave the same territories to the same players again, which means that it's not randomly giving territories to players.

File --> Preferences --> Uncheck Fixed Random Seeds (Yes, it actually says seeds :p)
 

Uszi

New Member
Reaction score
5
Er, tried it.
Still not dividing equally, or shelling out all of the territories. Unchecking "fixed random seeds" did make it random though.

Since that seemed to make a difference, I tried unchecking "Fixed Start" in the players menu, but that didn't change anything, as far as I can see.

Maybe I need to test it with people instead of just myself?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> assigned them to a region array variable (i.e. Territory[1-42])

Set CountMax = 0
Pick every player in (All players) and do
- Set CountMax = CountMax + 1
- Set Players[CountMax] = (Picked player)

Set Count = CountMax
For each Integer A from 1 to 42
- Set TempInteger = Random integer number between 1 and Count
- Set Owner[Integer A] = Players[TempInteger]
- Set Players[TempInteger] = Players[Count]
- Set Players[Count] = Owner[Integer A]
- Set Count = Count - 1
- If Count less than 1 then
- - Set Count = MaxCount


Expected result:
Owner[1 - 42] holds, randomly, but fairly, the owner of the corresponding region.

Unverified and untested :p
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top