Advertisement
Oppaceted

Untitled

Feb 11th, 2023
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. program hello
  3.     implicit none
  4.     character, allocatable :: table(:,:)
  5.     integer :: n,a,b,player
  6.     logical :: process
  7.     logical :: player_win
  8.     !
  9.     write (*,'(a$)') 'Enter the size of the field:'
  10.     read (*,*) n
  11.     allocate(table(n,n))
  12.     table(:,:) = '-'
  13.     process = .true.
  14.     player = 1
  15.     !
  16.     do while(process)
  17.         if (player_win(table)) then
  18.             write (*,'(a,1x,i1,1x,a)') 'Congrats! Player', player, 'won!'
  19.             exit
  20.         else
  21.             do while (.true.)
  22.                 write (*,'(a,1x,i1,1x,a)') 'Player',player,'walks'
  23.                 write (*,'(a$)') 'Enter a row: '
  24.                 read (*,'(i5$)') a
  25.                 write (*,'(a$)') 'Enter a column: '
  26.                 read (*,'(i5$)') b
  27.                 if ( (.not.((a<=n).and.(1<=a))) .or. (.not.((b<=n).and.(1<=b))) ) then
  28.                     write (*,*) 'Enter the correct value!'
  29.                     cycle
  30.                 else if  ( (table(a,b) == '0') .or. (table(a,b) == 'x') ) then
  31.                     write (*,*) 'Enter the correct value!'
  32.                     cycle
  33.                 else
  34.                     exit
  35.                 end if
  36.             end do
  37.             if (player == 1) then
  38.                 table(a,b) = 'x'
  39.                 player = 2
  40.             else
  41.                 table(a,b) = '0'
  42.                 player = 1
  43.             end if
  44.             call draw(n,table)
  45.         end if
  46.     end do
  47.     deallocate(table)
  48. end program
  49. subroutine draw(r,table_2)
  50.     integer :: r, i, j, m
  51.     character :: table_2(r,r)
  52.     !
  53.     do m =1,r
  54.         if (m /= r) then
  55.             write (*,'(1x,i2$)') m
  56.         else
  57.             write (*,'(1x,i2)') m
  58.         end if
  59.     end do
  60.     do i =1,r
  61.         do j =1,r-1
  62.             write (*,'(2x,a$)') table_2(i,j)
  63.         end do
  64.         write (*,'(2x,a,1x,i2)') table_2(i,r), i
  65.     end do
  66. end subroutine
  67. logical function player_win(table_3)
  68.     player_win = .false.
  69. end function
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement