program experiment6 implicit none real :: t, a, r, c, rand, finished real, parameter :: dt = 0.01 integer :: b, w, numwalls, wallx, wally, temp, blocked = 0, NTW = 0, NTS = 0 integer, parameter :: width = 100 integer, parameter :: height = 100 integer, parameter :: N = 500 type student integer :: xpos, ypos, nextx, nexty, dx, dy, destx, desty, destox, destoy, done, red real :: realx, realy, rand endtype student integer :: columns(width, height) type(student) :: students(1:N) open(unit=3, file="data.txt", action="WRITE") open(unit=4, file="env.txt", action="READ") read(4,*) numwalls write(3,*) N write(3,*) numwalls write(3,*) 1001 columns = 0 do b = 1,numwalls,1 read(4,*) wallx read(4,*) wally columns(wallx,wally) = 2 write(3,*) wallx write(3,*) height - wally enddo columns(1,1:height) = 2 columns(width,1:height) = 2 columns(1:width,1) = 2 columns(1:width,height) = 2 call random_seed() do b = 1, N, 1 12 call random_number(rand) students(b)%xpos = rand * width call random_number(rand) students(b)%ypos = rand * height call random_number(rand) students(b)%destox = rand * width call random_number(rand) students(b)%destoy = rand * height students(b)%destx = 11 students(b)%desty = 21 if(students(b)%xpos < 55 .and. students(b)%xpos > 45) then if(students(b)%ypos > 70 .and. students(b)%ypos < 80) then students(b)%destx = 46 students(b)%desty = 21 endif endif if(students(b)%xpos < 90 .and. students(b)%xpos > 80) then if(students(b)%ypos > 70 .and. students(b)%ypos < 80) then students(b)%destx = 81 students(b)%desty = 21 endif endif !if(students(b)%destx < 50) students(b)%destx = 11 !if(students(b)%destx >= 50) then !print *, "blorg." !students(b)%destx = 89 !endif !if(students(b)%desty < 50) students(b)%desty = 21 !if(students(b)%desty >= 50) then !print *, "blorg." !students(b)%desty = 79 !endif !if(students(b)%xpos < 50) students(b)%xpos = 25 !if(students(b)%xpos >= 50) students(b)%xpos = 75 !if(students(b)%ypos < 50) students(b)%ypos = 25 !if(students(b)%ypos >= 50) students(b)%ypos = 75 if(students(b)%xpos < 2) goto 12 if(students(b)%xpos > 99) goto 12 if(students(b)%ypos < 2) goto 12 if(students(b)%ypos > 99) goto 12 if(columns(students(b)%xpos, students(b)%ypos) == 2) goto 12 if(columns(students(b)%destox, students(b)%destoy) == 2) goto 12 students(b)%done = 0 students(b)%nextx = students(b)%xpos students(b)%nexty = students(b)%ypos students(b)%dx = 0 students(b)%dy = 0 students(b)%red = 0 enddo do a = 1, N, 1 students(a)%realx = students(a)%xpos * 1.0 / width * 1.0 students(a)%realy = students(a)%ypos * 1.0 / height * 1.0 enddo do t = 0, 10, dt write(3,'(f 20.2)') t do a = 1, N, 1 write(3,*) students(a)%red enddo write(3,'(f 20.2)') students%realx write(3,'(f 20.2)') students%realy do a = 1, N, 1 students(a)%destox = 11 students(a)%destoy = 21 blocked = 0 students(a)%realx = students(a)%xpos * 1.0 / width * 1.0 students(a)%realy = students(a)%ypos * 1.0 / height * 1.0 if(students(a)%done == 1) goto 11 if(students(a)%done == -1) then students(a)%done = 0 goto 11 endif if(students(a)%destx > students(a)%xpos) students(a)%dx = 1 if(students(a)%destx < students(a)%xpos) students(a)%dx = -1 if(students(a)%desty > students(a)%ypos) students(a)%dy = 1 if(students(a)%desty < students(a)%ypos) students(a)%dy = -1 if(students(a)%destx == students(a)%xpos) students(a)%dx = 0 if(students(a)%desty == students(a)%ypos) students(a)%dy = 0 if(NTW == 0) then if(students(a)%dx == 0 .or. students(a)%dy == 0) then else if((students(a)%dx*(students(a)%destx - students(a)%xpos)) > (students(a)%dy*(students(a)%desty - students(a)%ypos))) then students(a)%dy = 0 endif if((students(a)%dx*(students(a)%destx - students(a)%xpos)) < (students(a)%dy*(students(a)%desty - students(a)%ypos))) then students(a)%dx = 0 endif endif endif 10 if(students(a)%dx == 0 .and. students(a)%dy == 0) goto 11 students(a)%nextx = students(a)%xpos + students(a)%dx students(a)%nexty = students(a)%ypos + students(a)%dy if(students(a)%nextx == students(a)%destx .and. students(a)%nexty == students(a)%desty) goto 11 NTW = 0 if(columns(students(a)%nextx,students(a)%nexty) == 2) then ! print *, "BLARG!" blocked = blocked + 1 if(students(a)%dx == 1) then if(students(a)%dy == 0) NTW = 1 if(students(a)%dy == 1) NTW = 2 if(students(a)%dy == -1) NTW = 8 endif if(students(a)%dx == -1) then if(students(a)%dy == 0) NTW = 5 if(students(a)%dy == 1) NTW = 4 if(students(a)%dy == -1) NTW = 6 endif if(students(a)%dx == 0) then if(students(a)%dy == 1) NTW = 3 if(students(a)%dy == -1) NTW = 7 endif if(NTW == 1) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 endif if(NTW == 2) then if(columns(students(a)%xpos+1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos+1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%destx - students(a)%xpos) > (students(a)%desty - students(a)%ypos)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTW == 3) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 endif if(NTW == 4) then if(columns(students(a)%xpos-1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos+1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%xpos - students(a)%destx) > (students(a)%desty - students(a)%ypos)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTW == 5) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 endif if(NTW == 6) then if(columns(students(a)%xpos-1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos-1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%xpos - students(a)%destx) > (students(a)%ypos - students(a)%desty)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTW == 7) then students(a)%dx = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 endif if(NTW == 8) then if(columns(students(a)%xpos+1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos-1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%destx - students(a)%xpos) > (students(a)%ypos - students(a)%desty)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(blocked > 1) then print *, "BLAAAAAAAAAAAAaaaaaaaaaaaarrrrrg..." print *, students(a)%destx print *, students(a)%desty students(a)%red = 255 blocked = 0 students(a)%destx = students(a)%xpos students(a)%desty = students(a)%ypos students(a)%nextx = students(a)%xpos students(a)%nexty = students(a)%ypos students(a)%dx = 0 students(a)%dy = 0 students(a)%done = -1 endif goto 10 endif if(columns(students(a)%nextx,students(a)%nexty) == 1) then if((students(a)%dx .neqv. 0) .or. (students(a)%dy .neqv. 0)) then blocked = blocked + 1 if(blocked > 1) then ! print *, "blahg" students(a)%red = students(a)%red + 5 students(a)%nextx = students(a)%xpos students(a)%nexty = students(a)%ypos students(a)%dx = 0 students(a)%dy = 0 goto 11 endif if(students(a)%dx == 1) then if(students(a)%dy == 0) NTS = 1 if(students(a)%dy == 1) NTS = 2 if(students(a)%dy == -1) NTS = 8 endif if(students(a)%dx == -1) then if(students(a)%dy == 0) NTS = 5 if(students(a)%dy == 1) NTS = 4 if(students(a)%dy == -1) NTS = 6 endif if(students(a)%dx == 0) then if(students(a)%dy == 1) NTS = 3 if(students(a)%dy == -1) NTS = 7 endif if(NTS == 1) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 endif if(NTS == 2) then if(columns(students(a)%xpos+1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos+1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%destx - students(a)%xpos) > (students(a)%desty - students(a)%ypos)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTS == 3) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 endif if(NTS == 4) then if(columns(students(a)%xpos-1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos+1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%xpos - students(a)%destx) > (students(a)%desty - students(a)%ypos)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTS == 5) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 endif if(NTS == 6) then if(columns(students(a)%xpos-1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos-1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%xpos - students(a)%destx) > (students(a)%ypos - students(a)%desty)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif if(NTS == 7) then students(a)%dx = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 endif if(NTS == 8) then if(columns(students(a)%xpos+1, students(a)%ypos) == 2) then students(a)%dx = 0 if(students(a)%desty > height / 2) students(a)%dy = 1 if(students(a)%desty < height / 2) students(a)%dy = -1 else if(columns(students(a)%xpos, students(a)%ypos-1) == 2) then students(a)%dy = 0 if(students(a)%destx > width / 2) students(a)%dx = 1 if(students(a)%destx < width / 2) students(a)%dx = -1 else if((students(a)%destx - students(a)%xpos) > (students(a)%ypos - students(a)%desty)) then students(a)%dy = 0 else students(a)%dx = 0 endif endif endif ! print *, 'Blarg?' ! print *, t ! print *, students(a)%dx ! print *, students(a)%dy ! FIX THIS PLEASE ! if((students(a)%dx .neqv. 0) .and. (students(a)%dy .neqv. 0)) then ! students(a)%dy = 0 ! else ! temp = students(a)%dx ! students(a)%dx = students(a)%dy ! students(a)%dy = temp ! endif ! goto 10 endif endif if(students(a)%nextx < 0) then students(a)%dx = 0 students(a)%dy = -1 endif if(students(a)%nextx > width) then students(a)%dx = 0 students(a)%dy = 1 endif if(students(a)%nexty < 0) then students(a)%dy = 0 students(a)%dx = -1 endif if(students(a)%nexty > height) then students(a)%dy = 0 students(a)%dx = 1 endif if(students(a)%destx == 46 .and. students(a)%desty == 21) then if(students(a)%xpos < 55 .and. students(a)%xpos > 45) then if(students(a)%ypos > 20 .and. students(a)%ypos < 30) then students(a)%destx = 11 students(a)%desty = 21 endif endif endif if(students(a)%destx == 81 .and. students(a)%desty == 21) then if(students(a)%xpos < 90 .and. students(a)%xpos > 80) then if(students(a)%ypos > 20 .and. students(a)%ypos < 30) then students(a)%destx = 11 students(a)%desty = 21 endif endif endif 11 columns(students(a)%xpos,students(a)%ypos) = 0 students(a)%xpos = students(a)%nextx students(a)%ypos = students(a)%nexty if(students(a)%xpos == students(a)%destox .and. students(a)%ypos == students(a)%destoy) then students(a)%done = 1 columns(students(a)%xpos,students(a)%ypos) = 2 else columns(students(a)%xpos,students(a)%ypos) = 1 students(a)%done = 0 endif enddo enddo close(3) do a = 1,N,1 if(students(a)%done > -1) finished = finished + students(a)%done enddo print *, "Students successful: ", finished print *, "Percent successful: ", (finished*100.0 / N), "%" end program experiment6 ! x: 11-19, 20-45, 46-54, 55-80, 81-89 ! y: 21-29, 30-70, 71-79