Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. var numP = 5; //broj igrača
  2. var deck = [];
  3. var players = [];
  4. var table = [];
  5.  
  6. //Napravi špil
  7. for(var i=0; i<52; i++){
  8. deck.push(new Card(Math.floor(i/13), i%13));
  9. }
  10. shuffle();
  11.  
  12. //Napravi igrače
  13. for(var i=0; i<numP; i++){
  14. players.push(new Player);
  15. }
  16.  
  17. //Deli igračima
  18. dealP();
  19.  
  20. //Deli sto
  21. flop();
  22. turn();
  23. river();
  24.  
  25. function Card(suit,value){
  26. this.suit = suit;
  27. this.value = value;
  28. }
  29.  
  30. function Player(){
  31. this.money = 1000;
  32. this.pos = players.length;
  33. this.hand = [];
  34. }
  35.  
  36. function shuffle(moves = 100) {
  37. for(var i=0; i<moves; i++){
  38. var k1 = Math.floor(Math.random() * 52);
  39. var k2;
  40. do {
  41. k2 = Math.floor(Math.random() * 52);
  42. } while (k2 == k1);
  43. tmp = deck[k1];
  44. deck[k1] = deck[k2];
  45. deck[k2] = tmp;
  46. }
  47. }
  48.  
  49. function dealP(){
  50. for(var i=0; i<numP; i++){
  51. players[i].hand.push(deck.pop());
  52. players[i].hand.push(deck.pop());
  53. }
  54. }
  55.  
  56. function flop(){
  57. for(var i=0; i<3; i++){
  58. table.push(deck.pop());
  59. }
  60. }
  61.  
  62. function turn(){
  63. table.push(deck.pop());
  64. }
  65.  
  66. function river(){
  67. turn();
  68. }
  69.  
  70. function eval(){
  71. playerCombs = [];
  72. for(i=0; i<numP; i++){
  73. set = [players[i].hand[0], players[i].hand[0], table[0], table[1], table[2], table[3], table[4]]; //Sastavljanje skupa 7 karata
  74. combs = [];
  75. numCom = 0; //Broj kombinacija vec dodatih (od 21)
  76. ex1 = 0, ex2 = 1; //Karte koje se ne koriste u kombinaciji
  77. while(numCom<21){
  78. j = 0; //Indeks skupa 7 karata
  79. k = 0; //Broj karata dodatih u kombinaciju
  80. comb = [];
  81. while(k<5){
  82. if(j!=ex1 && j!=ex2){
  83. comb[k] = set[j];
  84. k++;
  85. }
  86. j++;
  87. }
  88. combs.push(comb);
  89. numCom++;
  90. if(ex2<6){
  91. ex2++;
  92. } else if (ex1!=5){
  93. ex1++;
  94. ex2=ex1+1;
  95. }
  96. }
  97. playerCombs.push(combs);
  98. }
  99. return playerCombs;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement