# Football tournament algorithm. Any advice would be greatly appreciated :)

Printable View

• 12-18-2013, 02:23 PM
Castro__711
Football tournament algorithm. Any advice would be greatly appreciated :)
Hi
again I am relatively new to Java and I am working on a personal project that I can use in a College/Work experience interview. The project is an application that can simulate a football tournament draw.

So far I have used a combination of arrays, scanners and lists in my class.
I display the teams with their corresponding index number;
and prompt the user to input the number of participants;
then the user selects from a possible of 26 teams by individually inputting their index number when prompted;
then I create a List and pass it the participants;
from here I can shuffle etc to get the desired randomness;

now here's my problem:
In the user interface the user can select from play each team once or play each team twice.
I am having problems creating an algorithm for each rounds fixture list where each team plays eachother once (or if twice once at home and once away), does not play a team already played etc etc.

If possible I would like to achieve this by using loops and not having to write tons and tons of code !

Here is a snipet of my code:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Code:

``` String[] homeGames;         homeGames = new String[ participants.length / 2 ];         String[] awayGames;         awayGames = new String[ participants.length / 2 ];                 ListIterator < String > iterator = list.listIterator();                         /*         *  Populate newly created arrays using the iterator         */                         for( int lcv = 0; lcv < participants.length / 2; lcv++ ){                         homeGames[ lcv ] = iterator.next();             awayGames[ lcv ] = iterator.next();                         System.out.printf( "%s\tVs\t%s\n", homeGames[ lcv ],                     awayGames[ lcv ] );                     } // end of for loop to populate homeGames and awayGames arrays                 String[][] fixtures;         fixtures = new String[ participants.length / 2 ]                 [ participants.length / 2 ];                 for( int lcv = 0; lcv < participants.length / 2; lcv ++ ){                         for( int cv = 0; cv < participants.length / 2; cv++ ){                                 System.out.printf( "%s\tVs\t%s\n", homeGames[ cv ],                         awayGames[ lcv ] );                                                             } // end of inner for loop to sort awayGames suitors                         System.out.println();                     } // end of outter for loop containing first set Of homeGames                             System.out.println();```
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

I am trying numerous things to get a solution I thought a two-dim array (fixtures) would help, but cannot quite figure out how?

I would really appreciate any help with this, even if you could point me to a site that helps to create/ understand algorithms, any tips or other options I could take to achieve this.

Thanks for reading this post :)
• 12-18-2013, 03:00 PM
gimbal2
Re: Football tournament algorithm. Any advice would be greatly appreciated :)
You will get more people to seriously read your post if you use proper code formatting tags as described here:

http://www.java-forums.org/forum-gui...w-members.html
• 12-18-2013, 03:31 PM
Castro__711
Re: Football tournament algorithm. Any advice would be greatly appreciated :)
Thanks for the tip :)
• 12-18-2013, 09:05 PM
JosAH
Re: Football tournament algorithm. Any advice would be greatly appreciated :)
Suppose you have a square matrix where the rows and columns represent teams; if an entry i,j in the matrix is marked, team i plays against team j. Note that entry i,i can never be marked (a team can't play against itself). If you want one match only (per team), you can only mark the upper (or lower) triangular matrix. For two matches per team you can mark the entire matrix. Both variants can be done with two nested loops per variant (don't forget to exclude the diagonal for the second variant).

kind regards,

Jos
• 12-18-2013, 10:07 PM
Castro__711
Re: Football tournament algorithm. Any advice would be greatly appreciated :)
Thank you very much Jos :) you have given me a direction. I am going to take this, do some homework on it and some trial and error. I really appreciate your help again thank you very much. I will post to let you know when I get success. :(nod):