1 00:00:00,100 --> 00:00:01,660 The following content is provided 2 00:00:01,660 --> 00:00:03,800 under a Creative Commons license. 3 00:00:03,800 --> 00:00:06,540 Your support will help MIT OpenCourseWare continue 4 00:00:06,540 --> 00:00:10,150 to offer high quality educational resources for free. 5 00:00:10,150 --> 00:00:12,690 To make a donation or to view additional materials 6 00:00:12,690 --> 00:00:16,580 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:16,580 --> 00:00:17,285 at ocw.mit.edu. 8 00:00:22,920 --> 00:00:26,610 PROFESSOR: All right, so that's a good start to Battlecode 9 00:00:26,610 --> 00:00:28,490 Lecture 2. 10 00:00:28,490 --> 00:00:29,700 Welcome. 11 00:00:29,700 --> 00:00:32,200 Today, we'll be talking about how to write your first player 12 00:00:32,200 --> 00:00:35,660 and then at 6:00 PM we're going to be having some Indian food. 13 00:00:35,660 --> 00:00:36,790 I'm pretty excited. 14 00:00:36,790 --> 00:00:39,631 And it looks like there will be enough Indian food for all 15 00:00:39,631 --> 00:00:40,130 of you. 16 00:00:40,130 --> 00:00:43,730 I correctly estimated how many of you would show up today. 17 00:00:43,730 --> 00:00:46,120 Isn't that a curious aspect of statistics, 18 00:00:46,120 --> 00:00:49,380 that you cannot tell what one person is going to do tomorrow, 19 00:00:49,380 --> 00:00:53,330 but you can tell, very accurately, what everyone, 20 00:00:53,330 --> 00:00:55,500 in aggregate, is going to do tomorrow? 21 00:00:55,500 --> 00:00:56,680 Quite interesting. 22 00:00:56,680 --> 00:01:02,600 I believe in 2006, the number of automobile accident deaths 23 00:01:02,600 --> 00:01:06,790 was correctly estimated to the last man, 24 00:01:06,790 --> 00:01:08,980 or something absolutely crazy like that. 25 00:01:08,980 --> 00:01:13,250 Because it's a number like 40,000 and it was unbelievable. 26 00:01:13,250 --> 00:01:21,480 So with that heartwarming opener about automobile homicide, 27 00:01:21,480 --> 00:01:27,410 I'm going to play some slightly less-- 28 00:01:27,410 --> 00:01:29,880 some slightly more calming images. 29 00:01:29,880 --> 00:01:32,240 So you'll see here on the screen is 30 00:01:32,240 --> 00:01:35,300 the evolution of a very simple rule. 31 00:01:35,300 --> 00:01:38,850 This rule is something like sum up 32 00:01:38,850 --> 00:01:42,800 the number of nearest neighbors and if that number is even then 33 00:01:42,800 --> 00:01:45,440 the square will be white in the next turn, 34 00:01:45,440 --> 00:01:48,880 and if the number is odd then the square will be black. 35 00:01:48,880 --> 00:01:51,570 It's something like that, in essence. 36 00:01:51,570 --> 00:01:56,560 And it ends up making this repeating pattern that 37 00:01:56,560 --> 00:02:00,470 is quite mesmerizing to see and is an excellent example 38 00:02:00,470 --> 00:02:02,650 of emergent complexity. 39 00:02:02,650 --> 00:02:04,530 So, what we'll be doing today is we're 40 00:02:04,530 --> 00:02:09,050 going to write code that's pretty darn simple. 41 00:02:09,050 --> 00:02:13,010 A rule like mod two = zero, something like that. 42 00:02:13,010 --> 00:02:15,290 And what we're going to get is some really awesome 43 00:02:15,290 --> 00:02:19,260 looking behavior that comes out of that very simple rule. 44 00:02:19,260 --> 00:02:22,610 So there you go, that's my tie-in for that. 45 00:02:22,610 --> 00:02:24,800 Administration stuff, so here I've 46 00:02:24,800 --> 00:02:28,960 brought up the Battlecode website. 47 00:02:28,960 --> 00:02:31,660 You should all be set up with Eclipse right now, already. 48 00:02:31,660 --> 00:02:33,705 If you haven't then you're falling behind, 49 00:02:33,705 --> 00:02:35,330 but then again, at the same time you've 50 00:02:35,330 --> 00:02:37,205 saved yourself some effort because we've just 51 00:02:37,205 --> 00:02:38,840 put out another release. 52 00:02:38,840 --> 00:02:42,440 So, what you want to do is download the installer 53 00:02:42,440 --> 00:02:44,370 and install it to the same directory 54 00:02:44,370 --> 00:02:46,146 where you currently have Battlecode. 55 00:02:46,146 --> 00:02:47,520 And that should update everything 56 00:02:47,520 --> 00:02:49,228 without deleting the progress that you've 57 00:02:49,228 --> 00:02:50,070 made on your player. 58 00:02:52,740 --> 00:02:53,792 So there's that. 59 00:02:53,792 --> 00:02:57,090 There's also some exciting things 60 00:02:57,090 --> 00:02:59,280 I'm supposed to be announcing. 61 00:02:59,280 --> 00:03:06,420 That we'll be giving away prizes for things other than winning. 62 00:03:06,420 --> 00:03:09,290 So, if you're going to see my amazing code 63 00:03:09,290 --> 00:03:11,056 and you're going to go, man, I didn't 64 00:03:11,056 --> 00:03:12,180 think I could do that well. 65 00:03:12,180 --> 00:03:14,080 Although, I find it much more likely 66 00:03:14,080 --> 00:03:17,230 that you could watch what I'm going to do and then go, pfft, 67 00:03:17,230 --> 00:03:19,300 I could have done that in my sleep, 68 00:03:19,300 --> 00:03:21,630 I can't believe this guy. 69 00:03:21,630 --> 00:03:23,640 But yeah, we'll be giving away prizes 70 00:03:23,640 --> 00:03:25,870 for doing things other than winning this year. 71 00:03:25,870 --> 00:03:28,494 And those things I'll be announcing throughout the year 72 00:03:28,494 --> 00:03:30,910 so you can keep them in the back of your mind and be like, 73 00:03:30,910 --> 00:03:36,450 oh I have code that does that I should think about doing this. 74 00:03:36,450 --> 00:03:38,790 There will be beating the reference player 75 00:03:38,790 --> 00:03:43,030 with the fewest total bytecodes, beating the reference player 76 00:03:43,030 --> 00:03:44,470 in the shortest possible time. 77 00:03:44,470 --> 00:03:46,678 By the way, we haven't released the reference player. 78 00:03:46,678 --> 00:03:51,740 We will be releasing one within the next couple of weeks. 79 00:03:51,740 --> 00:03:53,580 And, I don't know if I've said it yet, 80 00:03:53,580 --> 00:03:55,830 but to get credit for the course you 81 00:03:55,830 --> 00:03:58,770 have to beat the reference player that we'll 82 00:03:58,770 --> 00:04:02,150 provide on a map set that we provide. 83 00:04:02,150 --> 00:04:03,750 So it'll be called reference player 84 00:04:03,750 --> 00:04:07,680 and there will be more information about that later. 85 00:04:07,680 --> 00:04:11,110 You're also able to get credit by writing a short report 86 00:04:11,110 --> 00:04:13,534 on how your code works if you weren't 87 00:04:13,534 --> 00:04:14,950 able to beat the reference player. 88 00:04:14,950 --> 00:04:17,329 So don't fret too much. 89 00:04:17,329 --> 00:04:19,640 So, those two ways are ways of winning money. 90 00:04:19,640 --> 00:04:22,000 You can also have the most interesting use of our source 91 00:04:22,000 --> 00:04:26,210 code, like if you want to make it so that Nyan Cats are 92 00:04:26,210 --> 00:04:29,200 part of Battlecode, or some other silly thing, 93 00:04:29,200 --> 00:04:31,180 that might get you something. 94 00:04:31,180 --> 00:04:34,440 And there's also most impressive non-winning strategy, 95 00:04:34,440 --> 00:04:37,990 which may very well be the thing that we see today. 96 00:04:37,990 --> 00:04:41,310 All right, so here I'm going to go to Eclipse, 97 00:04:41,310 --> 00:04:43,880 this is our supported development environment, 98 00:04:43,880 --> 00:04:48,660 and I'm going to start setting up a new player. 99 00:04:48,660 --> 00:04:52,180 So, I've got all these extra Battlecode installs because 100 00:04:52,180 --> 00:04:55,470 of the development nonsense that went on. 101 00:04:55,470 --> 00:04:57,670 So what I'm going to do is I'm going to just start 102 00:04:57,670 --> 00:05:00,220 from scratch and I'm going to make sure 103 00:05:00,220 --> 00:05:04,840 that I talk about the functions that I'm using in ways that 104 00:05:04,840 --> 00:05:07,900 are useful to both beginners and intermediate people. 105 00:05:07,900 --> 00:05:10,310 So, beginners have to like hurry to catch up 106 00:05:10,310 --> 00:05:13,900 and intermediate people are more hearing about the Battlecode 107 00:05:13,900 --> 00:05:19,220 API and hearing about how things are put together, specifically, 108 00:05:19,220 --> 00:05:21,070 about Battlecode that they wouldn't already 109 00:05:21,070 --> 00:05:23,940 know from their job experience, for example. 110 00:05:23,940 --> 00:05:25,310 So, let's start this way. 111 00:05:25,310 --> 00:05:28,070 I'm going to make a new team that I 112 00:05:28,070 --> 00:05:31,290 can fight against my other teams that are here. 113 00:05:31,290 --> 00:05:33,310 Because I want to keep trying this. 114 00:05:33,310 --> 00:05:35,760 A big thing about programming is making 115 00:05:35,760 --> 00:05:38,070 it iteritable-- Iterable? 116 00:05:38,070 --> 00:05:38,670 Iterable. 117 00:05:38,670 --> 00:05:43,680 Interval implements runnable, anyway these kinds of things. 118 00:05:43,680 --> 00:05:46,214 And so, you'll want to have a bunch of different robots 119 00:05:46,214 --> 00:05:47,630 that can play against one another. 120 00:05:47,630 --> 00:05:48,910 And so, you can be like, all right, 121 00:05:48,910 --> 00:05:50,860 I'm going to right-click this team's folder 122 00:05:50,860 --> 00:05:52,880 and I'm going to go to Create Package 123 00:05:52,880 --> 00:05:54,450 and I'm going to call it-- What's 124 00:05:54,450 --> 00:05:57,540 a good name for this awesome robot that we're going to make? 125 00:05:57,540 --> 00:05:59,200 Yeah, Awesome Robot. 126 00:05:59,200 --> 00:05:59,700 OK. 127 00:05:59,700 --> 00:06:03,510 Play Awesome Robot player, all right, I guess that's decent. 128 00:06:03,510 --> 00:06:04,510 Yeah. 129 00:06:04,510 --> 00:06:08,050 And then, in this one, I go New File, 130 00:06:08,050 --> 00:06:10,785 and I call it robotplayer.java. 131 00:06:10,785 --> 00:06:13,410 It has to be called that because that's the thing that our game 132 00:06:13,410 --> 00:06:15,270 engine is looking for. 133 00:06:15,270 --> 00:06:17,080 So then, at the very top, we're going 134 00:06:17,080 --> 00:06:27,150 to write down package Awesome Robot player, 135 00:06:27,150 --> 00:06:28,910 and then we're going to put a semi-colon. 136 00:06:28,910 --> 00:06:30,970 Yeah, because you've got to do that. 137 00:06:30,970 --> 00:06:34,200 Then we'll import everything in Battlecode. 138 00:06:34,200 --> 00:06:41,090 So, we can use the Battlecode, the Battlecode API which 139 00:06:41,090 --> 00:06:44,440 is here in battlecode.common.star. 140 00:06:44,440 --> 00:06:47,280 So that'll give us everything that's in the Java Docs. 141 00:06:47,280 --> 00:06:51,080 So, what I'll want to do is have open the Java Docs, 142 00:06:51,080 --> 00:06:53,080 maybe in one window or on the side, 143 00:06:53,080 --> 00:06:54,730 and have open this in another window 144 00:06:54,730 --> 00:06:56,707 so that I can bounce back between them. 145 00:06:56,707 --> 00:06:58,290 I'm not going to do that at the moment 146 00:06:58,290 --> 00:07:01,891 because that would make things even harder to see. 147 00:07:01,891 --> 00:07:03,390 So, what I'm going to do here is I'm 148 00:07:03,390 --> 00:07:04,840 going to increase the text size because I 149 00:07:04,840 --> 00:07:06,339 know some of you at the back are not 150 00:07:06,339 --> 00:07:08,460 going to be able to see 100% of what I'm doing. 151 00:07:08,460 --> 00:07:11,440 If you want to follow along on your laptops, go ahead. 152 00:07:11,440 --> 00:07:15,980 I believe we'll be able to post this code after lecture, 153 00:07:15,980 --> 00:07:19,910 so don't worry too much about making sure 154 00:07:19,910 --> 00:07:23,050 that you can type as slowly as I can. 155 00:07:23,050 --> 00:07:24,140 Awesome. 156 00:07:24,140 --> 00:07:25,100 Is that too big? 157 00:07:25,100 --> 00:07:25,910 It might be. 158 00:07:25,910 --> 00:07:28,326 Here we're going to-- we're just going to run straight in. 159 00:07:28,326 --> 00:07:30,410 So, public class RobotPlayer. 160 00:07:30,410 --> 00:07:31,700 You've got to write that. 161 00:07:31,700 --> 00:07:34,250 So now, so you've written that. 162 00:07:34,250 --> 00:07:38,110 The Java IDE, you notice, will put these brackets 163 00:07:38,110 --> 00:07:39,690 in for us real nice. 164 00:07:39,690 --> 00:07:44,470 And you need a run method, public static void run. 165 00:07:44,470 --> 00:07:48,129 And that's going to take the argument, RobotController, 166 00:07:48,129 --> 00:07:49,920 and then you can name it whatever you want. 167 00:07:49,920 --> 00:07:52,520 I generally call it myRC. 168 00:07:52,520 --> 00:07:58,310 So, this RobotController object is the thing that is a robot. 169 00:07:58,310 --> 00:08:04,000 So, when you run this code every robot has is its own myRC. 170 00:08:04,000 --> 00:08:07,070 And so, the methods of myRC, which you'll see later, 171 00:08:07,070 --> 00:08:09,440 will apply to that particular robot. 172 00:08:09,440 --> 00:08:10,830 You'll see some examples. 173 00:08:10,830 --> 00:08:12,760 So, what I like to do is I like to make-- 174 00:08:12,760 --> 00:08:17,661 I like to define the variable for this RobotController 175 00:08:17,661 --> 00:08:18,160 object. 176 00:08:18,160 --> 00:08:19,760 I like to define a variable so it 177 00:08:19,760 --> 00:08:23,870 can be used throughout this class, throughout this package. 178 00:08:23,870 --> 00:08:29,060 So I'm going to type private static RobotController RC. 179 00:08:29,060 --> 00:08:33,780 And RC is going to be the thing that I define to myRC. 180 00:08:33,780 --> 00:08:36,260 I'm just going to say, there you are, now you've got it 181 00:08:36,260 --> 00:08:40,510 and I can use all of the methods in RobotController 182 00:08:40,510 --> 00:08:42,549 by typing rc. 183 00:08:42,549 --> 00:08:46,150 and then, bingo, right there, you 184 00:08:46,150 --> 00:08:48,460 see Eclipse is telling me all of the methods that 185 00:08:48,460 --> 00:08:52,980 are in the Battlecode.common directory that 186 00:08:52,980 --> 00:08:54,900 are all these methods that you can use. 187 00:08:54,900 --> 00:08:56,680 So, right here, it's like this is 188 00:08:56,680 --> 00:08:59,940 a really convenient way of doing things. 189 00:08:59,940 --> 00:09:04,420 And so, you're going to see that throughout today's lecture. 190 00:09:04,420 --> 00:09:07,540 So, what I want to do is I want to make sure 191 00:09:07,540 --> 00:09:10,770 that I've got everything organized in a way 192 00:09:10,770 --> 00:09:11,580 that I can use it. 193 00:09:11,580 --> 00:09:13,580 Because I'm sure everybody here has written code 194 00:09:13,580 --> 00:09:16,300 in some language or other that just goes on and on and on 195 00:09:16,300 --> 00:09:18,319 and it's absolutely massive. 196 00:09:18,319 --> 00:09:20,360 And so, every time you want to make a change down 197 00:09:20,360 --> 00:09:25,490 here, and up, and down here, you just get a headache 198 00:09:25,490 --> 00:09:28,470 and you have to fall over and it's not very good. 199 00:09:28,470 --> 00:09:31,990 Because you could be at elevation and falling over 200 00:09:31,990 --> 00:09:35,360 at elevation is highly damaging. 201 00:09:35,360 --> 00:09:38,190 So, what we want is this method will run, 202 00:09:38,190 --> 00:09:41,766 but if we only run it like this let's see what happens. 203 00:09:41,766 --> 00:09:43,140 Can any of you guess what's going 204 00:09:43,140 --> 00:09:45,594 to happen if we run Awesome Robot player? 205 00:09:45,594 --> 00:09:46,760 AUDIENCE: It's going to die. 206 00:09:46,760 --> 00:09:47,190 PROFESSOR: That's right. 207 00:09:47,190 --> 00:09:47,800 It's going to die. 208 00:09:47,800 --> 00:09:49,430 Can you tell me why it's going to die? 209 00:09:49,430 --> 00:09:52,010 AUDIENCE: Because run will reach the end of the method. 210 00:09:52,010 --> 00:09:53,010 PROFESSOR: That's right. 211 00:09:53,010 --> 00:09:55,460 That's right, because run will reach the end of a method. 212 00:09:55,460 --> 00:09:57,980 So, both of the teams explode. 213 00:09:57,980 --> 00:10:01,116 I'm kind of curious which team won that match. 214 00:10:01,116 --> 00:10:01,740 Let's see here. 215 00:10:01,740 --> 00:10:04,030 It says they both died. 216 00:10:04,030 --> 00:10:05,740 Ah, Team A won. 217 00:10:05,740 --> 00:10:09,780 Good thing to know, Team A will win if both teams die. 218 00:10:09,780 --> 00:10:13,566 So, let's make a while true. 219 00:10:13,566 --> 00:10:15,440 Yeah, yeah, all right, the game's unbalanced. 220 00:10:15,440 --> 00:10:16,390 I recognize that. 221 00:10:16,390 --> 00:10:19,570 We'll patch it in, I don't know, in two seconds or ten minutes, 222 00:10:19,570 --> 00:10:20,700 or whatever. 223 00:10:20,700 --> 00:10:25,850 We're up to-- did I mention that we're up to 1.1.0. 224 00:10:25,850 --> 00:10:28,040 So, definitely go install that. 225 00:10:28,040 --> 00:10:30,820 1.1.1, that's so fast. 226 00:10:30,820 --> 00:10:33,050 Our development cycle is amazing. 227 00:10:33,050 --> 00:10:35,330 AUDIENCE: [LAUGHTER] 228 00:10:35,330 --> 00:10:38,840 PROFESSOR: So, while true will just keep looping and so 229 00:10:38,840 --> 00:10:40,622 let's try this, let's do while true. 230 00:10:40,622 --> 00:10:41,580 What's going to happen? 231 00:10:41,580 --> 00:10:45,060 Can anybody tell me what's going to happen when I do while true? 232 00:10:45,060 --> 00:10:47,237 Something that's undesirable. 233 00:10:47,237 --> 00:10:50,040 AUDIENCE: It's going to stall? 234 00:10:50,040 --> 00:10:53,509 PROFESSOR: These guys are going to use 10,000 bytecodes 235 00:10:53,509 --> 00:10:55,800 because they just keep looping, while true, while true, 236 00:10:55,800 --> 00:10:56,758 while true, while true. 237 00:10:56,758 --> 00:10:58,350 And I guess, this one comparison, 238 00:10:58,350 --> 00:11:00,683 this going to the end of the loop and coming to the top, 239 00:11:00,683 --> 00:11:02,220 I guess, costs some non-zero amount. 240 00:11:02,220 --> 00:11:05,630 So, they end up reaching their bytecode limit, that's no good. 241 00:11:05,630 --> 00:11:08,800 So if we do RC.yield that ends the turn. 242 00:11:08,800 --> 00:11:14,140 So, whatever happens here above rc.yield will happen 243 00:11:14,140 --> 00:11:16,540 and then it will go to the next round. 244 00:11:16,540 --> 00:11:20,562 So now the bytecode usage for each robot, you'll see-- 245 00:11:20,562 --> 00:11:23,020 and right now all we've got are these headquarters robots-- 246 00:11:23,020 --> 00:11:24,560 the bytecodes used is three. 247 00:11:24,560 --> 00:11:26,310 I'll just have to read it out because it's 248 00:11:26,310 --> 00:11:27,750 so small you can't see. 249 00:11:27,750 --> 00:11:29,370 Yeah. 250 00:11:29,370 --> 00:11:31,480 Yeah, it's three so that's fantastic. 251 00:11:31,480 --> 00:11:33,780 That's the minimum that you can get. 252 00:11:33,780 --> 00:11:36,420 All right, so now we're going to put real stuff in. 253 00:11:36,420 --> 00:11:38,710 We want the headquarters to behave differently 254 00:11:38,710 --> 00:11:39,650 from the robots. 255 00:11:39,650 --> 00:11:42,140 For example, because the headquarters can never move, 256 00:11:42,140 --> 00:11:43,380 it can't walk around. 257 00:11:43,380 --> 00:11:46,522 So let's use if rc. 258 00:11:46,522 --> 00:11:49,630 Now, what we want is we want to figure out what type of robot 259 00:11:49,630 --> 00:11:53,140 it is, so let's look at the different options here. 260 00:11:53,140 --> 00:11:54,576 Oh look, there is an rc.getType. 261 00:11:58,320 --> 00:11:59,030 Yeah. 262 00:11:59,030 --> 00:12:01,000 All right, so now we can just say 263 00:12:01,000 --> 00:12:02,260 if that = RobotType.SOLDIER. 264 00:12:05,720 --> 00:12:07,400 That's not what I wanted. 265 00:12:07,400 --> 00:12:10,060 Soldie-- Yeah, if it's a soldier then 266 00:12:10,060 --> 00:12:13,510 we can put soldier code here and, otherwise, we 267 00:12:13,510 --> 00:12:15,750 can put headquarters code here. 268 00:12:15,750 --> 00:12:20,342 So, let's make a very simple, a very simple thing. 269 00:12:20,342 --> 00:12:22,050 Let's say we want to just kill the enemy. 270 00:12:22,050 --> 00:12:22,550 Kill them. 271 00:12:22,550 --> 00:12:23,850 Kill them dead. 272 00:12:23,850 --> 00:12:28,670 So, let's have, let's have us do this. 273 00:12:28,670 --> 00:12:32,480 We will define a new variable, right here now, in this space. 274 00:12:32,480 --> 00:12:34,810 Direction dir = rc.getLocation.directionTo. 275 00:12:38,300 --> 00:12:40,890 And now, we'll just-- we want to go straight to the enemy. 276 00:12:40,890 --> 00:12:43,640 We want to make, we want to find the direction to the enemy 277 00:12:43,640 --> 00:12:45,922 and then we want to go that direction. 278 00:12:45,922 --> 00:12:47,380 So it's telling me there's an error 279 00:12:47,380 --> 00:12:50,360 because the directionTo needs a direction to what. 280 00:12:50,360 --> 00:12:52,332 So let's give it a location. 281 00:12:52,332 --> 00:12:53,790 We're going to give it the location 282 00:12:53,790 --> 00:12:54,790 rc.senseEnemyHQLocation. 283 00:12:57,592 --> 00:12:58,300 So, there you go. 284 00:12:58,300 --> 00:13:00,670 Now we've already got the direction. 285 00:13:00,670 --> 00:13:02,860 I'm going to put a semicolon at the end of the line. 286 00:13:02,860 --> 00:13:06,180 And now, I can see I'm going to try to go that direction. 287 00:13:06,180 --> 00:13:08,571 To move in a direction you've got to be active. 288 00:13:08,571 --> 00:13:10,070 Because there are certain things you 289 00:13:10,070 --> 00:13:11,980 can do, like laying mines and defusing them, 290 00:13:11,980 --> 00:13:13,310 that make you inactive. 291 00:13:13,310 --> 00:13:15,880 So, I'm going to check if I'm active. 292 00:13:15,880 --> 00:13:17,920 If rc. 293 00:13:17,920 --> 00:13:22,360 is active which returns a Boolean true if I'm active. 294 00:13:22,360 --> 00:13:24,720 Well then, let's go ahead and try to move. 295 00:13:24,720 --> 00:13:26,610 And we'll see what happens when we 296 00:13:26,610 --> 00:13:30,810 try this, rc.move in direction dir. 297 00:13:30,810 --> 00:13:32,310 And so, now we're just going to see, 298 00:13:32,310 --> 00:13:33,330 we're going to see what happens. 299 00:13:33,330 --> 00:13:34,160 Oh, what's this? 300 00:13:34,160 --> 00:13:36,700 It's telling me that an unhandled exception is here. 301 00:13:36,700 --> 00:13:39,100 Move can throw exceptions. 302 00:13:39,100 --> 00:13:43,130 And so what we do is we put in add throws declaration. 303 00:13:43,130 --> 00:13:46,040 So then, up here RobotController is 304 00:13:46,040 --> 00:13:49,900 going to throw an error if this thing has a problem. 305 00:13:49,900 --> 00:13:51,770 And this is a way you can use-- this 306 00:13:51,770 --> 00:13:53,619 is Java's built-in form of debugging. 307 00:13:53,619 --> 00:13:56,160 And you're going to find it very useful because when you have 308 00:13:56,160 --> 00:13:58,240 a problem, it'll tell you what the problem is. 309 00:13:58,240 --> 00:14:00,040 So let's go ahead and do that. 310 00:14:00,040 --> 00:14:02,880 Hm, well, the problem is we don't have any soldiers, 311 00:14:02,880 --> 00:14:05,160 we can't produce any units, so there's 312 00:14:05,160 --> 00:14:06,910 nobody who can run this code. 313 00:14:06,910 --> 00:14:09,820 So, let's go ahead and add in some unit spawning abilities 314 00:14:09,820 --> 00:14:10,759 right over here. 315 00:14:10,759 --> 00:14:12,550 So I'm going to go to example folks player, 316 00:14:12,550 --> 00:14:14,840 open up robotplayer.Java, and I'm 317 00:14:14,840 --> 00:14:18,420 going to copy this part which is for if the robot is 318 00:14:18,420 --> 00:14:19,560 a headquarters. 319 00:14:19,560 --> 00:14:22,018 And I'm just going to go ahead and paste it right in there. 320 00:14:22,018 --> 00:14:24,060 And now, all of a sudden, I'm spawning units 321 00:14:24,060 --> 00:14:27,230 at random directions around myself as the headquarters. 322 00:14:27,230 --> 00:14:29,939 So now, we should have units in our Awesome Robot player 323 00:14:29,939 --> 00:14:31,480 and they start to run at one another. 324 00:14:31,480 --> 00:14:33,320 Oh, but something strange is happening, 325 00:14:33,320 --> 00:14:35,380 when they run into one another it seems like they 326 00:14:35,380 --> 00:14:38,430 are immediately colliding and exploding, boom. 327 00:14:38,430 --> 00:14:41,600 That one exploded, and then that one exploded, and that one did. 328 00:14:41,600 --> 00:14:42,900 That's weird looking, isn't it? 329 00:14:42,900 --> 00:14:45,350 It almost looks like this guy is changing color, 330 00:14:45,350 --> 00:14:48,420 but no, they're running into each other and exploding. 331 00:14:48,420 --> 00:14:51,104 And the problem, it's not just that they're going too fast, 332 00:14:51,104 --> 00:14:52,520 because that isn't the thing, it's 333 00:14:52,520 --> 00:14:54,380 that there's a game action exception. 334 00:14:54,380 --> 00:14:57,930 And you can see here that there's tons of exceptions. 335 00:14:57,930 --> 00:14:59,170 And they all showed up here. 336 00:14:59,170 --> 00:15:01,640 And I can be like, OK, I don't understand anything at all, 337 00:15:01,640 --> 00:15:05,400 I can't read any of this language, oh, but look, 338 00:15:05,400 --> 00:15:07,530 it says robotplayer.Java:15. 339 00:15:07,530 --> 00:15:09,170 I can just click there and it shows 340 00:15:09,170 --> 00:15:11,120 me what's throwing the exception. 341 00:15:11,120 --> 00:15:12,060 Oh, it's this line. 342 00:15:12,060 --> 00:15:14,730 Oh, I see, I see, it's having trouble moving there 343 00:15:14,730 --> 00:15:16,840 because, maybe, there's something in the way. 344 00:15:16,840 --> 00:15:19,870 So let's also stipulate that rc. 345 00:15:19,870 --> 00:15:21,247 move in the direction. 346 00:15:21,247 --> 00:15:22,830 This is another method that's provided 347 00:15:22,830 --> 00:15:25,070 to you that lets you check whether the direction is 348 00:15:25,070 --> 00:15:25,990 movable. 349 00:15:25,990 --> 00:15:29,160 So now, when we run the code, they're 350 00:15:29,160 --> 00:15:31,190 going to just go to the middle, kiss 351 00:15:31,190 --> 00:15:33,000 and kill each other nice and slow. 352 00:15:33,000 --> 00:15:34,100 Just like that. 353 00:15:34,100 --> 00:15:35,307 Wow, that's beautiful. 354 00:15:35,307 --> 00:15:36,140 AUDIENCE: [LAUGHTER] 355 00:15:36,140 --> 00:15:37,556 PROFESSOR: And I think that's just 356 00:15:37,556 --> 00:15:41,220 going to happen all day long until the end of, see when you 357 00:15:41,220 --> 00:15:43,710 get past a certain number of rounds, the headquarters 358 00:15:43,710 --> 00:15:45,670 begin to take end of round damage. 359 00:15:45,670 --> 00:15:48,020 So you can see, the headquarters are just going to die. 360 00:15:48,020 --> 00:15:48,960 And that happens. 361 00:15:48,960 --> 00:15:50,660 And they both die at once. 362 00:15:50,660 --> 00:15:53,104 And I believe player A will have won. 363 00:15:53,104 --> 00:15:54,048 Oh no, player B won. 364 00:15:54,048 --> 00:15:55,510 AUDIENCE: [LAUGHTER] 365 00:15:55,510 --> 00:15:58,415 PROFESSOR: Now, let me tell you, that's balanced. 366 00:15:58,415 --> 00:16:00,740 AUDIENCE: [LAUGHTER] 367 00:16:00,740 --> 00:16:02,920 PROFESSOR: Yeah, so we know what we're doing. 368 00:16:02,920 --> 00:16:07,570 All right, this is starting to get cluttered, right, 369 00:16:07,570 --> 00:16:08,740 I'm not happy with this. 370 00:16:08,740 --> 00:16:12,640 I'm not a neat freak, my wife kind of is. 371 00:16:12,640 --> 00:16:14,874 No, I shouldn't say anything about my wife on this 372 00:16:14,874 --> 00:16:16,290 because it's going to be recorded. 373 00:16:16,290 --> 00:16:19,170 No, she's not a neat freak, she's a very wonderful woman. 374 00:16:19,170 --> 00:16:22,109 OK, so, god I'm in so much trouble. 375 00:16:22,109 --> 00:16:24,400 All right, all right, so here's what we're going to do. 376 00:16:24,400 --> 00:16:26,983 We're going to make a new method that will clean the place up. 377 00:16:26,983 --> 00:16:32,980 We'll call it public static void, we'll call it hqCode. 378 00:16:32,980 --> 00:16:35,360 This is the headquarters code and it's the stuff 379 00:16:35,360 --> 00:16:36,990 that I want the headquarters to do. 380 00:16:36,990 --> 00:16:40,000 And I'm just going to copy this in here 381 00:16:40,000 --> 00:16:45,700 and then I'm going to put hqCode there, bing. 382 00:16:45,700 --> 00:16:49,150 So now, I'm calling this method which I've defined below. 383 00:16:49,150 --> 00:16:53,120 And that'll just insert that code right in there, 384 00:16:53,120 --> 00:16:54,151 really convenient. 385 00:16:54,151 --> 00:16:55,650 Now, can anybody tell me why there's 386 00:16:55,650 --> 00:16:58,517 a red underline under spawn? 387 00:16:58,517 --> 00:16:59,850 AUDIENCE: Game action exception. 388 00:16:59,850 --> 00:17:01,600 PROFESSOR: Yeah, a game action exception. 389 00:17:01,600 --> 00:17:04,530 So what'll happen is I'll just click on this button 390 00:17:04,530 --> 00:17:07,788 and now this code will have-- this guy 391 00:17:07,788 --> 00:17:08,829 will throw the exception. 392 00:17:08,829 --> 00:17:11,069 So, exceptions from here will throw up 393 00:17:11,069 --> 00:17:14,160 and they'll throw to here and then they'll throw even more. 394 00:17:14,160 --> 00:17:17,074 Now, let's say that we don't want 395 00:17:17,074 --> 00:17:18,740 to throw them all the way up to the top. 396 00:17:18,740 --> 00:17:21,980 Because you don't want run to ever throw an exception 397 00:17:21,980 --> 00:17:24,300 because it causes your robot to explode. 398 00:17:24,300 --> 00:17:29,370 So, how do you prevent thrown things from getting out? 399 00:17:29,370 --> 00:17:31,942 If Billy throws me a football, how 400 00:17:31,942 --> 00:17:33,400 do I keep the football from hitting 401 00:17:33,400 --> 00:17:34,800 my house, which is behind me? 402 00:17:34,800 --> 00:17:35,600 AUDIENCE: Catch it. 403 00:17:35,600 --> 00:17:37,100 PROFESSOR: That's right, I catch it. 404 00:17:37,100 --> 00:17:38,950 OK, and in Java, the way that that's 405 00:17:38,950 --> 00:17:41,570 done-- I know a lot of you this already, but some of you 406 00:17:41,570 --> 00:17:43,611 don't and you're going to think that was a really 407 00:17:43,611 --> 00:17:47,380 clever analogy-- is you put try on the outside. 408 00:17:47,380 --> 00:17:52,250 All right, and then you put, I think I want to put it here, 409 00:17:52,250 --> 00:17:53,870 I want to put catch here. 410 00:17:53,870 --> 00:17:54,490 Yeah. 411 00:17:54,490 --> 00:17:57,080 And so, specifically, I want to make sure 412 00:17:57,080 --> 00:17:58,450 that I catch the exception. 413 00:17:58,450 --> 00:18:00,290 So, I'll go, I'll catch exception 414 00:18:00,290 --> 00:18:03,590 e, which will be whatever exception comes out of try 415 00:18:03,590 --> 00:18:05,070 will go into e. 416 00:18:05,070 --> 00:18:06,980 Now, you see that the tabbing is messed up 417 00:18:06,980 --> 00:18:08,770 because try should have a tab after it. 418 00:18:08,770 --> 00:18:10,990 So I just highlight this and I do control I 419 00:18:10,990 --> 00:18:13,310 and that automatically tabs it out. 420 00:18:13,310 --> 00:18:16,570 95% of you knew that already, but the 1%, the 5%-- 421 00:18:16,570 --> 00:18:20,170 I can add-- the 5% that didn't know are like, oh, 422 00:18:20,170 --> 00:18:23,250 that saved me so much time, I'm so happy. 423 00:18:23,250 --> 00:18:25,310 Yeah, so you we're going to catch the exception 424 00:18:25,310 --> 00:18:28,660 and then we're going to do System.out.printline 425 00:18:28,660 --> 00:18:32,790 and we're just going to say "caught exception 426 00:18:32,790 --> 00:18:36,270 before it killed us." 427 00:18:36,270 --> 00:18:38,310 Yeah, and we're going to just print it. 428 00:18:38,310 --> 00:18:43,126 So we're going to go e.printStack.Trace, 429 00:18:43,126 --> 00:18:45,250 and we'll pick the third one because it looks good. 430 00:18:45,250 --> 00:18:48,000 Yeah, so now when there's an error 431 00:18:48,000 --> 00:18:51,470 it'll just print down to here, rather than killing the robot. 432 00:18:51,470 --> 00:18:54,900 At the same time, I should mention, that any time a try 433 00:18:54,900 --> 00:18:58,340 finds an error and moves to catch you get 500 bytecode 434 00:18:58,340 --> 00:18:59,550 penalty right there. 435 00:18:59,550 --> 00:19:02,110 So, that's not a great way to write code. 436 00:19:02,110 --> 00:19:04,282 You want to avoid, you want to avoid 437 00:19:04,282 --> 00:19:05,490 having the exceptions at all. 438 00:19:05,490 --> 00:19:07,330 All right, all right, but we're getting 439 00:19:07,330 --> 00:19:10,050 stuck because we haven't had as much killing 440 00:19:10,050 --> 00:19:11,930 as we really wanted to have. 441 00:19:11,930 --> 00:19:20,300 So, I've got an idea for how to make code that kills the enemy. 442 00:19:20,300 --> 00:19:26,380 So, let's go with that idea that I have, that I definitely have, 443 00:19:26,380 --> 00:19:29,400 and I'm not coming up with on the spot. 444 00:19:29,400 --> 00:19:31,510 So that, let's-- that was a joke, 445 00:19:31,510 --> 00:19:33,590 I actually am not coming up with it on the spot. 446 00:19:33,590 --> 00:19:36,230 I'm so offended that you didn't find that it was joke. 447 00:19:36,230 --> 00:19:38,360 I just have to find out where it is in the notes. 448 00:19:38,360 --> 00:19:44,040 It's in, it's in, capture encampments, 449 00:19:44,040 --> 00:19:47,180 oh, yeah, let's not capture an encampment yet, 450 00:19:47,180 --> 00:19:50,170 because that's not as exciting as-- because what we'd really 451 00:19:50,170 --> 00:19:52,240 like to do is just defeat the enemy 452 00:19:52,240 --> 00:19:57,610 and then we'll worry about shaming them 453 00:19:57,610 --> 00:20:00,510 into a greater defeat, subsequently. 454 00:20:00,510 --> 00:20:02,870 So, let's see here, if you're a soldier, 455 00:20:02,870 --> 00:20:06,150 maybe the right thing to do is start 456 00:20:06,150 --> 00:20:08,860 by massing up your troops in a place. 457 00:20:08,860 --> 00:20:11,760 So, let's get a place to mass up the troops. 458 00:20:11,760 --> 00:20:14,190 Now, maybe you only want to do this once. 459 00:20:14,190 --> 00:20:16,950 It's like a rally point for everybody. 460 00:20:16,950 --> 00:20:18,427 So, let's get this rally point. 461 00:20:18,427 --> 00:20:20,510 I'm going to make it here because I want everybody 462 00:20:20,510 --> 00:20:22,780 to know where this rally point is. 463 00:20:22,780 --> 00:20:25,030 So, a rally point is a map location 464 00:20:25,030 --> 00:20:28,550 because you want everybody to localize around a place. 465 00:20:28,550 --> 00:20:30,560 Now, a map location is yet another object, 466 00:20:30,560 --> 00:20:36,640 like RobotController, and it has its own methods and properties 467 00:20:36,640 --> 00:20:39,220 associated with it that you can find in the Java Docs 468 00:20:39,220 --> 00:20:41,790 and that you can call-- and that you can find your own way. 469 00:20:41,790 --> 00:20:45,381 So, let's do this, MapLocation rallyPoint. 470 00:20:45,381 --> 00:20:47,130 Yeah, we're just going to rally somewhere. 471 00:20:47,130 --> 00:20:49,860 This is going to be a good strategy, trust me 472 00:20:49,860 --> 00:20:51,260 you're going to be excited. 473 00:20:51,260 --> 00:20:53,950 So, let's do, let's find the rally point, start out. 474 00:20:53,950 --> 00:20:56,010 So, let's make a function because it's already 475 00:20:56,010 --> 00:21:01,300 getting far too fluffy, I think. 476 00:21:01,300 --> 00:21:02,800 So, let's find the rally point here. 477 00:21:02,800 --> 00:21:06,390 We'll say rallyPoint = findRallyPoint. 478 00:21:06,390 --> 00:21:07,340 Yeah. 479 00:21:07,340 --> 00:21:08,740 Now, where should we rally? 480 00:21:08,740 --> 00:21:10,691 I think a decent place-- oh, look at this, 481 00:21:10,691 --> 00:21:12,190 it's even going to help me out here. 482 00:21:12,190 --> 00:21:13,606 It noticed that there's no method, 483 00:21:13,606 --> 00:21:16,680 so I can just click here and it'll make me a nice method. 484 00:21:16,680 --> 00:21:19,100 Look at that, it's just like this hqCode 485 00:21:19,100 --> 00:21:20,690 with the private static and then it 486 00:21:20,690 --> 00:21:22,870 has the type that it returns. 487 00:21:22,870 --> 00:21:25,870 See, this time we're making a function that returns a type. 488 00:21:25,870 --> 00:21:30,000 This didn't return anything, it just did code here. 489 00:21:30,000 --> 00:21:32,172 But now, we want it to spit out an answer. 490 00:21:32,172 --> 00:21:34,380 So, we're going to have it return a map location when 491 00:21:34,380 --> 00:21:35,430 it's done. 492 00:21:35,430 --> 00:21:38,626 So, what we'll do is we're going to get some location between us 493 00:21:38,626 --> 00:21:40,250 and the enemy, seems like a great place 494 00:21:40,250 --> 00:21:41,650 to rally our troops. 495 00:21:41,650 --> 00:21:43,190 So, between us and the enemy. 496 00:21:43,190 --> 00:21:44,960 Let's see, the enemy location-- so, 497 00:21:44,960 --> 00:21:47,350 I'm just going to make this nice and simple-- MapLocation 498 00:21:47,350 --> 00:21:48,224 enemyLoc. 499 00:21:48,224 --> 00:21:49,890 You can define variables anyway, this'll 500 00:21:49,890 --> 00:21:51,631 be local to this function. 501 00:21:51,631 --> 00:21:53,130 The enemy location is rc.senseEnemy. 502 00:21:56,080 --> 00:21:57,490 Yeah, there. 503 00:21:57,490 --> 00:22:01,450 OK, MapLocation, our location is rc.senseHQLocation. 504 00:22:04,210 --> 00:22:05,230 Yeah. 505 00:22:05,230 --> 00:22:06,874 And now, I want to find the average. 506 00:22:06,874 --> 00:22:09,040 I'm not going to do it in the smartest possible way, 507 00:22:09,040 --> 00:22:11,289 I'm going to do it in a way that's easy to understand. 508 00:22:11,289 --> 00:22:13,520 Is I'm going to say there's an integer 509 00:22:13,520 --> 00:22:20,700 x which is enemyLoc.x + ourLoc.x. 510 00:22:20,700 --> 00:22:24,090 All right, now, I guess if you took the average of the two 511 00:22:24,090 --> 00:22:27,000 that would be in between, right, that would 512 00:22:27,000 --> 00:22:29,997 be in between the two. 513 00:22:29,997 --> 00:22:32,080 But we don't want it completely in between the two 514 00:22:32,080 --> 00:22:35,130 because we want to just move a little bit out. 515 00:22:35,130 --> 00:22:38,360 So let's make it more of ourLoc and less of theirs, so three 516 00:22:38,360 --> 00:22:39,130 of ours. 517 00:22:39,130 --> 00:22:42,410 And now we put a multiply and that 518 00:22:42,410 --> 00:22:45,300 should get us one quarter of the way to the enemy, 519 00:22:45,300 --> 00:22:47,830 because it's mostly us and somewhat them. 520 00:22:47,830 --> 00:22:48,450 Yeah. 521 00:22:48,450 --> 00:22:50,575 We'll do that for y as well. 522 00:22:50,575 --> 00:22:53,200 There's probably smarter ways of doing it than just writing out 523 00:22:53,200 --> 00:22:55,380 two lines, but it's pretty clear. 524 00:22:55,380 --> 00:22:56,840 And now, what we'll do is we'll use 525 00:22:56,840 --> 00:22:58,850 the constructor for map location. 526 00:22:58,850 --> 00:23:05,650 So, we'll say mapLocation rallyPoint = new MapLocation 527 00:23:05,650 --> 00:23:09,930 and we give it an x and a y. 528 00:23:09,930 --> 00:23:10,810 Yeah. 529 00:23:10,810 --> 00:23:14,180 Yeah, all right, now we can just say return rallyPoint. 530 00:23:14,180 --> 00:23:17,060 OK, so now, we're going to try to go to the rally point. 531 00:23:17,060 --> 00:23:21,070 RallyPoint has been defined here, that's useful. 532 00:23:21,070 --> 00:23:23,800 So now, later we don't have to give it a direction. 533 00:23:23,800 --> 00:23:28,065 We can just say Direction dir = getLocation.DirectionTo. 534 00:23:28,065 --> 00:23:30,490 Now we'll go to the rallyPoint instead. 535 00:23:30,490 --> 00:23:32,490 Yes, yes, to the rallyPoint. 536 00:23:36,530 --> 00:23:40,680 Let's see if our robots are going to the rallyPoint. 537 00:23:40,680 --> 00:23:43,900 I recommend that you try running your code every time 538 00:23:43,900 --> 00:23:45,761 you make a significant change. 539 00:23:45,761 --> 00:23:47,760 And look, they did, they went to the rallyPoint, 540 00:23:47,760 --> 00:23:49,790 but they went there in a dumb way. 541 00:23:49,790 --> 00:23:51,980 Because when one of them was in front of the other, 542 00:23:51,980 --> 00:23:54,200 they couldn't go around. 543 00:23:54,200 --> 00:23:56,980 Because now, this guy can't spawn anymore robots. 544 00:23:56,980 --> 00:23:59,650 I'm pretty sure he's trying, but it's not working. 545 00:23:59,650 --> 00:24:02,340 In fact, what error am I getting here? 546 00:24:02,340 --> 00:24:04,880 I'm getting you cannot move in the direction non or Omni. 547 00:24:04,880 --> 00:24:07,030 That's an interesting problem. 548 00:24:07,030 --> 00:24:10,290 That's the problem that when a robot is on top of the spot 549 00:24:10,290 --> 00:24:13,070 he shouldn't try to move to the spot that he's on top of. 550 00:24:13,070 --> 00:24:16,380 So, we should also specify that there's a distance 551 00:24:16,380 --> 00:24:18,570 and he should only try moving if there's a distance. 552 00:24:18,570 --> 00:24:23,250 So, let's just put dist = rc.getLocation.-- 553 00:24:23,250 --> 00:24:26,590 do you always do that too, I always put i before o-- 554 00:24:26,590 --> 00:24:32,750 .distanceSquaredTo, and distanceSquaredTo rallyPoint. 555 00:24:32,750 --> 00:24:35,260 Yes, that's a useful method. 556 00:24:35,260 --> 00:24:37,520 There are a lot of useful methods for getLocation. 557 00:24:37,520 --> 00:24:38,560 And you might say, all right, how 558 00:24:38,560 --> 00:24:40,434 was I supposed to know that distanceSquaredTo 559 00:24:40,434 --> 00:24:41,830 was a method from getLocation. 560 00:24:41,830 --> 00:24:44,430 I was going to write my own manual function that 561 00:24:44,430 --> 00:24:46,620 goes looking for x's and y's, and squaring 562 00:24:46,620 --> 00:24:49,800 them, and subtracting them, and so on, not that subtraction 563 00:24:49,800 --> 00:24:51,240 is really even relevant here. 564 00:24:51,240 --> 00:24:52,749 But, how was I supposed to know? 565 00:24:52,749 --> 00:24:54,790 Well I'll tell you how you were supposed to know. 566 00:24:54,790 --> 00:24:56,850 You just go to where you installed it. 567 00:24:56,850 --> 00:24:59,440 I put it in Battlecode 2013. 568 00:24:59,440 --> 00:25:03,750 You go to doc and you go to this thing, all classes frame, 569 00:25:03,750 --> 00:25:05,695 and this shows you all the classes. 570 00:25:05,695 --> 00:25:08,440 And one of those classes here is Map Location. 571 00:25:08,440 --> 00:25:11,360 And under Map Location, you see that you can add map locations 572 00:25:11,360 --> 00:25:15,380 to directions, you can add them to x's and y's, you 573 00:25:15,380 --> 00:25:17,230 can use directionTo, distanceSquared, 574 00:25:17,230 --> 00:25:19,650 you can check whether two map locations are equal to one 575 00:25:19,650 --> 00:25:20,990 another, if they're adjacent to one another. 576 00:25:20,990 --> 00:25:22,170 That's pretty useful. 577 00:25:22,170 --> 00:25:26,320 So, having a working understanding or memorization 578 00:25:26,320 --> 00:25:29,630 of these things will help you along the way. 579 00:25:29,630 --> 00:25:31,180 So, now we've got distanceSquaredTo. 580 00:25:31,180 --> 00:25:34,900 So now, we only want to move toward the enemy. 581 00:25:34,900 --> 00:25:38,610 So, if our distance is greater than 0, 582 00:25:38,610 --> 00:25:40,250 then we'll try moving there. 583 00:25:40,250 --> 00:25:42,530 Otherwise, let's not, because it's just 584 00:25:42,530 --> 00:25:44,030 going to end up giving us trouble. 585 00:25:44,030 --> 00:25:47,300 And once again I'm going to do control i to do this indenting. 586 00:25:47,300 --> 00:25:48,980 But this is getting somewhat cluttered, 587 00:25:48,980 --> 00:25:52,230 so why don't I just make this soldierCode, especially 588 00:25:52,230 --> 00:25:55,340 here when everything is a giant font 16. 589 00:25:55,340 --> 00:25:56,960 So, this is soldierCode and I'll just 590 00:25:56,960 --> 00:25:58,710 go ahead and have it automatically 591 00:25:58,710 --> 00:25:59,940 create me that method. 592 00:25:59,940 --> 00:26:02,230 I'm going to go ahead and put this in the method. 593 00:26:02,230 --> 00:26:04,660 And now rc.move has got a throw declaration. 594 00:26:04,660 --> 00:26:06,217 Do you see this? 595 00:26:06,217 --> 00:26:07,800 Pretty soon I'm not even going to need 596 00:26:07,800 --> 00:26:10,732 to be here because it's doing everything for me, my goodness. 597 00:26:10,732 --> 00:26:12,440 So now, they should go to the rally point 598 00:26:12,440 --> 00:26:14,530 and they shouldn't be throwing quite as many exceptions 599 00:26:14,530 --> 00:26:15,363 as they were before. 600 00:26:15,363 --> 00:26:18,150 Oh, look at that, in the game output window 601 00:26:18,150 --> 00:26:21,710 you see no exceptions from round 0 to 5,000, excellent. 602 00:26:21,710 --> 00:26:24,430 But, again, they're just stuck behind one another. 603 00:26:24,430 --> 00:26:26,620 How can we make it so that they're not stuck? 604 00:26:26,620 --> 00:26:29,150 Well, here's a good way to do It. 605 00:26:29,150 --> 00:26:31,380 So, here you're only trying one direction, 606 00:26:31,380 --> 00:26:35,170 but now let's make a way to try multiple directions. 607 00:26:35,170 --> 00:26:38,940 The way that I'm about to show has its own emergent complexity 608 00:26:38,940 --> 00:26:39,610 built in. 609 00:26:39,610 --> 00:26:43,090 You're going to like this a lot, I believe, so. 610 00:26:43,090 --> 00:26:45,120 Yes, let's do it. 611 00:26:45,120 --> 00:26:46,580 Let's define a list. 612 00:26:46,580 --> 00:26:49,682 Now, lists are defined this way, you put an open square bracket 613 00:26:49,682 --> 00:26:51,390 and I'm going to make a list of integers. 614 00:26:51,390 --> 00:26:54,464 Because I'm also going to use some tricks for direction 615 00:26:54,464 --> 00:26:56,630 because a lot of you are probably thinking, oh gosh, 616 00:26:56,630 --> 00:27:00,250 I noticed in the Java Docs that direction-- oh here, I'm 617 00:27:00,250 --> 00:27:03,160 going to go to Java Docs again-- direction is here 618 00:27:03,160 --> 00:27:05,190 and there's all these directions, 619 00:27:05,190 --> 00:27:06,885 east, north, northeast, blah. 620 00:27:06,885 --> 00:27:08,740 There are eight directions. 621 00:27:08,740 --> 00:27:10,730 I can rotate them left and right, 622 00:27:10,730 --> 00:27:13,350 but am I really going to enjoy rotating them again 623 00:27:13,350 --> 00:27:16,750 and again to find which direction I'm going to. 624 00:27:16,750 --> 00:27:20,010 OK, I could go forward, if forward is blocked, 625 00:27:20,010 --> 00:27:23,150 then rotate the direction left, if the left is blocked, 626 00:27:23,150 --> 00:27:25,220 then rotate-- no that would be actually really 627 00:27:25,220 --> 00:27:26,320 annoying to write. 628 00:27:26,320 --> 00:27:29,034 And it's not the most elegant way to do it. 629 00:27:29,034 --> 00:27:30,450 The way we're going to do is we're 630 00:27:30,450 --> 00:27:32,440 going to get the direction values 631 00:27:32,440 --> 00:27:35,790 and then we're going to use the direction list. 632 00:27:35,790 --> 00:27:38,809 So, the direction list consists of these eight things. 633 00:27:38,809 --> 00:27:40,350 I believe it starts at north and then 634 00:27:40,350 --> 00:27:43,200 it goes around to northwest. 635 00:27:43,200 --> 00:27:46,910 And so, direction list at 0 is north. 636 00:27:46,910 --> 00:27:49,360 And so, I'm going to show you how we're going to do that 637 00:27:49,360 --> 00:27:52,090 and what amazing result it has, because a lot of you 638 00:27:52,090 --> 00:27:53,510 already know how to code, but you 639 00:27:53,510 --> 00:27:55,220 don't know what amazing result it's going to have, 640 00:27:55,220 --> 00:27:56,090 or maybe you do. 641 00:27:56,090 --> 00:28:00,095 So, this integer I'm going to call the directionOffsets. 642 00:28:02,730 --> 00:28:05,540 And you can define an integer list 643 00:28:05,540 --> 00:28:08,350 by setting it equal to this construct. 644 00:28:08,350 --> 00:28:11,230 So, I'm just going to put curly brackets 645 00:28:11,230 --> 00:28:17,210 and now I'm going to do 0, 1, -1, 2, -2, yes. 646 00:28:17,210 --> 00:28:20,520 So, that now gets me some direction offsets 647 00:28:20,520 --> 00:28:23,090 and I need to start checking directions. 648 00:28:23,090 --> 00:28:32,590 So I'll use for integer d among the list directionOffsets. 649 00:28:32,590 --> 00:28:35,650 So now, this for loop will loop again and again 650 00:28:35,650 --> 00:28:40,380 and it'll put one of these integers in each time it runs. 651 00:28:40,380 --> 00:28:43,040 So, the first times it runs, d will be 0, 652 00:28:43,040 --> 00:28:46,370 the second time d will be 1, and so on. 653 00:28:46,370 --> 00:28:49,610 So this is for d in directionOffsets 654 00:28:49,610 --> 00:28:52,048 and there needs to be an s. 655 00:28:52,048 --> 00:28:55,350 And what I'll check is if I can move in that direction. 656 00:28:55,350 --> 00:28:56,980 So, let's go ahead and check that. 657 00:28:56,980 --> 00:28:59,347 Oh, by the way, let's simplify matters a little, 658 00:28:59,347 --> 00:29:01,180 because we've got is active here but there's 659 00:29:01,180 --> 00:29:03,840 no reason to look at directions if you're not active. 660 00:29:03,840 --> 00:29:07,274 So, let's go ahead and put this is active up here. 661 00:29:07,274 --> 00:29:09,690 Oh gosh, the guys of you who are following on your laptops 662 00:29:09,690 --> 00:29:12,750 must be just frantic at this point, 663 00:29:12,750 --> 00:29:14,890 yes, because it's like that, it's 664 00:29:14,890 --> 00:29:17,010 very emotional, very personal. 665 00:29:17,010 --> 00:29:19,920 So then, what we'll do is we'll check if you can move. 666 00:29:19,920 --> 00:29:22,190 If you can move-- Oh, but wait this isn't right, 667 00:29:22,190 --> 00:29:23,980 what direction is now important? 668 00:29:23,980 --> 00:29:26,965 Direction lookingatCurrently-- you 669 00:29:26,965 --> 00:29:29,550 can name these whatever you want-- the direction you're 670 00:29:29,550 --> 00:29:32,630 currently looking at is the following. 671 00:29:32,630 --> 00:29:35,350 First, you want to look at direction. 672 00:29:35,350 --> 00:29:39,930 And so, see dir up here is the direction to the rally point. 673 00:29:39,930 --> 00:29:43,410 So, we'll look at direction we'll say, OK, 674 00:29:43,410 --> 00:29:47,030 what is, oh, let's see here, ordinal? 675 00:29:47,030 --> 00:29:49,760 Ordinal gives me which number this 676 00:29:49,760 --> 00:29:51,870 is in the list of eight directions. 677 00:29:51,870 --> 00:29:55,831 So, if I'm currently looking at north, 678 00:29:55,831 --> 00:29:58,330 that is to say if the direction of the rally point is north, 679 00:29:58,330 --> 00:30:01,070 then dir.ordinal will return 0. 680 00:30:01,070 --> 00:30:06,420 Because the list of directions starts with north and in Java 681 00:30:06,420 --> 00:30:11,590 the index of a list starts at 0, so the first element is at 0. 682 00:30:11,590 --> 00:30:14,500 So dir.ordinal gets me 0. 683 00:30:14,500 --> 00:30:18,630 And then I'll add the direction offset number 684 00:30:18,630 --> 00:30:21,460 and now I will index into directions again. 685 00:30:21,460 --> 00:30:26,300 So, I'll say Direction.values is a list of directions. 686 00:30:26,300 --> 00:30:28,410 And the part of that that I take, 687 00:30:28,410 --> 00:30:33,150 indicated by the square brackets, will be dir.ordinal 688 00:30:33,150 --> 00:30:34,260 + d. 689 00:30:34,260 --> 00:30:36,630 I'll add 8 to make sure that's it's not negative, 690 00:30:36,630 --> 00:30:39,610 and then I'll do mod 8, the %8 is a mod 8. 691 00:30:39,610 --> 00:30:42,450 And you're going to find, this may be alien to you 692 00:30:42,450 --> 00:30:46,190 to begin with, but you'll find that this kind of construction 693 00:30:46,190 --> 00:30:47,280 helps you out immensely. 694 00:30:47,280 --> 00:30:49,760 So now, you're looking at a direction currently. 695 00:30:49,760 --> 00:30:52,060 If you can move in that direction, what you want to do 696 00:30:52,060 --> 00:30:54,280 is leave this loop. 697 00:30:54,280 --> 00:30:57,500 You don't want to stay in the loop anymore. 698 00:30:57,500 --> 00:31:00,080 It's giving me this, oh yes, semicolon? 699 00:31:00,080 --> 00:31:02,160 No, that's not right. 700 00:31:02,160 --> 00:31:03,700 Oh right, right, if I can move. 701 00:31:03,700 --> 00:31:05,470 I forgot to put if I can. 702 00:31:05,470 --> 00:31:09,590 Yeah, thank you for catching that me, yes. 703 00:31:09,590 --> 00:31:11,990 If I can move the direction I'm currently looking at I 704 00:31:11,990 --> 00:31:15,230 want to leave this loop, so I'm throwing a lot at you, 705 00:31:15,230 --> 00:31:17,290 but here you go. 706 00:31:17,290 --> 00:31:20,880 We'll name this thing the lookAround loop. 707 00:31:20,880 --> 00:31:25,370 And now, we can do break lookAround. 708 00:31:25,370 --> 00:31:30,650 And now, that will get us out of this piece. 709 00:31:30,650 --> 00:31:31,450 Yeah. 710 00:31:31,450 --> 00:31:33,200 Everybody likes to be splashed in. 711 00:31:33,200 --> 00:31:39,300 Nobody likes the first 27 pages of that intro to C++ book that 712 00:31:39,300 --> 00:31:42,140 talks about declaring variables and what the hell private 713 00:31:42,140 --> 00:31:43,020 static means. 714 00:31:43,020 --> 00:31:45,110 It doesn't matter what private static means, 715 00:31:45,110 --> 00:31:48,550 you don't need to know, you don't need to know. 716 00:31:48,550 --> 00:31:49,470 Don't you think? 717 00:31:49,470 --> 00:31:50,050 I hate that. 718 00:31:50,050 --> 00:31:52,650 I tried to learn languages so many times, 719 00:31:52,650 --> 00:31:55,180 here I'm thumping the desk. 720 00:31:55,180 --> 00:31:59,220 Anyway, I have nothing but animosity 721 00:31:59,220 --> 00:32:01,329 for their correct ways of doing things. 722 00:32:01,329 --> 00:32:03,495 That's why I don't study number theory, my goodness. 723 00:32:03,495 --> 00:32:04,195 AUDIENCE: Nonsense. 724 00:32:04,195 --> 00:32:05,653 PROFESSOR: Yeah, because they prove 725 00:32:05,653 --> 00:32:08,490 that addition works before they do any addition. 726 00:32:08,490 --> 00:32:10,930 I can't imagine how they get anything 727 00:32:10,930 --> 00:32:12,890 done under those circumstances. 728 00:32:12,890 --> 00:32:17,236 So, you can see here that nothing works at all. 729 00:32:17,236 --> 00:32:18,110 AUDIENCE: [LAUGHTER] 730 00:32:18,110 --> 00:32:21,760 PROFESSOR: Let's see, the robot is spawned, but it never moves. 731 00:32:21,760 --> 00:32:25,640 OK, so it can move, but it never actually did move. 732 00:32:25,640 --> 00:32:27,900 That's right, so what we need to do is make it move. 733 00:32:27,900 --> 00:32:31,630 So, within this loop, we've just exited the lookAround loop, 734 00:32:31,630 --> 00:32:32,810 that's this one. 735 00:32:32,810 --> 00:32:37,550 So, we're just going to put rc.move-- please move, 736 00:32:37,550 --> 00:32:41,210 please move-- atCurrently. 737 00:32:41,210 --> 00:32:48,030 Yes, when this guy moves-- Did I-- Oh, scope. 738 00:32:48,030 --> 00:32:49,330 Oh man, these guys are smart. 739 00:32:49,330 --> 00:32:53,500 So, you see here that this is inside this block 740 00:32:53,500 --> 00:32:55,080 so it can't be accessed from outside. 741 00:32:55,080 --> 00:32:59,870 So, what I'll do is I'll define it outside and I'll just equal, 742 00:32:59,870 --> 00:33:03,590 I'll pre-initialize it at dir and then when I use it in here 743 00:33:03,590 --> 00:33:05,270 it'll be accessible to that out there. 744 00:33:05,270 --> 00:33:07,120 Look, you think I made a mistake, 745 00:33:07,120 --> 00:33:09,630 but it was actually deliberate so that everybody 746 00:33:09,630 --> 00:33:13,390 would know about this scope problem, as you refer to it. 747 00:33:13,390 --> 00:33:18,190 Although, to be honest, Scope to me just means Listerine. 748 00:33:18,190 --> 00:33:21,520 All right, so now, what they're doing, it's hard to see, 749 00:33:21,520 --> 00:33:23,490 but they're moving around one another 750 00:33:23,490 --> 00:33:24,900 and they're oscillating. 751 00:33:24,900 --> 00:33:25,400 See that? 752 00:33:25,400 --> 00:33:27,030 Look at yellow. 753 00:33:27,030 --> 00:33:30,360 He's going around and that's because he's 754 00:33:30,360 --> 00:33:33,029 looking at the best direction that he can go in. 755 00:33:33,029 --> 00:33:34,070 Yeah, that's pretty cool. 756 00:33:34,070 --> 00:33:36,120 What is going on here? 757 00:33:36,120 --> 00:33:38,710 Cannot move in the given direction west, south, blah, 758 00:33:38,710 --> 00:33:39,550 blah, blah. 759 00:33:39,550 --> 00:33:42,180 Now why can't they move in that direction 760 00:33:42,180 --> 00:33:43,750 is an interesting question to ask. 761 00:33:43,750 --> 00:33:46,730 And it may be because some of them 762 00:33:46,730 --> 00:33:49,470 are entirely surrounded by other robots. 763 00:33:49,470 --> 00:33:52,744 This guy, for example, may end up 764 00:33:52,744 --> 00:33:54,410 being entirely surrounded by the robots. 765 00:33:54,410 --> 00:33:56,750 One of the problems that you will encounter 766 00:33:56,750 --> 00:34:00,690 is that every round robots move and they 767 00:34:00,690 --> 00:34:03,020 don't move synchronously. 768 00:34:03,020 --> 00:34:05,310 So it'll be really instructive, if I 769 00:34:05,310 --> 00:34:07,890 had the time I would show you that the number 770 00:34:07,890 --> 00:34:11,270 of adjacent robots is not the number that you might expect. 771 00:34:11,270 --> 00:34:13,855 Because, for example, let's say this guy 772 00:34:13,855 --> 00:34:14,980 wants to move to the right. 773 00:34:14,980 --> 00:34:17,070 Let's just say he does. 774 00:34:17,070 --> 00:34:18,880 He can't move to the right this turn 775 00:34:18,880 --> 00:34:21,894 if he executes before this guy. 776 00:34:21,894 --> 00:34:23,810 Let's say they both want to move to the right. 777 00:34:23,810 --> 00:34:25,960 But if this guy executes first then 778 00:34:25,960 --> 00:34:28,120 he'll move to the right, that'll take place, 779 00:34:28,120 --> 00:34:30,199 and then when this guy looks surround himself 780 00:34:30,199 --> 00:34:32,239 he's going to see an empty spot there. 781 00:34:32,239 --> 00:34:36,130 It can be very confusing for debugging. 782 00:34:36,130 --> 00:34:39,210 So, that's going to happen. 783 00:34:39,210 --> 00:34:41,810 And you might ask, OK, OK, I recognize that nothing 784 00:34:41,810 --> 00:34:44,550 can run synchronously because then two robots can try 785 00:34:44,550 --> 00:34:47,980 to move onto the same tile and who knows what would happen. 786 00:34:47,980 --> 00:34:51,000 It could be like Pauli Exclusion Principle is violated, 787 00:34:51,000 --> 00:34:53,500 two electrons occupy the same orbital 788 00:34:53,500 --> 00:34:58,140 and the world comes to an end, a screeching halt, as it were. 789 00:34:58,140 --> 00:34:59,200 So, here's how we do it. 790 00:34:59,200 --> 00:35:00,400 We use the robot ID. 791 00:35:00,400 --> 00:35:03,040 Now this is going to come back later, so don't think that it's 792 00:35:03,040 --> 00:35:05,040 just an obscure little thing, this is important. 793 00:35:05,040 --> 00:35:06,900 So, you can see here that when I click on a robot 794 00:35:06,900 --> 00:35:08,630 it tells me-- Oh, is this bothering you? 795 00:35:08,630 --> 00:35:10,100 I can tell it's bothering half of you. 796 00:35:10,100 --> 00:35:11,599 You've got like a twitch developing, 797 00:35:11,599 --> 00:35:14,350 you're starting to shake, the sweats are coming out. 798 00:35:14,350 --> 00:35:16,780 No sorry, that's me. 799 00:35:16,780 --> 00:35:18,990 So, the robot, you can see here, this 800 00:35:18,990 --> 00:35:20,860 is robot 38, the headquarters. 801 00:35:20,860 --> 00:35:24,740 This is robot 115, the lower the robot number, the sooner it 802 00:35:24,740 --> 00:35:26,830 executes, because they execute in that order. 803 00:35:26,830 --> 00:35:29,710 And I think when a robot dies it's number becomes available 804 00:35:29,710 --> 00:35:31,675 and another one can spawn into that number, 805 00:35:31,675 --> 00:35:32,800 in case you wanted to know. 806 00:35:32,800 --> 00:35:34,130 That's all too nitty gritty. 807 00:35:34,130 --> 00:35:35,620 So anyway, there we've got it. 808 00:35:35,620 --> 00:35:39,170 Let's start owning some noobs as it were. 809 00:35:39,170 --> 00:35:41,150 Let's destroy the enemy. 810 00:35:41,150 --> 00:35:45,460 It's not going to be as exciting if we're all the same person. 811 00:35:45,460 --> 00:35:48,810 So, let's make sure that we know who we are. 812 00:35:48,810 --> 00:35:51,900 Now, one problem here is that this only goes to rallyPoint. 813 00:35:51,900 --> 00:35:55,000 Let's put in an argument to soldierCode and change 814 00:35:55,000 --> 00:35:56,520 the name so it's more reasonable. 815 00:35:56,520 --> 00:35:59,440 So, that it's goToLocation. 816 00:35:59,440 --> 00:36:01,060 That's kind of nice. 817 00:36:01,060 --> 00:36:05,570 And we'll give it MapLocation whereToGo. 818 00:36:05,570 --> 00:36:09,920 Yeah, now we'll just put this in here 819 00:36:09,920 --> 00:36:12,720 and now this goToLocation function can be reused. 820 00:36:12,720 --> 00:36:16,340 So first, we'll just goToLocation rallyPoint 821 00:36:16,340 --> 00:36:18,880 and then after a certain number of turns maybe 822 00:36:18,880 --> 00:36:20,466 then we'll just go to the enemy base. 823 00:36:20,466 --> 00:36:22,340 Because we'll have all these clumped up guys, 824 00:36:22,340 --> 00:36:25,030 we'll be ready to own some noobs. 825 00:36:25,030 --> 00:36:26,640 So let's do that. 826 00:36:26,640 --> 00:36:30,150 Let's go to the enemy base, let's kill them dead. 827 00:36:30,150 --> 00:36:33,300 So let's say here, how are we going 828 00:36:33,300 --> 00:36:35,070 to figure out what round it is? 829 00:36:35,070 --> 00:36:38,904 This is sort of an obscure function, Clock.getRoundNum. 830 00:36:38,904 --> 00:36:40,320 I don't think that there's really, 831 00:36:40,320 --> 00:36:43,500 is there anything else under clock that's worth looking at? 832 00:36:43,500 --> 00:36:46,414 Clock, get bytecode number, oh, you 833 00:36:46,414 --> 00:36:48,330 can get the number of bytecodes you have left, 834 00:36:48,330 --> 00:36:49,530 that's pretty useful. 835 00:36:49,530 --> 00:36:51,980 So you can say, oh, is it worth doing this computation, 836 00:36:51,980 --> 00:36:55,600 I don't know if I need that many extra digits of pi. 837 00:36:55,600 --> 00:37:00,010 So here, if my clock, which returns an integer, 838 00:37:00,010 --> 00:37:04,610 if that clock number is less than 500, 839 00:37:04,610 --> 00:37:08,270 yeah maybe, let's just make it 200, we don't have all day. 840 00:37:08,270 --> 00:37:09,470 Yeah, we'll make it 200. 841 00:37:09,470 --> 00:37:11,950 If it's less than 200, then go to the rallyPoint. 842 00:37:11,950 --> 00:37:17,820 If it is more than 200, or equal to 200, 843 00:37:17,820 --> 00:37:24,060 let's go to rc.senseEnemy-- Yeah, let's go to the enemy, 844 00:37:24,060 --> 00:37:25,650 let's just go ahead and kill them. 845 00:37:25,650 --> 00:37:28,200 So now, we've got these two pieces in here. 846 00:37:28,200 --> 00:37:31,500 We're going to take our Awesome Robot player. 847 00:37:31,500 --> 00:37:33,700 We're going to play against Hardbot. 848 00:37:33,700 --> 00:37:37,470 Yeah, a bot that's supposed to be hard on my map tiny. 849 00:37:37,470 --> 00:37:38,382 Yeah. 850 00:37:38,382 --> 00:37:40,840 Cannot move and get-- Well, let's just hope that that's not 851 00:37:40,840 --> 00:37:41,756 going to be a problem. 852 00:37:41,756 --> 00:37:43,560 OK, so I'm getting ready, getting ready, 853 00:37:43,560 --> 00:37:44,560 get ready for the blitz. 854 00:37:44,560 --> 00:37:48,860 It's round, it's round 150, it's round 150, go, go, yeah. 855 00:37:48,860 --> 00:37:51,120 AUDIENCE: [LAUGHTER] 856 00:37:51,120 --> 00:37:54,560 PROFESSOR: Yes, knocking them out. 857 00:37:54,560 --> 00:37:55,850 Wa-bam. 858 00:37:55,850 --> 00:37:57,220 Wa-bam. 859 00:37:57,220 --> 00:38:00,200 One thing that's important is you've 860 00:38:00,200 --> 00:38:03,450 got give yourself a little pat on the back from time to time. 861 00:38:03,450 --> 00:38:07,974 That's what teammates are for, to pat each other on the back. 862 00:38:07,974 --> 00:38:09,390 My brother always used to do that. 863 00:38:09,390 --> 00:38:12,010 He'd give me a giant five star, when you slap someone 864 00:38:12,010 --> 00:38:15,250 so hard on the back that it leaves a handprint. 865 00:38:15,250 --> 00:38:18,227 Yeah, but that let me know that he cared, that was important. 866 00:38:18,227 --> 00:38:19,184 AUDIENCE: [LAUGHTER] 867 00:38:19,184 --> 00:38:20,850 PROFESSOR: I think every younger brother 868 00:38:20,850 --> 00:38:23,490 needs that and if you're the oldest brother in your family 869 00:38:23,490 --> 00:38:27,510 then just hit the guy twice as hard. 870 00:38:27,510 --> 00:38:29,520 So yeah, you see here that that worked. 871 00:38:29,520 --> 00:38:32,400 I might just go ahead and send myself an email saying Max, 872 00:38:32,400 --> 00:38:35,290 you sly dog, you made a player that beats the hard bot. 873 00:38:35,290 --> 00:38:37,540 I mean, the hard bot's not actually very hard. 874 00:38:37,540 --> 00:38:39,742 All right, all right, so we've got that. 875 00:38:39,742 --> 00:38:44,080 That was good, that was good, but maybe what we'd rather do 876 00:38:44,080 --> 00:38:48,690 is be more hunter like about, we'll be stealthy. 877 00:38:48,690 --> 00:38:50,530 What I think will be really cool is 878 00:38:50,530 --> 00:38:52,860 to go after the closest enemy unit. 879 00:38:52,860 --> 00:38:55,880 Now, you'll find in the documentation 880 00:38:55,880 --> 00:38:58,230 a lot of ways of getting enemy data. 881 00:38:58,230 --> 00:39:00,230 You can sense where their encampments are and go 882 00:39:00,230 --> 00:39:03,740 after those, you can sense where your mines are, 883 00:39:03,740 --> 00:39:05,480 you can sense where its headquarters are, 884 00:39:05,480 --> 00:39:08,430 you can sense where the enemy robots are. 885 00:39:08,430 --> 00:39:11,570 And you'll probably find yourself, at some point, 886 00:39:11,570 --> 00:39:13,900 going through a list and trying to find the closest 887 00:39:13,900 --> 00:39:16,460 enemy, or maybe the closest allied unit. 888 00:39:16,460 --> 00:39:18,580 So, we're going to do an example of that. 889 00:39:18,580 --> 00:39:20,490 And what we're going to use it for is-- 890 00:39:20,490 --> 00:39:23,520 See, for example, this case where they're trying to build 891 00:39:23,520 --> 00:39:26,030 this encampment and they're shooting at all of our dudes, 892 00:39:26,030 --> 00:39:29,220 and our dudes are just, they're getting hurt. 893 00:39:29,220 --> 00:39:31,814 They should just go gang up on that guy. 894 00:39:31,814 --> 00:39:33,230 Why aren't they ganging up on him? 895 00:39:33,230 --> 00:39:37,160 So, let's make a function for ganging up on the enemy. 896 00:39:37,160 --> 00:39:39,816 And it'll require that we locate the closest enemy. 897 00:39:39,816 --> 00:39:41,190 I mean, we could probably just go 898 00:39:41,190 --> 00:39:43,890 to the first one that's in the list. 899 00:39:43,890 --> 00:39:45,980 So, I don't know which one should we do? 900 00:39:45,980 --> 00:39:49,060 In fact, how about this, we could, 901 00:39:49,060 --> 00:39:52,230 we could make code-- Yeah, let's try this. 902 00:39:52,230 --> 00:39:53,230 OK, this is interesting. 903 00:39:53,230 --> 00:39:57,520 I don't always plan, but when I do I drink-- No, nevermind, 904 00:39:57,520 --> 00:39:59,370 that doesn't work. 905 00:39:59,370 --> 00:40:01,547 So, let's see if you can copy a package 906 00:40:01,547 --> 00:40:03,380 and then we'll be able to play Awesome Robot 907 00:40:03,380 --> 00:40:05,940 player against Awesomer Robot player. 908 00:40:05,940 --> 00:40:07,110 Yeah, paste. 909 00:40:07,110 --> 00:40:08,470 OK, enter a new name. 910 00:40:08,470 --> 00:40:10,000 Oh, that was helpful. 911 00:40:10,000 --> 00:40:12,930 I mean, it's not very smart, AwesomeRobotplayer.copy? 912 00:40:12,930 --> 00:40:14,480 No, it's Awesomer. 913 00:40:14,480 --> 00:40:15,200 Yeah. 914 00:40:15,200 --> 00:40:17,060 Look at that, and it even changed it for me. 915 00:40:17,060 --> 00:40:18,410 I tell you, I'm going to be out of a job 916 00:40:18,410 --> 00:40:19,710 before the end of the week. 917 00:40:19,710 --> 00:40:23,350 So, what we want to do now, in the remaining moments 918 00:40:23,350 --> 00:40:27,210 of lecture, is we want to find the closest enemy robot. 919 00:40:27,210 --> 00:40:29,590 Now, it may be that there are no enemy robots. 920 00:40:29,590 --> 00:40:31,709 This is the thing that I was talking about before. 921 00:40:31,709 --> 00:40:32,750 Let's do it, let's do it. 922 00:40:32,750 --> 00:40:33,520 OK, try. 923 00:40:33,520 --> 00:40:34,561 So here, I'm a soldier. 924 00:40:34,561 --> 00:40:36,560 OK, I don't need to do it if I'm a headquarters. 925 00:40:36,560 --> 00:40:38,143 So, let's just do it if I'm a soldier. 926 00:40:38,143 --> 00:40:40,450 We'll say MapLocation of the enemy robot 927 00:40:40,450 --> 00:40:43,430 because, after all, all we currently do is go to places, 928 00:40:43,430 --> 00:40:45,530 we go there and it's implied that we 929 00:40:45,530 --> 00:40:47,430 kill all the things that we find. 930 00:40:47,430 --> 00:40:52,060 Yes, so the map location of the closest enemy. 931 00:40:52,060 --> 00:40:52,950 Now, let's see here. 932 00:40:52,950 --> 00:40:55,200 This is only going to be valid when there are enemies. 933 00:40:55,200 --> 00:40:56,750 You've got to think about this. 934 00:40:56,750 --> 00:40:59,790 So let's instead do, let's get all the enemy robots. 935 00:40:59,790 --> 00:41:03,030 So, this is a robot list, a list of enemy robots, 936 00:41:03,030 --> 00:41:04,739 we'll call it enemyRobots, if we like. 937 00:41:04,739 --> 00:41:06,030 Doesn't matter what we call it. 938 00:41:06,030 --> 00:41:11,330 And we'll go rc.sense-- now this is the hardest 939 00:41:11,330 --> 00:41:13,936 thing to remember, this is the hardest ever possible thing 940 00:41:13,936 --> 00:41:15,907 to remember-- senseNearbyGameObjects. 941 00:41:15,907 --> 00:41:16,740 AUDIENCE: [LAUGHTER] 942 00:41:16,740 --> 00:41:20,940 PROFESSOR: It's hard to remember because it's so accurate. 943 00:41:20,940 --> 00:41:26,640 Robot.class, so we want robots, we want them anywhere. 944 00:41:26,640 --> 00:41:29,090 This is the range, the squared range 945 00:41:29,090 --> 00:41:31,630 that we're interested in picking up enemies. 946 00:41:31,630 --> 00:41:34,110 Now note, they won't show up unless they 947 00:41:34,110 --> 00:41:36,620 are within one of my allied units' sight range. 948 00:41:36,620 --> 00:41:39,130 I put in this huge number just because I'm 949 00:41:39,130 --> 00:41:42,330 willing to take those. 950 00:41:42,330 --> 00:41:44,670 I put in a million and then I'm going to make sure that 951 00:41:44,670 --> 00:41:49,510 they're enemy by doing rc.getTeam, so that's my team, 952 00:41:49,510 --> 00:41:53,570 and .opponent is a team method that gets me the opposing team. 953 00:41:53,570 --> 00:41:56,260 Now the two teams are Team A and Team B. 954 00:41:56,260 --> 00:41:59,450 So, that's literally written out as Team.A. 955 00:41:59,450 --> 00:42:03,150 So I could have written Team.A or Team.B, 956 00:42:03,150 --> 00:42:05,570 but then I would have had to check if I was Team A or Team 957 00:42:05,570 --> 00:42:07,530 B. So, you're better off doing it this way. 958 00:42:07,530 --> 00:42:09,500 So, I'm sensing the nearby game objects. 959 00:42:09,500 --> 00:42:12,860 Now, I need to know if that gave me any game objects. 960 00:42:12,860 --> 00:42:14,750 So, I don't know how big this list is. 961 00:42:14,750 --> 00:42:24,640 If the list has a length, if enemyRobots.length = 0, well, 962 00:42:24,640 --> 00:42:26,480 then there are no enemy robots. 963 00:42:26,480 --> 00:42:28,970 So, I should just do the same thing I was doing before. 964 00:42:28,970 --> 00:42:30,570 So, there you go. 965 00:42:30,570 --> 00:42:33,100 Now, we've got code that should be working. 966 00:42:33,100 --> 00:42:35,590 But, if there are robots-- Now, what have I done here? 967 00:42:35,590 --> 00:42:37,750 I haven't commented a single line of code. 968 00:42:37,750 --> 00:42:42,100 OK, enemies, no enemies nearby. 969 00:42:42,100 --> 00:42:42,820 Yeah. 970 00:42:42,820 --> 00:42:44,820 I heard somebody tell a real zinger over there. 971 00:42:44,820 --> 00:42:46,460 No, I'm just kidding. 972 00:42:46,460 --> 00:42:50,160 So, no enemies-- OK, someone spotted. 973 00:42:50,160 --> 00:42:52,060 OK, enemy is spotted. 974 00:42:52,060 --> 00:42:54,760 So, yeah, no that's not right, I put this in the wrong spot. 975 00:42:54,760 --> 00:42:57,180 You guys are not helping me, not helping 976 00:42:57,180 --> 00:42:59,030 me nearly as much as I was expecting. 977 00:42:59,030 --> 00:43:00,516 So, now what I'll do is I'll loop 978 00:43:00,516 --> 00:43:01,640 through each of the robots. 979 00:43:01,640 --> 00:43:03,360 Now, I could do the same looping thing 980 00:43:03,360 --> 00:43:05,490 that I did before, where I could say, 981 00:43:05,490 --> 00:43:10,000 Robot arobot among enemyRobots. 982 00:43:10,000 --> 00:43:11,985 And then, it would put arobot into each one, 983 00:43:11,985 --> 00:43:14,110 but instead I'm going to do it a different way just 984 00:43:14,110 --> 00:43:15,140 to demonstrate it. 985 00:43:15,140 --> 00:43:18,670 I'm going to define an integer i = 0. 986 00:43:18,670 --> 00:43:20,830 And then, there you go. 987 00:43:20,830 --> 00:43:22,910 Oh, thank you, I saw you we're going to help me 988 00:43:22,910 --> 00:43:24,460 and I really appreciate it. 989 00:43:24,460 --> 00:43:26,450 And we'll make sure that i-- And so, this 990 00:43:26,450 --> 00:43:29,735 is the format for a loop that goes with this type. 991 00:43:29,735 --> 00:43:31,360 Some of you are going to be like that's 992 00:43:31,360 --> 00:43:34,800 not the way that the words work that make it explained. 993 00:43:34,800 --> 00:43:37,490 And I'll tell you that you are right 994 00:43:37,490 --> 00:43:41,980 and you get a gold medal, as soon as we mint them. 995 00:43:41,980 --> 00:43:46,095 So yeah, enemyRobots.length and we'll do i++. 996 00:43:46,095 --> 00:43:48,950 So this'll make, i will go up by one every turn. 997 00:43:48,950 --> 00:43:54,600 So now, I can type Robot arobot, it's an enemy robot, 998 00:43:54,600 --> 00:43:59,820 = enemyRobots at i. 999 00:43:59,820 --> 00:44:02,150 And now, I'm going to look through and find the closest 1000 00:44:02,150 --> 00:44:02,560 one. 1001 00:44:02,560 --> 00:44:04,490 Now, I'm sure somebody's going to show me a way that I'm 1002 00:44:04,490 --> 00:44:06,573 doing it wrong, but here's how I'm going to do it. 1003 00:44:06,573 --> 00:44:09,440 I'm going to keep track of which one was closest 1004 00:44:09,440 --> 00:44:10,590 and how close it was. 1005 00:44:10,590 --> 00:44:12,560 So int closestDist, and I'm going 1006 00:44:12,560 --> 00:44:14,500 to initialize it at a large number. 1007 00:44:14,500 --> 00:44:18,540 And I'm going to make it a location. 1008 00:44:18,540 --> 00:44:22,950 And I'll do MapLocation closestEnemy. 1009 00:44:22,950 --> 00:44:24,800 Yeah, closestEnemy. 1010 00:44:24,800 --> 00:44:29,910 OK, so now, we'll have-- Now this is very tricky. 1011 00:44:29,910 --> 00:44:33,320 This little bit of sequence is very tricky in the Battlecode 1012 00:44:33,320 --> 00:44:33,986 API. 1013 00:44:33,986 --> 00:44:35,360 When I first did Battlecode, they 1014 00:44:35,360 --> 00:44:37,930 didn't give an example of this and it took me 10 years 1015 00:44:37,930 --> 00:44:38,730 to figure it out. 1016 00:44:38,730 --> 00:44:41,050 This is how to find out where an enemy is. 1017 00:44:41,050 --> 00:44:43,220 You type rc, that's like you're starting 1018 00:44:43,220 --> 00:44:47,580 from you, senseRobotInfo. 1019 00:44:47,580 --> 00:44:52,410 All right, and then you pass it the robot. 1020 00:44:52,410 --> 00:44:55,066 You tell it to sense the robot info. 1021 00:44:55,066 --> 00:44:56,190 Now what does that get you? 1022 00:44:56,190 --> 00:44:57,740 Does that get you the location? 1023 00:44:57,740 --> 00:44:59,280 No, that would be too easy. , So, 1024 00:44:59,280 --> 00:45:02,200 that gets you a robot info object. 1025 00:45:02,200 --> 00:45:08,660 So, now you've got RobotInfo arobotInfo = that. 1026 00:45:08,660 --> 00:45:10,360 So now, I've got some robot info. 1027 00:45:10,360 --> 00:45:13,760 Robot Info is yet another one of these classes. 1028 00:45:13,760 --> 00:45:15,300 So here in the Java docs. 1029 00:45:15,300 --> 00:45:17,700 Look at this, I keep opening more and more of them. 1030 00:45:17,700 --> 00:45:18,890 That's another one, there's another one, 1031 00:45:18,890 --> 00:45:19,460 they're multiplying. 1032 00:45:19,460 --> 00:45:20,530 AUDIENCE: [LAUGHTER] 1033 00:45:20,530 --> 00:45:24,610 PROFESSOR: So here, you could see Robot Info, there it was. 1034 00:45:24,610 --> 00:45:27,070 So, you can see that information about the enemy robots 1035 00:45:27,070 --> 00:45:29,195 can be things like the amount of shields they have, 1036 00:45:29,195 --> 00:45:32,440 the type of robot, its location. 1037 00:45:32,440 --> 00:45:34,730 One of the Robot Info things is Robot. 1038 00:45:34,730 --> 00:45:36,810 So, what you can do is you can sense the robot, 1039 00:45:36,810 --> 00:45:39,380 you can get the robot, sense its info, 1040 00:45:39,380 --> 00:45:42,810 and then do info.Robot, and then sense that things info, 1041 00:45:42,810 --> 00:45:44,107 and then you'll have the info. 1042 00:45:44,107 --> 00:45:45,690 So, you go back to the robot and it'll 1043 00:45:45,690 --> 00:45:46,898 be a really nice little loop. 1044 00:45:46,898 --> 00:45:49,120 It's wonderful, it's just, [KISSING SOUND] mmm, just 1045 00:45:49,120 --> 00:45:50,520 great. 1046 00:45:50,520 --> 00:45:53,210 I highly recommend that kind of code. 1047 00:45:53,210 --> 00:45:55,900 It just warms my heart. 1048 00:45:55,900 --> 00:46:01,580 So, like what a little kid does, is that computationally 1049 00:46:01,580 --> 00:46:02,080 impressive? 1050 00:46:02,080 --> 00:46:04,380 No, but it's cute, so it warms it anyway. 1051 00:46:04,380 --> 00:46:07,140 So, that was the reasoning behind that crazy stream 1052 00:46:07,140 --> 00:46:07,670 of logic. 1053 00:46:07,670 --> 00:46:09,281 So, here we go, we got Robot Info. 1054 00:46:09,281 --> 00:46:11,280 Let's check the distance, we'll be done with it. 1055 00:46:11,280 --> 00:46:14,180 So we'll say that the distance, which is an integer, 1056 00:46:14,180 --> 00:46:16,180 equals arobotInfo.location.distanceSquaredTo. 1057 00:46:21,374 --> 00:46:23,790 Of course, you can write your own distanceSquaredTo metric 1058 00:46:23,790 --> 00:46:26,373 or something or other, but we're just going to do it this way. 1059 00:46:26,373 --> 00:46:28,430 And we're going to make it the distance from, 1060 00:46:28,430 --> 00:46:31,470 I guess, it could be myself, as the robot. 1061 00:46:31,470 --> 00:46:35,640 So, distanceSquaredTo, hmm, it's sort of hard to decide. 1062 00:46:35,640 --> 00:46:37,990 It could be the one that's closest to me, 1063 00:46:37,990 --> 00:46:41,090 or let's just do me for the moment. 1064 00:46:41,090 --> 00:46:42,910 Maybe later we'll make it more complicated. 1065 00:46:42,910 --> 00:46:43,914 Actually, we're going to run out of time 1066 00:46:43,914 --> 00:46:45,230 and we're just going to end up eating Indian food. 1067 00:46:45,230 --> 00:46:46,850 But that's wonderful. 1068 00:46:46,850 --> 00:46:49,090 How many of you have eaten at India Samraat? 1069 00:46:49,090 --> 00:46:51,030 That place is fantastic. 1070 00:46:51,030 --> 00:46:53,880 Wow, oh my goodness, you're in for such a treat. 1071 00:46:53,880 --> 00:46:56,180 I don't know if it's going to be considered 1072 00:46:56,180 --> 00:46:57,860 the same level of treat as-- Oh anway, 1073 00:46:57,860 --> 00:46:59,110 I'm just going on and on. 1074 00:46:59,110 --> 00:47:03,190 So if the distance that we're currently looking at is less 1075 00:47:03,190 --> 00:47:07,690 than the closestDist, then we'll say that is the new 1076 00:47:07,690 --> 00:47:12,690 closestDist, and we will assign closestEnemy=. 1077 00:47:20,360 --> 00:47:22,297 Well, I didn't record it anywhere. 1078 00:47:22,297 --> 00:47:22,880 It's this one. 1079 00:47:26,260 --> 00:47:27,809 Yes, so there it is. 1080 00:47:27,809 --> 00:47:28,850 That's the closest enemy. 1081 00:47:28,850 --> 00:47:31,041 So, once again, if there were no enemies 1082 00:47:31,041 --> 00:47:33,540 nearby we would either go to the rallyPoint or goToLocation. 1083 00:47:36,130 --> 00:47:38,460 But now, what we want to do-- Oh, goodness, 1084 00:47:38,460 --> 00:47:42,080 hey quit sending me things on the-- Anyway. 1085 00:47:42,080 --> 00:47:44,756 So now, what we'll do is we'll just go straight to the enemy. 1086 00:47:44,756 --> 00:47:45,630 That's what we'll do. 1087 00:47:45,630 --> 00:47:47,780 If we see one, we'll go kill them. 1088 00:47:47,780 --> 00:47:50,430 So now, what we'll do is we'll pit this code 1089 00:47:50,430 --> 00:47:52,650 against the previous version of this code 1090 00:47:52,650 --> 00:47:53,950 and we'll see which one wins. 1091 00:47:53,950 --> 00:47:56,100 It's an interesting question. 1092 00:47:56,100 --> 00:47:59,220 Which code is better, to go straight for the enemy base, 1093 00:47:59,220 --> 00:48:01,300 or to go for the closest enemy robot? 1094 00:48:01,300 --> 00:48:03,020 Because maybe on their way to the base, 1095 00:48:03,020 --> 00:48:05,317 I mean everybody shoots on the way to everywhere, 1096 00:48:05,317 --> 00:48:06,400 but what's the best thing? 1097 00:48:06,400 --> 00:48:08,230 I'm think it'll be quite interesting. 1098 00:48:08,230 --> 00:48:09,580 So let's see, where do we shoot? 1099 00:48:09,580 --> 00:48:10,080 It's here. 1100 00:48:10,080 --> 00:48:11,880 So, now we can go to the location. 1101 00:48:11,880 --> 00:48:13,900 And we can go to the closest enemy. 1102 00:48:13,900 --> 00:48:18,490 Yeah, because there's guaranteed to be an enemy to go to. 1103 00:48:18,490 --> 00:48:19,220 Oh bother. 1104 00:48:19,220 --> 00:48:20,595 It's another one of these things. 1105 00:48:20,595 --> 00:48:22,800 No, wait that's there, goToLocation, closestEnemy. 1106 00:48:22,800 --> 00:48:24,300 Oh, right I've got to initialize it. 1107 00:48:24,300 --> 00:48:25,590 Yes, so I put null. 1108 00:48:25,590 --> 00:48:28,270 It'll never see null, but I've got to put it there anyway 1109 00:48:28,270 --> 00:48:29,740 so that it's comforted. 1110 00:48:29,740 --> 00:48:32,100 I believe that's the technical explanation for what's 1111 00:48:32,100 --> 00:48:36,370 going on in the background of Eclipse. 1112 00:48:36,370 --> 00:48:37,710 I'm pretty sure. 1113 00:48:37,710 --> 00:48:38,670 So now let's run. 1114 00:48:38,670 --> 00:48:40,960 Oh man, this is getting exciting, it's 5:55. 1115 00:48:40,960 --> 00:48:44,170 I guess I'll have some closing remarks. 1116 00:48:44,170 --> 00:48:46,390 But this'll be the thing that is supposed 1117 00:48:46,390 --> 00:48:47,770 to be exciting and amazing. 1118 00:48:47,770 --> 00:48:49,930 We'll have awesome versus awesomer. 1119 00:48:49,930 --> 00:48:55,600 All right, these guys are so, they have a lot of fun. 1120 00:48:55,600 --> 00:48:56,570 That's so important. 1121 00:48:56,570 --> 00:48:58,210 I didn't say that again. 1122 00:48:58,210 --> 00:49:01,420 All right so, raise your hand if you think that Awesome Robot 1123 00:49:01,420 --> 00:49:05,510 player, the original awesome is going to win. 1124 00:49:05,510 --> 00:49:06,800 Three hands. 1125 00:49:06,800 --> 00:49:11,000 How many people think that Awesomer Robot is going to win? 1126 00:49:11,000 --> 00:49:13,600 Four hands. 1127 00:49:13,600 --> 00:49:16,960 OK, well, I recognize that premature arthritis 1128 00:49:16,960 --> 00:49:18,580 can be caused by coding. 1129 00:49:18,580 --> 00:49:21,230 Raising an arm may be beyond some of us, 1130 00:49:21,230 --> 00:49:25,300 in terms of, oh, ohh. 1131 00:49:25,300 --> 00:49:26,850 OK, we're going to find out. 1132 00:49:26,850 --> 00:49:28,920 OK, I actually don't know the answer. 1133 00:49:28,920 --> 00:49:31,590 OK, so they're just grouping. 1134 00:49:31,590 --> 00:49:34,130 It's round 70, round 80, it's round 100. 1135 00:49:34,130 --> 00:49:36,239 At round 200, exciting stuff's going to happen. 1136 00:49:36,239 --> 00:49:37,530 I wish we could slow this down. 1137 00:49:37,530 --> 00:49:38,905 It's going to happen all at once. 1138 00:49:38,905 --> 00:49:39,500 Boom. 1139 00:49:39,500 --> 00:49:40,880 Ah. 1140 00:49:40,880 --> 00:49:42,550 Oh, but they stopped them. 1141 00:49:42,550 --> 00:49:44,420 They stopped them. 1142 00:49:44,420 --> 00:49:47,500 The Awesomer player has won, hurray. 1143 00:49:47,500 --> 00:49:48,570 Did you see that? 1144 00:49:48,570 --> 00:49:50,360 It was all too fast. 1145 00:49:50,360 --> 00:49:53,420 It just went by before, I mean before I even noticed it was, 1146 00:49:53,420 --> 00:49:55,140 ah goodness gracious. 1147 00:49:55,140 --> 00:49:56,510 So, here it goes. 1148 00:49:56,510 --> 00:49:58,400 These guys will run back to the base, 1149 00:49:58,400 --> 00:50:00,970 but these guys will be following them the whole way through. 1150 00:50:00,970 --> 00:50:03,260 OK, so let's back it up a little bit. 1151 00:50:03,260 --> 00:50:04,495 This is interesting. 1152 00:50:04,495 --> 00:50:08,490 Now, I think if you push like f, or b, or c, 1153 00:50:08,490 --> 00:50:11,480 you can turn off the circles, maybe not. 1154 00:50:11,480 --> 00:50:15,440 OK, so they're forming a concave. 1155 00:50:15,440 --> 00:50:17,334 Oh man, a lot of them are blowing up. 1156 00:50:17,334 --> 00:50:18,750 It's hard to tell what's going on. 1157 00:50:18,750 --> 00:50:21,774 OK, so here it looks pretty darn even, 1,2,3, 4,5,6, 1158 00:50:21,774 --> 00:50:27,510 7,8,9 versus 1, I can't tell if he's dying, 1159 00:50:27,510 --> 00:50:30,650 2,3,4, 5,6,7, 8,9,10. 1160 00:50:30,650 --> 00:50:32,390 OK, so it's 10 versus 9. 1161 00:50:32,390 --> 00:50:35,205 The blue guys have done well, pretty well already. 1162 00:50:35,205 --> 00:50:37,470 Oh, but then they just ping, they just 1163 00:50:37,470 --> 00:50:39,190 ping and turn around and kill everything. 1164 00:50:39,190 --> 00:50:41,280 I've got to step forward more slowly. 1165 00:50:41,280 --> 00:50:43,635 This is a fast-paced game, let me tell you. 1166 00:50:43,635 --> 00:50:45,010 Let me tell you, you're not going 1167 00:50:45,010 --> 00:50:47,440 to be here for an hour watching somebody-- 1168 00:50:47,440 --> 00:50:47,940 Oh man. 1169 00:50:47,940 --> 00:50:50,060 OK, so these guys are all working over there. 1170 00:50:50,060 --> 00:50:51,180 Oh, look at that. 1171 00:50:51,180 --> 00:50:53,870 Meanwhile, these guys are ganging up 1172 00:50:53,870 --> 00:50:58,310 on him and these three guys are getting totally double-teamed, 1173 00:50:58,310 --> 00:51:00,950 or quadruple-teamed, or whatever the word is, by these fellows. 1174 00:51:00,950 --> 00:51:04,351 Oh, I'm pointing with my finger, how can you see that? 1175 00:51:04,351 --> 00:51:05,915 AUDIENCE: [LAUGHTER] 1176 00:51:05,915 --> 00:51:07,040 PROFESSOR: Oh, my goodness. 1177 00:51:10,000 --> 00:51:12,567 Look I'm enjoying myself OK. 1178 00:51:12,567 --> 00:51:14,900 Yeah, and then they turn around and they kill the enemy, 1179 00:51:14,900 --> 00:51:17,191 and then they turn around and they kill the enemy base. 1180 00:51:17,191 --> 00:51:18,980 There you have it, boom, done. 1181 00:51:18,980 --> 00:51:21,470 All right so, final closing remarks. 1182 00:51:25,740 --> 00:51:28,120 I'm looking at the wrong page. 1183 00:51:28,120 --> 00:51:32,250 Yeah, so improvements to this robot, 1184 00:51:32,250 --> 00:51:35,280 there's lots of things that you could do, that you would do, 1185 00:51:35,280 --> 00:51:37,340 that are worth doing. 1186 00:51:37,340 --> 00:51:39,830 For example, everybody's making decisions independently, 1187 00:51:39,830 --> 00:51:41,640 you could be using messaging. 1188 00:51:41,640 --> 00:51:44,900 I think this is a big point because somebody asked me 1189 00:51:44,900 --> 00:51:48,270 the other day, what is the point of messaging. 1190 00:51:48,270 --> 00:51:50,150 Because all of my robots have access 1191 00:51:50,150 --> 00:51:52,130 to all of my other robots' data. 1192 00:51:52,130 --> 00:51:53,710 And you saw that happen here. 1193 00:51:53,710 --> 00:51:55,350 Because would these guys have been 1194 00:51:55,350 --> 00:51:57,990 able to respond intelligently? 1195 00:51:57,990 --> 00:52:00,590 Would this guy have come-- Gosh, I'm using my finger 1196 00:52:00,590 --> 00:52:05,290 again-- would these fellows be able to come all the way back? 1197 00:52:05,290 --> 00:52:08,827 I agree Steven, I should close GChat when presenting. 1198 00:52:08,827 --> 00:52:11,160 Would these guys have been able to come all the way back 1199 00:52:11,160 --> 00:52:13,781 to here if they didn't have shared data? 1200 00:52:13,781 --> 00:52:14,530 No, they wouldn't. 1201 00:52:14,530 --> 00:52:17,530 So, they have shared data, why would you ever use messaging? 1202 00:52:17,530 --> 00:52:21,400 Because you could simplify it by having your headquarters do 1203 00:52:21,400 --> 00:52:23,150 the processing, and say, all right, 1204 00:52:23,150 --> 00:52:25,220 I want everybody to attack this guy. 1205 00:52:25,220 --> 00:52:27,775 And then they all just go ahead and follow that command, 1206 00:52:27,775 --> 00:52:29,900 rather than having to do the processing themselves. 1207 00:52:29,900 --> 00:52:31,524 Because if everybody has the same data, 1208 00:52:31,524 --> 00:52:34,170 why should everybody process on the same data? 1209 00:52:34,170 --> 00:52:35,920 So, there you go that is a reason, 1210 00:52:35,920 --> 00:52:37,865 it doesn't prove that it's always better, 1211 00:52:37,865 --> 00:52:40,490 because it may be much better to have a decentralized approach, 1212 00:52:40,490 --> 00:52:41,124 and so on. 1213 00:52:41,124 --> 00:52:43,040 There are very many reasons, but there you go, 1214 00:52:43,040 --> 00:52:44,456 that's an answer to that question. 1215 00:52:44,456 --> 00:52:45,990 You saw Awesome, you saw Awesomer, 1216 00:52:45,990 --> 00:52:47,580 and you saw it right here. 1217 00:52:47,580 --> 00:52:48,680 Thank you for coming. 1218 00:52:48,680 --> 00:52:52,240 The next-- Just remain calm in your seats 1219 00:52:52,240 --> 00:52:53,380 and there will be food. 1220 00:52:53,380 --> 00:52:55,380 The food guy probably arrive already, I'm sorry, 1221 00:52:55,380 --> 00:52:57,596 yesterday I thought the food guy hadn't arrived. 1222 00:52:57,596 --> 00:52:59,220 They don't mind being called food guys, 1223 00:52:59,220 --> 00:53:00,894 don't worry it's not insulting. 1224 00:53:00,894 --> 00:53:02,310 I thought he hadn't arrived, but I 1225 00:53:02,310 --> 00:53:04,809 think he was poking is head in and out like a drinking bird, 1226 00:53:04,809 --> 00:53:08,810 and I just didn't see it because of various myopia and such, no, 1227 00:53:08,810 --> 00:53:10,310 what do they call it, tunnel vision. 1228 00:53:10,310 --> 00:53:12,890 So, yes, the next lecture. 1229 00:53:12,890 --> 00:53:14,450 I'm sure you enjoyed this one a lot, 1230 00:53:14,450 --> 00:53:16,570 even if you know Java already. 1231 00:53:16,570 --> 00:53:18,929 Because you could see the warmth and the smiles 1232 00:53:18,929 --> 00:53:21,220 on the faces of the people who didn't know Java and now 1233 00:53:21,220 --> 00:53:24,110 do because of this amazing whirlwind tour. 1234 00:53:24,110 --> 00:53:27,920 So, yes, the next lecture will be on navigation, 1235 00:53:27,920 --> 00:53:29,570 as if this one wasn't. 1236 00:53:29,570 --> 00:53:32,120 Yeah, and you're going to hear all kinds of amazing things 1237 00:53:32,120 --> 00:53:33,495 that you never would've expected. 1238 00:53:33,495 --> 00:53:36,275 And you're going to see this like awesome visualizer that's 1239 00:53:36,275 --> 00:53:38,650 a little bit like the fractals that I was showing before. 1240 00:53:38,650 --> 00:53:42,040 It's made in Mathematica and it's made in the USA. 1241 00:53:42,040 --> 00:53:44,710 And yeah, hurray. 1242 00:53:44,710 --> 00:53:45,752 So, thank you for coming. 1243 00:53:45,752 --> 00:53:47,043 And this is the end of lecture. 1244 00:53:47,043 --> 00:53:48,840 And I'll just be here answering questions. 1245 00:53:48,840 --> 00:53:50,380 Again, there's lab after lecture. 1246 00:53:50,380 --> 00:53:52,838 My god, this is like one of those symphonies that you think 1247 00:53:52,838 --> 00:53:54,490 keeps ending, but it doesn't end. 1248 00:53:54,490 --> 00:53:55,560 And that will be all. 1249 00:53:55,560 --> 00:53:57,880 Thank you. 1250 00:53:57,880 --> 00:53:59,430 AUDIENCE: [APPLAUSE]