Python代写:IFB104 Jigsaw Pullze Part2

Introduction

接着之前的Part1继续用Python的turtle库来画拼图,这次的拼图增加的缺失部分,难度增加了不少。

Overview

This is the second part of a two-part assignment. This part is worth 8% of your final grade for IFB104. Part A which preceded it was worth 17%. This part is intended as a last-minute extension to the assignment, thereby testing the maintainability of your code from Part A and your ability to work under time presssure. If you have a neat, clear solution to Part A you will find completing Part B much easier. For the whole assignment you will submit only one file, containing your combined solution to both Parts A and B, and you will receive one grade for the whole 25% assignment.

Motivation

One of the most common tasks in “Building IT Systems” is modifying some existing code. In practice, computer programs are written only once but are subsequently modified and extended many times during their operational lifetime. Code changes may be required in response to internal factors, such as the need to correct design flaws or coding errors, or external factors, such as changes in consumer requirements.
This task requires you to extend your solution to Part A of the assignment by adding an additional feature. It tests:

  • Your ability to work under time pressure; and
  • The quality and clarity of your code for Part A, because a well-written solution to Part A will make completing this part of the assignment much easier.

Goal

In Part A of this assignment you were required to create code that simulated attempts to solve a four-piece jigsaw puzzle. In real life, however, one of the most frustrating aspects of solving jigsaw puzzles is discovering at the end that one or more pieces is missing! Therefore, in Part B of this assignment you will simulate this real-life annoyance.
To complete this task you must create a “broken image” icon which will replace certain jigsaw pieces we assume are missing. If you study the data sets in the provided Python file, jigsaw_puzzle.py, you will see that attempt_30 to attempt_33 all have an extra value ‘X’ associated with certain pieces. This value marks pieces that we will assume are missing when this attempt is made to solve the puzzle. Your task for Part B of the assignment is to show visually that these pieces are missing by drawing your “broken image” icon in their place.
You have a free choice of what symbol to draw to indicate a missing piece, but it must have a “reasonable” degree of complexity and must clearly indicate to the observer that something is wrong with the attempt to solve the puzzle. As Internet users we are all familiar with the icons that web browsers use to indicate a missing image in a Web document, so it is suggested that you adapt such an image for the purposes of this assignment. The appendix below shows some typical “broken image” symbols as a starting point, but you are free to design your own.
You will complete this part of the assignment by extending your code for Part A. No additional Python template file is supplied for this part of the assignment. You are required to use Turtle graphics to draw the broken image icon, instead of a puzzle piece, as specified in a given data set. Your program must work for all of the data sets in the supplied Python file, and any other similar data sets in the same format.

Illustrative example

To illustrate the requirement we’ll continue our example from the Part A instructions. Recall that we created four jigsaw puzzle pieces that, when assembled correctly, produced a handsome portrait of caveman Barney Rubble.
We are now obliged to replace our pieces A and D with a broken image icon, because both have been marked as missing by the presence of an ‘X’.
Your first task, therefore, is to design and develop some Turtle graphics code for drawing a broken image icon. For the purposes of our example we produced the following image of a cracked picture hanging on a wall, in sombre shades of grey (symbolic of our gloom at discovering the puzzle piece missing!).
Note that this broken image icon is much smaller than our 300 × 300 pixel puzzle pieces, to ensure that it does not overlap the tabs of any adjacent pieces. You should choose the size of your icon so that it is clearly visible, but does not interfere with any other pieces. (The precise size depends on how big you have made your tabs.)
Your next task is to use this symbol in place of missing pieces, as directed by the instructions in the given data set. For instance, when we now draw the image corresponding to attempt_32 we will show that pieces A and D are sadly missing, as shown overleaf…
As per this example, your broken image icon must neatly replace any jigsaw pieces marked with an ‘X’ in any of the “attempt” data sets, or any other data sets in the same format. (In the given data sets only pieces appearing in the puzzle template on the left of the drawing canvas are ever shown as missing. Pieces in the box on the right are never marked as missing, so you don’t have to produce code for drawing the missing piece icon in the box.)

Requirements and marking guide

To complete this task you are required to extend your Part A jigsaw_puzzle.py file by modifying the code that draws the jigsaw puzzle pieces so that a missing piece icon is displayed in lieu of pieces marked with an ‘X’ in any given data sets. Your submitted solution for both Parts A and B will consist of a single Python file. Your Part B extension must satisfy the following criteria. Marks available are as shown.

  1. Drawing a missing piece icon (3%). Your extended program must be able to draw a missing piece icon, which provides a clear visual indication that one of the jigsaw puzzle pieces is missing. The icon does not need to be very complex, but a few separate Turtle graphics shapes will likely be needed. (The icon must be of an appropriate size for compatibility with your jigsaw pieces. When substituted for a missing piece it should not overlap with any of the pieces that do exist.)
  2. Replacing missing pieces (3%). Your extended program must be capable of replacing any piece marked as missing with your icon, as specified by any of the given data sets. In doing so, the original piece should not be drawn at all in these cases. Your solution for showing that a piece of the puzzle is missing must work for all of the provided data sets and any other data sets in the same format. You cannot “hardwire” your solution for specific data sets and you may not change the data sets provided.
  3. Code quality and presentation (2%). Your additional program code for Part B must be presented in a professional manner. See the coding guidelines in the IFB104 Code Presentation Guide (on Blackboard under Assessment) for suggestions on how to achieve this. In particular, given the obscure and repetitive nature of the code needed to draw complex images using Turtle graphics, each significant code segment must be clearly commented to say what it does, e.g., “Draw picture frame”, “Draw crack”, etc.

You must complete this task using basic Turtle graphics and maths functions only. You may not import any additional modules or files into your program other than those already included in the original jigsaw_puzzle.py template. In particular, you may not import any image files for use in creating your jigsaw pieces or the missing image icon.
Most importantly, you are not required to copy the missing piece icon shown in this document. Instead you are strongly encouraged to be creative and to design your own version.

Development hints

  • It should be possible to complete this task merely by adding code to your existing solution, with little or no change to the code you have already completed.
  • If you are unable to complete the whole task, just submit whatever part you can get working. You will receive partial marks for incomplete solutions.
  • Keep in mind that pieces in the box are never marked as missing, so you don’t need to create code to draw the missing piece icon in the box.