Python代做 | assignment – Assignment 2, final version

Assignment 2, final version

Python代做 | assignment – 这个题目属于一个Python的代写任务, 包括了Python等方面, 这是值得参考的assignment代写的题目

python代写 代写python

COMP9021, Term 1, 2021

  1. General matter

1.1. Aims. The purpose of the assignment is to:

  • design and implement an interface based on the desired behaviour of an application program;
  • practice the use of Python syntax;
  • develop problem solving skills.

1.2. Submission. Your program will be stored in a file namedtangram.py. After you have developed and tested your program, upload it using Ed (unless you worked directly in Ed). Assignments can be submitted more than once; the last version is marked. Your assignment is due by April 26, 10:00pm.

1.3. Assessment. The assignment is worth 13 marks. It is going to be tested against a number of input files. For each test, the automarking script will let your program run for 30 seconds.

Late assignments will be penalised: the mark for a late submission will be the minimum of the awarded mark and 13 minus the number of full and partial days that have elapsed from the due date.

The outputs of your programs should be exactly as indicated.

1.4. Reminder on plagiarism policy. You are permitted, indeed encouraged, to discuss ways to solve the assignment with other people. Such discussions must be in terms of algorithms, not code. But you must implement the solution on your own. Submissions are routinely scanned for similarities that occur when students copy and modify other peoples work, or work very closely together on a single implementation. Severe penalties apply.

1
  1. Background

The game of tangram consists in creating shapes out of pieces. We assume that each piece has its own colour, different to the colour of any other piece in the set we are working with. Just for reference, here is the list of colours that are available to us (you will not make use of this list):

https://www.w3.org/TR/2011/REC-SVG11-20110816/types.html#ColorKeywords

A representation of the pieces will be stored in an.xmlfile thanks to a simple, fixed syntax.

2.1. Pieces. Here is an example of the contents of the filepieces_A.xml, typical of the contents of any file of this kind (so only the number of pieces, the colour names, and the various coordinates can differ from one such file to anotherwe do not bother with allowing for variations, in the use of space in particular).

Opened in a browser,pieces_A.xmldisplays as follows:

Note that the coordinates are nonnegative integers. This means that the sets of pieces we consider rule out those of the traditional game of tangram, where

2 is involved everywhere...

We require every piece to be a convex polygon. An.xmlfile should represent a piece withnsides (n 3 ) by an enumeration ofnpairs of coordinates, those of consecutive vertices, the first vertex being arbitrary, and the enumeration being either clockwise or anticlockwise.

The pieces can be flipped over horizontally, flipped over vertically, and rotated by 90 degrees. For instance, the filepieces_AA.xmlwhose contents is

and which displays as

represents the same set of pieces (the fact that the latter appear as smaller than the former is just due to the different scaling of the included pdfs; the sizes of the pieces are actually the same in terms of the coordinates of their vertices).

The pieces can overlap, but that does not concern us. In practice, we will just use representations where the pieces do not overlap as that allows us to visualise the pieces properly when we open the corresponding.xml file, but it is just for convenience and irrelevant to the tasks we tackle.

2.2. Shapes. A representation of a shape is provided thanks to an.xmlfile with the same structure, storing the coordinates of the vertices of just one polygon.

The fileshape_A_1.xmlwhose contents is

and which displays as

is such an example. The fileshape_A_2.xmlwhose contents is

and which displays as

is another such example.

Contrary to pieces, shapes are not assumed to be convex polygons. Still they are assumed to be simple polygons (the boundary of a simple polygon does not cross itself; in particular, it cannot consist of at least 2 polygons that are connected by letting two of them just touch each other at one of their vertices e.g. , two rectangles such that the upper right corner of one rectangle is the lower left corner of the other rectangle; that is not allowed).

Whereas you will have to check that the representation of the pieces in an.xmlfile satisfies our constraints, you will not have to do so for the representation of a shape; you can assume that any shape we will be dealing with satisfies our constraints.

2.3. Tangrams. The first shape can be built from our set of pieces, in many ways. Here is one, given by the filetangram_A_1_a.xmlwhose contents is

and which displays as follows.

Here is another one, given by the filetangram_A_1_b.xmlwhose contents is

and which displays as follows.

The second shape can also be built from our set of pieces, in many ways. Here is one, given by the file tangram_A_2_a.xmlwhose contents is

and which displays as follows.

Here is another one, given by the filetangram_A_2_b.xmlwhose contents is

and which displays as follows.

  1. First task (4 marks)

You have to check that the pieces represented in an.xmlfile satisfy our constraints. So you have to check that each piece is convex, and if it represents a polygon withnsides (n 3 ) then the representation consists of an enumeration of thenvertices, either clockwise or anticlockwise. Here is the expected behaviour of your program.

$ python …

from tangram import * TangramPieces(‘pieces_A.xml’) <tangram.TangramPieces object at …> TangramPieces(‘pieces_AA.xml’) <tangram.TangramPieces object at …> TangramPieces(‘incorrect_pieces_1.xml’) … tangram.TangramPiecesError: At least one piece is invalid TangramPieces(‘incorrect_pieces_2.xml’) … tangram.TangramPiecesError: At least one piece is invalid TangramPieces(‘incorrect_pieces_3.xml’) … tangram.TangramPiecesError: At least one piece is invalid TangramPieces(‘incorrect_pieces_4.xml’) … tangram.TangramPiecesError: At least one piece is invalid

  1. Second task (4 marks)

You have to check whether the sets of pieces represented in two.xmlfiles are identical, allowing for pieces to be flipped over horizontally, flipped over vertically, and rotated by 90 degrees. Here is the expected behaviour of your program.

$ python …

from tangram import * pieces_1 = TangramPieces(‘pieces_A.xml’) pieces_2 = TangramPieces(‘pieces_AA.xml’) pieces_1.are_identical_to(pieces_2) True

Next line is OK as the shape in shape_A_1.xml, being convex, is a valid piece

pieces_3 = TangramPieces(‘shape_A_1.xml’) pieces_1.are_identical_to(pieces_3) False

Note that the methodare_identical_to()does not print outTrueorFalse, but returnsTrueorFalse.

  1. Third task (5 marks)

You have to check whether the pieces represented in an.xmlfile are a solution to a tangram puzzle represented in another.xmlfile. Here is the expected behaviour of your program.

$ python …

from tangram import * shape = TangramShape(‘shape_A_1.xml’) pieces = TangramPieces(‘tangram_A_1_a.xml’) shape.has_as_solution(pieces) True pieces = TangramPieces(‘tangram_A_1_b.xml’) shape.has_as_solution(pieces) True pieces = TangramPieces(‘tangram_A_2_a.xml’) shape.has_as_solution(pieces) False shape = TangramShape(‘shape_A_2.xml’) pieces = TangramPieces(‘tangram_A_2_a.xml’) shape.has_as_solution(pieces) True pieces = TangramPieces(‘tangram_A_2_b.xml’) shape.has_as_solution(pieces) True pieces = TangramPieces(‘tangram_A_1_a.xml’) shape.has_as_solution(pieces) False

Note that the methodshape.has_as_solution()does not print outTrueorFalse, but returnsTrueorFalse.