Jump to content

Zugzwangle

Members
  • Posts

    56
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Zugzwangle's Achievements

Member

Member (2/5)

0

Reputation

  1. I have been given this formula. n = teams / 2... The teams should only be even numbers. n is always even!! (1,2,3,4... 2n .... ) which sums up to: if (i v j) ---> 1 < (|i-j| % 2n) < n - 1 , i = home, if (i v j) ---> n + 1 < (|i-j| % 2n) < 2n - 1, i = home, if (i v j) ---> (|i-j| % 2n) = n and ( i > j) i = home else i = away This produces an array of 12 teams such as: Where Rounds --> Matches --> Teams --> Team numbers Array ( [0] => Array ( [0] => Array ( [0] => 7 [1] => 1 ) [1] => Array ( [0] => 8 [1] => 2 ) [2] => Array ( [0] => 9 [1] => 3 ) [3] => Array ( [0] => 10 [1] => 4 ) [4] => Array ( [0] => 11 [1] => 5 ) [5] => Array ( [0] => 12 [1] => 6 ) ) [1] => Array ( [0] => Array ( [0] => 2 [1] => 1 ) [1] => Array ( [0] => 3 [1] => 7 ) [2] => Array ( [0] => 4 [1] => 8 ) [3] => Array ( [0] => 5 [1] => 9 ) [4] => Array ( [0] => 6 [1] => 10 ) [5] => Array ( [0] => 12 [1] => 11 ) ) [2] => Array ( [0] => Array ( [0] => 1 [1] => 3 ) [1] => Array ( [0] => 4 [1] => 2 ) [2] => Array ( [0] => 5 [1] => 7 ) [3] => Array ( [0] => 6 [1] => 8 ) [4] => Array ( [0] => 12 [1] => 9 ) [5] => Array ( [0] => 11 [1] => 10 ) ) [3] => Array ( [0] => Array ( [0] => 4 [1] => 1 ) [1] => Array ( [0] => 5 [1] => 3 ) [2] => Array ( [0] => 6 [1] => 2 ) [3] => Array ( [0] => 12 [1] => 7 ) [4] => Array ( [0] => 11 [1] => 8 ) [5] => Array ( [0] => 10 [1] => 9 ) ) [4] => Array ( [0] => Array ( [0] => 1 [1] => 5 ) [1] => Array ( [0] => 6 [1] => 4 ) [2] => Array ( [0] => 3 [1] => 12 ) [3] => Array ( [0] => 2 [1] => 11 ) [4] => Array ( [0] => 10 [1] => 7 ) [5] => Array ( [0] => 9 [1] => 8 ) ) [5] => Array ( [0] => Array ( [0] => 6 [1] => 1 ) [1] => Array ( [0] => 5 [1] => 12 ) [2] => Array ( [0] => 4 [1] => 11 ) [3] => Array ( [0] => 3 [1] => 10 ) [4] => Array ( [0] => 2 [1] => 9 ) [5] => Array ( [0] => 8 [1] => 7 ) ) [6] => Array ( [0] => Array ( [0] => 1 [1] => 12 ) [1] => Array ( [0] => 11 [1] => 6 ) [2] => Array ( [0] => 10 [1] => 5 ) [3] => Array ( [0] => 9 [1] => 4 ) [4] => Array ( [0] => 8 [1] => 3 ) [5] => Array ( [0] => 7 [1] => 2 ) ) [7] => Array ( [0] => Array ( [0] => 11 [1] => 1 ) [1] => Array ( [0] => 10 [1] => 12 ) [2] => Array ( [0] => 9 [1] => 6 ) [3] => Array ( [0] => 8 [1] => 5 ) [4] => Array ( [0] => 7 [1] => 4 ) [5] => Array ( [0] => 2 [1] => 3 ) ) [8] => Array ( [0] => Array ( [0] => 1 [1] => 10 ) [1] => Array ( [0] => 9 [1] => 11 ) [2] => Array ( [0] => 8 [1] => 12 ) [3] => Array ( [0] => 7 [1] => 6 ) [4] => Array ( [0] => 2 [1] => 5 ) [5] => Array ( [0] => 3 [1] => 4 ) ) [9] => Array ( [0] => Array ( [0] => 9 [1] => 1 ) [1] => Array ( [0] => 8 [1] => 10 ) [2] => Array ( [0] => 7 [1] => 11 ) [3] => Array ( [0] => 12 [1] => 2 ) [4] => Array ( [0] => 3 [1] => 6 ) [5] => Array ( [0] => 4 [1] => 5 ) ) [10] => Array ( [0] => Array ( [0] => 1 [1] => 8 ) [1] => Array ( [0] => 7 [1] => 9 ) [2] => Array ( [0] => 10 [1] => 2 ) [3] => Array ( [0] => 11 [1] => 3 ) [4] => Array ( [0] => 12 [1] => 4 ) [5] => Array ( [0] => 5 [1] => 6 ) ) ) If displayed as, Teams --> Rounds --> Home / Away.. it looks like this: Array ( [1] => Array ( [0] => 1 [1] => 1 [2] => 0 [3] => 1 [4] => 0 [5] => 1 [6] => 0 [7] => 1 [8] => 0 [9] => 1 [10] => 0 ) [2] => Array ( [0] => 1 [1] => 0 [2] => 1 [3] => 1 [4] => 0 [5] => 0 [6] => 1 [7] => 0 [8] => 0 [9] => 1 [10] => 1 ) [3] => Array ( [0] => 1 [1] => 0 [2] => 1 [3] => 1 [4] => 0 [5] => 0 [6] => 1 [7] => 1 [8] => 0 [9] => 0 [10] => 1 ) [4] => Array ( [0] => 1 [1] => 0 [2] => 0 [3] => 0 [4] => 1 [5] => 0 [6] => 1 [7] => 1 [8] => 1 [9] => 0 [10] => 1 ) [5] => Array ( [0] => 1 [1] => 0 [2] => 0 [3] => 0 [4] => 1 [5] => 0 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 0 ) [6] => Array ( [0] => 1 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 1 ) [7] => Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 0 ) [8] => Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 1 ) [9] => Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 1 [4] => 0 [5] => 1 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 1 ) [10] => Array ( [0] => 0 [1] => 1 [2] => 1 [3] => 0 [4] => 0 [5] => 1 [6] => 0 [7] => 0 [8] => 1 [9] => 1 [10] => 0 ) [11] => Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 0 [4] => 1 [5] => 1 [6] => 0 [7] => 0 [8] => 1 [9] => 1 [10] => 0 ) [12] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 0 [10] => 0 ) ) As you can see, although there ARE a fairly distributed number of teams with home or away, in some cases there are long strings of matches at home, for some teams!! Can you help me sort this one out!! Please try if you can. Thanks in advance
  2. Hi all. I have a question involving a Round Robin sporting event. I want to create a formula to evenly distribute home and away matches. Firstly, to less complicate the situation, I need only consider even number participants in the tournament, as I would substitute a 'bye' with an extra number if need be. You can visualise the Round Robin Schedule below. However I am going to complicate the issue. This is a Single Round robin - so each team plays each other team ONCE only. From my own mathematical findings, I have found that: Participants 1). Matches per round = P / 2 2). Rounds = P - 1 3). Games (or I considered this the 'area' of the triangle, and hence a triangle number) , so the nth triangle number = (P^2 - P) / 2. (Multiply matches per round by Rounds) 4). If I create a Round Robin using a rotating formula such as this where the numbers rotate around the first number (1) the numbers are not correctly distributed between home and away R1 R2 R3 R4 12 16 15 etc .... 63 52 41 .... 54 43 32 .... =>>>> works out as If H = Home, A=Away Participant 1 HHHHH Participant 2 AAHHH Participant 3 AAHHH Participant 4 AAHHH Participant 5 AAHHH Participant 6 AAHHH An example of how the finished tournament would look like: Participant 1 HAHAH Participant 2 AHAHA Participant 3 HAHAH Participant 4 AHAHA Participant 5 HAHAH Participant 6 AHAHA Given I have already paired the participants, how might I go about formulating an equally distributed Single Round Robin Tournament!!
  3. Please excuse me requinix. That is correct!! $check_valid produces nothing, even though $team_selection echo's the team, and check_invalid_lineup() is a valid callable function...
  4. I have the following code: $new_model = new Model; $check_valid = $new_model->check_invalid_lineup($team_selection); echo $check_valid fails to work. I have checked, it is a valid function, with in my Model class, and I have set it to simply return the input parameter. So it looks like this: public function check_invalid_lineup($teamid) { return $teamid; } The variable $team_selection, is gained from another method in the Model class, instantiated by: $new_model = new Model; $user_info_select = $new_model->user_info(); $team_selection = $user_info_select['team']; I am stumped as to why I can echo $team_selection with no problem, yet when I insert it as a parameter in the function, check_invalid_lineup() it fails to work! Have been puzzling over this for a good few days, shifting code and having no success. Any ideas?
  5. Hi there - thanks in anticipation of any help you may offer!!! I am using the following function, to generate a round robin tournament: function round_robin($teams){ if (count($teams)%2 != 0){ array_push($teams,"Bye"); } $away = array_splice($teams,(count($teams)/2)); $home = $teams; for ($i=0; $i < count($home)+count($away)-1; $i++){ for ($j=0; $j<count($home); $j++){ $round[$i][$j]['Home']=$home[$j]; $round[$i][$j]['Away']=$away[$j]; } if(count($home)+count($away)-1 > 2){ array_unshift($away,array_shift(array_splice($home,1,1))); array_push($home,array_pop($away)); } } return $round; } This produces a round robin tournament, but this does not outcome in evenly distributed data. For example if you insert an array of values 'Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', it revolves the other teams around 'Team 1' meaning, 'Team 1' gets 6x Home games. I added bit of code to even it up. $unformatted_matches = round_robin($teams_entered); foreach ($unformatted_matches as $key => $value) { if($key % 2 !== 1) { $reversed = array_reverse($value[0]); array_values($reversed); $unformatted_matches[$key][0] = $reversed; } } However the produces a schedule such as shown at this link: https://docs.google.com/spreadsheet/ccc?key=0AvUWywpDuSKudFZId1NUSGltVll6dlVKanluQjhGWmc&usp=sharing where all but 'Team 1' face consecutive matches away or at home!! I hope you are still following at this point! What I would like to achieve, is to make the matches distributed evenly, so each team would play Home Away Home Away etc!! It would be great to get some help here. Thanks Zugz
  6. I found my answer!! function sort_array($array, $orderArray) { $ordered = array(); foreach($orderArray as $key => $value) { if(array_key_exists($key,$array)) { $ordered[$key] = $array[$key]; unset($array[$key]); } } return $ordered + $array; } Thanks for reading anyhow.
  7. No, it is not directly from a query. I have already had to play around with the data to get the format above.. I think usort is the way to go, but I am trying to work out how to use usort!! Thanks for replying anyway. Zugz
  8. Hi there all, Thank you for your suggestions and help in anticipation of your help!! I have 2x arrays. The first is an array of the totals for each round. The second is an array split into weeks (the weeks being the first level keys. I would like to arrange all of the second subarray team names, in order of the teamnames of the first array. so in order of [team3], [team5], [team1], [team2] and [team4].. I hope you follow what I mean.. Here are the first and second arrays!! First array (Total of rounds) Array ( [Team3] => Array ( [brd_points] => 14 [ttl_points] => 5 [games] => 3 ) [Team5] => Array ( [brd_points] => 12 [ttl_points] => 3 [games] => 2 ) [Team1] => Array ( [brd_points] => 7 [ttl_points] => 3 [games] => 2 ) [Team2] => Array ( [brd_points] => 16 [ttl_points] => 1 [games] => 3 ) [Team4] => Array ( [brd_points] => 7 [ttl_points] => 0 [games] => 2 ) )1 // Second array - individual rounds. Array ( [1] => Array ( [Team3] => Array ( [brd_points] => 4 [ttl_points] => 2 ) [Team2] => Array ( [brd_points] => 6 [ttl_points] => 0 ) [Team4] => Array ( [brd_points] => 6 [ttl_points] => 0 ) [Team1] => Array ( [brd_points] => 2 [ttl_points] => 2 ) [Team5] => Array ( [brd_points] => Bye [ttl_points] => Bye ) ) [2] => Array ( [Team3] => Array ( [brd_points] => 5 [ttl_points] => 2 ) [Team4] => Array ( [brd_points] => 1 [ttl_points] => 0 ) [Team5] => Array ( [brd_points] => 7 [ttl_points] => 2 ) [Team2] => Array ( [brd_points] => 5 [ttl_points] => 0 ) [Team1] => Array ( [brd_points] => Bye [ttl_points] => Bye ) ) [3] => Array ( [Team2] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team3] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team5] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team1] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team4] => Array ( [brd_points] => Bye [ttl_points] => Bye ) ) ) 1 Again thanks for your help!!
  9. Figured it out!! (Missed 2x parameters). foreach ($totals as $key => $row) { $ttl_points_check[$key] = $row['ttl_points']; $brd_points_check[$key] = $row['brd_points']; } array_multisort( $ttl_points_check, SORT_DESC, $brd_points_check, SORT_DESC, $totals);
  10. Hi all, I sorted this array: array ( 'team4' => array ( 'brd_points' => 16, 'ttl_points' => 1, ), 'team1' => array ( 'brd_points' => 14, 'ttl_points' => 5, ), 'team3' => array ( 'brd_points' => 12, 'ttl_points' => 3, ), 'team2' => array ( 'brd_points' => 7, 'ttl_points' => 3, ), 'team5' => array ( 'brd_points' => 7, 'ttl_points' => 0, ), ) Into this array: array ( 'team1' => array ( 'brd_points' => 14, 'ttl_points' => 5, ), 'team2' => array ( 'brd_points' => 7, 'ttl_points' => 3, ), 'team3' => array ( 'brd_points' => 12, 'ttl_points' => 3, ), 'team4' => array ( 'brd_points' => 16, 'ttl_points' => 1, ), 'team5' => array ( 'brd_points' => 7, 'ttl_points' => 0, ), ), By using this code with array_multisort() foreach ($totals as $key => $row) { $ttl_points_check[$key] = $row['ttl_points']; } array_multisort( $ttl_points_check, SORT_DESC, $totals); That works fine, but what if I firstly want to sort by 'ttl_points', and then by 'brd_points'.. In the case above, team3, should be above team 2!! Thanks for reading and replying!
  11. Thanks for your posts.. That really helped me, ta. Jeff Morris
  12. Hi all, I have this array: Array ( [3] => Array ( [Team1] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team2] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team3] => Array ( [brd_points] => 5 [ttl_points] => 1 ) [Team4] => Array ( [brd_points] => 5 [ttl_points] => 1 ) ) [2] => Array ( [Team2] => Array ( [brd_points] => 5 [ttl_points] => 2 ) [Team5] => Array ( [brd_points] => 1 [ttl_points] => 0 ) [Team3] => Array ( [brd_points] => 7 [ttl_points] => 2 ) [Team1] => Array ( [brd_points] => 5 [ttl_points] => 0 ) ) [1] => Array ( [Team2] => Array ( [brd_points] => 4 [ttl_points] => 2 ) [Team1] => Array ( [brd_points] => 6 [ttl_points] => 0 ) [Team5] => Array ( [brd_points] => 6 [ttl_points] => 0 ) [Team4] => Array ( [brd_points] => 2 [ttl_points] => 2 ) ) ) 1 I would like to get an array of the sum of all the [brd_points] and [ttl_points] for each team.. so... it would become.. Array ( [Team1] => Array ( [brd_points] => 16 // 5 + 5 + 16 [ttl_points] => 1 // 1 + 0 + 0 ) [Team2] => Array ( [brd_points] => ?? [ttl_points] => ?? ) etc...
  13. You were right on: Thank you for taking the time to post. You have helped me out a lot. Zugz
  14. I have overwritten the whole forum with a fresh install.. Still no joy. Database problem do you think?
  15. It is the inbuilt phpbb function. I will overwrite the phpbb with new files I guess, to see if that eliminates that avenue.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.