Staggan Posted October 7, 2013 Share Posted October 7, 2013 Hello I am looking for some help.... I am trying to shuffle an array based on an ELO rating as part of a tournament system.... I currently select the teams taking part and create an array which is currently ordered by their team ID... but this can result in tournaments where the competitors in each round are always the same Instead I would to order the array by the teams ELO which is a numerical rating from 0 upwards What I would like to do is as follows: At the start of each round split the array into 2... so one new array contains teams with higher ELOs and another with the lower Then randomize each array Then add the arrays back together taking one element from each of the two arrays at a time... Ending up with something like... Array 1 element 1 Array 2 element 1 Array 1 element 2 Array 2 element 2 and so on... I also need it to work with an odd number of teams to start With the final array my system then creates the tournament games and rounds etc.... I have no idea where to start.. so any suggestions would be greatly appreciated Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted October 7, 2013 Share Posted October 7, 2013 sort teams array by ELO use array_slice to get 2 arrays shuffle them Quote Link to comment Share on other sites More sharing options...
Staggan Posted October 7, 2013 Author Share Posted October 7, 2013 I almost have this working now... But how do I combine my two final, shuffled arrays back into a single array without one just being tagged on the end of the other.. This is what I want to do: Array1 = 1,3,5,7 Array2 = 2,4,6,8 finalArray = 1,2,3,4,5,6,7,8 So my merge takes 1 element from each array at a time when merging... Thanks Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted October 7, 2013 Solution Share Posted October 7, 2013 A simple loop to take the elements from each array and build a third one? Quote Link to comment Share on other sites More sharing options...
Staggan Posted October 7, 2013 Author Share Posted October 7, 2013 Thanks All sorted..... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.