- #1
eng909
- 1
- 0
Hi, i have an assignment to make a code for a connect 4 game,using module and subroutines, but as of now I am stuck, and do not now where to go. Any help would be great. here's what I have so far. I'm stuck on how to declare where the X's and O's will show up and how to determine when 4 in a row has been found
MODULE datamod
!7 COLUMNS
!6 ROWS
INTEGER, DIMENSION (6,7):: BOARD
INTEGER:: PLAYER
END MODULE datamod
PROGRAM C4
use datamod
INTEGER:: X,O
DO
WRITE(*,*) "Player 1's turn"
CALL drawboard(j,i)
WRITE(*,*) 'In which column would you like to place your piece (X)?'
READ (*,*) X
!Code on where to put X
WRITE(*,*) "Player 2's turn"
CALL DRAWBOARD(j,i)
WRITE(*,*) 'In which column would you like to place your piece (O)?'
READ (*,*) O
!code for placement of O's
END DO
END PROGRAM
Subroutine drawboard (j,i)
USE datamod
IMPLICIT NONE
integer::i, j
1 FORMAT (a,\)
Print *, ' 1 2 3 4 5 6 7'
Do i=6,1,-1
Do j=1,7
Print 1, ' | '
If (board(j,i)==0) Then
Print 1, ' '
ELSE IF (board(j,i)==1) Then
Print 1, 'X'
Else If (board(j,i)==2) Then
Print 1, 'O'
Else If (board(j,i)==3) Then
Print 1, '4'
End if
End do
Print *, '|'
Print "(1x, 29('-'))"
End do
End Subroutine drawboard
thanks for any help!
MODULE datamod
!7 COLUMNS
!6 ROWS
INTEGER, DIMENSION (6,7):: BOARD
INTEGER:: PLAYER
END MODULE datamod
PROGRAM C4
use datamod
INTEGER:: X,O
DO
WRITE(*,*) "Player 1's turn"
CALL drawboard(j,i)
WRITE(*,*) 'In which column would you like to place your piece (X)?'
READ (*,*) X
!Code on where to put X
WRITE(*,*) "Player 2's turn"
CALL DRAWBOARD(j,i)
WRITE(*,*) 'In which column would you like to place your piece (O)?'
READ (*,*) O
!code for placement of O's
END DO
END PROGRAM
Subroutine drawboard (j,i)
USE datamod
IMPLICIT NONE
integer::i, j
1 FORMAT (a,\)
Print *, ' 1 2 3 4 5 6 7'
Do i=6,1,-1
Do j=1,7
Print 1, ' | '
If (board(j,i)==0) Then
Print 1, ' '
ELSE IF (board(j,i)==1) Then
Print 1, 'X'
Else If (board(j,i)==2) Then
Print 1, 'O'
Else If (board(j,i)==3) Then
Print 1, '4'
End if
End do
Print *, '|'
Print "(1x, 29('-'))"
End do
End Subroutine drawboard
thanks for any help!