字幕列表 影片播放
All right.
Hello, world.
This is CS Moody Live.
My name is Colton Ogden.
In case you're tuning in and you're not sure what sees 50 is CS 50 is Harvard's Internet computer science, taught by David Malin, and this is sort of offshoot livestream format.
But if you'd like a more traditional introduction of computer science, as taught here at Harvard University, definitely check out our YouTube channel youtube dot com slash CS 50 where you might actually watching this video now and check out David's lecture series.
We do a lecture series every year, but check out the latest one or go back in time if you want to see some of the earlier P sets and other lectures that we did.
But anyways, this is a separate sort of Siri's from that.
This is where we do live programming, and we talk about technology and do all sorts of other things.
And today in particular, is part three of a Siri's that we've done recently on a game called 2048 which is a sliding tile game on, and we're implementing this in Lewis and Love to D and so shot it's all the people that live in the chat there.
Bella cares.
Job on three.
I saw a few other folks beforehand, but I think the twitch chat it got refresh because I brought it up.
Pop out money, but say hi.
If I didn't shut your name and I will say hi back.
I'm gonna switch over to my laptop screen here.
Like this.
Um, and interestingly, it is.
Wait, why is it showing up like that?
That is weird.
It is an outdated screen for some reason.
Unless I am.
Unless I'm just tripping out.
Oh, is it set to a second monitor?
That might be it.
Hold on one second.
Let me just confirm that that is indeed the case displays.
Am I not mirroring displays?
I am marrying displays.
Why is it being weird like that?
It got froze air.
Sorry.
Let me just unplug and re plug it in.
It looks like it got messed up when we were testing things out.
Give it, give it a sec.
And that looks more.
And now it's not smearing this place because I think I turned that button off.
So let me let me unseated again.
Let me hit mirror displays and Where is that?
It is displays color mayor options on the menu and available.
This is this is whack.
Sorry, everybody going Thio We started off so strong and then it just kind of got destroyed their cause My, for some reason, they see my connection got really wacky Gather windows arrangement mere displays.
And if we're lucky, everything should now be mirrored.
Awesome.
So what?
I meant what I meant to say.
Great too was the love to D, uh, sort of website here because this is the game framework that we're using to implement 2048.
And if you're tuning in now, it might be better to turn into the prior two streams on 2048 just that you you can see where we've come from.
From the very beginning, we implemented sort of the grid on the first dream a little bit, And then the second stream we got to the actual numbers sliding and then combining together.
And today we're gonna actually take everything to the very end and talk about getting the numbers to properly combine and move around, and then also calculate winning and losing and also sort of deriving an arbitrary score formula where we've taken a consideration How many times the user has made a move before they got into the number 2048.
And I did a little bit of prior work on this just to prevent this from going into a part for and wrote in advance a sort of series of notes here and actually a separate get huh branch.
So if we go over to the repo, I'm gonna actually go to my terminal here when l s I'm going to get pole because this repo is a little bit out of date and I should not be able to get check out complete, which I'm already on.
It turns out I might have actually done this in advance.
And if I go ahead and run this in my editor, which is here, just make sure I'm in the right place around This should be able to move everything and it I actually think it's not even I don't think it's currently up to date.
You know, this doesn't look accurate for some reason, So let me go ahead and get status or get log.
Actually, just make sure that this is the right.
Oh, interesting.
It didn't actually pull the correct.
It didn't actually pull the correct stuff.
So let me go ahead and get check out or get fetch and then get status.
I should have probably tested this in advance.
Yeah, this this is for some reason, not.
It didn't actually pull the code from get home.
So I'm gonna I'm gonna just pull the repo completely.
See, You can see stable moving and combining them.
It was my last commit.
So what I'm gonna do is I'm gonna actually just fresh clone this.
I tested this on my other account.
Not actually my, um, test account and I assumed to get pulled was going to work, but it doesn't look like that's actually the case.
So I'm going to CD backwards and just going Thio, delete this.
Go and get clone.
If you get cloned, the report now from get hub, it should just work automatically.
And then Aiken, check out complete, actually, after CD into it 1st 2048 get check out.
Complete and complete is not a accurate sort of word to describe this branch.
It is.
The combining of numbers is complete, but rather than the branch name was just to sort of be farther ahead than the stream itself, and we will be today sort of working backwards from the We'll be working backward as much as we'll be looking at the prior code from last week and sort of getting it up to date with what's incomplete.
The branch, if you're not familiar with get hub and get branching.
Branches are sort of two different alternate paths that your code splits off to when your programming using get, which is a source control ah, form of source control and the master branch is usually what's ever in production.
So you have sort of your main sort of a timeline of get snapshots.
You know where you sort of saved your code.
You can always revert back to a prior snapshot or commit history, and branches sort of deviate from the master branch.
And they sort of are sort of like alternate timelines almost, um, and you can switch back and forth between them as you want to, and then even merge prior branches into the master so you can actually have that branch upper below your your master sort of come back into Master at some point and then become part of your production branch.
And I created a separate branch just so that we could go back to the prior coat from last week while also having a sort of firm point at which we know we're working towards, If that makes sense, So I'm going to now open up the coat.
I'm gonna quit V s code, and I'm going to reopen the repo in V s code here, which now, if we go to maine dot Lou and we go to the very bottom, we'll see that things have definitely changed.
You can see that.
I've actually brought out a few of the functions separately from the all those individual.
Move up.
Move down.
Move left, move right commands.
I've taken out some of the code that was common to those, and we'll take a closer look at this one.
Perfect revert back to the main branch, but it's allowed me to shrink down the functions.
The move functions to not too long, still a bit long.
I didn't spend enough time to actually turn this into an abstract function that would take care of all directions and one function.
But you could visualize, you know, possibly a way to do that, Certainly with enough work.
But here are some of the small functions.
Last week we actually separated out merge Tween, and, um, was it merged Tween and many, uh, move Tween.
I think it was these two functions and added make merge and make movies were just blocks of code that we're in the move up, move down, move left, move right functions, but were repeated, and I just basically parameter rise them a little bit just to make it a little bit easier.
So if I run this code now, if I move everything, you can see that it does behave correctly, which is nice.
So it does.
There is a part of this where it'll actually, if there are three like numbers on the same row or if they're too like numbers that mixed together, and then the that larger times two number is to the left of those or wherever, and they all move together, it will combine up to three numbers.
There is a way to protect against that, but currently the code does not support that.
But we could we could We could, uh add that without too much difficulty, but you can see that it does work now.
Um, all of the stuff is nicely mixing together, which is nice.
See you.
See, Right there.
It happened here at the very bottom.
There was a four.
There were two twos on a four here.
So the two twos mixed into a four and then that for mixed this into an eight.
Now, depending on your philosophy, maybe that's a feature and not a bug.
It's kind of a bug if we're looking at it from the perspective of the original code base, because I don't believe the original code based worked that way.
But all we would really need to do is set a flag on that tile to say that it's already been involved in a mixed operation.
So we could set the flag to maybe mixed equals True.
And then when we actually test for that merge, we can say if the tile that were emerging to or we potentially moving too dot um, mixed is equal to true or false.
Then merge accordingly.
So we can say only merge if mixed is equal to false, and that would prevent the behavior that we're just that we've just observed.
Um, okay, so let me just go ahead and read.
Guy White says, Morning, Colton, will you be facilitating cease indie gaming at Harvard Summer this year?
Thanks for these learning so much.
Um, I will be.
Yeah.
Course instructor for the For the game, Of course.
This summer?
Yes, if that's what you mean.
If there is another meeting to that, I definitely do.
Do you write that in the chat?
Nadia says hi, Colton.
How are you?
I'm doing great.
Thank you very much.
Feeling feeling pretty Spritely em, Kloppenburg.
Hello, everyone.
Berries and cream says hello.
Albin off.
3398 Says, yo.
Hello, Oben.
Auf.
Good to see you on.
Yeah.
So this is what I did last night to get us sort of up and running.
Oh, Jail 97 says love the podcast.
Awesome.
Thank you so much.
Will be releasing another episode very shortly.
Potentially even today, depending on we're basically waiting for the r s s to spread up to Spotify and iTunes.
So whenever that's all done, we'll, uh, we'll pub the next episode of the podcast, but yeah, that one's get I think this this last podcast episode was pretty good.
They were filming another one tomorrow, actually.
Did I push these changes to get him as well?
I did.
So you'll see all of the changes in get hub and specifically these air located in the complete branch, which is right here.
So if you want to download all this code, clone it as normal and then run the command that I did, which was get check out where I do it complete right here.
So that will actually switch you into a branch if it already exists.
And if it doesn't exist, I believe you have to actually get check out or get branch.
Um, and then the name.
And then well, actually, that will take your existing code and create a new branch.
But named that that's that you can develop in