Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

**PYTHON** The program This project is focused on implementing the mechanics of Columns, along with a program that you can run in the Python shell

**PYTHON**

The program

This project is focused on implementing the mechanics of Columns, along with a program that you can run in the Python shell with a very spartan user interface that you'll use to test it and that we'll use to automatically test it, making it crucial that you get the format of the program's input and output right according to the specification below. Spacing, capitalization, and other seemingly-minor details are critical; every part of your output needs to be correct to the individual character.

Using your test program, you won't be able to play a fully-functioning game of Columns, but you will be able to determine whether you've handled all of the game's mechanics correctly: fallers, movement and rotation, freezing, matching, and so on. Note, too, that you don't need to implement all of the logic to receive at least some credit for the project; details are described a little later in the project, but you can receive substantial partial credit for a partially complete implementation, as long as some of the features are working with precisely correct output.

The next project will allow you to take the game mechanics you've implemented here and build a playable game out of them. But, as with a lot of game implementation, first thing's first: Without the underlying logic working, you can't have a game you can play.

A detailed look at how your program should behave

Your program will read its input via the Python shell (i.e., using the built-in input() function), printing no prompts to a user with no extraneous output other than precisely what is specified below. The intent here is not to write a user-friendly user interface; what you're actually doing is building a tool for testing your game mechanics, which we'll then be using to automatically test them. So it is vital that your program reads inputs and write outputs precisely as specified below. You can freely assume that the input will match the specification described; we will not be testing your program on any inputs that don't match the specification.

First, your program needs to know the size of the field. It will always be a rectangle, but the number of rows and columns can vary.

First, your program reads a line of input specifying the number of rows in the field. You can assume this will be no less than 4.

Next, your program reads a line of input specifying the number of columns in the field. You can assume this will be no less than 3.

At any given time, the field contains jewels that are one of seven colors. The colors are represented by these uppercase letters (and only these letters): S, T, V, W, X, Y, Z. In both the input and output, we'll use these seven letters to denote the seven colors.

Now, your program needs to know what jewels are in the field to begin with. There are two situations: We might want to start with an empty field, or we might want to specify the contents of the field in the input.

If the field is to begin empty, the word EMPTY will appear alone on the next line of input.

If instead we want to specify the contents of the field in the input, the word CONTENTS will appear alone on the next line of input. Given that there are r rows and c columns in the field, there would then be r lines of input, each of which will contain exactly c characters; these characters represent the contents of each of the field's cells to start with.

For a cell that should contain a jewel of some color, an uppercase letter describing each color will be used.

For a cell that should be empty, a space will be used instead.

Note that when we're specifying the contents of the field explictly, the spaces will always be present in the input for every cell that's empty; the program should expect to read exactly the correct number of characters.

At this point, the game is ready to begin. From here, we will repeatedly do two things: Display the field, then read a command from the user.

The rules for displaying the field are:Given that the field has r rows, the field will be displayed as a total of r + 1 lines of output. The first r will correspond to the r rows of the field, which each row displayed like this:The vertical bar character '|', followed by three characters for each of the c columns in that row, followed by another vertical bar character '|'. For each column in that row, the three characters will be:

Three spaces if the cell is empty

A space, followed by an uppercase letter if the cell contains a jewel that has been frozen.

A left bracket character '[', followed by an uppercase letter, followed by a right bracket character ']' if the cell contains a jewel that is part of the faller (if any).

A vertical bar character '|', followed by an uppercase letter, followed by another vertical bar character '|' if the cell contains a jewel that is part of a faller that has landed but not yet frozen.

An asterisk character '*', followed by an uppercase letter, followed by another asterisk character '*' if the cell contains a jewel that has frozen and has been recognized as a match.

After the last row of the field, a space, followed by 3c dashes, followed by another space is displayed.

The commands that you would read are:A blank line, which is a crude representation of the passage of time. (In our complete game, this would happen without any input; instead, when a certain amount of time passes, we would see the appropriate effect.)

If there is a faller present, it falls; if there is a faller that has landed (and has not been moved so that it is no longer in a landed position), it freezes; and so on.

F, followed by an integer that is a column number (the columns are numbered 1 through c, if there are c columns), followed by a space, followed by three uppercase letters (representing colors), each of these things separated by spaces (e.g., F 1 S T V). This means to create a faller in column 1, with a jewel of color S on the top, a jewel of color T below it, and a jewel of color V below that.

