2

I'm sure this topic has been covered to bits, but I've spent hours trying to work something out and I can't find enough resources that explain the process. Please note, I am new to JS and still relying on tutorials and code snippets to write code. I'm still not confident enough to write code from complete scratch.

THE GOAL:

  1. In JavaScript, 'draw' 5 random cards

  2. Evaluate the cards' rank among all possible hands

  3. Return a score from a Variable min/max, based on the rank of the card, unless it's less than a pair.

  4. Lastly, be able to draw a RANDOM hand based on rank (less than, more than, or exactly) EG. Return a hand that is of rank 100 or smaller. (could bring back 100 different hands)

Eg. While Min-Max score is 10-30. If a royal flush comes out, return 30 (best hand means best score). If low Two Pair (6H 6D 2C 2H 5S) comes out return 13. If high Two Pair (AH AD QC QH 5S), return 14. Etc. [Those are probably not accurate scores but you get the drift]

My Research results:

  1. Random Draw: Many applications have achieved this. My favorite so far has been this tutorial: http://www.informit.com/library/content.aspx?b=STY_JavaScript_24_hours&seqNum=229 it is quite simple and gets the result, however does not offer a full evaluation, only by category (pair, two pair, three of a kind etc). I need an evaluation that would be able to give a higher score to the superior of two hand that have two pairs.

  2. Evaluators: This got a bit confusing. I found a very basic evaluator, that uses javascript: http://jsfiddle.net/subskybox/r4mSF/ but it was too basic. Doesn't give me a complete rank. I found this one too: https://github.com/chenosaurus/poker-evaluator which uses the Two Plus Two algorithm and a lookup table. Now, it sounds really good, but I'm terribly confused as to how to install it on into my website, or how to use it. It says: to install: npm install poker-evaluator, which I never heard of before.

  3. Convert rating to score: Should be fairly easy maths. Perhaps: thisRank/maxRank*(MaxScore-MinScore)+MinScore

  4. Draw hand by rank: Haven't seen any way of doing this anywhere. Wouldn't mind seeing some examples or ideas. I'm not sure this can be done with the Two Plus Two poker-evaluator. It's more like the reverse process.

Now, it feels like I'm getting close with all this, but I'm not a 100% sure how to compile this completely. I feel like I could use the code I found in section 1, and the Two Plus Two poker-evaluator to achieve what I need. I would love to it if you could shed a light on the 'npm install', if I'm going in the right direction, or if you know other methods I could achieve the same thing.

Please don't tell me I have to try doing it myself first, because I really don't know how to do this from scratch without a little guidance.

toms
  • 515
  • 6
  • 23
  • 1
    I understand your difficulty - designing an algorithm properly is an art that mainly comes with experience. However, I also hope you understand that answering a broad question like this properly would take a considerable amount of time. I typically get paid pretty well to design good algorithms. I am totally willing to point others in (what I think is) the right direction, which would only take minutes, but I don't feel like really designing something new. Of course, this is just my opinion, but I can imagine I'm not alone in this and you will have hard time getting specific answers here. – Vincent van der Weele Jul 04 '14 at 12:06
  • @Heuster I would never ask anyone to write the code for me (without pay). What I asked is if I'm going in the right direction with the code I found, how to install the Evaluation code I found on GitHub and suggest methods or existing code that could be of use to me. I rely on code snippets and existing programs to write my code and expand my understanding of JS. – toms Jul 05 '14 at 02:08
  • 1
    [npm](https://www.npmjs.com/) is Node Package Manager. It is included when you install [NodeJS](http://nodejs.org/) in your computer. It is a command-line tool that helps you download & install nodejs modules. Running `npm install poker-evaluator` in your shell will instantly download `poker-evaluator` module in your current directory. – topher Dec 11 '14 at 02:38

1 Answers1

2

I will post another beginner's advice :

  • Write the algorithm of what you want to achieve in pseudo-code (e.g., words that are easy for you to read). If the algorithm is not clear in your head before you start coding it is not going to get clearer by itself.
    You are not able to write code : it is fine;
    you hope to write a program without having a detailed low-level vision of every one of its steps : it is not.
    At least that is how I see things.

    Example of pseudo-code that I would write for this case:

    1-
    create card deck 
      loop on number of cards to be drawn
          -generate random integer and remove corresponding card from card deck
          -add drawn card to hand
      end loop
    
    2-
    check if hand is highest figure and associate rating
         else check if hand is 2nd highest and associate rating
                    else...
    
    OR
    
    get data with all possible hands and search for this hand to retrieve score... 
    (see github repo)
    
    3-
    I did not get 3-
    
    4- If you have data with all hands and their value, you just have 
    to search this data by value instead of searching by hand like in 2-
    

  • Second, looking for code snippets on github is a good idea; read the javascript files in the projects which interest you and understand what they do. I think you will need to install node.js for that particular project, because it is used to import the lookup table. Just download the javascript files and include them in your project...do not forget to credit/thank the author.

  • Third, your question is not about a precise difficulty : it is a question about how to start programming stuff when you never did it before. I do not think stackoverflow is the right place for this, but I still answered your question because after all, this is also a help forum.
    My last advice would be to find a good book / tutorial; in every good book there is a sample project to follow in which you develop a complete program and will teach you the basics.

    P.S.: if you are really interested, don't give up because programming can be hard but it is also very rewarding to see stuff work...

  • IazertyuiopI
    • 488
    • 2
    • 12
    • maybe move to programmers stackexchange – IazertyuiopI Jul 04 '14 at 11:13
    • I do have some coding experience in PHP and JS, but never created something this complicated. I learn through working with code and by challenging myself with small projects and finding solutions- I'm not interested in mastering JS. I appreciate you may not have much patience to indulge a noob question as broad as mine. If you are unable to direct me in the direction I need to complete my **very** specific task, that's fine. Telling me to go read a book or a generic tutorial is really unhelpful. I didn't ask anyone to write the code for me, only give guidance, direction, and some explanation. – toms Jul 04 '14 at 11:55
    • @toms Was the answer at least helpul regarding how to use the github repository? – IazertyuiopI Jul 04 '14 at 12:04
    • The problem is that you don't have a "very specific task", you have at least four, which you've already divided into subquestions. You may have better luck asking four separate questions. – Teepeemm Jul 04 '14 at 12:38
    • Just the work of breaking this into questions will most likely be a huge step towards solving your problem... – IazertyuiopI Jul 04 '14 at 12:43
    • Thank you @lazertyuiopl and @Teepeemm. I may have to ask this in 4 different questions then. I understand why you suggested I break this down into a pseudo-code, but I'm not trying to write it from scratch or get anyone to write it for me. I'm looking for examples that already exist out there for me to learn from and use as a base for my program. I've explained what I need this program to do, I don't know if writing it in pseudo-code will make it any clearer to anyone. I'm still not sure how to install that `node.js` but I'm sure that will come up on google search. – toms Jul 04 '14 at 22:18