Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var numP = 5; //broj igrača
- var deck = [];
- var players = [];
- var table = [];
- //Napravi špil
- for(var i=0; i<52; i++){
- deck.push(new Card(Math.floor(i/13), i%13));
- }
- shuffle();
- //Napravi igrače
- for(var i=0; i<numP; i++){
- players.push(new Player);
- }
- //Deli igračima
- dealP();
- //Deli sto
- flop();
- turn();
- river();
- function Card(suit,value){
- this.suit = suit;
- this.value = value;
- }
- function Player(){
- this.money = 1000;
- this.pos = players.length;
- this.hand = [];
- }
- function shuffle(moves = 100) {
- for(var i=0; i<moves; i++){
- var k1 = Math.floor(Math.random() * 52);
- var k2;
- do {
- k2 = Math.floor(Math.random() * 52);
- } while (k2 == k1);
- tmp = deck[k1];
- deck[k1] = deck[k2];
- deck[k2] = tmp;
- }
- }
- function dealP(){
- for(var i=0; i<numP; i++){
- players[i].hand.push(deck.pop());
- players[i].hand.push(deck.pop());
- }
- }
- function flop(){
- for(var i=0; i<3; i++){
- table.push(deck.pop());
- }
- }
- function turn(){
- table.push(deck.pop());
- }
- function river(){
- turn();
- }
- function eval(){
- playerCombs = [];
- for(i=0; i<numP; i++){
- set = [players[i].hand[0], players[i].hand[0], table[0], table[1], table[2], table[3], table[4]]; //Sastavljanje skupa 7 karata
- combs = [];
- numCom = 0; //Broj kombinacija vec dodatih (od 21)
- ex1 = 0, ex2 = 1; //Karte koje se ne koriste u kombinaciji
- while(numCom<21){
- j = 0; //Indeks skupa 7 karata
- k = 0; //Broj karata dodatih u kombinaciju
- comb = [];
- while(k<5){
- if(j!=ex1 && j!=ex2){
- comb[k] = set[j];
- k++;
- }
- j++;
- }
- combs.push(comb);
- numCom++;
- if(ex2<6){
- ex2++;
- } else if (ex1!=5){
- ex1++;
- ex2=ex1+1;
- }
- }
- playerCombs.push(combs);
- }
- return playerCombs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement