Closed QuincyLarson closed 2 years ago
@UsamaHameed Awesome! Welcome back! We would welcome your help. First of all, I recommend implementing a basic poker game in TypeScript - something that can give out two hands of cards and determine which one wins.
From there we can discuss specific ways we can incorporate TypeScript features into the project and how we can teach them through a series of tests.
Hey Quincy, I'm interested in this project as well. To clarify:
enum
for the suit (i.e. spade, heart, club, and diamond)type
for the numbers (i.e. 2 - 10, J, Q, K, and A)interface
Card
for the data shape of the random card, and Array<Card>
for the cards of each player (if multiple)class
for the skeleton of the project
constructor
to initialize players: name, cashgenerateCards
, compare
, determineWinner
, probably calculateCash
as well. Then, updateCash
. For each of those, the function returned type could be utilizedI will try working on this as long as I am cleared with the stuff mentioned above.
@S1ngS1ng Great questions.
Does the application works something like: Two (or more) players sitting in front of ONE computer Each player places their initial bet One (or two?) cards are given to each player. The winner is determined at this point
It doesn't need to be that complicated. I think a single-player version where people play against the computer would be fine, and it could treat each hand as one-off. The main thing would be determining which player's hand won.
If this is the case, we may need to utilize Local Storage (or maybe Firebase) for storing user info (such as name, total cash, statistics, etc.)
If it's only one player, and we don't store data between hands, then we wouldn't need to worry about covering local storage here.
The main goal is to build a simple project while using TypeScript and some of its core features.
Should this be an online game rather than local? If so, we may have to utilize something like socket.io
This would be cool, but I think it's beyond the scope of trying to teach TypeScript. We do want to teach websockets later in the curriculum, though.
Out of my mind, to utilize TypeScript should be fairly straightforward as per these scopes: enum for the suit (i.e. spade, heart, club, and diamond) Union type for the numbers (i.e. 2 - 10, J, Q, K, and A) interface Card for the data shape of the random card, and Array
for the cards of each player (if multiple) class for the skeleton of the project Use constructor to initialize players: name, cash Has methods generateCards, compare, determineWinner, probably calculateCash as well. Then, updateCash. For each of those, the function returned type could be utilized
Yes - these all sound like suitable types and scopes for various aspects of the game.
When each player has multiple cards, how should we determine which player wins? Simply by adding up the sum: J, Q, K, A worth 11, 12, 13, 14, respectively? Based on Poker Hands (e.g. Flush, two pairs, etc.). TBH, this is pretty hard to implement: Should we include the Wild card as well?
We should cover the types of hands, including the ones listed here: https://www.cardplayer.com/rules-of-poker/hand-rankings
I don't think we need to include wild cards.
I will try working on this as long as I am cleared with the stuff mentioned above.
I hope I've done a good enough job of answered your questions. I am excited to see what you come up with. Let me know if I can be of any help. Thanks again for helping build this.
@S1ngS1ng Hey! I am busy this week and then I am on vacation for two more weeks. Feel free to go ahead and take a shot at this. When I get back to work, I will let you know and we can work on it if there is something that needs doing.
@UsamaHameed Sure, enjoy your vacation 🏖
@QuincyLarson Thanks for your clarification. Here is a quick summary, please let me know if there is any mistake below:
Also, a sorted value array (e.g. [10, 'J', 'Q', 'K', 'A']) will be included for the comparison later on. As per the sorting, there will be a corner case that I could come up with: the wheel (i.e., A, 2, 3, 4, 5)
It might take another few days for me to implement this. I'll keep you posted. 🍻
@S1ngS1ng This all looks correct. And yes - that algorithm all looks right based on my reading of it.
I'm excited to see this. Thanks again for your contributions, and for keeping us posted on your progress on this. 🍻
@QuincyLarson Hey Quincy, here are some update for the poker game.
Babel
heresortedValue
: The card values sorted based on value point only (where 2 ~ 10 as is, "J" ~ "A" as in 11 ~ 14, refence)suit
: the suit count object (i.e. suit => count)value
: the cardValue count object (i.e. cardValue => count)I'd consider it to be straight forward. Now that each part is based on module, and I've added enough, if not all type documentation (example here). After I am done with rest of the UI and logic, I'll work on converting it to TypeScript
@S1ngS1ng, this looks great! And thank you for your thorough breakdown of the project and the bonus April Fools joke :+1: :+1:
As for the UI, don't worry so much about how it looks. The main focus is to teach TypeScript, and I'm sure users will appreciate spending more time building the game rather than making the page look good. For showing the poker hands, using Unicode could be a good option: https://en.wikipedia.org/wiki/Playing_cards_in_Unicode
Here's a CodePen I found showing Unicode playing cards with some simple styling: https://codepen.io/ogab/pen/peXpqW
Hope that helps. Can't wait to see the finished project. Really looking forward to building this myself!
@scissorsneedfoodtoo Thanks for your suggestions. Yes, I've found some similar stuff on CodePen as well 😃 As per the suits, I've noticed that an HTML entity could work as well. Should we use Unicode or HTML entity, or either one should be fine (#bikeshedding)?
@S1ngS1ng, it's totally up to you! Go with whichever you feel is best.
@scissorsneedfoodtoo Cool. Thanks
@QuincyLarson Here is another update F.Y.I. @scissorsneedfoodtoo Here is the online preview, if you are interested 😃 If you guys think that I am missing something, or if you have any questions/comments/concerns, please do let me know.
Next
button (to start a new bet)End
button (to end current session)
Outdated, see below
extends
within modules? Though, I coded most of the stuff as in module, but I didn't figure out a way to utilize extends
in this case. Still, I believe it is nice to have@QuincyLarson @UsamaHameed @scissorsneedfoodtoo Here is the final version (w/ JS). Please let know how you guys like it 🍻 The source code is here, and here is the online preview
And a quick gif demo:
I've included some animations comparing to the previous version. In case of any questions/concerns, please let me know. Meanwhile, I'll work on converting it to the TypeScript version.
From the previous thread:
Any suggestions please?
@S1ngS1ng, wow, this looks amazing! Just played a few hands and had a lot of fun :+1: :+1:
Unfortunately, I noticed a couple of bugs:
Could you add some logic to prevent these from happening?
About your questions:
@scissorsneedfoodtoo Thanks! That was a good catch, spot on!.
Looks like I did set the max
for range input, while not for the text input 🤦♂️
Sure, I'll fix that tonight.
Also, thanks for your thought on the questions.
extends
to be necessary as well. Feel free to open an issue/comment/PR there. Or if you'd prefer some "offline" discussion, please let me know.@scissorsneedfoodtoo I've made some changes. Now that the text input is removed. Here is what it looks like now: In this way, at least it minimize the effort to deal with the input validation XD For displaying the poker hand details, I am still working on it. There are some method to be re-implemented, which should be done by tomorrow.
@S1ngS1ng, looks great! Removing the text input is a good way to avoid that issue. I like the slider more anyway :+1:
Just one more thing I noticed with the text. Could we change it to: "You bet $__. Good luck!"
"You're the winner! Yay!" "You won $__!"
"The bot won. Darn it!" "You lost $__!"
About discussing about extends
, I'd be happy to talk about that or other parts of your project if you'd like. I'll send you an email and we can set something up.
@scissorsneedfoodtoo
Few updates here:
result-rank-container
timeout
to 0.5 secondsI'd like to hear about your thought on the text: The bot has Three of a kind, Your have High card.
Does that make sense? If there is a better way to describe that, please lemme know 😃
@S1ngS1ng, lookin' good! Thanks again for taking the time to walk me through your project yesterday and for your updates.
It seems like you're using rankMap
to update the language in the result-rank-container
, so maybe you could modify the text to the following:
this.rankMap = {
1: 'high card',
2: 'a pair',
3: 'two pair',
4: 'three of a kind',
5: 'a straight',
6: 'a flush',
7: 'a full house',
8: 'four of a kind',
9: 'a straight flush/royal flush'
};
I'm not sure if it's more appropriate to say "The bot has the high card" or "The bot has high card," but it seems like they're titles for the types of hands, so the object above should be fine. Also, it would probably be best to write just "It's a draw!" and leave cashContent
blank in case of a draw.
Anyway, hope that helps! Let me know what you think.
@scissorsneedfoodtoo Sounds good! I'll be working on that tonight. Thanks for the advice
@S1ngS1ng, awesome! This looks and plays great. Looking forward to seeing it in TypeScript now :+1: :+1:
@S1ngS1ng You did a great job on the UI. I'm excited to go through and build this project myself based on your tests! :)
@QuincyLarson Thanks! I am working on converting that to TypeScript.
Also, I've added pug
as the template engine.
For the bundle tool, I've been trying out Parcel
and would add that to the TypeScript version as well.
@S1ngS1ng, sounds good! Parcel seems like a really neat tool to get things up and running quickly. I don't think we'll be able to use actual Pug template files on the final platform, but we'll certainly be able to use any HTML files that it renders!
@scissorsneedfoodtoo All right.
Though, I am using pug
right now. Here is the repo for your interest.
Now I am working on the logic part. You may expect some updates this weekend if things are working out on my side 😂
@S1ngS1ng, it's no problem for the prototype! Just wanted to let you know before you start breaking things down into steps, even if you'll only be breaking down the JS/TS parts. Everything in that repo LGTM :+1: :+1:
Alright, sounds good. Just let us know how everything's going and if we can help with anything.
i am belatedly arriving here and realizing this project is mostly done. any typescript stuff you may want me to look at let me know! is this the source? where is the typescript in this?
@sw-yx Hey, thanks for the comment. Yes, that is the source. I am working on the conversion to TypeScript right now. Will let you know when it is done. And it would be great if you could review my code later on. Thanks in advance 🙏
sure thing tag me when you want me
Thank you for your help, @sw-yx!
Hi @S1ngS1ng, how's everything going with converting your prototype to TypeScript? Anything we can help out with?
@scissorsneedfoodtoo Hey, my apologize for the delay. We've been working on the moving since last week, and we'll be on a vacation in the next few days. I've made some changes on my local machine regarding the conversion of TypeScript, will push those changes before we head off tomorrow.
@S1ngS1ng, no need to apologize! Hope the move went well and you had a nice vacation.
I'm sorry for taking so long to respond. Not sure if you saw, but we moved off of Medium, and it was all hands on deck for a while there. Now that things have settled down I'm getting all caught up on things around here. Looking forward to seeing your changes soon!
Hi @S1ngS1ng how is this project coming along? We are excited to get Typescript into the curriculum. This is commonly requested.
@QuincyLarson Hey Quincy. I've been constantly working on it. I ran into some OOP design issues, and have it mostly resolved over last weekend. I'll try to make some updates before this weekend. What I am doing now is rewriting some classes and putting them together.
@QuincyLarson @scissorsneedfoodtoo @sw-yx https://github.com/S1ngS1ng/freeCodeCampProject/tree/master/poker-game-ts
Here is a quick preview of what I currently have. Still, it is not fully functional since I am still working on some refactoring on my side. Please let me know if you guys have any questions or concerns. Comments and suggestions are always welcome, for sure XD
(Should be able to make some updates early next week
interesting way to code this. looks like Angular, but entirely done with dom api's!
not much comments apart from that i personally would opt for far fewer files, collapsing interfaces w implementations where possible. many files is scary to me as a beginner.
Thank you for your continued efforts on this project, @S1ngS1ng. Looking forward to seeing your fully functional project.
@sw-yx brings up a good point. Would it be possible to simplify further and reduce the number of files? Having a few longer files will be easier for learners to grasp, and will also make things easier on us when it's time to start breaking this project up into steps.
@sw-yx Thanks a lot for your feedback.
many files is scary to me as a beginner
That is actually scary to me as well 😂But TBH, it is pretty common in the real world. With the help of those up-to-date editor/IDE, spreading out the code is (IMO) kind of beneficial, especially for larger projects.
@scissorsneedfoodtoo
Would it be possible to simplify further and reduce the number of files?
That said, we don't have any limitations on the max lines of a file? If so, I'll definitely work on that after it is fully functional. I'll merge those interface, class, enums (if any) together. The ultimate goal could be the project w/o directory. Still, I'd consider splitting based on logic/duty (e.g. DOM manipulation and Poker Service) to be valid. What's your opinion? @sw-yx @scissorsneedfoodtoo
🤷♂️
@S1ngS1ng, that's also a valid point.
It's hard to say right now because I don't have any concrete details about the new platform yet, it's just something we've talked about. Why don't we stick to the way you've been splitting files based on logic/duty now? Then we can consider consolidating later if it's necessary due to platform limitations or how learners react to projects earlier in the curriculum.
Is this project still being worked on?
Code wise, it is ready to go. I was working on the documentation (guide) and have yet to update the codebase. @scissorsneedfoodtoo As far as I remember, you mentioned that this was not on a high priority when we talked about it last time. Is there any updates regarding this (i.e. the project-based challenge, as mentioned last time)?
Hi @JoshuaPelealu, thanks for your interest. Also thanks for the update @S1ngS1ng. Awesome to hear that you were able to rework everything into TypeScript.
There's still a lot of deliberation about how to handle these later Front End Libraries projects, especially this one since we need a way to run TypeScript in the browser. At the moment we're working on getting the Front End Libraries projects broken up into steps, then we'll move onto the JavaScript Data Structures and Algorithm projects.
For now, could you create a PR for the code you have @S1ngS1ng? Would be great to see your finished prototype. But let's hold off on breaking up into steps until we have a better idea about how to handle these later projects.
@scissorsneedfoodtoo Sorry for the delay Kris. We were mostly out of town last week and over the weekends. I'll create a PR this evening. I will link this issue to the PR as well. Again, sorry for the delay 🤦♂️
PR created https://github.com/freeCodeCamp/CurriculumExpansion/pull/305 Feel free to include more reviewers. In case of any comments/concerns, I'd address that as soon as I can. @scissorsneedfoodtoo Please take a look at the README. This might help when breaking up this challenge into steps. Please let me know what would be the best way to break it down and I should be able to work on it this weekend. Last but not least, here is the online demo
Hey @S1ngS1ng, thank you for your patience and all the hard work you put into this. I took a quick look and everything LGTM :+1: :+1: Like you mentioned, the README will really help break this project down into steps.
We're in the process of moving some projects around and trying to figure out the best way to implement this one. We'll definitely reach out about how you might break this project down once we decide all that.
Thanks again! I'll go ahead and merge your PR now.
Hello, I would like to work on this. Please let me know what the requirements are. Also, if you need help with any other typescript related curriculum challenges/projects, please feel free to ask me. I'd be more than happy to help.