Butifyou'd like a moretraditionalintroductionofcomputerscience, astaughthereatHarvardUniversity, definitelycheckoutourYouTubechannelyoutubedotcomslashCS 50 whereyoumightactuallywatchingthisvideonowandcheckoutDavid's lectureseries.
Wedo a lectureserieseveryyear, butcheckoutthelatestoneorgobackintimeifyouwanttoseesomeoftheearlier P setsandotherlecturesthatwedid.
Butanyways, thisis a separatesortofSiri's fromthat.
Andtodayinparticular, ispartthreeof a Siri's thatwe'vedonerecentlyon a gamecalled 2048 whichis a slidingtilegameon, andwe'reimplementingthisinLewisandLoveto D andsoshotit's allthepeoplethatliveinthechatthere.
Bellacares.
Jobonthree.
I saw a fewotherfolksbeforehand, but I thinkthetwitchchatitgotrefreshbecause I broughtitup.
Fromtheverybeginning, weimplementedsortofthegridonthefirstdream a littlebit, Andthenthesecondstreamwegottotheactualnumbersslidingandthencombiningtogether.
Andtodaywe'regonnaactuallytakeeverythingtotheveryendandtalkaboutgettingthenumberstoproperlycombineandmovearound, andthenalsocalculatewinningandlosingandalsosortofderivinganarbitraryscoreformulawherewe'vetaken a considerationHowmanytimestheuserhasmade a movebeforetheygotintothenumber 2048.
And I did a littlebitofpriorworkonthisjusttopreventthisfromgoinginto a partforandwroteinadvance a sortofseriesofnoteshereandactually a separategethuhbranch.
Soifwegoovertotherepo, I'm gonnaactuallygotomyterminalherewhen l s I'm goingtogetpolebecausethisrepois a littlebitoutofdateand I shouldnotbeabletogetcheckoutcomplete, which I'm alreadyon.
Itturnsout I mighthaveactuallydonethisinadvance.
Andif I goaheadandrunthisinmyeditor, whichishere, justmakesure I'm intherightplacearoundThisshouldbeabletomoveeverythingandit I actuallythinkit's noteven I don't thinkit's currentlyuptodate.
And I created a separatebranchjustsothatwecouldgobacktothepriorcoatfromlastweekwhilealsohaving a sortoffirmpointatwhichweknowwe'reworkingtowards, Ifthatmakessense, So I'm goingtonowopenupthecoat.
I'm gonnaquit V s code, and I'm goingtoreopentherepoin V s codehere, whichnow, ifwegotomainedotLouandwegototheverybottom, we'llseethatthingshavedefinitelychanged.
Youcanseethat.
I'veactuallybroughtout a fewofthefunctionsseparatelyfromtheallthoseindividual.
Moveup.
Movedown.
Moveleft, moverightcommands.
I'vetakenoutsomeofthecodethatwascommontothose, andwe'lltake a closerlookatthisone.
I thinkitwasthesetwofunctionsandaddedmakemergeandmakemovieswerejustblocksofcodethatwe'reinthemoveup, movedown, moveleft, moverightfunctions, butwererepeated, and I justbasicallyparameterrisethem a littlebitjusttomakeit a littlebiteasier.
Soif I runthiscodenow, if I moveeverything, youcanseethatitdoesbehavecorrectly, whichisnice.
Soitdoes.
Thereis a partofthiswhereit'llactually, iftherearethreelikenumbersonthesameroworifthey'retoolikenumbersthatmixedtogether, andthenthethatlargertimestwonumberistotheleftofthoseorwherever, andtheyallmovetogether, itwillcombineuptothreenumbers.
Thereis a waytoprotectagainstthat, butcurrentlythecodedoesnotsupportthat.
Soweneedtodoiskeeptwonumbersinsideoftheinsideofthetiledatastructure, a numberintheactualnumberthatit's holdinginsideofitselfandthenthenumberit's displaying.
So I calleditdisplaynumb.
Andsowhatweneededtoendupdoingforthatisactuallygoingintohereandaddingtothetileclass a selfdotdisplaygnome, whichisequaltoitsown, um, bydefault.
DaLuaandletmejustfinishwritingthisTweensothiswilltake a tile, andit's essentiallygoingtobethiscodehere, but a littlebitMaura, littlebitdifferent, so I'lljustrideitouthere.
So, uh, wedo, isweget a tilefirstif I'm doingthiscorrectly.
Andthenafterthatweaken d'oh, ourusualtimerdotTween, we'redoingitoverthespanof 0.0.1 seconds, andthenittakesin a anobject, a table, andit's gonnatakethetileright, andit's goingtosetitsgridequalThiogridgridtilethattileWhytilethattileexdotExeandthenwhySettogriddotgridattilethattile y tiledottileexdotWhy?
RightsaysthisistheTweenobjectsorofthelistofkeyvaluepairsatwhichweretweetingtheobjecttowardsWe'retakingthetileobjectandthenwe'reTweeningthe, umthe, uhPereirathefieldsthatwecareaboutinthiscase, the x and y.
Sowe'retakingthetileweretweetingIt's x towardsthis X thetiles.
Forthatreason, I wouldprobablyuseif I weregoingtogoessupercommercial, and I wantedittobeavailableon, like, theswitch.
Andlikeallovertheplace, I wouldprobablytryandfitmycodebaseintounitysomehowanddoitthatway.
And I alsoasanintellectualexercise, wouldliketogetmoreacquaintedwithunity.
I thinkunityis a prettycoolplatform.
Thatsaid, Lovehasanappealformepersonally, andso I finditmoreenjoyabletoprogramwithlovethan a Then I enjoyprogrammingimmunitysofarthatmightchangeinthefuture.
I haven't done a lotoftwo D gamedevelopmentwithunity, whichis a bigpartofthat.
Um, it's a littlebithardertodocertainthings.
I rememberhaving a toughtimegettingpixelperfectretroresolutionworkinginunity.
But I wasabletogetitworkinginlovewiththehelpof a libraryveryeasily, anditwasamazing.
Soithas a specialplaceinmyheart.
But I think, um, honestlyandpragmatically, unitywouldprobablymakethemostmarketsense.
Sothat's probablywhere I wouldsay, I wouldsay, probablyprobablylearnedthatunlessyouliketheAP, I forLouandforloveto d.
Umthensoifit's thecasethatfarthest X plusoneisstillwithinthegridboundary, Whatwe'lldoiswe'llsay, um, localfarthistileisequalthiogridatgettilefarthis X plusone.
Sowhat I wassayingpreviouslywasthat I don't thinkit's worththetimeforustow, sinceeverything's alreadylaidouttojustmanuallygothroughthesefunctionsandrefactoredinthesameway I illustratedherehowwerefactoredthemoverightfunction, Butthesameprocessexistsfor a moveup.
Movedown.
Moveleft.
Sowhat I thinkwe'regoingtodois I'lljustgobacktothecompletebranch, andyoucancheckthisoutonyourmachine.
Um, couldsavetheoretically a bitmoreifwewantedtotakethetimetoactuallyrefactortheupdownleft, rightfunctionstheonefunction, Ahmahn a function, I guessyoucouldsay, butnowwewon't worryaboutthattoomuch.
Sonowwehavethiscode, wecanrunit.
Everythingsortofworksthewaythatweexpectitto.
Umyeah, prettyawesome.
Yeah, I willsay I'm I'm prettyhappyafterafteritfeelslikewe'vebeenon a longjourneyafter, youknow, howevermany, uh, weeksit's beeningettingthisactuallyworkingtoseeifwecangetThea, let's seehow I'llseehowhighwecanget.
Let's let's enjoythefactthatwegottothispointrightandseehowhighof a numberwecanget.
Thereare a fewcorefunctionsthatweremissingbeforeweactuallyhavethegamefinishedandbadignitesisyeacool.
It's workingvinylitWe'restillcopypasting, meaningwestillhave a chancetofactoredout.
Yep, thatiscorrect, butwedohave a chancetorefactorit.
It's goingtotake a littlebitofworkjustbecausetheweredoinganaccessflipin 90 degreeswheneverwedowantto.