Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By gimbal2
  • 1 Post By JosAH

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

  1. #1
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Question 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:

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

    Java 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 :)
    Last edited by Castro__711; 12-18-2013 at 02:48 PM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default 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:

    Guide For New Members
    Castro__711 likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

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

    Thanks for the tip :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default 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
    Castro__711 likes this.
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Join Date
    Dec 2013
    Location
    Dublin
    Posts
    32
    Rep Power
    0

    Default 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.

Similar Threads

  1. Replies: 2
    Last Post: 09-23-2013, 02:16 AM
  2. Replies: 1
    Last Post: 02-21-2013, 07:20 PM
  3. Help would be Greatly Appreciated.. please
    By aejames23 in forum New To Java
    Replies: 6
    Last Post: 11-04-2012, 10:54 PM
  4. Replies: 5
    Last Post: 10-24-2012, 07:17 PM
  5. Java Calculator Help Would Be Greatly Appreciated
    By TommyR in forum New To Java
    Replies: 1
    Last Post: 03-14-2011, 09:30 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •