COMP9021代做、代写Python编程语言
Assignment 2 version 1.2
COMP9021, Trimester 1, 2025
1 General matters
1.1 Aim
The purpose of the assignment is to:
• develop your problem solving skills;
• design and implement the solutions to problems in the form of medium sized Python programs;
• design and implement an interface based on the desired behaviour of an application program;
• organise code into classes and implement special methods;
• possibly practice using the re and numpy modules;
• optionally practice the design and implementation of search techniques, with recursion as a good
approach.
1.2 Submission
Your program will be stored in a file named tangram.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 28, 11:59am.
1.3 Assessment
The assignment is worth 13 marks, plus 5 bonus marks. It is going to be tested against a number of
inputs. For each test, the automarking script will let your program run for 30 seconds.
Assignments can be submitted up to 5 days after the deadline. The maximum mark obtainable reduces
by 5% per full late day, for up to 5 days. Thus if students A and B hand in assignments worth 12 and 11,
both two days late (that is, more than 24 hours late and no more than 48 hours late), then the maximum
mark obtainable is 11.7, so A gets min(11.7, 12) = 11.7 and B gets min(11.7, 11) = 11.
The outputs of your programs should be exactly as indicated.
Important notice:
• The bonus mark is an option only for programs submitted by the deadline, NOT for
programs submitted within 5 days after the deadline.
• The final mark for the course is capped to 100; the bonus mark cannot let you score more than 100
in the course.
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
people’s work, or work very closely together on a single implementation. Severe penalties apply.
1
2 Tangram puzzles and the TangramTikz package
See Tangram for an overview on Tangram puzzles. All shapes under consideration consist of a unique
connected component without inside hole.
We play with 2 large triangles, a medium triangle, 2 small triangles, a square and a parallelogram of
the following sizes in centimetres, first positioned as shown, the red dot playing the role of an “anchor”.
2
2
2
1
1
1
1
1
1
1
Each piece can be flipped about the vertical line that goes through the anchor, flipped about the
horizontal line that goes through the anchor, and rotated about its anchor (as if it was a pivot) by a
multiple of 45 degrees, before being moved to let the anchor be positioned at given x- and y-coordinates.
We work with .tex files, any of which can be given as argument to pdflatex to generate a .pdf file.
• Here is a .tex file for the solved Tangram of a kangaroo, and here is the associated pdf file.
• Here is a .tex file for the solved Tangram of a cat, and here is the associated pdf file.
• Here is a .tex file for the solved Tangram of a goose, and here is the associated pdf file.
More precisely, the .tex files we work with have the following structure:
\documentclass{standalone}
\usepackage{TangramTikz}
\begin{document}
\begin{EnvTangramTikz}
...
\end{EnvTangramTikz}
\end{document}
Between \begin{EnvTangramTikz} and \end{EnvTangramTikz} are 7 lines, one for each piece, that read
as:
\PieceTangram[TangSol](...,...){...}
or as
\PieceTangram[TangSol]<...>(...,...){...}
... between the curly braces at the end is one of
2
• TangGrandTri for any of the two large triangles,
• TangMoyTri for the medium triangle,
• TangPetTri for any of the two small triangles,
• TangCar for the square, and
• TangPara for the parallelogram.
Both ... within the pair of parentheses are for the x- and y-coordinates of the point where the anchor
of the piece has to be moved, after the piece has been possibly flipped and rotated. These coordinates
are of the form a, a+sqrt(2), a-sqrt(2), a+b*sqrt(2), a-b*sqrt(2), sqrt(2), +sqrt(2), -sqrt(2)
or a*sqrt(2) where a and b are integers or floating point numbers with b being 0 or strictly positive.
Floating point numbers have a dot in their representation. When positive, a can start with + whereas
b can’t. Floating point numbers can start with any number of 0s, and 0 before the dot is optional in
floating point numbers whose absolute value is smaller than 1 (essentially, any sequence of digits and one
dot that Python accepts as a floating point literal is valid).
... between the less than and greater than signs is for one, two or three distinct options, consecutive
options being separated by a comma. The possible options are:
• xscale=-1, to flip the piece so left becomes right and right becomes left,
• yscale=-1, to flip the piece so top becomes bottom and bottom becomes top, and
• rotate=_ with _ an integer that is a multiple of 45 (positive values are for anticlockwise rotation,
negative values are for clockwise rotation).
The options can appear in any order; their sequence determines the order in which the associated trans formations are applied to the piece. It is always possible to have either no option, or a rotation, or an
x-flip (that is, a flip about the vertical line that goes through the anchor), or a rotation followed by an
x-flip.
In the whole .tex file, there can be blank lines and whitespace (space and tab characters) between
tokens everywhere. Also, the leftmost occurrence of a % marks the beginning of a comment that runs
from this symbol included all the way to the end of the physical line, including the \n character.
3
3 The tasks to perform
Your program will allow TangramPuzzle objects to be created from .tex files that you can assume are
stored in the working directory, and whose contents satisfy all conditions spelled out in Section 2.
3.1 Reporting on the transformations applied to each piece (3 marks)
A TangramPuzzle object has a transformations attribute, whole value is a dictionary with 7 keys,
one for each piece. The keys are 'Large triangle 1', 'Large triangle 2', 'Medium triangle',
'Small triangle 1', 'Small triangle 2', 'Square' and 'Parallelogram'. The order of the large
and small triangles are given by the order they have in the .tex file. More generally, the keys of the
dictionary are created in the order of the corresponding pieces in the .tex file. The value for each key is
itself a dictionary whose keys are 'rotate' and 'xflip' . The value for 'rotate' is an integer between
0 included and 360 excluded. The value for 'xflip' is either True or False. So the transformation
applied to each piece is normalised, consisting of first a rotation (maybe equal to 0) possibly followed by
an x-flip.
Here is a possible interaction.
3.2 Reporting on the coordinates of the vertices (4 marks)
Printing out a TangramPuzzle object outputs for each piece, the coordinates of the vertices.
• Pieces are listed from the ones whose leftmost topmost vertices are highest to the ones whose leftmost
topmost vertices are lowest. When the heights of the leftmost topmost vertices of two pieces are
the same, the piece that is to the left of the other piece is listed first. Essentially, the plane is
scanned from top to bottom and from left to right and when the leftmost topmost vertex of a piece
is encountered, the piece is listed.
• Coordinates have the simplest possible form, as shown in the provided examples here. Binary +
and - have a space on both sides, there is no addition of 0, there is no multiplication by 0, there
is no multiplication by 1 or -1, fractions are simplified, integers are used instead of fractions whose
denominator would be 1, and fractions are surrounded by parentheses when followed by √2 to avoid
that it be wrongly believed that √
2 is multiplied by the denominator.
• For a given piece, the enumeration of vertices proceeds clockwise starting from the leftmost topmost
vertex.
3.3 Creating a file to represent the pieces of the solved puzzle (3 marks)
The TangramPuzzle class has a draw_pieces() method that takes the name of a .tex file as argument,
to represent a solved tangram using the tikz package rather than the TangramTiks package, easily taking
advantage of what has been done for the previous part. The order of the pieces, the order of the vertices
of a given piece, are the same as for the previous part. The origin of the plane is represented by a red dot.
The grid in the background extends in such a way that there is at least one square (of 5mm by 5mm)
and strictly less than 2 squares above the topmost vertex, to the right of the rightmost vertex, below
the bottommost vertex and to the left of the leftmost vertex. For example: if the x-coordinate of the
rightmost vertex of the shape is equal to 3.01 or 3.5, then the grid extends to the right to an x-coordinate
of 4; if the x-coordinate of the rightmost vertex of the shape is equal to 3.51 or 4, then the grid extends
to the right to an x-coordinate of 4.5.
Executing
$ python3
...
>>> from tangram import *
4
>>> TangramPuzzle('kangaroo.tex').draw_pieces('kangaroo_pieces_on_grid.tex')
>>> TangramPuzzle('cat.tex').draw_pieces('cat_pieces_on_grid.tex')
>>> TangramPuzzle('goose.tex').draw_pieces('goose_pieces_on_grid.tex')
produces this, this and this .tex files, respectively, with this, this and this associated .pdf files.
It is advisable to make sure that the spaces in the .tex files produced during the interaction are
exactly as shown. Still, whitespace will be ignored for assessment purposes, but of course, all other
nonspace characters have to be exactly the same, character for character, with all lines in the same order.
3.4 Creating a file to represent the outline of the solved puzzle (3 marks)
The TangramPuzzle class has a draw_outline() method that takes the name of a .tex file as argument,
to represent a solved tangram by drawing the outline of its shape as opposed to each piece, starting
from the leftmost topmost vertex and moving in a clockwise direction. Straight line segments extend as
much as possible between vertices. Again, the origin is represented by a red dot. Again, the grid in the
background extends in such a way that there is at least one square (of 5mm by 5mm) and strictly less
than 2 squares above the topmost vertex, to the right of the rightmost vertex, below the bottommost
vertex and to the left of the leftmost vertex.
Executing
$ python3
...
>>> from tangram import *
>>> TangramPuzzle('kangaroo.tex').draw_outline('kangaroo_outline_on_grid.tex')
>>> TangramPuzzle('cat.tex').draw_outline('cat_ouline_on_grid.tex')
>>> TangramPuzzle('goose.tex').draw_outline('goose_outline_on_grid.tex')
produces this, this and this .tex files, respectively, with this, this and this associated .pdf files.
Again, it is advisable to make sure that the spaces in the .tex files produced during the interaction
are exactly as shown. Still, whitespace will be ignored for assessment purposes, but of course, all other
nonspace characters have to be exactly the same, character for character, with all lines in the same order.
3.5 Solving a puzzle (5 bonus marks)
A function solve_tangram_puzzle() takes a file name as argument and returns a TangramPuzzle object,
making the following interaction successful:
$ python3
...
>>> from tangram import *
>>> solve_tangram_puzzle('kangaroo_outline_on_grid.tex').draw_pieces('solved_kangaroo.tex')
>>> solve_tangram_puzzle('cat_outline_on_grid.tex').draw_pieces('solved_cat.tex')
>>> solve_tangram_puzzle('goose_outline_on_grid.tex').draw_pieces('solved_goose.tex')
>>> ^D
$ diff kangaroo_pieces_on_grid.tex solved_kangaroo.tex
$ diff cat_pieces_on_grid.tex solved_cat.tex
$ diff goose_pieces_on_grid.tex solved_goose.tex
$
5

热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图