Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python 3.6 Requriements Submit only the files requested Print all real numbers to 2 decimal points unless stated otherwise Restrictions No global variables may be

python 3.6

Requriements

Submit only the files requested

Print all real numbers to 2 decimal points unless stated otherwise

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

The first 3 inputs specify thte game to be played. They will be entered in the following order

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

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 input 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

Assumptions

Input will not always be valid

If invalid input is entered 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 program took me about 350 lines of code to complete

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

You can draw a lot of inspiration from tic tac toe

Here are some of the functions I had in my program

get_game_attributes

make_empty_board, display_board

play_connectn, get_move, is_valid_move

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

Enter the number of rows: 3 Enter the number of columns: 4 Enter the number of pieces in a row to win: 3 0 1 2 3 2 * * * * 1 * * * * 0 * * * * Enter the column you want to play in: 1 0 1 2 3 2 * * * * 1 * * * * 0 * X * * Enter the column you want to play in: 2 0 1 2 3 2 * * * * 1 * * * * 0 * X O * Enter the column you want to play in: 2 0 1 2 3 2 * * * * 1 * * X * 0 * X O * Enter the column you want to play in: 0 0 1 2 3 2 * * * * 1 * * X * 0 O X O * Enter the column you want to play in: 2 0 1 2 3 2 * * X * 1 * * X * 0 O X O * Enter the column you want to play in: 3 0 1 2 3 2 * * X * 1 * * X * 0 O X O O Enter the column you want to play in: 3 0 1 2 3 2 * * X * 1 * * X X 0 O X O O Enter the column you want to play in: 1 0 1 2 3 2 * * X * 1 * O X X 0 O X O O Enter the column you want to play in: 3 0 1 2 3 2 * * X X 1 * O X X 0 O X O O Player 1 won!

Example 2

Enter the number of rows: bob Enter the number of rows: -4 Enter the number of rows: 1 Enter the number of columns: jack Enter the number of columns: -3 Enter the number of columns: 2 Enter the number of pieces in a row to win: -4 Enter the number of pieces in a row to win: mom Enter the number of pieces in a row to win: 100 0 1 0 * * Enter the column you want to play in: monkey Enter the column you want to play in: 10 Enter the column you want to play in: 2 Enter the column you want to play in: -3 Enter the column you want to play in: 0 0 1 0 X * Enter the column you want to play in: math Enter the column you want to play in: 3.2 Enter the column you want to play in: 1.2 Enter the column you want to play in: 1 0 1 0 X O 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_2

Step: 3

blur-text-image_3

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

4. Evaluation is ongoing and used to improve the system.

Answered: 1 week ago

Question

6. Effectively perform the managers role in career management.

Answered: 1 week ago