Qbasicnews.com

Full Version: Fixtures
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Can anybody help me with this i'm trying to get 20 teams that play each other twice i.e

Brazil V Argentina
Argentina V Brazil

and so on, each round wil be ten games and the whole thing will be 38 rounds
posting a bit of your own code first would be courteous Wink
put all 20 teams into an array TeamName$(1 to 20)

then

Code:
for team1% = 1 to 20
for team2% = 1 to 20
  if team1%<>team2% then print TeamName$(team1%);" vs. ";TeamName$(team2%)
next team2%, team1%

But for 20 teams to have 2 games against every other team...that's a ton of games. So I'm not sure if I'm understanding the situation correctly.

*peace*

Meg.
Here is my code

Code:
Randomize timer
dim team$(20)
restore dt:for a=1 to 20:read team$(a):next a
dt:
data "Arsenal","Aston Villa","Birmingham","Blackburn","Bolton"
data "Charlton","Chelsea","Crystal Palace","Everton","Fulham"
data "Liverpool","Manchester City","Man Utd","Middlesborough"
data "Newcastle","Norwich","Portsmouth","Southampton"
data "Tottenham","West Brom"
screen 13
color 1
round=1
rn:
for v=1 to 10:color 7:locate v+2,20:print "V":next
locate 1,1:print "round ";round
h=int(rnd*19)+1
if h=1 then color 4:locate 3,2:print team$(h)
'and so on until h=20
a=int(rnd*19)+1
if a=1 then color 4:locate 3,22:print team$(a)

thats the basis of the code
As I see it, you solve this problem:
19 rounds of ten games
Each team play each of the others once

Then simply repeat the solution.

Assume 4 teams
Then there would be 3 rounds of 2 games
Code:
Round 1
  a-b
  c-d
Round 2
  a-c
  b-d
Round 3
  a-d
  b-c
Assume 6 teams
Then there would be 5 rounds of 3 games
Code:
Round 1
  ad
  be
  cf
Round 2
  ae
  bf
  cd
Round 3
  af
  bd
  ce
Round 4
  ab
  cd
  ef
Round 5
  ac
  de
  fb

Hmmm. Must be a pattern here somewhere.

Mac
Well, not all problems have a solution.

I am betting that this problem cannot be solved.

It may be you can only solve it with pure multiples of two
2,4,8,16,32 players
not 20 players.

Not sure

Mac
Can anybody help me with this, i want to make a fixture list of soccer teams (8,10,12,14,16,18,20,22 & 24 teams)

The computer should pick the teams who play each other.

i.e. for 10 teams

there will be 18 weeks in the season
and that makes 5 games each week.

Week 1
Team 1 v team 2
team 3 v team 4
team 5 v team 6
team 7 v team 8
team 9 v team 10

week 2
team 10 v team 5
team 9 v teeam 1
team 8 v team 4
team 7 v team 3
team 6 v team 2

and so on till each team will have played each other twice (home and away)
For what it may be worth to Champions_2002, I would propose:

Quote:'SOCCER. '
'The program is to pick all the games for a given even number N of teams
'that are to play each other twice.

'My strategy would be to first make up all the possible combinations of
'teams, set up in an array arrangement. For example, for 6 teams, the
'array arrangement would be:

' 1,2, 1,3, 1,4, 1,5, 1,6
'2,1, 2,3, 2,4, 2,5, 2,6
'3,1, 3,2, 3,4, 3,5, 3,6
'4,1, 4,2, 4,3, 4,5, 4,6
'5,1, 5,2, 5,3, 5,4, 5,6
'6,1, 6,2, 6,3, 6,4, 6,5

'As can be seen, the diagonal of the above would consist of the combination
'of a team with itself, which is a nonsense occurance, and is thus eliminated
'from the arrangement, as well as from further consideration.

'With the above array formed, we can assign the combinations to a single
'dimension array, say CHOICE(30). It now becomes a matter of randomly
'chosing one of the 30 elements for the first game, and eliminating that
'array element from te CHOICE() array, and so on, until the coupled teams
'for the first 5 games are established.

'The above would be repeated for the second series of games, and so on for
'the 6 series of games, when no array element is left of the 30 elements.

'For the example of 6 teams, the total number of games are 6 * 5 = 30.

'In general, for N teams, the array CHOICE() would be dimensioned per the
'total number of teams to the second power, or DIM CHOICE(N * N), and the
'total number of games would be N * (N-1).
Quote:Can anybody help me with this, i want to make a fixture list of soccer teams (8,10,12,14,16,18,20,22 & 24 teams)

Well, at least I know this is not homework since you waited a WHOLE YEAR to check on this thread. Must not be in a big rush. :rotfl:

Here is a program that produces a file I happened to call z.dat.

It contains stuff like this:

ghabcdef
egfhacbd
dfehagbc
cfdeahbg
bhceadfg
cgbfdhae
afdgbech
ijabcdefgh
bcdiahegfj
aidgfhbjce
bideagcfhj
...

The top line is round one. The teams playing are
gh ab cd ef

Next round: eg fh ac bd

When the lines get larger, it is the next case you wanted.
ij ab cd ef gh is round one for 10 teams.

You get the idea. You can use that file to print something nicer looking.

Just do the whole thing again to reverse home team and visitors.

Mac

Code:
CONST Alpha = "abcdefghijklmnopqrstuvwxyz"
DECLARE SUB d (s AS STRING)
DIM SHARED p(1000) AS STRING * 2
DIM SHARED px AS INTEGER
DIM SHARED c AS STRING * 1
DIM SHARED Result(100) AS STRING
DIM SHARED ResultX AS INTEGER
CLS
PRINT "It's running. Be patient."
RANDOMIZE TIMER
DIM SHARED WeGotIt AS INTEGER
OPEN "z.dat" FOR OUTPUT AS #1
FOR t% = 8 TO 24 STEP 2
  DO
    ResultX = 0
    CALL d(LEFT$(Alpha, t%))
  LOOP UNTIL WeGotIt
  FOR i = 1 TO ResultX: PRINT #1, Result(i): NEXT i
NEXT t%
CLOSE #1
CLS : PRINT "Done"
SYSTEM

SUB d (s AS STRING)
DIM cnt AS INTEGER: cnt = LEN(s)
DIM Rounds AS INTEGER: Rounds = cnt - 1
DIM Games AS INTEGER: Games = cnt / 2
'PRINT "Rounds to play: "; Rounds
'PRINT "Games per round: "; Games
px = 0
DIM i AS INTEGER, j AS INTEGER
FOR i = 1 TO LEN(s) - 1
  c = MID$(s, i, 1)
  FOR j = i + 1 TO LEN(s)
    px = px + 1
    p(px) = c + MID$(s, j, 1)
  NEXT j
NEXT i
FOR round = 1 TO Rounds: GOSUB DoRound: NEXT round
WeGotIt = -1
EXIT SUB
DoRound:
Oldpx = px
DO
  tries = tries + 1: IF tries > 1000 THEN EXIT SUB
  rz$ = p(px): px = px - 1
  FOR uu% = 1 TO Games: GOSUB Do1: NEXT uu%
  IF LEN(rz$) = cnt THEN EXIT DO
  px = Oldpx
  FOR i = 1 TO px
    SWAP p(i), p(1 + INT(RND * px))
  NEXT i
LOOP
ResultX = ResultX + 1: Result(ResultX) = rz$
RETURN

Do1:
FOR i = 1 TO px
  cz$ = p(i)
  IF INSTR(rz$, LEFT$(cz$, 1)) = 0 THEN
    IF INSTR(rz$, RIGHT$(cz$, 1)) = 0 THEN
      rz$ = rz$ + cz$
      IF i <> px THEN SWAP p(i), p(px)
      px = px - 1
      EXIT FOR
    END IF
  END IF
NEXT i
RETURN

END SUB
Hope this isn't a real problem, but, in line 3 and in line 11, I see ag repeated! Sad
And, in lines 1 and 8, cd is repeated. I won't look further...
Pages: 1 2