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 The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top