The faller begins with only the bottommost of the three jewels visible. See the example outputs below for more details.

Note that there can only be one faller at a time, so this command has no effect if there is a faller that has not already been frozen.

R alone on a line, which rotates the faller, if there is one. If there is no faller currently, this command has no effect. Note, though, that it is possible to rotate a faller that has landed but not yet frozen.

< alone on a line, which moves the faller one column to the left, if there is one (and if it not blocked by jewels already frozen on the field or by the edge of the field). If there is no faller or the faller can't be moved to the left, this command has no effect. Note, though, that it is possible to move a faller that has landed but not yet frozen, which can take it out of its "landed" status (if it moves to a column with nothing underneath it).

> alone on a line, which moves the faller one column to the right, if there is one (and if it not blocked by jewels already frozen on the field or by the edge of the field). If there is no faller or the faller can't be moved to the right, this command has no effect. Note, though, that it is possible to move a faller that has landed but not yet frozen, which can take it out of its "landed" status (if it moves to a column with nothing underneath it).

Q alone on a line, which means that to quit the program.

There are two ways for the program to end:

If the user specifies the command Q, the program ends, with no additional output being printed.

When a faller freezes without all three of its jewels being visible in the field (for example, if it lands on a jewel that's two rows below the top and then freezes), the game ends, so the program ends, as well. In that case, you would print GAME OVER before ending the program.

Two complete examples of program execution

Below are two examples of the program's execution, which you can consult when there are minor issues that you're not sure how to resolve. Boldfaced, italicized text indicates input, while normal text indicates output. Note that blank lines are actually blank input lines; there are no blank output lines in this program's design. Some additional commentary appears to the right of the example, italicized and written in the form of Python comments; that would not appear in your program's output, but will help you to understand the examples.

Beginning with an empty field

4 3 EMPTY # begin with an empty field with 4 rows and 3 columns | | | | | | | | --------- F 3 X Y Z # create a faller containing colors X, Y, Z in column 3 | [Z]| | | | | | | --------- # this is a blank line of input; there are lots of them in these examples | [Y]| | [Z]| | | | | # the faller begins falling --------- | [X]| | [Y]| | [Z]| | | --------- | | | |X|| | |Y|| # the faller has landed | |Z|| # note the multi-step process here --------- | | | X | | Y | | Z | # the faller has frozen --------- F 1 Y Z X |[X] | | X | | Y | | Z | --------- |[Z] | |[X] X | | Y | | Z | --------- |[Y] | |[Z] X | |[X] Y | | Z | --------- R # rotating the faller |[X] | |[Y] X | |[Z] Y | | Z | --------- > # moving the faller to the right | [X] | | [Y] X | | [Z] Y | | Z | --------- > | [X] | | [Y] X | | [Z] Y | | Z | # moving to the right again has no effect; it's blocked --------- | | | |X| X | | |Y| Y | | |Z| Z | --------- | | | X X | | Y Y | | Z Z | --------- F 1 T Z S |[S] | | X X | | Y Y | | Z Z | --------- |[Z] | |[S] X X | | Y Y | | Z Z | --------- |[T] | |[Z] X X | |[S] Y Y | | Z Z | --------- | | ||T| X X | ||Z| Y Y | ||S| Z Z | --------- R rotation and moving is permitted before freezing | | ||S| X X | ||T| Y Y | ||Z| Z Z | --------- | | | S X X | | T Y Y | |*Z**Z**Z*| # we have a match! --------- | | | | | S X X | | T Y Y | # and now the matching jewels disappear --------- F 1 V W Z |[Z] | | | | S X X | | T Y Y | --------- ||W| | ||Z| | | S X X | | T Y Y | --------- | W | | Z | | S X X | | T Y Y | # landed, but it doesn't fit! --------- GAME OVER 

Beginning with the field contents specified

4 4 CONTENTS  Y X S V  TXYS X XY | | | S V X | | T Y Y S | # all jewels immediately fill empty space below them |*X**X**X* Y | # which can trigger matching, as happens here ------------ | | | X | | S V S | | T *Y**Y**Y*| ------------ | | | | | S X | | T V S | ------------ F 2 X Y Z | [Z] | | | | S X | | T V S | ------------ Q # quitting early is allowed; program ends

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

Students also viewed these Databases questions