I'm trying to create a turn-based board game for 2-5 players. At the beginning of the game I need to check which player is active, and make each of them roll a dice to determine their turn order. I'm having a headache trying to sort the players according to the score they obtained with the dice, and storing this somehow to make sure the turn order is set once and for all, in a variable I can refer to later... Any idea on how to do this?
I don't need the players to actually "roll" a dice. It's just a randomized value for each player, and the one who gets the best score starts first, and so on until everyone gets a rank in the turn order. I thought it was easy to do but I've been on it for 2 hours now and I'm back to where I started...
@SouLCarveRR: GoI don't understand a word you're saying... If you're telling me to have an integer with array to store the values, it's just a part of the solution I already figured. What I need the most is how to compare the values and do something different depending on which player is in which place. What is this "initiative roll" you speak of? Is it some function I need to code, or can I find it directly through usual triggers? I absolutely have no idea whatsoever...
if your using a random number generator. Then set that as a variable array. Use if then else triggers to determine who goes first depending on their variable arrays(arrays refering to each player). Shouldn't be that hard. If that doesn't work. You might want to set the random number variable as a constant so it doesn't keep changing. But if you save it into a variable. It shouldn't change.
Hey!
At first I was gonna write it here using "pseudo-code" but it turned out to be too complicated, and I rememberd how much I hate that when people use stuff that they aren't even sure if they exist...
so I opened up the editor and simply did it... it turned out to take a lot more time than it should have taken rofl... Idk if it's because they changed a bunch of stuff since the beta or what (adressing players numbers...very fustrating because of their "newb proof system").... but anyways here it is!
It should work ... (did some testing but could be different online) and I added some comments so you can understand what I did (sorry btw english isn't my first language).
You will see notice that my variables have strange names (zz in front of em) .. it's just for you to "spot" them better and understand faster what I did.
The more talented users might find my code disgusting and there are probably other cleaner, cleverer ways to achieve what you want, but this is my way.
So anyways, GL!
-Koro
PS: You can test the placement order by using the command "--testPlacement" ingame.
EDIT: Sigh... just re-read your original post..damn it ! I didn't integrate the rolling value/comparison thingy..well hopefully you can still use a part of my code QQ. You probably can find plenty of algorithm on the internet on how to sort depending of a score.
Use if then else triggers to determine who goes first depending on their variable arrays(arrays refering to each player).
This is actually the tricky part... If you have 5 players you must compare the score of each to check if player 1 is first or not... Then repeat for player2, etc... Until the "first" player is set in the turn order. Then repeat the process X times (where X is the number of players not placed yet), to determine who is playing when. It needs something like 30 tests if you do it that way, which is obviously not a good idea. This is why I asked for help, I needed something simple because, obviously, what I thought of first was going nowhere. I thought it was easy at first, but it becomes tricky really fast.
Anyway, I checked what Koronis did and it's really close to (if not totally) what I needed. It sounds so obvious now that I have it in front of me... Instead of making each player rolling a dice and compare the score (which is exponentially tricky depending on how many players there is), you just need to roll a dice which will set the player with the matching result (a score of 1 will be player 1) to the next place available in the turn order. Repeat the process X times until each player is placed. The second tricky part was to figure who was already placed in the turn order, to prevent a player from playing more than others... I needed the same process to take a random card only once from a deck, so Koronis's triggers seem to fit perfectly for that. Anyway, thanks Koronis. I'll try that.
that is easily achieved by using the "for each integer" trigger.
Make a temporary number local variable set to 0. and have it do from 1 to total number of players. Do this for each player. So that would mean you will use 2 for each integer trigger all in the same trigger. I havn't gone in an do it but this is probarly where I start.
@gamfvr: GoI started this way, it ended up in a pretty big mess (it's really not as easy as it looks if you go the wrong way to begin with). I was taking the problem from the wrong side (you must focus on rolling the dice instead of comparing results pointlessly).
I did what Koronis suggested and it works fine... just had to change the order at which actions were done (remove the player from the group as first action) to prevent the last player(s) to be skipped, otherwise the execution of the loop itself is faster than executing the actions. I applied the same method to shuffle the content of a deck (deck content is defined through another trigger with a huge switch), and it works like a charm. No card can be given twice and it just requires a While loop. It's a bit more complex with the cards though, but since it's done through one trigger only, without tons and tons of conditions, it's not that much of a deal anymore... Thanks for the help anyway. :)
You would use a basic sorting method to sort the players by thier random initiative roll. Sorting can seem complex at first but its really not. You just need to sit down and logically work your way through it..
Creat a temp array in the function that you will sort the players into.
Loop through all the players twice to get them all sorted.
Search google for sorting algorithms for a better idea of ways to logically sort sets of data
once they are sorted into a new array. you can just loop through the new array and have them fire off what ever in order of thier initiative.
Rollback Post to RevisionRollBack
Skype
KageNinpo = SN
My Libraries
DialogLeaderboard & TeamSort
My Projects
SPACEWAR Tribute
Infinite TD
@Kueken531: Go
Hmm OK, just checked... It seems totally fitting but I still need to take some time to test how these are used. Damn, I'll have to rebuild my whole set of scripts now... :D
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I'm trying to create a turn-based board game for 2-5 players. At the beginning of the game I need to check which player is active, and make each of them roll a dice to determine their turn order. I'm having a headache trying to sort the players according to the score they obtained with the dice, and storing this somehow to make sure the turn order is set once and for all, in a variable I can refer to later... Any idea on how to do this?
I don't need the players to actually "roll" a dice. It's just a randomized value for each player, and the one who gets the best score starts first, and so on until everyone gets a rank in the turn order. I thought it was easy to do but I've been on it for 2 hours now and I'm back to where I started...
mmm Initiative roll
@SouLCarveRR: GoI don't understand a word you're saying... If you're telling me to have an integer with array to store the values, it's just a part of the solution I already figured. What I need the most is how to compare the values and do something different depending on which player is in which place. What is this "initiative roll" you speak of? Is it some function I need to code, or can I find it directly through usual triggers? I absolutely have no idea whatsoever...
if your using a random number generator. Then set that as a variable array. Use if then else triggers to determine who goes first depending on their variable arrays(arrays refering to each player). Shouldn't be that hard. If that doesn't work. You might want to set the random number variable as a constant so it doesn't keep changing. But if you save it into a variable. It shouldn't change.
This is actually the tricky part... If you have 5 players you must compare the score of each to check if player 1 is first or not... Then repeat for player2, etc... Until the "first" player is set in the turn order. Then repeat the process X times (where X is the number of players not placed yet), to determine who is playing when. It needs something like 30 tests if you do it that way, which is obviously not a good idea. This is why I asked for help, I needed something simple because, obviously, what I thought of first was going nowhere. I thought it was easy at first, but it becomes tricky really fast.
Anyway, I checked what Koronis did and it's really close to (if not totally) what I needed. It sounds so obvious now that I have it in front of me... Instead of making each player rolling a dice and compare the score (which is exponentially tricky depending on how many players there is), you just need to roll a dice which will set the player with the matching result (a score of 1 will be player 1) to the next place available in the turn order. Repeat the process X times until each player is placed. The second tricky part was to figure who was already placed in the turn order, to prevent a player from playing more than others... I needed the same process to take a random card only once from a deck, so Koronis's triggers seem to fit perfectly for that. Anyway, thanks Koronis. I'll try that.
@ZealNaga: Go
that is easily achieved by using the "for each integer" trigger.
Make a temporary number local variable set to 0. and have it do from 1 to total number of players. Do this for each player. So that would mean you will use 2 for each integer trigger all in the same trigger. I havn't gone in an do it but this is probarly where I start.
@gamfvr: GoI started this way, it ended up in a pretty big mess (it's really not as easy as it looks if you go the wrong way to begin with). I was taking the problem from the wrong side (you must focus on rolling the dice instead of comparing results pointlessly).
I did what Koronis suggested and it works fine... just had to change the order at which actions were done (remove the player from the group as first action) to prevent the last player(s) to be skipped, otherwise the execution of the loop itself is faster than executing the actions. I applied the same method to shuffle the content of a deck (deck content is defined through another trigger with a huge switch), and it works like a charm. No card can be given twice and it just requires a While loop. It's a bit more complex with the cards though, but since it's done through one trigger only, without tons and tons of conditions, it's not that much of a deal anymore... Thanks for the help anyway. :)
You would use a basic sorting method to sort the players by thier random initiative roll. Sorting can seem complex at first but its really not. You just need to sit down and logically work your way through it..
Creat a temp array in the function that you will sort the players into.
Loop through all the players twice to get them all sorted.
Search google for sorting algorithms for a better idea of ways to logically sort sets of data
once they are sorted into a new array. you can just loop through the new array and have them fire off what ever in order of thier initiative.
Blizzard implemented a bunch of sorting algorithms already, you can simply use them.
Have a look at the libraries in the trigger editor (ctrl+shift+L to show them), select Built-in -> Template -> Algorithms and there they are.
Good too know. Havent used to much sorting for my own uses but from what this guy wants It might be just the right time to try them out.
@Kueken531: Go Hmm OK, just checked... It seems totally fitting but I still need to take some time to test how these are used. Damn, I'll have to rebuild my whole set of scripts now... :D