Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please using C, not C+ or C++, Thanks. Files to submit: all files necessary to create an executable named connectn.out, a Makefile to compile those

Please using C, not C+ or C++, Thanks.

Files to submit: all files necessary to create an executable named connectn.out, a Makefile to compile those files

Time it took Matthew to Complete: 50 mins

Requriements

Program must compile with both -Wall and -Werror options enabled

Submit only the files requested

Use doubles to store real numbers

Print all doubles to 2 decimal points unless stated otherwise

NEW: Your submission must consit of at least two .c files and one .h file

Restrictions

No global variables may be used

Your main function may only declare variables and call other functions

Description

Write a program to implement the game connect-n. Connect-n is like Connect-4 but the size of the board the number of pieces in a row needed to win are user parameters. If you have never played Connect-4 before you can play it here: https://www.mathsisfun.com/games/connect4.html. The basic gist of the game is that each player takes a turn dropping one of their pieces into a column. Pieces land on top of pieces already played in that column. Each player is trying to get n pieces in a row either veritcally, horizontally or diagonally. The game ends if either player gets n pieces in a row or the board becomes full.

Additional Details

Your program should accept 3 command line parameters:

The number of rows on the board

The number of columns on the board

The number of pieces in a row needed to win

It is ok if the number of pieces in a row is larger than what can fit on a board

For example on a 3 X 3 board it is ok for the number of pieces in a row needed to win to be 100

If the user does not enter enough arguements, too many arguements or invalid values your program should show the user how to call your program and then terminate

You may find exit here

Player 1's pieces are represented by X

Player 2's pieces are represented by O

Capital Oh, not zero

Player 1 always plays first

If the user enters an invalid play your program should continue to ask them for input until valid input is entered

After the game is over a winner should be declared if there is one and if there is no winner a tie should be declared

You must split your code into at least 2 different .c files

I personally had 4

You must submit a Makefile that will compile your program

The executable created by this Makefile should be named connectn.out

Assumptions

Input will not always be valid

If invalid input is entered on the command line your program should show the user how to use the program and then quit

If invalid input is entered when the program is running your program should continue to ask for input until valid input is entered

Valid Input

Number of rows

An integer greater than 0

Number of columns

An integer greater than 0

Number of pieces in a row needed to win

An integer greater than 0

User Move

An integer specifying a column between 0 and the number of columns - 1 that is not already full

Hints

This is our first large program. It took me about 300 lines of code to complete it

You will want to break your problem down into logical steps before begninning on it.

Each of these steps will become a function

Each of these steps might have steps within them so you should create functions here as well to help break down the problem even farther

Once you get to small enough step go ahead and solve it

Here are some of the functions I had in my program

read_args

create_board, print_board, destroy_board

play_game, get_play, play_is_valid

game_over, game_won, row_win, col_win, diag_win, right_diag_win, left_diag_win

Examples

User input has been underlined to help you differentiate between what the user is entering and what the program is ouputting. You do not need to underline anything.

Example 1

./connectn.out Not enough arguments entered Usage connectn.out num_rows num_columns number_of_pieces_in_a_row_needed_to_win

Example 2

./connectn.out 1 2 3 4 5 Too many arguments entered Usage connectn.out num_rows num_columns number_of_pieces_in_a_row_needed_to_win

Example 3

./connectn.out 3 3 3 2 * * * 1 * * * 0 * * * 0 1 2 Enter a column between 0 and 2 to play in: 0 2 * * * 1 * * * 0 X * * 0 1 2 Enter a column between 0 and 2 to play in: 1 2 * * * 1 * * * 0 X O * 0 1 2 Enter a column between 0 and 2 to play in: 0 2 * * * 1 X * * 0 X O * 0 1 2 Enter a column between 0 and 2 to play in: 0 2 O * * 1 X * * 0 X O * 0 1 2 Enter a column between 0 and 2 to play in: 0 Enter a column between 0 and 2 to play in: 0 Enter a column between 0 and 2 to play in: -2 Enter a column between 0 and 2 to play in: 4 Enter a column between 0 and 2 to play in: 1 2 O * * 1 X X * 0 X O * 0 1 2 Enter a column between 0 and 2 to play in: 2 2 O * * 1 X X * 0 X O O 0 1 2 Enter a column between 0 and 2 to play in: 2 2 O * * 1 X X X 0 X O O 0 1 2 Player 1 Won!

Example 4

./connectn.out 1 2 3 0 * * 0 1 Enter a column between 0 and 1 to play in: 0 0 X * 0 1 Enter a column between 0 and 1 to play in: 1 0 X O 0 1 Tie game!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss guidelines for ethical business communication.

Answered: 1 week ago

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago