×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need Desperate help to create a tournament matrix in Fortran

Need Desperate help to create a tournament matrix in Fortran

Need Desperate help to create a tournament matrix in Fortran

(OP)
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="Rankings.txt")
Print*, "Enter number less than 1000"
Read*, randomseed
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) ,&
&  " games", losses , " games",y, " games"
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), "beat", 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close