Python代写:COMP9021-Tangram

Overview

The request consists of three parts, from easiest to more difficult. Each part is worth 3 marks.
For each test, the automarking script will let your program run for 30 seconds.

As all output is True or False, each test will actually consist of a number of subtests of similar difficulty, and passing one test will mean passing all associated subtests; failing at least one of the subtests of a test will result in scoring 0 to that test.
Up to one mark will reward good comments, good choice of names for identifiers and functions, readability of code, simplicity of statements, compactness of functions. This will be determined manually.

One extra mark will be awarded for making available to the class a good test case, consisting of two similar sets of pieces and two solved tangrams built from such a set, which can then be used by everyone for testing purposes.

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

Specification

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 the colours that are available to us

Pieces

Here is an example of the contents of the file pieces 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 another - we do not bother with allowing for variations, in the use of space in particular).

1
2
3
4
5
6
7
8
9
<svg version ="1.1" xmlns ="http://www.w3.org/2000/svg">
<path d="M 50 50 L 50 90 L 90 90 z" fill="red" />
<path d="M 160 170 L 160 130 L 120 130 z" fill="green" />
<path d="M 200 30 L 180 30 L 180 50 L 220 50 z" fill="blue" />
<path d="M 40 100 L 40 140 L 60 140 L 60 120 z" fill="yellow" />
<path d="M 210 70 L 230 90 L 270 90 L 270 50 L 230 50 z" fill="purple" />
<path d="M 180 130 L 180 170 L 220 210 L 240 190 z" fill="olive" />
<path d="M 100 200 L 120 180 L 80 140 L 80 180 z" fill="magenta" />
</svg>

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 .xml file should represent a piece with n sides (n > 3) by an enumeration of n pairs of coordinates, those of consecutive vertices, the first vertex being arbitrary, and the enumeration being either clockwise or anticlockwise.

First Task

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

Second Task

You have to check whether the sets of pieces represented in two .xml files are identical, allowing for pieces to be flipped over and allowing for different orientations. Here is the expected behaviour of your program.

Third Task

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