Advertisement
Oppaceted

x0_2

Feb 16th, 2023
372
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,win,a,b,player
  6.     logical :: process
  7.     integer :: player_win
  8.     !
  9.     do while(.true.)
  10.         write (*,'(a$)') 'Enter the size of the field:'
  11.         read (*,*) n
  12.         if ( (n >= 20) .or. (n <= 0) ) then
  13.             write (*,'(a)') 'Too big or incorrect value, try again.'
  14.             cycle
  15.         else
  16.             exit
  17.         end if
  18.     end do
  19.     do while(.true.)
  20.         write (*,'(a$)') 'Enter the number of cells required to win:'
  21.         read (*,*) win
  22.         if ( (win > n) .or. (win <= 0) ) then
  23.             write (*,'(a)') 'Too big or incorrect value, try again.'
  24.             cycle
  25.         else
  26.             exit
  27.         end if
  28.     end do
  29.     allocate(table(n,n))
  30.     table(:,:) = '-'
  31.     player = 1
  32.     process = .true.
  33.     !
  34.     do while(process)
  35.         if (player_win(n,table)==1) then
  36.             write (*,'(a)') 'Congrats! Player 1 won!'
  37.             exit
  38.         elseif (player_win(n,table)==2) then
  39.             write (*,'(a)') 'Congrats! Player 2 won!'
  40.             exit
  41.         elseif (player_win(n,table)==3) then
  42.             write (*,'(a)') 'No one won!'
  43.             exit
  44.         else
  45.             do while (.true.)
  46.                 write (*,'(a,1x,i1,1x,a)') 'Player',player,'walks'
  47.                 write (*,'(a$)') 'Enter a row: '
  48.                 read (*,'(i5$)') a
  49.                 write (*,'(a$)') 'Enter a column: '
  50.                 read (*,'(i5$)') b
  51.                 if ( (.not.((a<=n).and.(1<=a))) .or. (.not.((b<=n).and.(1<=b))) ) then
  52.                     write (*,'(a)') 'Enter the correct value!'
  53.                     cycle
  54.                 else if  ( (table(a,b) == '0') .or. (table(a,b) == 'x') ) then
  55.                     write (*,'(a)') 'Enter the correct value!'
  56.                     cycle
  57.                 else
  58.                     exit
  59.                 end if
  60.             end do
  61.             if (player == 1) then
  62.                 table(a,b) = 'x'
  63.                 player = 2
  64.             else
  65.                 table(a,b) = '0'
  66.                 player = 1
  67.             end if
  68.             call draw(n,table)
  69.         end if
  70.     end do
  71.     deallocate(table)
  72. end program
  73. subroutine draw(draw_size,draw_table)
  74.     integer :: draw_size, i, j, m
  75.     character :: draw_table(draw_size,draw_size)
  76.     !
  77.     do m =1,draw_size
  78.         if (m /= draw_size) then
  79.             write (*,'(1x,i2$)') m
  80.         else
  81.             write (*,'(1x,i2)') m
  82.         end if
  83.     end do
  84.     do i =1,draw_size
  85.         do j =1,(draw_size-1)
  86.             write (*,'(2x,a$)') draw_table(i,j)
  87.         end do
  88.         write (*,'(2x,a,1x,i2)') draw_table(i,draw_size), i
  89.     end do
  90. end subroutine
  91. integer function player_win(siz, table_3)
  92.     integer :: ch_1, ch_2, siz
  93.     character :: table_3(siz,siz)
  94.     !
  95.     player_win = 3
  96.     do ch_1 = 1, siz
  97.         do ch_2 = 1, siz
  98.             if ( table_3(ch_1,ch_2) == '-' ) then
  99.                 player_win = 0
  100.             end if
  101.         end do
  102.     end do
  103. end function
  104. !
  105. integer function check(check_win,check_table)
  106.     integer :: check_win
  107.     character :: check_table(check_win,check_win)
  108.  
  109. end function
  110. !
  111. integer function truncation(tr_win, tr_size, tr_table)
  112.     integer :: tr_win, tr_size
  113.     character :: tr_table(tr_size,tr_size)
  114.  
  115. end function
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement