# Need Desperate help to create a tournament matrix in Fortran

Status
Not open for further replies.

#### dannyf

##### Technical User
I really need desperate help to do this. If somebody can help me I would really appreciate it.

This is the exact assignement:

Tournament Simulation:

This project simulates a tournament or sports league. Start with N players or teams. Each player is assigned a rating. The probability of player I beating player J depends on their ratings, e.g

p(I,J)=1/2 + 1/2(r(I)-r(J))/(r(I)+r(J))

In the simplest tournament, each player plays each other player M times. A random number generator is used to decide which player wins a game. CAlling the intrinsic subroutine

CALL RANDOM_NUMBER(x)

returns a number between 0 and 1 randomly (a different number each time). Note: you get the same sequence of random numbers each time you run the program. This is often useful, especially for checking error.

Obtain the final rankings of the players. Did the best player win?

Basic Program:

The players should be given names. On output, the ratings of each player should be printed, as well as the final rankings after one tournament.

Options:
1. Play many tournaments. How often does each player win or become champion.
2. Include possibility of draws.
3. Include playoffs, divisions, promotion relegation,etc.
4. Simulate an actual tournament or league

Here is the code that I have written so far:

Program Tournament
Implicit None

Integer, Parameter :: ntotal=5
Integer :: Ratings(ntotal), position, wins(ntotal)=0, details(ntotal, ntotal) = 0
Integer :: randomseed, losses=0, y=0, i
Character (len=10) :: Names(ntotal)
Real :: x
open(13, file=&quot;Rankings.txt&quot
Print*, &quot;Enter number less than 1000&quot;
Do i = 1, randomseed
Call random_number(x)
End Do
Names(1)='Michelle'
Names(2)='David'
Names(3)='Mark'
Names(4)='Diana'
Names(5)='Jimmy'
Ratings = (/ 3, 7, 8, 2, 9 /)
write(13,*)'Player1 Player2'

Do i = 1, ntotal
write(*, *) array(i)
end do

Call RoundRobin()
write(13,*)'Name Rating Games won Games Lost Games Drawn'
Do position = 1, ntotal
losses = (ntotal-1) - wins(position)
write(13, '(a, 2i4, a,i4, a, i4, a)' ) names(position),ratings(position), wins(position) ,&
& &quot; games&quot;, losses , &quot; games&quot;,y, &quot; games&quot;
End Do
contains

Function Tourn(I, J)
Integer, intent(in) :: I, J
Real :: Tourn
Tourn = 0.5 + 0.5*(ratings(I) - ratings(J))/(ratings(I) + ratings(J))
End Function Tourn

Subroutine Game(position1, position2)
Integer, intent(in) :: position1, position2
Real :: Prob
Call Random_Number(x)
Prob = Tourn(position1, position2)
If (x > prob) then !!person at position 2 beats person at position 1
wins(position2) = wins(position2) + 1
details(position2, position1) = details(position2, position1) + 1
Else If (x < prob)then !!person at position 1 won
wins(position1) = wins(position1) + 1
write(13,*)names(position1), &quot;beat&quot;, names(position2)
Else
y = y + 1
End If
End Subroutine Game

Subroutine RoundRobin()
Integer :: posn1, posn2
Do posn1 = 1,ntotal-1
Do posn2 = posn1+1,ntotal
Call Game(posn1, posn2)
End Do
End Do
End Subroutine RoundRobin
End Program Tournament

Status
Not open for further replies.

Replies
2
Views
114
Replies
7
Views
234
Replies
11
Views
170
Replies
28
Views
402
Replies
4
Views
122