Quantcast
Channel: Latest Questions by MFen
Viewing all articles
Browse latest Browse all 8

I have 2 Arrays, find all combinations order does not matter

$
0
0
Okay so a little more than the title says, with these two arrays the second array will only ever have one parameter to match, I'll just write out what I expect: Arr1 = player1, player2, player3 Arr2 = ai1, ai2, ai3 combos would be: (Player1,ai1), (Player1,ai2), (Player1,ai3), (Player2,ai1), (Player2,ai2), (Player2,ai3), (Player3,ai1), (Player3,ai2), (Player3,ai3), (Player1,Player2,ai1), (Player1,Player3,ai1), (Player2,Player3,ai1), (Player1,Player2,ai2), (Player1,Player3,ai2), (Player2,Player3,ai2), (Player1,Player2,ai3), (Player1,Player3,ai3), (Player2,Player3,ai3), (Player1,Player2,Player3,ai1),(Player1,Player2,Player3,ai2),(Player1,Player2,Player3,ai3) Also, these variables are bools, and would preferably be linked to the resulting combination so when player one is true than it also triggers the same bool in all combination arrays. Here's some code so far - public bool[] playerParams = new bool[3]; public bool[] aiParams = new bool[3]; public List instrinsicParams = new List(); public List exstrinsicParams = new List(); List Matchup(ref AISelectionMatrix aiSelections) { List currentList = new List(); int matchAmount = 2; for(int i = 0; i < aiSelections.playerParams.Length; i++) { for(int k = 0; k < aiSelections.aiParams.Length; k++) { bool[] temp = new bool[matchAmount]; for(int m = 0; m < matchAmount; m++) { temp[m] = aiSelections.playerParams[i]; } temp[matchAmount-1] = aiSelections.aiParams[k]; if(!findMatch(ref currentList, temp)) currentList.Add(temp); } } for (int i = 0; i < currentList.Count; i++) Debug.Log (currentList [i]); return currentList; } The reason I need this dynamic rather than just writing out combinations like I did is that the list of parameters may change and its preferable if the combinations update accordingly. Any help or push in the right direction would be very appreciated!

Viewing all articles
Browse latest Browse all 8

Trending Articles