Hogwarts School of Witchcraft and Wizardry Prepares for Duels
Total Page:16
File Type:pdf, Size:1020Kb
HOGWARTS SCHOOL OF WITCHCRAFT AND WIZARDRY PREPARES FOR DUELS Grupptentamen i Programmeringsparadigm REGLER FÖR GRUPPTENT v Webben är öppen för deltagarna. v Deltagarna får endast kommunicera (angående tenten) med varandra. v Att aktivt begära hjälp eller information av utomstående via mejl, chatforums eller andra kanaler är förbjudet v Tentttiden är 6h och slutar 19:15 (+2h för de som jobbar i par). REGLER FÖR GRUPPTENT v Det finns 9 olika uppgifter i tenten. Sammanlagt kan de ge 20p. v Ni får fritt välja vem som kodar vilken uppgift eller hur ni samarbetar kring dem. v Ni får fritt välja för varje uppgift separat om ni kodar den på Haskell eller Prolog. v Det ska stå som kommentar för varje inlämnad uppgift vilken språkversion och OS som använts. REGLER FÖR GRUPPTENT v Inlämningen sker via mejl till [email protected] v Haskell-uppgifterna ska samlas i en fil, prolog-uppgifterna i en annan. Ifall ni använder system som inte är ömsesidigt kompatibla, får ni mejla flera filer (dokumentera detta i så fall!) v Varje inmejlad fil ska ha en kommentar om vilken grupp som producerat den. Koden ska ha kommentarer som visar hur den ska anropas. REGLER FÖR GRUPPTENT v Själva uppgifterna beskrivs på engelska, eftersom svenska språket än så länge är obekant vid Hogwarts. TEST DATA v You should use these lists to test the tasks that follow (naturally, you will decide how to represents the data in the lists, here they are given in pseudocode): v Slytherin students: • ("Draco Malfoy", "owl”) • ("Vincent Crabbe", "rat”) • ("Pansy Parkinson", "cat”) • ("Gregory Goyle", "cat”) TEST DATA v Gryffindor students: • ("Harry Potter", "owl”) • ("Hermione Granger", "cat”) • ("Ron Weasly", "rat”) v Ravenclaw students: • ("Luna Lovegood", "cat”) • ("Cho Chang", "rat”) • ("Padma Patil", "cat”) • ("Marcus Belby", "owl”) TEST DATA v Hufflepuff students: • ("Cedric Diggory", "cat”) • ("Hannah Abbot", "owl”) • ("Pomona Sprout", "rat”) TASK 1: DUELSTART 1P v In Hogwarts the unit that partakes in duels is a student and his/her magical pet. For duelStart you should model such a pair and then prepare this pair for the duel so that the points awarded for this pair start from 0. v You can write a Haskell function or a Prolog predicate for this; the functionality should be: v E g input: (”Harry Potter”, owl) output: (”Harry Potter”, owl) 0 (You choose how to represent this) TASK 2: DUELREADY 1P v In duelReady you work with a list of student & magical pet couples. duelReady should take a list of such couples and make them ready for a duel, using the function/predicate duelStart from the last task. The expected result is naturally of list of these couples, ready for duel: v E g • ("Cedric Diggory", "cat”) • ("Hannah Abbot", "owl”) • ("Pomona Sprout", "rat”) should be turned into … … TASK 2: DUELREADY 1P • ("Cedric Diggory", "cat"), 0 • ("Hannah Abbot", "owl"), 0 • ("Pomona Sprout", "rat”), 0 v You decide how to model this, but the result must be the same list of students, all ready for duel. TASK 3: PAIR FOR DUEL 2P v The function/predicate pairForDuel takes in two lists where the elements are student-pet couples, and pairs these couples with other such couples, so that one couple comes from one list , the other couple from the other list. pairForDuel must give as result all such possible couplings. v See next slide for example! TASK 3: PAIR FOR DUEL 2P v E g first list: • ("Harry Potter", "owl”) • ("Hermione Granger", "cat") v Second list: • ("Cedric Diggory", "cat”) • ("Hannah Abbot", "owl”) • ("Pomona Sprout", "rat") v … should yield ... TASK 3: PAIR FOR DUEL 2P v The result should be: • ("Harry Potter", "owl”) & ("Cedric Diggory", "cat”) • ("Harry Potter", "owl”) & ("Hannah Abbot", "owl”) • ("Harry Potter", "owl”) & ("Pomona Sprout", "rat”) • ("Hermione Granger", "cat") & ("Cedric Diggory", "cat”) • ("Hermione Granger", "cat") & ("Hannah Abbot", "owl”) • ("Hermione Granger", "cat") & ("Pomona Sprout", "rat”) TASK 4: SAME ANIMAL 1P v This function/predicate should check whether two student-pet couples have the same animal or not. v E g: • ("Harry Potter", "owl”) & ("Cedric Diggory", "cat”) => false • ("Harry Potter", "owl”) & ("Hannah Abbot", "owl”) => true TASK 5: PAIR FOR ANIMAL DUEL 3P v This function/predicate should work as pairForDuel, but only couples with the same kind of magical pets are allowed in the result: v E g • ("Harry Potter", "owl”) & ("Cedric Diggory", "cat”) • ("Harry Potter", "owl”) & ("Hannah Abbot", "owl”) • ("Harry Potter", "owl”) & ("Pomona Sprout", "rat”) • ("Hermione Granger", "cat") & ("Cedric Diggory", "cat”) • ("Hermione Granger", "cat") & ("Hannah Abbot", "owl”) • ("Hermione Granger", "cat") & ("Pomona Sprout", "rat”) TASK 6: COUPLE FOR DUEL 3P v Again we need to form (student, pet) pairs for duelling, but this time we simply pair the couples in the order that they have in the lists: the first couples from both lists will form a pair, the second couples the second pair and so on. However, as the House Lists are not equally long, there is a risk that some students will not get paired off. We might wish to find pairs for them later. So, coupleForDuel must give three results: (next slide!) TASK 6: COUPLE FOR DUEL 3P v Say whether all students in both the lists got paired off or not v Give the list of the new pairs v Give a list of those student-pet couples that did not get a pair (this list may be empty) v See next slide for an example! TASK 6: COUPLE FOR DUEL 3P v E g first list: • ("Harry Potter", "owl”) • ("Hermione Granger", "cat") v Second list: • ("Cedric Diggory", "cat”) • ("Hannah Abbot", "owl”) • ("Pomona Sprout", "rat") v … should yield ... TASK 6: COUPLE FOR DUEL 3P v ”There were students left over” v The list of pairs: • ("Harry Potter", "owl”) & ("Cedric Diggory", "cat”) • ("Hermione Granger", "cat") & ("Hannah Abbot", "owl”) v The list of those left over: • ("Pomona Sprout", "rat") TASK 7: THREAT 3P v threat is used to controll that two students do not threaten each other while training on a 5 x 5 field. The spells are cast on straight lines, so that the row and the column where the student stands are effected by the spell. (The magical architecture of the 5 x 5 training hall reflects the spells so that the whole row and the whole column where the student is standing are effected by the spell, but the rest of the space is uneffected.) v NB! The wizards/witches may NOT stand in the same slot!! (Next slide!) TASK 7: THREAT 3P v The function/predicate threat must check the position of a student casting the spell in this hall against the position of another student planning to enter the hall (remember, (s)he may choose to apparate in any slot) and say whether there is a threat that this student might be effected by the spell cast by the first student. v Threat must also see to it that the second student may not apparate on the slot reserved by the student casting the spell! (Next slide!) TASK 7: THREAT 3P 1 1 Hint: think very, very carefully 2 what you need to 2 know to model the task! Do NOT model what Student 2 is not is not needed … Student 2 is threatened threatened by the spell by the spell cast by cast by student 1 student 1 TASK 8: CROSSFIRE 3P v The function/predicate crossFire will help to determine whether a third person risks being hit by crossfire if (s)he enters the training local described above, with two students already casting spells in it. v Crossfire is defined as all the slots where the spells cast meet. v Remember to analyse the situation both for the case where the wizards training do not threaten each other, and for the one where they do! We are still working in the 5 x 5 training hall. (Next slide!) TASK 8: CROSSFIRE 1 1 crossFire must produce a list of 2 the slots to be 2 avoided (those with crossfire). 1 and 2 do not threaten Students 1 and 2 are each other. Crossfire threatened by each other. positions are marked in Crossfire positions are red. marked in red. TASK 9: SAFE 3P v A third person will apparate onto the arena at a given position – but is it safe? v Safe positions to apparate in are those that are not under threat (see task 7) or those where one risks crossfire (see task 8). v The function/predicate safe must check whether the slot where the third person plans to apparate is safe or not. GOOD LUCK WITH YOUR CODING MAGIC! https://www.google.com/search?q=hogwarts&biw=1440&bih=749&tbm=isch&imgil=8Db5n-ewbR6CBM%253A%253BUmXnQO0O_YykpM %253Bhttps%25253A%25252F%25252Fen.wikipedia.org%25252Fwiki%25252FHogwarts&source=iu&pf=m&fir=8Db5n-ewbR6CBM%253A %252CUmXnQO0O_YykpM%252C_&usg=__MQlngaztgHhWNUqsyl_nshvOzJI %3D&ved=0ahUKEwjNy_Dr45_MAhUOb5oKHSm5C00QyjcIJQ&ei=As4YV83COI7e6QSp8q7oBA#imgdii=8Db5n-ewbR6CBM%3A%3B8Db5n- ewbR6CBM%3A%3B50Cw-vVa3QB-4M%3A&imgrc=8Db5n-ewbR6CBM%3A .