Coding Challenge #94: 2048 - Part 1

preview_player
Показать описание


Other Parts of this Challenge:

References:

Videos:

Related Coding Challenges:

Timestamps:
0:00 Introducing today's topic: 2048 sliding puzzle game
2:50 How does the game work?
5:16 Let's Code!
6:10 Write an addNumber function
8:12 Use the ternary operator to pick either a 2 or 4
9:54 Draw the board
14:38 Write a slide function
18:10 Add a keyPressed function to slide the numbers
19:13 Write a combine function
25:23 Write an operate function
31:29 Check to see if a number has moved
33:09 Write a function to compare two different matrices
34:50 Conclusion and next steps

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

#2048 #slidingpuzzlegame #javascript #p5js
Рекомендации по теме
Комментарии
Автор

I just wanted to thank you real quick! Your videos got me into programming which ended up changing my life over the last 13 months and I still watch your videos frequently and learn new concepts. Thanks!

uplife
Автор

Thank you! I kept suggesting a 2048 game for almost a year, and now I finally have it! 😀
This is my last year in highschool and with the help of your awesome videos and tutorials I learned programing and I want to continue with computer science.
Thank you for everything! 😀👍

sebastiantv
Автор

How do you manage to be so happy in every video haha

Insaniaq
Автор

I like how you knew it was a bug to have the array manipulation functions behave differently, brushed it off that you'll remember, then IMMEDIATELY wrote a bug because of it

cheekoli
Автор

I have decided to take on the challenge of creating a self learning neural net that can win at 2048.
My grade 10 teacher told me if you want to solve a problem do it yourself OR find someone that has already solved the problem. I am using the latter strategy to deal with the first level of 2048 and then move on


I love your enthusiasm btw. I love that you are open about the journey being adventures and ideas we learn via by trial and error.

silentgrove
Автор

Your coding challenge is great, Dan! Honestly, it feels good to see how you code without planning it in advance. I can see your thought process and it's very helpful to improve my problem-solving ability. Thank you so much! Xoxo

gggogopowerrangers
Автор

This is by far the best YouTube channel!
I wish all people who call themselves as programmers could be as passionate as you!

agampreetsingh
Автор

Your every action puts a mile long smile on my face.

cameron
Автор

Got inspired to do this challenge myself in the Unity game engine.
Finished in a little less than 3 hours.

I went for a solution with a nested loop for each direction and used some helper variables (that is reset each row/collumn).
firstFreeSlotId = first slot with zero, that a number can be moved to. I add/remove 1 based on direction when assigned to.
lastNumber = the last non-zero number value I encountered. To check if I add it to that slot or to the first free slot.
lastNumberId = the id of the last non-zero number I found. Used if matching number and I have to merge them.

There was also some forward and backward looping through the x and y values nessesary in the nested loops based on the directions chosen.
And of course I have to reset some of those variables when I merge and what not, so that multiple numbers dont merge to the same one!
Looking forward to the remaining parts. Hope any of you found this method helpful. =)

AleksanderFimreite
Автор

All aboard! Thus is going to be a long journey..

algc
Автор

Just finished this challenge myself, now to see how you implement the tile shifting! (I was stuck on it for longer than I'm proud to admit, considering how simple it sounds).

joshuaharvey
Автор

I have coded this game in Java, great game to earn experience

matteoZattera
Автор

"We don't speak of part 4"
- Dan Shiffman

thtgi
Автор

Love your videos keep them coming!
Watching from South Africa.

SirCatzilla
Автор

omg i JUST finished my own 2048! next step: neural network to play it!

amanmahendroo
Автор

Dan, awesome as always! We definitely need more coding challenges!

sonik
Автор

Yet another coding challenge goes by without a foreach loop ;-;

sadhlife
Автор

doing this for a class project, I've got the board set up written, (like place 2s and 4s down in a random spot) and let me just say, my code is WAY messier than the like 50 lines it took you to write it

Ash-bxkq
Автор

I tried to make this game a few years ago and failed miserably. At that time I was still just a JS scrub though. Should definitely come back to it and see what I can come up with.

camelcase
Автор

Man you should have a tv program. Great content as usual ! I would love to see you doing some Node.js. Greetings from Spain

EnriqueMartinezAgraAgra