2020/3/14 Assignment 2: CSC148H1 S 20201:Introduction to Computer Sciencehttps://q.utoronto.ca/courses/130571/pages/assignment-2 1/14Assignment 2CSC148:Assignment 2: BlockyDue date: Tuesday, March 31, 2020 before noon sharp (not 12:10).You may complete this assignment individually or with a partner who can be from any section ofthe course.Learning goalsBy the end of this assignment, you should be able to:model hierarchical data using treesimplement recursive operations on trees (both non-mutating and mutating)convert a tree into a flat, two-dimensional structureuse inheritance to design classes according to a common interfaceCoding GuidelinesThese guidelines are designed to help you write well-designed code that will adhere to theinterfaces we have defined (and thus will be able to pass our test cases).You must:write each method in such a way that the docstrings you have been given in the starter codeaccurately describe the body of the method.avoid writing duplicate code.write a docstring for any class, function, or method that lacks one.You must NOT:change the parameters, parameter type annotations, or return types in any of the methods orfunction you have been given in the starter code.add or remove any parameters in any of the methods you have been given in the starter code.change the type annotations of any public or private attributes you have been given in thestarter code.create any new public attributes.create any new public methods.write a method or function that mutates an object if the docstring doesn’t that it will bemutated.add any more import statements to your code, except for imports from the typing module.You may find it helpful to:2020/3/14 Assignment 2: CSC148H1 S 20201:Introduction to Computer Sciencehttps://q.utoronto.ca/courses/130571/pages/assignment-2 2/14create new private helper methods or functions for the classes you have been given.if you create new private methods or functions you must provide type annotations for everyparameter and return value. You must also write a full docstring for this method asdescribed in the function design recipe(https://q.utoronto.ca/courses/130571/files/5593988/download) *create new private attributes for the classes you have been given.if you create new private attributes you must give them a type annotation and include adescription of them in the class’s docstring as described in the class design recipe(https://q.utoronto.ca/courses/130571/files/5594041/download) *import more objects from the typing moduleoverride the inherited version of the __eq__ special method in some cases (this is not thesame as creating a new public method).While writing your code you can assume that all arguments passed to the methods and functionsyou have been given in the starter code will respect the preconditions and type annotationsoutlined in the methods’ docstrings.Introduction: the Blocky gameBlocky is a game with simple moves on a simple structure. But, like a Rubik’s Cube, it is quitechallenging to play. The game is played on a randomly-generated game board made of squaresof four different colours, such as this:(https://q.utoronto.ca/courses/130571/files/6426939/download?wrap=1)Each player has their own goal that they are working towards, such as creating the largestconnected “blob” of blue. After each move, the player sees their score, which is determined byhow well they have achieved their goal and which moves they have made. The game continuesfor a certain number of turns, and the player with the highest score at the end is the winner. Next,let’s look in more detail at the rules of the game and the different ways it can be configured forplay.The Blocky board and terminologyWe call the game board a ‘block’, which is best defined recursively. A block is either:2020/3/14 Assignment 2: CSC148H1 S 20201:Introduction to Computer Sciencehttps://q.utoronto.ca/courses/130571/pages/assignment-2 3/14a square of one colour, ora square that is subdivided into 4 equal-sized blocks.The larges
姓名:
年龄:
电话: