30: Abstract Data Types in C - Richard Buckland UNSW

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hey we weren't being recorded in where we were we being recorded no not cool okay someone did ask me about the MiGs let me get a related attack is a famous attack called the man-in-the-middle attack the man-in-the-middle attack is what you have to be worried about when you're doing your ssh initialization so someone was quite rightly worried well no it's probably fine about that on the weekend man-in-the-middle can happen like this I think I'm communicating with this is it's and oh oh sorry I might always say that don't know what's and I was just talking to you before where are you yeah yeah okay so I want to communicate with OMA so I said I'm gonna now negotiate a protocol and we're gonna set up some sort of link but evil man in the middle who's Brad has sniffed out but brett has snipped our phone wire and the phone wire now goes from me to Brett and then Brett can do whatever Brett's compute and then Brett has it to you so I'm negotiating I think I'm negotiating a connection with you but really I'm negotiating with Brett and simultaneously Brett is negotiating the connection with you does that make sense now it's very hard to detect this because I could say something to detect it's not Brett I could say something like maybe you and I agreed in advance the secret color was puce okay so I could say just to check I really made the connection with Omar hey Omar what's the secret color Brett thinks I don't know what the secret color is so what does he do here cuz it back to oma hey Omar what's the secret color Omar says puce Redick pues as long as he keeps echoing everything backwards and forwards weak it's very hard for us to tell he's there does that make sense that's called a man-in-the-middle attack and the famous example that's called the mig in the middle attack how'd it work I'll probably get the u.s. s and USSR mixed up here you were saying USSR make stuff work at remember wish I was which but essentially you know radar sends a pulse out to detect something and the bounces off the thing goes back so I could just go and it hits you and bounces back can I get boom coming back and fight Tommy how long it takes does that make sense but someone worked out well that's a lot of I'm spending a lot of power to broadcast that high-frequency radar pulse I think it's very high frequency is that right or is a very low frequency lofric lower than light is it okay I'm using a lot of power to broadcast that low frequency radar pulse why don't I encode some information into it because it's just a radio it's like radio it's just different Riggle t so instead of going I say something like what's your password and when he gets a pulse from me instead of just echoing back boom which will happen automatically up he's right up he also broadcasts back my class word is Simon or something like that does that make sense so you can actually use like my right eye detector can detect who he is as well as a pom so then on my screen as well as saying a little blitz coming towards me I'm also saying names under them like Simon and bad guy and things like that if I'm a bad guy does that make sense so you so in the early days they set it up so that the guy the systems that detected planes could also request authentication from the planes and in the response that would broadcast back some authentication and that way you'd be absolutely safe because you'd only fight down and kill their bad guys and you wouldn't fire does it all make sense and to stop a replay attack which is someone just tape recording what's your name bomb Simon and just replaying back bomb Simon when everyone says Bing what's your name they we have a challenge response system so I say what's apply the special function 252 and you'll go bomb the answer is 19 and I'll never ask that for 52 again next time I'll say apply the special function to 76 and you go bomb the answer is 112 and as long as I ask different questions every time you can't replay a tape of that because the your response has to relate to my specific question does it all make sense okay that's just a basic thing so anyway how the funny thing work was and I can't remember which side worked it out but if if there were Russian let's suppose the US worked it out now let's suppose the Russians worked it out it's more exciting that way so here's a u.s. battleship and here's a Russian me zooming in and the u.s. battleship in the middle fighting that this is a call boy runs just annoying each other okay and and the u.s. battleship sends a message out saying and he's a good he's a good guy he's Mike who is good guy can't remember the name of the guy Tom Cruise he's Tom Cruise happy with their triumphal music tan tan-tan and he's coming in and the ship goes what's the magic number 442 and the Russian what does he do he goes sends up to here at pulse to Tom Cruise what's the message 442 and Tom Cruise says pong it's 17 and he goes bong at 17 and the sheik goes it's Tom Cruise so as long as you were flying this is very clever you see it's called the MIG in the middle like the man in the middle that's very cool and the anyway he's very cool okay I probably was the other way around I probably flipped the mission office that was a complete distraction now what were we talking about okay so the big question the big question we left with was this Shh the big question we left with was how can we achieve our dream state and our dream state is a way of defining types so they've got functions on them that can change the implementation of the functions can change yeah the the behavior of the function stays the same but the implementation can change well we have that already by breaking the two different files but also so the type can change again the functions still work but the underlying type is different like I've taken up my engine I've replaced it with pygmies yeah but as long as the steering wheel and blinkers and pedals and all the interface things to work it shouldn't matter whether there's an engine in there or a pigmy does that make sense and everything should still work correctly and then you put in the most appropriate thing whichever makes the car go best in the particular circumstance you've got okay so how can we achieve this and were we to be able to achieve this we're going to call the type we create an abstract type well in some language is it easy in some languages you just create the type and say this type is abstract and once you've said that in the language it means no one's allowed to use the type that can only use the interface functions so if anyone tried to use properties of the type the system would crash if they tried to initialize it using an array initializer the system wouldn't even check to see if it was allowed or not they got busy you can't access his time and tried to pass it one way rather than other way this is we go you can't even assume that the system would just catch them but that's a modern language sees a very old language none of this stuff existed they didn't even have abstract types probably when C was invented no one even thought of the idea so C just let you do anything you want so we can't rely on C to stop us doing it in some modern languages like object-oriented languages you get this behavior for free and that's fantastic anyone that's programmed in an object-oriented language is just you you're normally so happy and overjoyed because you're dealing with abstraction all the time and it just works and you can't break it no matter how hard you try that's a really lovely thing but see unfortunately lets us break it and the danger of breaking it let me just repeat why it's so bad to break it is if it's possible for this guy or this guy to rely on this being an array if it's possible for them to do that then one day we're going to change this and they're gonna break and we never want that to happen in the old days of the Intel chips when they were released they had all the interface functions are they also had some undocumented functions there were functions you could call on the chip that did special things but they weren't guaranteed in the interface like for example if anyone's been using Tim's four eight nine one seven emulator you'll have found there are some onion might have found there are some undocumented opcodes that do really funny things there's one that if you call one function in passing the right number it starts a little movie showing Tim dancing around after it's finished running the program there's all these undocumented features you can call and use no but because we haven't told you them in the interface we're free to get rid of them at any time did you see that because no one can rely on but what happened with the Intel chips does anyone know there were these undocumented features and undocumented features in in the BIOS no undocumented features in the law look how all these undocumented features everywhere special features now buildings your operating system depend on this no but it was almost as bad what happened was if you wanted to do graphics the features the operating system gave you to do graphics were to crap new graphic was just big chuck blobs of stuff moving around really slowly but if you look closely to how the whole graphics cell system were in the graphics chip in the memory mapping you could work out clever undocumented ways of making graphics super cool and super fast so all the game programs started using all these undocumented features of the chip does that make sense and undocumented features of the BIOS I can't remember which I said it was using but some undocumented features and the games run like anything and then when the new chip came out or the new BIOS came out maybe these undocumented features didn't work anymore because I won't guaranteed so suddenly a whole lot of games just stopped working now how did that make people feel it made them feel happy with Microsoft and there was such a backlash against it that wondered what what actually eventually had to happen those undocumented functions were then documented and retro built into it because no one wanted to annoy hundreds of people who bought PCs to play games or thousands or whatever so they became official features now this is a danger we face anything we have in the interface here like oh I'm using an array even if it's not we're not regarding it as important and we're not regarding it as a key feature we're not regarding it is part of the interface specification if it's in there and people can make use of it they will and once they've made use of it we're stuck with it forever so we've made our interface too big we've put in stuff we didn't need to put in and now we dama have to support that forever and it's a real pain because it means forever now we stuck with the race and there's so many better ways of doing it so the danger is if people are if programmers can even get a sniff at what the type is they'll rely on it and once ever live on it we're screwed and we can never change it so we want to prevent the programmers for ever using it now I recommend the sec yes oh yes okay good all right you let me get to that in a second that is a very good solution but it's not gonna work but it's a step in the right direction it's oh it's very clever I like essentially I reckon our possible solutions to this problem fall into two categories category one is trust people to do the right thing in that one here we say up here it's an array but then we put in a comment saying but although it's an array now this could change in the future so please don't rely on it being an array now what do you think of the trust people to do the right thing approach I can't even put a mars bar in the fridge and trust myself not to eat it trusting people I like the way you like it I mean it would be good if the world was like that if we could trust people look a people I love people but speaking as a people we're stupid so we'll we'll use it without even reading the comment or will misunderstand it or we'll use it by mistake so we stupid and - we're lazy so we'll think oh I'll use it now and I'll fix it later and we never will and three we're just you know annoying so we'll think he said I can't use it oh yeah I'm using it everywhere now so we just cannot rely on people so what we need is some way of enforcing it so not that we hope the programmers went to it that they just can't do it now you had a good idea which was well maybe instead of putting the type in this stage we put the type in another dot H and this dot H includes that dot H two things to say one as a general principle we don't like that H is including other dot H is because it can cause a problem so we try and avoid that but - if this stage can include this stage then this must be visible and readable so the programmer can find this dot H and so it's really like that dot H was really inside there remember hash include' means it just write it in so he'll find this and use it and rely on it the trick is if the programmer can know it's an array they can assume it's an array in everything so we don't want them to even be able to find out that it's in a right so here's how we do it and see it's slightly convoluted we do the following diabolical thing we are going to have to put some type in here because Sudoku grid is used here and the type Sudoku grid is used here and these programs are going to chuck a wobbly if they don't see a definition of Sudoku grid when we try and use it so there's going to have to be a definition of Sudoku grid up here but we're going to do what you think the definition of Sudoku grid up here is going to be a lame definition that doesn't tell the full story and the full story will be told over here in a way that they can never see here's how we do it at the top of Sudoku grid H let me write Sudoku grid H or let's say I'll talk about the project and say I was gonna do in the project let's do it Sudoku creepers in the top of Sudoku grid not H we say type def struct Sudoku grid I know I'm putting a silly thing in how s a oh okay sausage P we say type def struct sausage P then we're going to put and then all we're gonna say is so you know what I've done so far what have I done so far I've said I'm about to define a type def and the words going to be Sudoku grid so whenever you see the word Sudoku grid it means this so I'm defining Sudoku grid to be a struct okay so it's going to be something that holds multiple pieces of data but here's the diabolical thing I'm going to do Sudoku grid is a pointer to a struct now that tells C's a lot of information that tells see that Sudoku grid is a pointer which means house it passed its passed by reference so we know all is passing by reference so we know that now we're not relying anything we'd it tells us how much memory to set aside for us to do could grid how much memory does a Sudoku grid need four bytes as much for a pointer so now whenever it sees the definition of a Sudoku grid to consider side memory for a pointer so main is going to be completely happy but it's a pointer to what what it's a pointer to a struct called sausage P and what does a sausage P Potts track look like that's a right answer can we just have that so the question is the question that every programmer wants to know is okay it's appointed to a struct and what is that struct and the answer is yeah and that's telling you I don't know who cares so we don't tell the programmer the programmer sits there and worries and they dream a better they think maybe it's a struct it looks like this well maybe it's a strike that looks like this well maybe they don't know they'll never know they can't access it they can't use it it's just a pointer to a struct does that make sense now what do we have to put in Sudoku grid see we've been a define it yeah in Sudoku grid see we say strapped sausage P curly-brace is and whatever we said it was before its contents with your values and it's my name that's a counter of something whatever does that make sense so now lo and behold we have a time that we've created it's defined in here the definition belongs to here and we can change that definition as much as we want because only the functions in here can access that struck no one over here can access the struck because they're not allowed to know what the struct looks like does that make sense we're all the people over here don't know the names of the variables in the string so if the people over here suppose I main if I wanted to set cell 7 to 5 and I've got a grid how can I set cell 7 to 5 I have to use set cell which is an interface function I cannot say cell dot contents dot 5 because I don't know about contents it belongs over here I haven't imported Sudoku grid dot C and I know about contents does that make sense so this guy is forced to only use the interface functions yes thank you what's your name Rob has hit the mean dollar question the unit test it was the key to the whole thing why did I write a get sell when we didn't need one don't because this lets us access a cell without being able to access the array so in other words we can access a cell without knowing what the type is so we can unit test because we couldn't unit test without a get cell if this was going to be abstract so I can say set cell seven to five and then how am I going to test it I can't look at the array to see that till 75 because I'm not allowed to know it's an array what do I have to do get cell and see if it's five they don't have to be correct they just have to match each other whether they're correct or not that's an intentional thing that's what cheering would say how do you know if it's really self-aware you don't you never do you never can it doesn't matter it's just if it appears to be correct it is correct so if set cell and get cell work perfectly and who cares if they store the away this way or they store the right that way or they store it in a spiral voice don't store it isn't a riot doesn't matter does that make sense so is full and get free sort of work together clear cell and is full sort of work together these guys also to work together so you would test these functions using each other to test them because you're never allowed to access the time does that make sense yes yes yes all right well we have 20 minutes left in these remaining 20 minutes I'm going to show you one piece of syntax you need and then I'm going to talk about the project and how all this applies to the project the one piece of syntax you need is is let's look at the problems we had over in Maine remember I said there were three problems that related to the type three ways main assume the type was a particular type one of them was it could just peep into the arrays directly so that's not allowed to do one is the way it passes it assumes passed by reference which was assuming it's an array well now can we assume our abstract types are passed by reference yes they all are because they're all pointers now so the pointer is copied yeah yeah but we're sharing a pointer to the same underlying object so everything sort of passed by reference now and the third way is how we set it up to start with like for example in unit test you remember we set it up with an array initializer you can't create a new guy unless you know what the guy is like I can't say make me a new Sudoku grid you would quite rightly say but what's the Sudoku grid if I told you what to an array of 81 in so you've got okay here's a new one if I told you it was a structure that contained array of anyone in Centre County you got this one if I told you it was three arrays all linked together with cross pointers in two strikes and nine bullying's all linked together with a char wallah he's a big one here but unless I tell you unless you know what type it is you can't make one of them so that tells us who has the job of making an abstract type once you're going to abstract type who gets to make those guys yes this side they've got to be made over here the users cannot make them because they don't know enough about them to make them so and there has to be an interface function here that lets you make them and I didn't give you one for the first assignment I didn't give you any way of making one of these guys we made it in Maine and we made it in unit test I gave you a filling up with values using retail I give you a way of making one to start with so we need to be able to make them why didn't I give you a way of making them because it would have made the assignment much closer to this next assignment I was thinking oh I really want to give them a function to make it there has to be an interface function to make one of these guys because all abstract types need a function to make them so I need to give you a funky to make a Sudoku grid why didn't I give you a function to make a Sudoku grid it would become a lot more complex and you wouldn't become a lot more errors yes and why in particular would that be the case I mean that is the reason yes come yes thank you very much if now let's go back to our code here Sudoku grid see Sudoku grid dots see suppose it had an interface function called make grid here's how make grid works does a lot of stuff and what does it return at the end returns agreed that we've just made somehow now how did it make the grid well it must have made the grid by putting it on the stack so make grid would put a grid on the stack and then at the end it would return that grid and the outside world would have a grid but what's the problem yeah the grids in array so the erase it up on the stack here as soon as this function term and we return a pointer into the array that's what an array is as soon as that function terminates what happens to that array it's gone forever the problem with most of our variables is when we create them they disappear forever when the function stops the only things that doesn't happen for the concrete types like in sand chars they get copied out and the copies perfect but if a pointer gets copied out if an array gets copied out I mean if array gets passed out it's just a pointer into the array and if you're raised to find on the stack when the stack finishes the array is gone you need a way of creating a variable that's not on the stack so that's spot on common well done so you need a play a way of creating putting aside it's an area of memory which won't get destroyed when the function terminates and there's a way of doing that in C and it's called Malik Malik is a guess memory allocation or perhaps it's no that's it's a really lame joke that's not even funny enough for me to say okay you can guess fill in your own joke it will be funnier than their job and tell me later on and I will claim credit for the best of them all yes that's what it was it was that one yes yeah well then okay what was it now I can tell you no it's abstract can t no no no can t like it's an abstract joke I can't tell you what the joke is but you can query the joke you can say was it funny always very funny say the joke twice ha ha ha ha ha ha made me laugh twice but you can't actually ever find out what the joke is because it's completely abstract we hide it away ok so there's a there's a cacique command called Malick and what Malick does is if I draw a picture of memory let's draw a whole computer's memory you know in a way we've always been drawing it with big addresses down the bottom little addresses at the top remember our code lives up here somewhere and down the bottom what lives down here the stack we don't want to store down here remember because that gets bad is that when the function finishes and the Coyotes up here in something called the code segment it's a whole area of memory and we know exactly how big that is before the program starts because we're pre-compiled the program so we know where that finishes and underneath that we have an area of memory called the heap has anyone heard of the heap before the heaps an area of memory just five people who want to use memory its stack is really organized the heaps like if you've got a heap of clothes what does it look like it's a big mess it's a big ugly mess you just chuck it in you pull things out you do whatever you want it's a big mess it's up to you to look after the heap of clothes so the memory heap is just a whole heap of random memory and anyone who wants can use it and sup to you to look after it wears on the stack it gets looked after for you doesn't it when your function terminates the memory gets reused automatically the biggest danger with using memory on the heap as I say ah hey give me a couple of bytes and the heat goes okay Richard you can have these bytes and how does it tell me where those bytes are it gives me a point yeah so it hands me a pointer to a couple of lights maybe ask for 20 bytes so says ok Richard he's appointed for those 20 bytes they belong to you now well I said oh thanks I put a whole lot of crap in there that's like my bedroom pull it off with rubbish and then I finished now what do I do see if I'm good I tidy it all up and I said oh by the way I don't need that memory anymore thank you very much and it says are cool thanks let me I'll hand it to the next person needs it but probably what do I do I'm like I finished with that now I'm gonna go and do something more interesting I mean and the operating system doesn't know in that bit of memory sit aside forever for me even though I'm never gonna use it again and suppose I ask to this 20 bytes inside a function and that function gets called a thousand times every time it gets called ask for a new piece of 20 bytes I've got 20,000 bytes of memory that I've used up on the heat that I'm never going to restore that's really bad that's called a memory leak and if your program has a memory leak the longer it runs the more memory it sets aside and forgets to restore at the end eventually your computer runs really slowly I don't know if any of you run an operating system that has this property that off you've been running it for a while starts to seem to be more slow yeah that's so so a good nice tidy Boy Scout or Girl Guide programmer will always request memory with malloc and then when they're finished they'll always free the memory now the commands to get memory if I wanted if I wanted to get enough memory so what have I got I've defined let's have a look here Sudoku grid oh no what have I done wrong here is everyone happy with that now this is from the previous like Sudoku grid is a pointer to a struct and thus track looks like that so if I wanted to set aside enough memory I would go Sudoku grid game now enough memory is set aside for game how much memory does going need 4 bytes because what's gained it's a pointer to a thing ok so four bytes get set up here now that's cool and they set up on the stack ok there's just a normal variable and then I'd go what am I gonna call it yeah that's a problem isn't it all right let's not worry about what I gotta call it to get a pointer to it I'm gonna say Malik game what done that right what have I done do I need to do size of game this is something I should have thought about a little bit before the lecture and I will think about immediately after the lecture you call the Malik and you say how many bytes you want I don't think you're given an exemplar I think you say the number of bytes is that correct so I would have to say something like malloc sizeof hmm let me write this bigger somewhere let's move that up there so we can see that that's right here I would have to say now I'm gonna create it so where am I at the moment where's this code residing am I talking about code that lives in Sudoku grid dot C or code that lives in Maine here because only this guy can make it okay only this guy knows what it looks like this guy doesn't know what it looks like this guy does know what it looks like so this guy's going to have to say something like oh I think I need another type tip then I am I gonna go strut I don't want to write distract sausage Pete yeah oh I certainly have to say set me enough memory aside sighs off I need yeah so I need a name for struck sausage Pete yeah I need a name for that no I don't want to say struck sausage Pete I think I need another type tip I think I can do with another type def in an e I mean I just got to remember the neat way of doing it we have a neat convention we follow but is it right that I can just do man I think I need another type therefore what are Sudoku grid points too how I can say struck but we had this rule that we weren't gonna say strikes anywhere except in the dead alright well we say at any alright I'll have to modify this dog up we can say struct here alright struct sausage P X oh yeah I don't I need a pointer to it don't do the whole thing thank you very much so I need size up strapped sausage P and what I've been agonizing about is I've been going to and fro is thinking I didn't really want to write this here I want it no I don't have to what I want to do but I can't do at the moment is I want to have typed if this to be something yes I know I know okay but let's for the moment say we're doing this now let's just decode what we've done here in steps Shh sausage P is the underlying hidden type okay strike sausage P that's the struck that we're about to create that these guys know about and these guys don't know that size of tells me how many bytes that takes malloc that many bytes is asking the operating system to give me that many bytes now let's think about what it'll probably be if I'm storing 81 chars that's going to probably take 81 bytes and I'm also storing an int and that takes four bytes so that's eight what's 81 plus four is 85 and it probably rounds it to the nearest it probably starts them on boundaries so it probably pads it out a little bit it might need eighty eight bytes to store that say so it's probably gonna say this struct is eighty eight bytes P because it won't actually put the intermediately next to the array probably depending on the way I put them around probably anyway so it'll ask for some number of memory round about 88 or 85 bytes or however much it needs and this will allocate it then that will be a point of that - that will be returned so this one is going to get returned is a pointer to one of these struts now what do we call a pointer to a struct one of these drugs we called it a Sudoku grid so what we'll get is Sudoku grid grid equals malloc sizeof riveted um now someone tell me join need to typecast or is it just going to typecast automatically in C it's going to type custom suddenly Shh to be absolutely perfect the question I just asked these guys is I tried it before I came here I didn't need to do it but I was surprised what's happened is this is returning a pointer to one of those structs C might not know what it's a pointer to so I might have to tell it it's a pointer to one of these fancy things so that would be a type diff I mean a typecast that I put in here but I think I can leave that out so let's leave it like this and if if you have to if we have to fix it up we'll do it in the toots but I'm pretty sure this will work so this now this line of code is better than this line of code even though it does the same thing this line of code created an area of memory called the grid and gave us a pointer to it this line of code sets aside an area of memory called a grid and gives us a pointer to it but this one set the memory aside on the stack which is tidied up at the end and this one set the memory memory up on the heap so our function can return it and when the function terminates it still lives it so we've created a new thing if we've created a new thing we've got to be able to destroy it at some Steen's later on if we're going to be a good housekeeper so there should also be an interface function called dispose of grid and dispose of grid has to do something like that remember the operation we need is called free so you go free grid does that make sense and that will destroy that will free up that piece of memory now there's a lot of danger with freeing up memory what could happen what's that yeah yeah you know it doesn't delete it it just like says all that's available for other people to reuse but yeah you could pass in a pointer to something you're still using you could get it mixed up a bit and say delete that the operating system will go okay huh it's gone the contents are still there but it's available for reuse now and if it was something that you were using and I accidentally deleted your thing yeah you're a function over there you're happily using some piece of memory and I said dilute his piece of memory then your piece of memory as far as you can tell still looks all right and you save stuff to it and still they're still memory it still exists and your values haven't been deleted they're still there so you keep using the memory but unfortunately the operating system Phillip now thinks that's a free piece of memory and if someone else is hey I'd like a megabyte of memory please Philip ago sure and you can have this piece too he was holding out to sell out he was holding out the whole block but now we sold this last lot on the block we've got a whole megabyte free you can have that megabyte and you're living in the middle of that megabyte and you start writing zeroes throughout the whole megabyte you're in the middle of fooling around with you a little special bit and some walrus all full of zeroes how did that happen so you write your values back and you thought you'd clean it now it's got a little house in the middle again because it makes sense so you don't want to free something unless you're absolutely sure then no one's ever gonna use it again so freeing is uh is is fraught with danger but if you don't free then everything turns into a mess eventually if you call your function 20,000 times all right so I believe that's all the C syntax you now need to know to create an abstract type and any type you create in this way we're going to call abstract and it's going to get the badge of honor what's the badge of honor for an abstract type capital S so this would be how we define Sudoku grid now let me tell you about the project it's almost exactly the same as this your project is in three phases it's got the same it's over here a different name all right everything's looking good your project is to play the game that you've all been playing blackout on Boulder your ultimate objective at the end of phase 3 is you will have written a diabolical player to play this game and your player will be cunning and clever and really good at playing the game they they cannot cheat we put a comment in somewhere saying please don't cheat now here's how we go let's look at time a picture of time here's what time looks like in case you've ever wondered this is phase 1 phase 2 phase 3 phase 1 is a whole lot of group work do really soon you work on that in your tooth if you've got a Thursday chewed you got much more time to plan and much less time to code if you've got a Tuesday toot you have no time to plan and heaps of time to code no one's gonna be happy if you're in the middle you haven't got enough time to play at all code so what you're gonna have to do is you've got to choose that route you're gonna look at the spec what you choose that money to if you look at the spec say tomorrow morning don't you you choose that you're leaving now and you're gonna look at the spec they'll give me an like half an hour to answer questions to get back to my office to make it all public and then you gotta look at the spec and you're gonna dream about it tonight and think about it tonight and when you talk to chew tomorrow you'll already know what you're gonna do and you're gonna have the most time to code of anyone and if you got a Thursday one you're gonna start thinking straightaway and you maybe will even contact other people in your troop before the shoot and maybe your tutor will too and you'll start bouncing ideas off each other and you'll have a rough idea of what it looks like and by the time you chew comes up you'll have already worked out probably exactly what you're gonna do oh that's so so good G both of those sounds good it's just support people in the middle I feel sorry for okay so here's what I'm gonna do you're gonna do a whole lot of group work here Shh the group work happens in two stages Stage one is the whole shoot together agrees on an interface which means in practice you're agreeing on a dot H file the whole shoot agrees on the interface and everyone's happy you've got a half an hour in the to time to do it and an hour in the lab time to do it and someone's going to document it and write it up afterwards and let's hope they do that once the dot H file is agreed in the groups you broke into last week which it'll give your team your little groups of four or three a name so we can call all the teams names because you'll your names will be appearing in your team suppose you're in team blue someone had a team blue suppose you're on Team Blue team blue will write some code which implements this interface they will actually implement an ADT and then I'll hand that in and get a group back for that plus a few other little jobs after I test is written a little referee that's what the groups do and that's phase one so the end of phase one you know what the interface is you've got each group has an implementation of the interface each group has written one of these and you're ready to go then in in face who individual work now you write your player and the player plays the game and any time the player wants to know something about the the game wants to know how many cards have been played or whose turn it is or if this is a legal move or any or how many cards this guy's played already or who passed laughs or any questions like that he the player is not going to work those out the play is going to ask the ATT and the ATT is in charge of representing all the state about the game so the interface functions here that you'll pick on your tooth will be a whole lot of useful ones that you really think your play is going to want to have and then your player is not gonna have to think about any of those details your play is just going to work out how to play the game in a cunning way and throughout all phase two you write a cunning player or it could be a really stupid player that just works out a random legal move and makes it that would also be fine and then phase three and you submit that at the end of phase 2 phase 3 we start the competition and every night we run a competition where all the players play each other and we come up with a massive ranking of who's the best player on who's the worst player does that make sense every night we do that some of the nights it's for marks and some of the nice is just to practice and in phase 3 you can resubmit your player as often as you want so you'll look oh man I'm coming number 7 Oh coming seven and suddenly super lightning plain ever through it comes along and knocks everyone out and beats everyone and you look at the logs and you see how they playing you think oh I can beat that boy or you just down the bottom you're always playing number 200 you think why am I always coming 200 well I'm always Baldrick I hide it and then you have this brilliant idea one night I know I should play cards when I can so you change your code and and you resubmit does that make sense you resubmit and then okay so the idea is a big competition that runs every night so phase one is we write the ODT Phase two is we use the ADT to write our player phase three as we keep working on our player to make it better and better and better and better and better at the end of phase three so there are five performance marks handed out over this week and the end of Phase three we then just run a big competition with no more updates allowed and there's another five performance marks handed out for how well your final player goes does that make sense yes shoot one player each group work to write the ADT shoot wide to write an interface individual to write a player does that make sense marks for all the bits now Shh to get you warmed up to get you thinking along the right tracks oh we've got like only seconds here's the question you're gonna have to answer in your tutorial you're gonna have to think what function should go in the interface well think about it what functions should go in the interface you already know - that should be in there something to make something that represents the state of the game and something to delete it need a creator in Adelita but think what other functions you're gonna need does that make sense you just think of all the useful things you could want but here's that here's the twist if you put too many functions in the interface what's the cost you have to write them all it's a real pain but you have to write them in your group so that's not too bad what happens if you put too few functions in the interface your player has to do all the work so the interface moves work from your player to the group so make it big enough that your group can do it but not so big you can't do it or not so small you have to do all the work yourself come and see me come come down to
Info
Channel: UNSW eLearning
Views: 30,437
Rating: undefined out of 5
Keywords: abstraction, ADT, richard, buckland, unsw, computer, science, comp1917, university, lecture
Id: 23mp8IUA6z4
Channel Id: undefined
Length: 45min 7sec (2707 seconds)
Published: Thu May 22 2008
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.