python程序代写  assignment

word search puzzle


The goal of this assignment is to get you started reading and writing Python code. You'll understand how to
use existing code, call existing functions, write your own functions, and call functions you've written. This
work is not harder than what you've been doing in your exercises, but it will take substantially longer, so
start early. Make sure you read this entire document all the way through at least once before you start.

What Not to Use
You can complete this assignment using only the material covered in the rst three weeks of the course.
In particular, you are not allowed to use any if-statements (there is no good reason to use them in this
assignment!), and do not use string methods.

Word Search
A word search puzzle is a rectangular grid of letters that contains hidden words. In the word searches we
use here, words can be hidden in one of four directions:
 left-to-right (horizontal forwards)
 right-to-left (horizontal backwards)
 top-to-bottom (vertical starting from the top)
 bottom-to-top (vertical starting from the bottom)
The rst two of these directions are in the horizontal dimension, and the second two are in the vertical
Download and open It is a Python le in which you will solve 12 tasks related to word searches. Not
all tasks will be marked, but later tasks build on earlier ones. You are strongly encouraged to complete all
tasks { you'll thank me later!

Starter Code
At the top of the le are some comments. Please read those comments now, and complete the header... go
on... I'll wait here.
Next, you see a variable assignment to PUZZLE1. PUZZLE1 is a word search with nine rows and nine columns
in which the following words are hidden:
 marzieh (2 instances)
 brian (2 instances)
 nick (2 instances)
 eric (1 instance1)

Before continuing, nd all of the words in the puzzle by hand. Remember that they can be in any of four
directions. Here's a hint for nding the brians: one instance is right-to-left , the other is bottom-to-top.
Below PUZZLE1 is PUZZLE2. It's a bigger puzzle with the same words hidden in it, but we're not telling you
the number of instances of each word that are in there. We'll come back to this puzzle later.
Below PUZZLE2, we have given you two starter functions that you will use in completing some of the tasks.
These functions use Python concepts that we haven't covered yet, so don't concern yourselves with the
implementations. (If you are interested, the code is well-commented, so that by reading the comments you
should get an idea of what's happening.) Instead, to learn what the functions do, read the docstrings and
experiment in the shell. The two functions are as follows:
rotate puzzle
As indicated by the docstring, this function rotates a puzzle by 90 degrees to the left. ... What exactly does
that mean? To get an idea of what the function does, run and call rotate puzzle from the shell.
For example, try rotate puzzle(PUZZLE1). Observe the e ect. Try it on smaller "puzzles" too, like this:
rotate puzzle('abcnndef'). Do you understand what the function is doing? (The nn there is just the
code for a newline character.
lr occurrences
This function takes a puzzle and a word, and returns the number of times the word occurs in the left-to-
right direction in the puzzle. Play around with this function before continuing. You know the number of
occurrences of each word in PUZZLE1; use this function to verify the number of left-to-right occurrences of
these words. Try it on PUZZLE2 as well!2
On line 103 of is a comment indicating that your code should be below. You are not allowed to modify
anything above this line, except for the header. Below this point, there are 12 tasks to complete. Be careful:
they are not listed in the code in numerical order. Make sure you work on the tasks in order of number, not
the order that they occur in the code.


Pygame development


In the previous project, you implemented a Columns game with a fairly primitive user interface that ran within the Python shell, in the spirit of the user interfaces we've been building all quarter. This didn't make for a particularly fun game, but it did let us focus our energies on the precise rules of our game, so we could get all of the various mechanics right, before turning our attention to making a playable game out of it. In this project, we'll switch over to making the game playable.

In recent lectures, we've been learning more about PyGame, a third-party library — not one built into Python, but nonetheless one that is easily downloaded and installed for your use. This project asks you to take the program you wrote for the previous project and replace its user interface with a graphical one. You'll build your game using the PyGame library, as we've been doing in lecture. Rather than simulating the passage of time by pressing the Enter key, the game will move on its own; this will add the key elements of challenge and fun to it.

The program

This project asks you to build a graphical, playable version of Columns, based on the game mechanics from the previous project. However, we'll need to make a couple of minor changes to it:

  • The field will always consist of 13 rows and 6 columns, and will always start out empty.

  • The seven colors of jewels were represented as uppercase letters previously. Instead, choose seven colors — you can choose any colors you'd like, though they should be different enough that you can easily tell the difference between them at a glance. (You might want your game mechanics to still refer to them using uppercase letters, and that's fine; but when you display them, what differentiates the jewels should be their colors.)

  • There needs to be some kind of visual cue when fallers land. Additionally, if you support matching, you would ideally want a visual cue when jewels match before they disappear, as well. You have your choice about these visual cues — you can use colors or other visual effects.

  • Rather than the user adding fallers manually, they appear randomly. Whenever there isn't a faller in the field, a new one appears in a randomly-chosen column and consisting of random colors.

  • Rather than the user pressing the Enter key to simulate the passage of time, you'll instead "tick" the game mechanics once per second automatically.

  • Rather than the user typing commands like R, <, and > in the Python shell to rotate and move the faller, the user instead should move them by pressing keys on the keyboard; every keypress rotates or moves the faller once. So that we'll know how to grade your project, we'll all use the same keys: left arrow and right arrow should move the faller to the left and right, respectively, while the spacebar should rotate the faller.