Hi everybody 
(sorry that message is very long but if you are willing to read the beginning you will soon understand why
)
I am struggling with something which has pissed me of for a long time: setting teams in a game I developed and which is now already in production. This game is the Toc.
Why is it such a trouble? Because I implemented it on Studio and everything works fine for each test I have run (no bug + teams set correctly), whereas on the mainsite, when I activate that feature, bugs come very soon and very often in the very beginning of the game: https://boardgamearena.com/bug?id=13713. That's it, it is a bug I do not manage to reproduce on Studio.
I have changed my approach and my code many times, but I am still stuck and I think I am missing the same thing all along. In order to eventually solve this problem once and for all, I think it would be wise to ask YOU how you would do that from scratch, instead of doing bug hunting for ever (which is difficult since I cannot reproduce that bug).
So if you are willing to propose your method and even your code I think that would help me a lot. No knowledge on the game itself is needed, I now give every details of what I want functionnally.
Situation
This is a game for 2 to 6 players. When there are 4 or 6 players, the admin can set the team mode (2 vs 2 with 4 players and 2 vs 2 vs 2 with 6). This part is OK., and we don't care about free-for-all games.
Now, I have set the game options to give the admin the possibility to set fixed teams (according to the position of the player in the table lobby) or leave them random or even do a combination of both (for example: in 2 vs 2 vs 2, two players in particular want to play together, leaving the four remaining spots random).
You can open a new table to see what these options are: https://boardgamearena.com/gamepanel?game=toc
One option for each teammate to set. In 4 players: Team A - player / Team A - teammate / Team B - player / Team B - teammate. And one Team C so two more options to set Team C. All of these can be set on Random (this is the default) or set on a particular player based on its order in the table (1 to 4 or 1 to 6 depending of the case).
Constraints
All teammates must sit in front of each other. That means in a 4 player game, if one teammate is now playing, an opponent will play after that, then the other teammate, then the other opponent. With 6 players, 2 opponents will play after the current player before his teammate plays.
This constraint must be honoured in the creation and the game and reflected in the turn order which is fixed then (so visible in the succession of player panels).
However, the position of the players in the team must remain random and also the order of the teams to play.
For example, if the settings are those: Team A : player 1, Team A : player 2, Team B : player 3, Team C : player 4, there is no reason that the succession in play is 1 > 3 > 2 > 4. Other valid examples are 4 > 1 > 2 > 3 or 2 > 3 > 1 > 4 for instance.
In a 6 player game, there is no reason that team A plays first then team B then team C, the succession can be A > B > C or B > A > C and the team who begins is also random.
Variables in code
Goal
Write your valid version of self::rearrangePlayersForTeams($players). I intentionnaly give no details about what I know about the bug of my version because I rather would like to see what come out from scratch, without a bias point of view like mine. I will give details later if that approach does not work.
Thanks really, really a lot if you have time to look at this. Don't hesitate to ask me questions if I am not clear.
That's a big thing I know, but I cannot tell you all valuable your help with that can be
I would not have posted that monster if I had not run out of other options...
Cheers,
Woodruff
(sorry that message is very long but if you are willing to read the beginning you will soon understand why
I am struggling with something which has pissed me of for a long time: setting teams in a game I developed and which is now already in production. This game is the Toc.
Why is it such a trouble? Because I implemented it on Studio and everything works fine for each test I have run (no bug + teams set correctly), whereas on the mainsite, when I activate that feature, bugs come very soon and very often in the very beginning of the game: https://boardgamearena.com/bug?id=13713. That's it, it is a bug I do not manage to reproduce on Studio.
I have changed my approach and my code many times, but I am still stuck and I think I am missing the same thing all along. In order to eventually solve this problem once and for all, I think it would be wise to ask YOU how you would do that from scratch, instead of doing bug hunting for ever (which is difficult since I cannot reproduce that bug).
So if you are willing to propose your method and even your code I think that would help me a lot. No knowledge on the game itself is needed, I now give every details of what I want functionnally.
Situation
This is a game for 2 to 6 players. When there are 4 or 6 players, the admin can set the team mode (2 vs 2 with 4 players and 2 vs 2 vs 2 with 6). This part is OK., and we don't care about free-for-all games.
Now, I have set the game options to give the admin the possibility to set fixed teams (according to the position of the player in the table lobby) or leave them random or even do a combination of both (for example: in 2 vs 2 vs 2, two players in particular want to play together, leaving the four remaining spots random).
You can open a new table to see what these options are: https://boardgamearena.com/gamepanel?game=toc
One option for each teammate to set. In 4 players: Team A - player / Team A - teammate / Team B - player / Team B - teammate. And one Team C so two more options to set Team C. All of these can be set on Random (this is the default) or set on a particular player based on its order in the table (1 to 4 or 1 to 6 depending of the case).
Constraints
All teammates must sit in front of each other. That means in a 4 player game, if one teammate is now playing, an opponent will play after that, then the other teammate, then the other opponent. With 6 players, 2 opponents will play after the current player before his teammate plays.
This constraint must be honoured in the creation and the game and reflected in the turn order which is fixed then (so visible in the succession of player panels).
However, the position of the players in the team must remain random and also the order of the teams to play.
For example, if the settings are those: Team A : player 1, Team A : player 2, Team B : player 3, Team C : player 4, there is no reason that the succession in play is 1 > 3 > 2 > 4. Other valid examples are 4 > 1 > 2 > 3 or 2 > 3 > 1 > 4 for instance.
In a 6 player game, there is no reason that team A plays first then team B then team C, the succession can be A > B > C or B > A > C and the team who begins is also random.
Variables in code
- One global variable, game_type, which is set to 2 in a 2 vs 2 game, and to 3 in a 2 vs 2 vs 2 player game. (1 is for free-for-all but we don't care)
- A set of 4 or 6 global variables used for team settings. Their value is 0 if that teammate is random, or indicates a player based on his order (player_table_no) in the table lobby. A control ensures that no player can appear twice.
- For a 2 vs 2 game, these variables are
- team_A1_2vs2
- team_A2_2vs2
- team_B1_2vs2
- team_B2_2vs2
- For a 2 vs 2 vs 2 game:
- team_A1_2vs2vs2
- team_A2_2vs2vs2
- team_B1_2vs2vs2
- team_B2_2vs2vs2
- team_C1_2vs2vs2
- team_C2_2vs2vs2
- For a 2 vs 2 game, these variables are
- The array $players is the associative array that stores all players to be written in the database. As you may know, it is passed as a parameter to the self::setupNewGame fonction. It has been shuffled by the BGA framework first. The keys are the player_id, the values stores the informations about the player, and specifically its order in the table lobby: player_table_no. This is that value which is referenced by the team settings when it is not set to random.
- A function self::rearrangePlayersForTeams, which is called once in the game setup, and with $players as a parameter. Its sole purpose is to change the order of the $player array in a way that is valid according to the team settings described above. THIS is the function I would like you to propose a code for, since my version is buggy. It is called with that line of code inside self::setupNewGame:(That function is called if and only if :
Code: Select all
$players = self::rearrangePlayersForTeams($players, $player_table_orders_by_team);- This is really a team game (game_typeequals 2 or 3)
- At least two options to define the teammates are not set on random (ie not zero). Indeed, if there is none or only one player specified, there is no point in shuffling the array since it has already be done before by the BGA framework and the result is valid.
Goal
Write your valid version of self::rearrangePlayersForTeams($players). I intentionnaly give no details about what I know about the bug of my version because I rather would like to see what come out from scratch, without a bias point of view like mine. I will give details later if that approach does not work.
Thanks really, really a lot if you have time to look at this. Don't hesitate to ask me questions if I am not clear.
That's a big thing I know, but I cannot tell you all valuable your help with that can be
I would not have posted that monster if I had not run out of other options...
Cheers,
Woodruff