Final Program-2

Frog Crocodile is a game played on a 5 x 5 square board. The board starts empty, except that a single 'T' symbol may appear in one of the 25 squares.

There are two players: F and C. They take turns to make moves, with F starting. In each move a player puts her symbol in one of the empty squares. Player F's symbol is 'F', and player C's symbol is 'C'.

After a player's move, if there is a row, column or a diagonal containing 5 of that player's symbols, or containing 4 of her symbols and the 'T' symbol, she wins and the game ends. Otherwise the game continues with the other player's move. If all of the fields are filled with symbols and nobody won, the game ends in a draw. See the sample input for examples of various winning positions.

Given a 5 x 5 board description containing 'F', 'C', 'T' and '.' characters (where '.' represents an empty square), describing the current state of a game, determine the status of the Frog Crocodile game going on. The statuses to choose from are:

"Frog won" (the game is over, and Frog won)

"Crocodile won" (the game is over, and Crocodile won)

"Draw" (the game is over, and it ended in a draw)

"Game has not completed" (the game is not over yet)

If there are empty cells, and the game is not over, you should output "Game has not completed", even if the outcome of the game is inevitable.

Input Format

Input consists of 5 lines with 5 characters each, with each character being 'C', 'F', '.' or 'T' (quotes for clarity only

Output Format

If the input consists of any character other than 'C', 'F', '.' or 'T', print “Invalid Input”.

The output consists of a string that is in one of the cases mentioned above

Sample Input 1:

FFFFT
.....
CC...
.....
CC...F

Sample Output 1:

Frog won

Sample Input 2:

FCFTC
FFCCC
CFCFC
FFCCC
FCFCF

Sample Output 2:

Draw

Sample Input 3:

FCF..
CF...
.....
.....
T....

Sample Output 3:

Game has not completed

Sample Input 4:

CCFFF
CFFFF
CF...
C...C
C....

Sample Output 4:

Crocodile won

Sample Input 5:

CFCFF
FC...
..D..
...C.
F...C

Sample Output 5:

Invalid Input

1 comment: