[MUSIC] Hey, now today we want to look at some more algorithms for building our AI into our X program, remember our term project. We're going to use all our technique to really have a first rate X player and min-max is the basic algorithm for doing that. And then we're also going to show, remember we did a lot of the last few times with inheritance, but now we want to show how C++11, the new standard, is going to influence how to build those classes. So I want to look at some critical new features that'll affect your coding style, if not already, in the next couple of years. So hopefully you already have a compiler capable of compiling C11 code, C++11 code, but if you don't you'll shortly be able to. So we're going to show some of the major effects of the new standard on class design and class coding. And we're also going to show this very basic artificial intelligence algorithm called the min-max algorithm. All right, one of the very biggest deals and no question even if you came into this class knowing a fair amount of C++ or Java this is going to be entirely new. It's entirely new because the ideas in it are actually new ideas at the high level language level for most languages. And this is something called move semantics, so recall, C++ is about providing the professional with the widest tool set to build effective and efficient, efficient is critical, efficient code. We are not a interpretive system remember Python, Lisp, Java they were based on interpreters. Interpreters are another layer of software that comes between you and the machine. And therefore, you're not using every cycle in solving or executing your algorithm. C++ grow out of C a system implementation language which was not meant to hide the hardware, the metal. So this is supposed to let you put the pedal to the metal as they say and write the most efficient code. And move semantics are a new idea to get you even more efficient. Now most of you may not need to use move semantics because largely move semantics were incorporated to very much improve the libraries, especially the standard template libraries. So we're going to get some ideas there, so the code I'm going to look at is code that's going to allow you to design a sequential container class. And this sequential container class is a class that is already in C++11. It's called the array class, and it allows as a template, that you can specify a template that in effect is a fixed length array. Now, why should you want to do that? You all ready have a vector, well, a vector is an expandable length container class, an expandable sequential container class that gives you array like semantics, it gives you more stuff. You don't get that extra stuff without some price, so generally speaking, while you get more flexibility with a vector than you do with an array, it comes at a cost. Now of course you can go back to what might be called the native array class, your basic allocated array, one dimensional array in C. However that one dimensional array doesn't get you a lot of extra stuff, it's very raw. So you have to discipline yourself to not have off by one errors, to not have addressing errors. So this kind of array class, fixed length array, gets you something intermediate. It maintains the high level of efficiency of a raw array, but give some extra functionality. We're going to see how to designer own version of that. And we want to see what move semantics will give us when we are just typically move semantics are used for things like container classes, for things in which large aggregates are going to be stored. So instead of array, I'm going to do my primitive form of array, I'm going to call it my_container, it's going to be a class template. And notice that it has two template arguments, right, it's going to be a template, again, so it's just like if you want something like this, include sharp, include array. And you will get a fixed length array, and this is, again, a C++11 STL feature, and we're seeing how to build that. We have two parameters, For the template. One is the type to be stored, so here's a base pointer. Have it private. And the other is the size, the fixed size. My constructor, Should really have, this is the signature should've been int n there, because we want the size of our array to go in there and we don't have it defaulted. And then traditionally we want to be a good citizen, and so the D structure, recall again that since we are allocating an array of objects, we de-allocate using the delete with the brackets, that means delete an array. So what's going to be built here is an array of a particular size, if n is 100 we're going to have T⋆ of a an effect, it'll have 100 elements there, right. And it'll be whatever type this is, so it could like an integer array or a double array or an array of whatever we want it to be based on the template structure. Okay, so given that piece of code, what would the declaration of my container data<int of 5> produce? The answer is, it would produce basically some array where I had 5 elements, those elements were ints that were being stored. a is the pointer to the base of that array. Notice that since declaration is going to involve int and 5, I made a mistake about that constructor. Int n was not in the signature. I had forgotten, it was actually a parameter to the template. So hopefully you've all caught that, but that was a useful mistake that I made. So here we had a parameter that wasn't a type parameter, it was an actual parameter of an integer type, and that is part of the typing. So that's another thing critical to this, that part of the typing of all of those arrays is not just the type T but the specific allocator. The specific size of the allocated array, so a size 10 array integer is going to be a different type than a size 20 integer array. That's different again than a vector, and it's different again than the native pointer types in C.