Guest User

Untitled

a guest
Feb 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 120.27 KB | None | 0 0
  1. //AT THE END THIS PROGRAM WILL BE A DISCORD BOT USING EVENT LISTENERS
  2. //while(arg[0] != "quite")
  3.  
  4. //might need an object for cards to easily compare
  5. //PLAYER SHOULD HOLD AMOUNT OF PAIRS OR FLUSHES EtC?
  6. //need a method for every hand
  7.  
  8. //NEED TO CATCH EXCEPTIONS FOR INPUT
  9. import java.util.*;
  10. import java.util.concurrent.ThreadLocalRandom;
  11. import java.util.concurrent.TimeUnit;
  12. import java.util.Scanner;
  13.  
  14.  
  15. public class Cardgame{
  16.  
  17. //method that shuffles the deck 3 times.
  18. public static ArrayList<String> shuffle(ArrayList<String> deck){
  19. for(int i = 0; i<3; i++){
  20. for (int counter = 0; counter < deck.size(); counter++) {
  21. int randomNumA = ThreadLocalRandom.current().nextInt(0, 51 + 1);
  22. // int randomNumB = ThreadLocalRandom.current().nextInt(0, 51 + 1);
  23. // System.out.println(randomNumA+" "+randomNumB);
  24. Collections.swap(deck, i, randomNumA);
  25. }}
  26. return deck;
  27. }
  28.  
  29.  
  30. //deal method that deals 1 card to a player from top of the deck
  31. public static void deal(Player player, ArrayList<String> deck){
  32. player.addhand(deck.get(deck.size()-1));
  33. deck.remove(deck.size()-1);
  34. }
  35.  
  36. // deal method that deals 1 card to the middle of the table from the top of the deck
  37. public static void dealtable(Table table, ArrayList<String> deck){
  38. table.addtablecards(deck.get(deck.size()-1));
  39. deck.remove(deck.size()-1);
  40. }
  41.  
  42. //clears screen
  43. public static void clearScreen() {
  44. System.out.print("\033[H\033[2J");
  45. System.out.flush();
  46. }
  47.  
  48.  
  49. //poker game mode; need to create a number of players based on user input. Players will be stored in an arraylist
  50. //RECURSIVE
  51. public static ArrayList<Player> betting(ArrayList<Player> players, Table table, ArrayList<String> deck, ArrayList<Player> foldplayers){
  52. /*
  53. //the ante is 4 chips
  54. //set fold is reset
  55. //previous bets are cleared
  56. for(int t=0; t<players.size();t++){
  57. players.get(t).removechips(4);
  58. players.get(t).setrecentbet(0);
  59. players.get(t).clearfold();
  60. }
  61. //2 cards are dealt
  62. for(int x=0; x<players.size();x++){
  63. deal(players.get(x), deck);
  64. deal(players.get(x), deck);
  65. //players.get(x).setrecentbet(0);
  66. }
  67. */
  68. //create array of players that didnt fold
  69. ArrayList<Player> nonfoldplayers = new ArrayList<Player>();
  70. int fix = 0;
  71. Scanner input = new Scanner(System.in);
  72. //This sequence should be repeated until all non-fold player bets are equivalent OR UNTIL THE LENGTH OF NON-FOLD PLAYERS IS 1
  73. for(int z=0; z<players.size();z++){
  74.  
  75.  
  76. //THIS SHOUDLNT DO ANYTHING!!!
  77. if (nonfoldplayers.size()==0 && z == (players.size()-1)){
  78. System.out.println(players.get(players.size()-1).getName()+" has won the pot!");
  79. System.out.println(table.getpot()+" chips have been added to "+players.get(players.size()-1).getName()+"'s account.");
  80. players.get(players.size()-1).addchips(table.getpot());
  81. table.clearpot();
  82. System.out.println("ADAM NEEDS TO CHECK THIS ERROR");
  83. //return the winner?
  84. // System.out.println("THIS IS A TEST YOOOOOOOOOOO")
  85. fix=1;
  86. ArrayList<Player> nonfoldplayerz = new ArrayList<Player>();
  87. nonfoldplayerz.add(players.get(players.size()-1));
  88. return nonfoldplayerz;
  89.  
  90. }
  91.  
  92.  
  93. System.out.println((players.get(z)).getName() + "'s turn is commencing. All other players should temporarily leave the area.\n");
  94. // int password = 0;
  95. // while(password != (players.get(z)).getpassword()){
  96. // System.out.println("\nPlease enter your three digit password.");
  97. //password = input.nextInt();
  98. // }
  99.  
  100.  
  101. //catch input mismatch exception
  102. int password=0;
  103. do {
  104. try {
  105. System.out.print("\nPlease enter your three digit password: ");
  106. password = input.nextInt();
  107. } catch (InputMismatchException e) {
  108. System.out.print("Incorrect three digit passowrd. ");
  109. }
  110. input.nextLine(); // clears the buffer
  111. } while (password != (players.get(z)).getpassword());
  112.  
  113.  
  114.  
  115.  
  116. System.out.println("\nThe ante was "+ table.getante() +" chips this round.\n");
  117. System.out.println("\nThere are "+ table.getpot()+ " chips in the pot.\n");
  118. if(table.gettablecards().size() != 0){
  119. System.out.println("The cards on the table are ");
  120. table.printtablecards();
  121. }
  122. System.out.println("\nYour hand is ");
  123. players.get(z).gethand();
  124. System.out.println("\nYou have "+ (players.get(z)).getchips() +" chips in your possession.\n");
  125. System.out.println("The most recent bets are as follows: ");
  126. for(int d=0; d<players.size();d++){
  127. if(players.get(d).getallin() > 0){
  128. System.out.println(players.get(d).getName()+" is all in with "+ players.get(d).gettotalbet()+ " chips!");
  129. System.out.println(players.get(d).getName() + " last bet " + players.get(d).getrecentbet() + " chips.");
  130. }
  131. else if(players.get(d).getfold() == 0){
  132. System.out.println(players.get(d).getName() + " has " + players.get(d).getchips() + " chips in his account.");
  133. System.out.println(players.get(d).getName() + " last bet " + players.get(d).getrecentbet() + " chips.");
  134. System.out.println(players.get(d).getName() + "'s total bet is " + players.get(d).gettotalbet() + " chips.\n");
  135. }
  136. }
  137.  
  138. if(foldplayers.size() != 0){
  139. System.out.println("The fold players recent bets are as follows: ");
  140. for(int tt=0; tt<foldplayers.size();tt++){
  141. System.out.println(foldplayers.get(tt).getName()+" FOLDED on round "+ foldplayers.get(tt).getfold());
  142. System.out.println(foldplayers.get(tt).getName() + " last bet " + foldplayers.get(tt).getrecentbet() + " chips.");
  143. System.out.println(foldplayers.get(tt).getName() + "'s total bet is " + foldplayers.get(tt).gettotalbet() + " chips.\n");
  144.  
  145. }
  146. System.out.println(" ");
  147. }
  148.  
  149. String betorder="unknown";
  150. if(z==0){betorder="first";}
  151. else if(z==1){betorder="second";}else if(z==2){betorder="third";}else if(z==3){betorder="fourth";}else if(z==4){betorder="fifth";}else if(z==5){betorder="sixth";}
  152. else if(z==6){betorder="seventh";}else if(z==7){betorder="eighth";}else if(z==8){betorder="ninth";}else if(z==9){betorder="tenth";}
  153. System.out.println("You were "+betorder+" to bet this betting round.");
  154.  
  155. //print the person that raised the bet
  156. //this was changed from nonfoldplayers to just use players
  157. for(int ticka=0; ticka<players.size();ticka++){
  158. if(players.get(ticka).gethighbet() == 1 && players.get(ticka).gettotalbet() != 0){
  159. System.out.println(players.get(ticka).getName()+" has raised the bet!");
  160. }
  161.  
  162. }
  163. System.out.println("\nEnter the amount you want to bet. Enter 0 if you do not wish to bet or if you wish to fold. If your bet amount is not higher than\nthe previous player's TOTAL bet FROM THIS ROUND, then you fold (unless you are ALL IN).\n");
  164. //int newbet = -9999999;
  165. // while(newbet > players.get(z).getchips() || newbet < 0){
  166. //System.out.println("\nPlease enter a bet that is less than or equal to your total chips.");
  167. // newbet = input.nextInt();
  168. // }
  169.  
  170. int newbet=-99999;
  171. do {
  172. try {
  173. System.out.print("\nPlease enter your bet: ");
  174. newbet = input.nextInt();
  175. } catch (InputMismatchException e) {
  176. System.out.print("Please enter a bet that is less than or equal to your total chips.");
  177. }
  178. input.nextLine(); // clears the buffer
  179. } while (newbet > players.get(z).getchips() || newbet < 0);
  180.  
  181.  
  182.  
  183. players.get(z).addtotalbet(newbet);
  184.  
  185. //bet must match last persons bet or be ur total number of chips
  186. //might need to track all in
  187. /*
  188. int poop=0;
  189. //check if the current bet is less than all the previous highest bet
  190. for(int poo; poo<players.size();poo++){
  191. if(z != poo){
  192. if(players.get(z).gettotalbet()<players.get(poo).gettotalbet()){
  193. poo++;
  194. }
  195. }
  196. }
  197. */
  198. //find the highest total bet
  199. int poop=0;
  200. for(int poo=0; poo<players.size();poo++){
  201. if(players.get(poo).gethighbet()==1){
  202.  
  203. poop = players.get(poo).gettotalbet();
  204. }
  205. }
  206.  
  207.  
  208. if(players.get(z).gettotalbet() < poop && newbet != players.get(z).getchips()){
  209. System.out.print("This bet is less than the previous bet THEREFORE, you have FOLDED!");
  210. //sets fold to 1
  211. players.get(z).setfold(table.getbettinground());
  212. players.get(z).subtotalbet(newbet);
  213. foldplayers.add(players.get(z));
  214. }
  215. ///THERE SHOULD BE A CASE FOR ALL IN AND FOR SECOND ROUND FIRST POSITION
  216. else{
  217. players.get(z).setrecentbet(newbet);
  218. players.get(z).removechips(newbet);
  219. table.addpotchips(newbet);
  220. }
  221.  
  222. //all in case
  223. if(players.get(z).getchips() == 0){
  224. System.out.println(players.get(z).getName()+" has went all in with "+players.get(z).gettotalbet()+" chips!");
  225. players.get(z).setallin(players.get(z).gettotalbet());
  226. }
  227.  
  228. System.out.println("\n\nYour turn is now over, please exit the computer when the screen clears and allow the next player their turn.");
  229. // 6 second delay and clear screen
  230. try {
  231. TimeUnit.SECONDS.sleep(6);
  232. }catch (InterruptedException e){
  233. //handle the exception
  234. System.out.println("Please don't input while delaying");
  235. }
  236. // clearScreen();
  237. for(int bp=0;bp<300;bp++){
  238. System.out.println(" ");
  239. }
  240. //non fold array list
  241. if(players.get(z).getfold() == 0){
  242. nonfoldplayers.add(players.get(z));
  243. //set high better (person that originally raised the bet)
  244. //the last added will bet size()-1
  245. //doesnt work for cycle?
  246. //more than one player didnt fold and not on the first player (cycle doesnt matter)
  247. if(nonfoldplayers.size() != 1 && z!=0 && nonfoldplayers.get(nonfoldplayers.size()-1).gettotalbet() > nonfoldplayers.get(nonfoldplayers.size()-2).gettotalbet()){
  248. nonfoldplayers.get(nonfoldplayers.size()-1).sethighbet();
  249. nonfoldplayers.get(nonfoldplayers.size()-2).clearhighbet();
  250. }
  251. //back on first person condition after 1 cycle
  252. else if(table.getbetcycle() != 0 && z==0 && nonfoldplayers.get(nonfoldplayers.size()-1).gettotalbet() > players.get(players.size()-1).gettotalbet()){
  253. nonfoldplayers.get(nonfoldplayers.size()-1).sethighbet();
  254. players.get(players.size()-1).clearhighbet();
  255. }
  256. //first thing on first cycle
  257. else if(z==0 && table.getbetcycle()==0){
  258. nonfoldplayers.get(nonfoldplayers.size()-1).sethighbet();
  259. }
  260.  
  261. }
  262.  
  263.  
  264. //if fold=1 remove them from the arraylist (if they were already added)
  265. //maybe this is not necessary
  266. // else if(players.get(z).getfold() == 1 && table1.getbetcycle() >= 1){
  267. // nonfoldplayers.get(z).remove();
  268. //}
  269. /*
  270.  
  271.  
  272. //index out of bounds here
  273. //set high better (person that originally raised the bet)
  274. if(z!=0 && nonfoldplayers.get(z).getrecentbet() > nonfoldplayers.get(z-1).getrecentbet()){
  275. nonfoldplayers.get(z).sethighbet();
  276. nonfoldplayers.get(z-1).clearhighbet();
  277. }
  278.  
  279. else if(z==0 && nonfoldplayers.get(z).getrecentbet() > 0){
  280. nonfoldplayers.get(z).sethighbet();
  281. }
  282. */
  283.  
  284. }
  285. //adds 1 to cycle
  286. table.addbetcycle();
  287.  
  288. //TO ACCOUNT FOR ALL IN, YOU ONLY NEED TO CHECK THAT THE NON-ALLINS ARE EQUIVALENT TO MOVE ON
  289. ArrayList<Player> nonallinlist = new ArrayList<Player>();
  290. nonallinlist.addAll(nonfoldplayers);
  291.  
  292. /*
  293. ///TEST... THE LISTS ARE THE SAME HERE, SO THIS IS CORRECT
  294. System.out.println("THE NONALLINLIST IS: (SHOULD EQUAL NONFOLDPLAYERS HERE)");
  295. for(int bruh=0;bruh<nonallinlist.size();bruh++){
  296. System.out.println(nonallinlist.get(bruh).getName());}
  297. System.out.println("\nTHE NONFOLDPLAYERS:");
  298. for(int bruhx=0;bruhx<nonfoldplayers.size();bruhx++){
  299. System.out.println(nonfoldplayers.get(bruhx).getName());}
  300. System.out.println("\n\n");
  301.  
  302.  
  303.  
  304. //remove the allins.. THIS WONT WORK BECAUSE REMOVING SOMETHINGS CHANGES EVERYTHING ELSES INDEXES AND ALSO THE ARRAY SIZE
  305. for(int fg=0; fg<nonallinlist.size(); fg++){
  306. // for some reason this print line only grabs
  307. System.out.print(nonallinlist.get(fg).getName()+" has an allin value of "+nonallinlist.get(fg).getallin()+"\n");
  308.  
  309. // if(nonallinlist.get(fg).getallin() != 0){
  310. // nonallinlist.remove(nonallinlist.get(fg));}
  311.  
  312. }
  313. */
  314.  
  315. Iterator<Player> myiterator = nonallinlist.iterator();
  316. while(myiterator.hasNext())
  317. {
  318. if(myiterator.next().getallin() != 0)
  319. myiterator.remove();
  320. }
  321.  
  322. /*
  323.  
  324. System.out.print("if nonzero they are removed");
  325. ///TEST... FOR SOME REASON ONE OF the all-in players isn't being removed from the
  326. System.out.println("\nTHE NONALLINLIST IS:");
  327. for(int bruh=0;bruh<nonallinlist.size();bruh++){
  328. System.out.println(nonallinlist.get(bruh).getName());}
  329. System.out.println("\nTHE NONFOLDPLAYERS ARE:");
  330. for(int bruhx=0;bruhx<nonfoldplayers.size();bruhx++){
  331. System.out.println(nonfoldplayers.get(bruhx).getName());}
  332. */
  333.  
  334.  
  335.  
  336.  
  337. int checking =0;
  338. //checking if all players have the same bet
  339. for(int jk=0; jk<nonallinlist.size();jk++){
  340. if(nonallinlist.get(0).gettotalbet() == nonallinlist.get(jk).gettotalbet() ){
  341. checking++;
  342. }
  343.  
  344. }
  345.  
  346. //if one player left then he or she wins the pot
  347. //there will 1 player in this array and a winnder if
  348. //if size is 1 and you are out of the loop
  349. if (nonfoldplayers.size()==1 ){
  350. System.out.println(nonfoldplayers.get(0).getName()+" has won the pot!");
  351. System.out.println(table.getpot()+" chips have been added to "+nonfoldplayers.get(0).getName()+"'s account.");
  352. nonfoldplayers.get(0).addchips(table.getpot());
  353. table.clearpot();
  354. return nonfoldplayers;
  355. }
  356.  
  357. //needs to handle ALL IN
  358. //if all nonallin players are equal in bets then you can move on
  359. else if(checking == nonallinlist.size() && fix == 0){
  360. String roundstring = "NULL";
  361. if(table.getbettinground() == 1){roundstring = "Three cards";}
  362. else{roundstring = "One card";}
  363. //return nonfoldplayers
  364. System.out.println("The first round of betting has commenced. "+roundstring+" will now be placed on the table\n");
  365. return nonfoldplayers;
  366.  
  367. }
  368.  
  369. else{
  370. betting(nonfoldplayers, table, deck, foldplayers); //{
  371.  
  372.  
  373.  
  374. }
  375.  
  376. return null;
  377.  
  378. /*
  379.  
  380. //HOW DO I USE WHILE LOOP AND HOW DO I GEt LAst person that didnt fold
  381. for(int b=0; b<players.size();b++){
  382. //WHILE LOOP NEEDED HERE
  383. While(y!==0 && players.get().getfold() != 0 && player.get(y).getrecentbet <= player.get(y-1).getrecentbet || ){
  384. //handle raising of bet and checking
  385. for(int y=0; y<players.size();y++){
  386. //must be greater than the last person THAT DID NOT FOLD
  387. if(y!==0 && players.get(y).getfold() != 0 && player.get(y).getrecentbet <= player.get(y-1).getrecentbet){
  388. //cant pinpoint who raised the bet??
  389. System.out.println("The bet has been raised by. You must match the new bet or raise the bet, otherwise you fold.\n");
  390. }
  391. //first person
  392. else if(y==1 && players.get(y).getfold() != 0 && player.get(y).getrecentbet <= last person that didnt fold){
  393.  
  394. }
  395.  
  396. }}}
  397. */
  398.  
  399. // System.out.println("The first round of betting has commenced. Three cards will now be placed on the table\n");
  400. }
  401.  
  402.  
  403.  
  404.  
  405. //VOID OR NOT?? in this form should be players.twopair()?? --nevermind
  406. // form of checkpair(table1, players);
  407. public static void checkpair(Table table, ArrayList<Player> players){
  408. int checker=0;
  409. for(int q=0; q<players.size();q++){
  410. //may need to clear arraylist at start??
  411. //combine hand and tablecards into new arraylist
  412. ArrayList<String> newlist = new ArrayList<String>(players.get(q).returnhand());
  413. newlist.addAll(table.gettablecards());
  414. for(int pair=2; pair<15;pair++){
  415. String pairstring = Integer.toString(pair);
  416. if(pair == 11){pairstring="Jack"; }
  417. else if(pair==12){pairstring="Queen";}
  418. else if(pair==13){pairstring="King";}
  419. else if(pair==14){pairstring="Ace";}
  420.  
  421. //reset paircount for next number
  422. int paircount =0;
  423. for(int h=0; h<newlist.size();h++){
  424. if (newlist.get(h).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ) {
  425. paircount++;
  426.  
  427. if(paircount==2){
  428.  
  429. System.out.println(players.get(q).getName()+" has a pair of "+ pairstring+"'s");
  430. players.get(q).setlowpair(pair);
  431. //set second pair which his the higher pair
  432. if(players.get(q).getlowpair() != 0 && players.get(q).getlowpair() != pair){
  433. players.get(q).sethighpair(pair);}
  434.  
  435. }
  436. if(paircount==3){
  437. System.out.println(players.get(q).getName()+" has three "+ pairstring+"'s");
  438. players.get(q).setthreeofakind(pair);
  439.  
  440. if((players.get(q).getlowpair() != 0 || players.get(q).gethighpair() != 0) && players.get(q).getthreeofakind() != 0 && players.get(q).getthreeofakind() != players.get(q).gethighpair() && players.get(q).getthreeofakind() != players.get(q).getlowpair()){
  441. players.get(q).setfullhouse(players.get(q).getthreeofakind());
  442. System.out.println(players.get(q).getName()+" has a FULLHOUSE!");
  443. }
  444. /*
  445. if(players.get(q).gethighpair()==players.get(q).getthreeofakind() && players.get(q).returnfullhouse() == 0){
  446. players.get(q).clearhighpair();
  447. }
  448. if(players.get(q).getlowpair()==players.get(q).getthreeofakind() && players.get(q).returnfullhouse() == 0){
  449. players.get(q).clearlowpair();
  450. }
  451. */
  452.  
  453.  
  454. }
  455. if(paircount==4){
  456. System.out.println(players.get(q).getName()+" has four "+ pairstring+"'s");
  457. players.get(q).setfourofakind(pair);
  458. if(players.get(q).getlowpair()==players.get(q).getfourofakind()){
  459. players.get(q).clearlowpair();
  460. }
  461. if(players.get(q).gethighpair()==players.get(q).getfourofakind()){
  462. players.get(q).clearhighpair();
  463. }
  464. if(players.get(q).getthreeofakind()==players.get(q).getfourofakind()){
  465. players.get(q).clearfourofakind();
  466. }
  467.  
  468.  
  469. }
  470.  
  471. }
  472. }
  473.  
  474. }
  475.  
  476. }
  477. //return null;
  478. }
  479.  
  480. public static void flush(Table table, ArrayList<Player> players){
  481. for(int q=0; q<players.size();q++){
  482. //may need to clear arraylist at start??
  483. //combine hand and tablecards into new arraylist
  484. ArrayList<String> newlist = new ArrayList<String>(players.get(q).returnhand());
  485. newlist.addAll(table.gettablecards());
  486.  
  487. for(int pair=2; pair<6;pair++){
  488. String pairstring = Integer.toString(pair);
  489. if(pair == 2){pairstring="Spades";}
  490. else if(pair==3){pairstring="Clubs";}
  491. else if(pair==4){pairstring="Diamonds";}
  492. else if(pair==5){pairstring="Hearts";}
  493.  
  494. //reset paircount for next number
  495. int paircount =0;
  496. for(int h=0; h<newlist.size();h++){
  497. if (newlist.get(h).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ) {
  498. paircount++;
  499. if(paircount >=5){
  500. System.out.println(players.get(q).getName()+" has a flush of "+ pairstring+"'s");
  501. players.get(q).setflush();
  502. }
  503.  
  504. }
  505. }
  506.  
  507. }
  508.  
  509.  
  510. }
  511. //return null;
  512. }
  513.  
  514.  
  515.  
  516.  
  517.  
  518. public static void straightflush(Table table, ArrayList<Player> players){
  519. for(int q=0; q<players.size();q++){
  520. //may need to clear arraylist at start??
  521. //combine hand and tablecards into new arraylist
  522. ArrayList<String> newlist = new ArrayList<String>();
  523. newlist.clear();
  524. newlist.addAll(table.gettablecards());
  525. newlist.addAll(players.get(q).returnhand());
  526.  
  527. ArrayList<String> flushcards = new ArrayList<String>();
  528. int flush = 0;
  529. String pairstring ="ok";
  530.  
  531. for(int pair=2; pair<6;pair++){
  532.  
  533. if(pair == 2){pairstring="Spades";}
  534. else if(pair==3){pairstring="Clubs";}
  535. else if(pair==4){pairstring="Diamonds";}
  536. else if(pair==5){pairstring="Hearts";}
  537. //remake the array for each suit
  538. flushcards.clear();
  539.  
  540. //reset paircount for next number
  541. int paircount =0;
  542. for(int h=0; h<newlist.size();h++){
  543. if (newlist.get(h).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ) {
  544. paircount++;
  545. flushcards.add(newlist.get(h));
  546. if(paircount >=5){
  547. flush = 1;
  548. int found=0;
  549. if(flush ==1 && h==newlist.size()-1){
  550. // System.out.println("FLUSH FOUND");
  551.  
  552. for(int m=2;m<14;m++ ){
  553. pairstring = Integer.toString(m);
  554. //sort the cards an check for 5 in a row
  555. if(m == 11){pairstring="Jack";}
  556. else if(m==12){pairstring="Queen";}
  557. else if(m==13){pairstring="King";}
  558. //else if(m==14){pairstring="Ace";}
  559.  
  560.  
  561. int check = found;
  562. // System.out.println("check is "+check);
  563. //System.out.println("the flush cards are ");
  564. //for(String obj:flushcards){
  565. // System.out.println(obj);}
  566.  
  567. for(int k=0; k<flushcards.size();k++){
  568.  
  569. if (flushcards.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ){
  570. found++;
  571. //five continous cards found
  572. // System.out.println(players.get(q).getName()+" found = " +found);
  573. //break so not to add more than once for one card
  574.  
  575. if(found>=5) {
  576. System.out.println(players.get(q).getName()+" has a straightflush of "+ pairstring+" high");
  577. players.get(q).setstraightflush(m);
  578. if(pairstring=="Ace"){System.out.println(players.get(q).getName()+" has a ROYAL FLUSH!");
  579. players.get(q).setroyalflush();
  580. }
  581. }
  582. break;
  583. }
  584.  
  585. }
  586. //if found did not increase, then reset found
  587. if(found == check){found = 0;}
  588.  
  589. //looking as if sorted??
  590. }
  591.  
  592. }
  593. //add all five or more cards to an arraylist
  594. } } }
  595.  
  596. }
  597.  
  598.  
  599. // if(flush == 1 &&){
  600. //check the order here
  601. // System.out.println(players.get(q).getName()+" has a straightflush of "+ pairstring+" high");
  602. // }
  603.  
  604. }
  605. }
  606. //return null;
  607. // }
  608.  
  609.  
  610. public static void straight(Table table, ArrayList<Player> players){
  611. for(int q=0; q<players.size();q++){
  612. //may need to clear arraylist at start??
  613. //combine hand and tablecards into new arraylist
  614. ArrayList<String> newlist = new ArrayList<String>(players.get(q).returnhand());
  615. String pairstring ="ok";
  616. newlist.addAll(table.gettablecards());
  617. int found = 0;
  618. for(int m=2;m<15;m++ ){
  619. pairstring = Integer.toString(m);
  620. //sort the cards an check for 5 in a row
  621. if(m == 11){pairstring="Jack";}
  622. else if(m==12){pairstring="Queen";}
  623. else if(m==13){pairstring="King";}
  624. else if(m==14){pairstring="Ace";}
  625.  
  626.  
  627. int check = found;
  628. // System.out.println("check is "+check);
  629. //System.out.println("the flush cards are ");
  630. //for(String obj:flushcards){
  631. // System.out.println(obj);}
  632.  
  633. for(int k=0; k<newlist.size();k++){
  634.  
  635. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ){
  636. found++;
  637. //five continous cards found
  638. // System.out.println(players.get(q).getName()+" found = " +found);
  639. //break so not to add more than once for one card
  640.  
  641. if(found>=5) {
  642. System.out.println(players.get(q).getName()+" has a straight of "+ pairstring+" high");
  643. players.get(q).setstraight(m);
  644.  
  645. }
  646. break;
  647. }
  648.  
  649. }
  650. //if found did not increase, then reset found
  651. if(found == check){found = 0;}
  652.  
  653. //looking as if sorted??
  654. }
  655.  
  656.  
  657.  
  658. }
  659. //return null;
  660. }
  661.  
  662. public static void highcard(Table table, ArrayList<Player> players){
  663. String newhighcard = "no card found";
  664. String newlowhighcard = "no card found";
  665. int position=0;
  666. int positionA=0;
  667. int positionB=0;
  668. int positionC=0;
  669. int positionD=0;
  670. int positionE=0;
  671.  
  672. for(int q=0; q<players.size();q++){
  673. position=0;
  674. //may need to clear arraylist at start??
  675. //combine hand and tablecards into new arraylist
  676. ArrayList<String> newlist = new ArrayList<String>(players.get(q).returnhand());
  677. String pairstring ="ok";
  678. newlist.addAll(table.gettablecards());
  679. int found = 0;
  680. for(int m=2;m<15;m++ ){
  681. pairstring = Integer.toString(m);
  682. //sort the cards an check for 5 in a row
  683. if(m == 11){pairstring="Jack";}
  684. else if(m==12){pairstring="Queen";}
  685. else if(m==13){pairstring="King";}
  686. else if(m==14){pairstring="Ace";}
  687.  
  688. //store the position of the highcard
  689.  
  690. for(int k=0; k<newlist.size();k++){
  691. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 ){
  692. newhighcard = pairstring;
  693. players.get(q).sethighcard(m);
  694. position=k;
  695.  
  696. }
  697.  
  698.  
  699. }
  700.  
  701. }
  702.  
  703.  
  704. for(int m=2;m<15;m++ ){
  705. pairstring = Integer.toString(m);
  706. //sort the cards an check for 5 in a row
  707. if(m == 11){pairstring="Jack";}
  708. else if(m==12){pairstring="Queen";}
  709. else if(m==13){pairstring="King";}
  710. else if(m==14){pairstring="Ace";}
  711. for(int k=0; k<newlist.size();k++){
  712.  
  713. //findlwohighcard
  714. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 && k != position){
  715. newlowhighcard = pairstring;
  716. players.get(q).setlowhighcard(m);
  717. positionB=k;
  718.  
  719. }
  720.  
  721. }
  722. }
  723.  
  724. for(int m=2;m<15;m++ ){
  725. pairstring = Integer.toString(m);
  726. //sort the cards an check for 5 in a row
  727. if(m == 11){pairstring="Jack";}
  728. else if(m==12){pairstring="Queen";}
  729. else if(m==13){pairstring="King";}
  730. else if(m==14){pairstring="Ace";}
  731. for(int k=0; k<newlist.size();k++){
  732.  
  733. //findlwohighcard
  734. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 && k != positionB && k != position){
  735. // newlowhighcard = pairstring;
  736. players.get(q).setlowhighcardA(m);
  737. positionC=k;
  738.  
  739. }
  740.  
  741. }
  742. }
  743.  
  744. for(int m=2;m<15;m++ ){
  745. pairstring = Integer.toString(m);
  746. //sort the cards an check for 5 in a row
  747. if(m == 11){pairstring="Jack";}
  748. else if(m==12){pairstring="Queen";}
  749. else if(m==13){pairstring="King";}
  750. else if(m==14){pairstring="Ace";}
  751. for(int k=0; k<newlist.size();k++){
  752.  
  753. //findlwohighcard
  754. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 && k != positionC && k != positionB && k != position){
  755. // newlowhighcard = pairstring;
  756. players.get(q).setlowhighcardB(m);
  757. positionD=k;
  758.  
  759. }
  760.  
  761. }
  762. }
  763.  
  764. for(int m=2;m<15;m++ ){
  765. pairstring = Integer.toString(m);
  766. //sort the cards an check for 5 in a row
  767. if(m == 11){pairstring="Jack";}
  768. else if(m==12){pairstring="Queen";}
  769. else if(m==13){pairstring="King";}
  770. else if(m==14){pairstring="Ace";}
  771. for(int k=0; k<newlist.size();k++){
  772.  
  773. //findlwohighcard
  774. if (newlist.get(k).toLowerCase().indexOf(pairstring.toLowerCase()) != -1 && k != positionD && k != positionC && k != positionB && k != position){
  775. // newlowhighcard = pairstring;
  776. players.get(q).setlowhighcardC(m);
  777. positionE=k;
  778.  
  779. }
  780.  
  781. }
  782. }
  783.  
  784. System.out.println(players.get(q).getName()+"'s high card is "+ newhighcard);
  785. System.out.println(players.get(q).getName()+"'s lowhigh card is "+ newlowhighcard);
  786.  
  787.  
  788.  
  789.  
  790. }
  791. //return null;
  792. }
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802. //this method resets all players quantities
  803. public static void resetplayersandtable(ArrayList<Player> players, Table table){
  804. for(int b=0;b<players.size();b++){
  805.  
  806.  
  807. players.get(b).clearhand();
  808. table.cleartablecards();
  809.  
  810. players.get(b).clearflush();
  811. players.get(b).clearhighbet();
  812. players.get(b).clearlowpair();
  813. players.get(b).clearhighpair();
  814. players.get(b).clearroyalflush();
  815. players.get(b).clearfourofakind();
  816. players.get(b).clearstraightflush();
  817. players.get(b).clearfullhouse();
  818. players.get(b).clearthreeofakind();
  819. players.get(b).clearstraight();
  820. players.get(b).clearhighcard();
  821. players.get(b).cleartotalbet();
  822. players.get(b).clearfold();
  823. players.get(b).clearrecentbet();
  824. players.get(b).clearallin();
  825. players.get(b).clearlowhighcard();
  826. players.get(b).clearlowhighcardA();
  827. players.get(b).clearlowhighcardB();
  828. players.get(b).clearlowhighcardC();
  829.  
  830.  
  831.  
  832. table.clearbetcycle();
  833. table.clearbettinground();
  834.  
  835.  
  836. }
  837.  
  838. }
  839.  
  840.  
  841.  
  842. public static void winnerselection(ArrayList<Player> players, Table table){
  843.  
  844.  
  845.  
  846. int l;
  847. int d;
  848. int straightflushcount =0;
  849. int fourofakindcount = 0;
  850. int fullhousecount =0;
  851. int flushcount =0;
  852. int threeofakindcount =0;
  853. int paircount =0;
  854. int straightcount=0;
  855.  
  856.  
  857. ArrayList<Player> narrowedlist = new ArrayList<Player>();
  858. int reward = 0;
  859. int royalflushcount =0;
  860. int winner=0;
  861. //look for royal flush
  862. for(d=0;d<players.size();d++){
  863. if(players.get(d).getroyalflush() == 1){
  864. royalflushcount++;
  865. winner=d;
  866. narrowedlist.add(players.get(d));
  867. }
  868. }
  869.  
  870. //if only 1 royal flush
  871. //should add potchips to him and remove them from table
  872. if(royalflushcount==1){
  873. System.out.print(players.get(winner)+" has won with a ROYAL FLUSH!");
  874. players.get(winner).addchips(table.getpot());
  875. }
  876.  
  877. //if more than 1 player has a royal flush
  878. else if(royalflushcount > 1){
  879. System.out.println("The players below ALL have ROYAL FLUSHES! Therefore the pot will be split between these players:\n");
  880. for(int p=0;p<narrowedlist.size();p++){
  881. reward = (table.getpot())/narrowedlist.size();
  882. narrowedlist.get(p).addchips(reward);
  883. System.out.println(narrowedlist.get(p).getName() +" was rewarded "+ reward+ " chips");
  884. }
  885. }
  886.  
  887.  
  888.  
  889. if(royalflushcount==0){
  890.  
  891. ArrayList<Player> narrowedlistA = new ArrayList<Player>();
  892. reward = 0;
  893. straightflushcount =0;
  894. winner=0;
  895. //hold value of highest straight flush
  896. int highsf =0;
  897.  
  898. int changes =0;
  899. int winnerA =0;
  900. int maxstraightflush =0;
  901. int winnerK =0;
  902. int countL =0;
  903. //look for straight flush
  904. for(d=0;d<players.size();d++){
  905. if(players.get(d).getstraightflush() > 1){
  906. straightflushcount++;
  907. winner=d;
  908. }
  909. /*
  910. //if we dont get the same high value more than once than we can just use the winnerA
  911. if(players.get(d).getstraightflush() == highsf){
  912. changes = 1;
  913. narrowedlistA.add(players.get(d));
  914. }
  915.  
  916. if(players.get(d).getstraightflush() > highsf){
  917. //if there is one greater than we clear all others
  918. narrowedlistA.clear();
  919. highsf = players.get(d).getstraightflush();
  920. winnerA = d;
  921. narrowedlistA.add(players.get(d));
  922. }
  923. */
  924. //corrected here
  925. if(players.get(d).getstraightflush() > maxstraightflush){
  926. maxstraightflush=players.get(d).getstraightflush();
  927. winnerK=d;
  928. }
  929.  
  930. }
  931.  
  932.  
  933. for(d=0;d<players.size();d++){
  934. if(players.get(d).getstraightflush() == players.get(winnerK).getstraightflush()){
  935. countL++;
  936. narrowedlistA.add(players.get(d));
  937. }
  938.  
  939. }
  940.  
  941.  
  942.  
  943. //if only 1 player has a straight flush & thats the highest
  944. if(straightflushcount == 1){
  945. System.out.print(players.get(winner).getName()+" has won with a STRAIGHT FLUSH!");
  946. players.get(winner).addchips(table.getpot());
  947.  
  948. }
  949.  
  950. //need to make sure the flushes arent
  951.  
  952. //case that there are multiple straight FLUSHES
  953. //use high straightflush.. if equal split pot
  954. else if(straightflushcount > 1 && countL==1){
  955. System.out.println(players.get(winnerA).getName()+" has won with a STRAIGHT FLUSH that is higher than the other straight flushes.");
  956. players.get(winnerK).addchips(table.getpot());
  957. }
  958.  
  959. //case that there are multiple straight flushes that are all equal
  960. else if(straightflushcount > 1 && countL>1){
  961.  
  962. System.out.println("The players below ALL have equivalent STRAIGHT FLUSHES! Therefore the pot will be split between these players:\n");
  963. for(int p=0;p<narrowedlistA.size();p++){
  964. reward = (table.getpot())/narrowedlistA.size();
  965. narrowedlistA.get(p).addchips(reward);
  966. System.out.println(narrowedlistA.get(p).getName() +" was rewarded "+ reward+ " chips");
  967. }
  968. }
  969.  
  970.  
  971.  
  972. }
  973.  
  974.  
  975.  
  976. if(royalflushcount==0 && straightflushcount==0){
  977.  
  978. ArrayList<Player> narrowedlistC = new ArrayList<Player>();
  979. reward = 0;
  980. fourofakindcount =0;
  981. winner=0;
  982. //hold value of highest four of a kind
  983. int highsf =1;
  984.  
  985. int changes =0;
  986. int winnerA =0;
  987. int countk=0;
  988. int countl=0;
  989. int highcardmaxZ=0;
  990. //look for four of a kind
  991. for(d=0;d<players.size();d++){
  992. if(players.get(d).getfourofakind() >= highsf){
  993. fourofakindcount++;
  994. winner=d;
  995. highsf=players.get(d).getfourofakind();
  996. }
  997.  
  998. //if we dont get the same high value more than once than we can just use the winnerA
  999. // if(players.get(d).getfourofakind() == highsf){
  1000. // changes = 1;
  1001. // narrowedlistB.add(players.get(d));
  1002. // }
  1003.  
  1004. // if(players.get(d).getfourofakind() > highsf){
  1005. //if there is one greater than we clear all others
  1006. // narrowedlistB.clear();
  1007. // highsf = players.get(d).getfourofakind();
  1008. // winnerA = d;
  1009. // narrowedlistB.add(players.get(d));
  1010.  
  1011. // }
  1012. // }
  1013. }
  1014.  
  1015. for(d=0;d<players.size();d++){
  1016. if(players.get(d).gethighcard() >= highcardmaxZ && players.get(d).getfourofakind() == highsf){
  1017. highcardmaxZ=players.get(d).gethighcard();
  1018. winnerA=d;
  1019.  
  1020. }}
  1021.  
  1022. //check for repetition
  1023. for(d=0;d<players.size();d++){
  1024. if(players.get(d).getfourofakind() == highsf){
  1025. countk++;
  1026. }
  1027. if(players.get(d).gethighcard() == highcardmaxZ && players.get(d).getfourofakind() == highsf){
  1028. countl++;
  1029. narrowedlistC.add(players.get(d));
  1030. }
  1031. }
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037. //1 player has four of a kind
  1038. if(fourofakindcount==1){
  1039. System.out.println(players.get(winner).getName()+" has won with FOUR OF A KIND!");
  1040. players.get(winner).addchips(table.getpot());
  1041. }
  1042.  
  1043. //Multiple players have four of a kind
  1044. else if(fourofakindcount > 1 && countk == 1){
  1045. System.out.println(players.get(winnerA).getName()+" has won with a FOUR OF A KIND that is higher than the other FOUR OF A KINDS.");
  1046. players.get(winnerA).addchips(table.getpot());
  1047.  
  1048. }
  1049.  
  1050. else if(countl > 1 && fourofakindcount >1){
  1051. System.out.print("These players have the exact same FOUR OF A KIND and HIGH CARDS. THE POT WILL BE SPLIT");
  1052. for(l=0;l<narrowedlistC.size();l++){
  1053. reward = table.getpot()/narrowedlistC.size();
  1054. System.out.println(narrowedlist.get(l).getName()+" has been awarded "+reward+" chips.");
  1055. narrowedlistC.get(l).addchips(reward);
  1056. }}
  1057.  
  1058. /*
  1059. //Players have equivalent four of a kinds
  1060. //use kicker to determine winner
  1061. else if(fourofakindcount > 1 && changes==1){
  1062. //find the player with the best high cards
  1063. int maxhighcard =0;
  1064. int maxhighcardB =0;
  1065. int checkz =0;
  1066. int checkzA =0;
  1067. winnerA=0;
  1068. ArrayList<Player> narrowedlistC = new ArrayList<Player>();
  1069. winner=0;
  1070. int k=0;
  1071. for(d=0;d<narrowedlistB.size();d++){
  1072.  
  1073. if (narrowedlistB.get(d).gethighcard() > maxhighcard){
  1074. maxhighcard=narrowedlistB.get(d).gethighcard();
  1075. winner = d;
  1076. }
  1077.  
  1078. }
  1079.  
  1080. for(d=0;d<narrowedlistB.size();d++){
  1081. if (narrowedlistB.get(d).getlowhighcard() > maxhighcardB && narrowedlistB.get(d).gethighcard() == maxhighcard)){
  1082. maxhighcardB=narrowedlistB.get(d).getlowhighcard();
  1083. winnerA = d;
  1084. }
  1085. }
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091. //check for repeated high cards
  1092. for(d=0;d<narrowedlistB.size();d++){
  1093.  
  1094. if (narrowedlistB.get(d).gethighcard() == maxhighcard){
  1095. checkz++;
  1096. }
  1097. if (narrowedlistB.get(d).getlowhighcard() == maxhighcardB){
  1098. checkzA++;
  1099. narrowedlistC.add(narrowedlistB.get(d));
  1100. }
  1101. }
  1102. //ccase that the highcard is NOT repeated
  1103. if(checkz==1){
  1104. System.out.println(narrowedlistB.get(winner).getName() + " has won with a FOUR OF A KIND and a HIGH CARD.");
  1105. narrowedlistB.get(winner).addchips(table.getpot());
  1106. }
  1107. //case that highcards are the same so the lowhighcard is used
  1108. //this case the low high card is not repeated
  1109.  
  1110. //THIS WAS EDITED 12/20/2017 BECAUSE ONLY FIVE CARDS CAN BE USED
  1111. // else if(checkzA==1){
  1112. // System.out.println(narrowedlistB.get(winnerA).getName() + " has won using a FOUR OF A KIND, a HIGH CARD and a 2nd HIGH CARD .");
  1113. // narrowedlistB.get(winner).addchips(table.getpot());
  1114.  
  1115. // }
  1116. //SAME EXACT HAND
  1117. else if(checkz >1){
  1118. System.out.print("These players have the exact same FOUR OF A KIND and HIGH CARDS. THE POT WILL BE SPLIT");
  1119. for(l=0;l<narrowedlistC.size();l++){
  1120. reward = table.getpot()/narrowedlistC.size();
  1121. System.out.println(narrowedlist.get(l).getName()+" has been awarded "+reward+" chips.");
  1122. narrowedlistC.get(l).addchips(reward);
  1123. }
  1124.  
  1125. }
  1126.  
  1127.  
  1128.  
  1129.  
  1130. }
  1131. */
  1132. }
  1133.  
  1134. if(royalflushcount==0 && fourofakindcount==0 && straightflushcount==0){
  1135.  
  1136. fullhousecount =0;
  1137. winner=0;
  1138. int counta =0;
  1139. int countj =0;
  1140. int winnerB=0;
  1141. int countD=0;
  1142. int countq=0;
  1143. ArrayList<Player> narrowedlistC = new ArrayList<Player>();
  1144.  
  1145. for(d=0; d<players.size();d++){
  1146. if(players.get(d).returnfullhouse() > 0){
  1147. fullhousecount++;
  1148. if(players.get(d).returnfullhouse() > players.get(winner).returnfullhouse() ){
  1149. winner=d;
  1150.  
  1151. }
  1152. }
  1153. //searches for highest pair
  1154. // if(players.get(d).gethighpair() > 0){
  1155. // countj++;
  1156. // if(players.get(d).gethighpair() > players.get(winnerB).gethighpair() ){}
  1157. // winnerB=d;
  1158. // countj++;
  1159. // }
  1160. }
  1161.  
  1162. for(d=0; d<players.size();d++){
  1163. if(players.get(d).gethighpair() > players.get(winnerB).gethighpair() && players.get(d).returnfullhouse() == players.get(winner).returnfullhouse() ){
  1164. winnerB=d;
  1165. countj++;
  1166. }
  1167. }
  1168.  
  1169.  
  1170.  
  1171.  
  1172. //check if the high value is repeated
  1173. for(d=0; d<players.size();d++){
  1174. if(players.get(d).returnfullhouse() == players.get(winner).returnfullhouse()){
  1175. counta++;
  1176.  
  1177. }
  1178. //check for repeated highpair
  1179. if(players.get(d).gethighpair() == players.get(winnerB).gethighpair()){
  1180. countD++;
  1181. }
  1182. //if both pair an trio are the same as the max then add to array
  1183. if(players.get(d).gethighpair() == players.get(winnerB).gethighpair() && players.get(d).returnfullhouse() == players.get(winner).returnfullhouse()){
  1184. countq++;
  1185. narrowedlistC.add(players.get(d));
  1186. }
  1187. }
  1188.  
  1189.  
  1190. //FULLHOUSE & only one
  1191. if(fullhousecount ==1){
  1192. System.out.println(players.get(winner).getName()+" has won with a FULLHOUSE!");
  1193. players.get(winner).addchips(table.getpot());
  1194. }
  1195.  
  1196. // multiple fullhouses but one higher trio
  1197. else if(counta==1 && fullhousecount>1){
  1198. System.out.println(players.get(winner).getName()+" has won with a FULLHOUSE! (higher three of a kind)");
  1199. players.get(winner).addchips(table.getpot());
  1200. }
  1201.  
  1202. // multiple fullhouses but one higher pair
  1203. else if(countD==1 && countj>1 && players.get(winnerB).returnfullhouse() == players.get(winner).returnfullhouse() && fullhousecount>1){
  1204. System.out.println(players.get(winnerB).getName()+" has won with a FULLHOUSE! (higher pair)");
  1205. players.get(winnerB).addchips(table.getpot());
  1206. }
  1207.  
  1208. // exact same fullhouses
  1209. else if(countq > 1 && fullhousecount>1){
  1210. System.out.println("The following players have identical FULLHOUSES, THE POT WILL BE SPLIT BETWEEN THEM!");
  1211. for(int p=0;p<narrowedlistC.size();p++){
  1212.  
  1213. reward = table.getpot()/narrowedlistC.size();
  1214. System.out.println(narrowedlistC.get(p).getName()+" has been awarded "+reward+" chip.");
  1215. narrowedlistC.get(p).addchips(reward);
  1216. }
  1217.  
  1218.  
  1219. }
  1220.  
  1221. }
  1222.  
  1223. if(royalflushcount==0 && fourofakindcount==0 && fullhousecount ==0 && straightflushcount==0){
  1224. //SEARCHING FOR FLUSHES AND DETERMING winner
  1225. flushcount=0;
  1226. int flushmax=0;
  1227. int highcard=0;
  1228. int highcardA=0;
  1229. int highcardB=0;
  1230. int highcardC=0;
  1231. int highcardD=0;
  1232. int winnerA=0;
  1233. int winnerB=0;
  1234. int winnerC=0;
  1235. int winnerD=0;
  1236. int winnerE=0;
  1237. int counta=0;
  1238. int countb=0;
  1239. int countc=0;
  1240. int countd=0;
  1241. int counte=0;
  1242. reward=0;
  1243. ArrayList<Player> narrowedlistD = new ArrayList<Player>();
  1244.  
  1245. for(int k=0; k<players.size();k++){
  1246. if(players.get(k).returnflush() ==1){
  1247. flushcount++;
  1248. winner = k;
  1249.  
  1250. //find max of each card position
  1251.  
  1252. }
  1253. }
  1254. //find max of each card position
  1255. // if(players.get(k).gethighcard() > highcard && players.get(k).returnflush()==1){
  1256. // highcard = players.get(k).gethighcard();
  1257. // winnerA=k;
  1258. // }
  1259. /*
  1260. if(players.get(k).getlowhighcard() > highcardA && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard){
  1261. highcardA = players.get(k).getlowhighcard();
  1262. winnerB=k;
  1263. }
  1264. if(players.get(k).getlowhighcardA() > highcardB && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA){
  1265. highcardB = players.get(k).getlowhighcardA();
  1266. winnerC=k;
  1267. }
  1268. if(players.get(k).getlowhighcardB() > highcardC && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA && players.get(k).getlowhighcardA() == highcardB){
  1269. highcardC = players.get(k).getlowhighcardB();
  1270. winnerD=k;
  1271. }
  1272. if(players.get(k).getlowhighcardC() > highcardD && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA && players.get(k).getlowhighcardA() == highcardB && players.get(k).getlowhighcardB() == highcardC){
  1273. highcardD = players.get(k).getlowhighcardC();
  1274. winnerE=k;
  1275. }
  1276. */
  1277.  
  1278.  
  1279.  
  1280. for(int k=0; k<players.size();k++){
  1281. if(players.get(k).gethighcard() > highcard && players.get(k).returnflush()==1){
  1282. highcard = players.get(k).gethighcard();
  1283. winnerA=k;
  1284. }
  1285. }
  1286. for(int k=0; k<players.size();k++){
  1287. if(players.get(k).getlowhighcard() > highcardA && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard){
  1288. highcardA = players.get(k).getlowhighcard();
  1289. winnerB=k;
  1290. }
  1291. }
  1292. for(int k=0; k<players.size();k++){
  1293. if(players.get(k).getlowhighcardA() > highcardB && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA){
  1294. highcardB = players.get(k).getlowhighcardA();
  1295. winnerC=k;
  1296. }
  1297. }
  1298. for(int k=0; k<players.size();k++){
  1299. if(players.get(k).getlowhighcardB() > highcardC && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA && players.get(k).getlowhighcardA() == highcardB){
  1300. highcardC = players.get(k).getlowhighcardB();
  1301. winnerD=k;
  1302. }
  1303. }
  1304. for(int k=0; k<players.size();k++){
  1305. if(players.get(k).getlowhighcardC() > highcardD && players.get(k).returnflush()==1 && players.get(k).gethighcard() == highcard && players.get(k).getlowhighcard()==highcardA && players.get(k).getlowhighcardA() == highcardB && players.get(k).getlowhighcardB() == highcardC){
  1306. highcardD = players.get(k).getlowhighcardC();
  1307. winnerE=k;
  1308. }
  1309. }
  1310.  
  1311.  
  1312. //check if the high value is repeated
  1313. for(d=0; d<players.size();d++){
  1314. if(players.get(d).gethighcard() == players.get(winnerA).gethighcard()){
  1315. counta++;
  1316.  
  1317. }
  1318. //check for repeated lowhigh
  1319. if(players.get(d).getlowhighcard() == players.get(winnerB).getlowhighcard()){
  1320. countb++;
  1321. }
  1322. if(players.get(d).getlowhighcardA() == players.get(winnerC).getlowhighcardA()){
  1323. countc++;
  1324. }
  1325. if(players.get(d).getlowhighcardB() == players.get(winnerD).getlowhighcardB()){
  1326. countd++;
  1327. }
  1328. //all cards are equal
  1329. if(players.get(d).getlowhighcardC() == players.get(winnerE).getlowhighcardC()){
  1330. counte++;
  1331. narrowedlistD.add(players.get(d));
  1332. }
  1333.  
  1334. }
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342. //THERE IS ONLY ONE FLUSH
  1343. if(flushcount == 1){
  1344. System.out.println(players.get(winner).getName()+ " has won with a FLUSH!");
  1345. players.get(winner).addchips(table.getpot());
  1346. }
  1347. //multiple flush highcard1
  1348. else if(flushcount > 1 && counta==1 ){
  1349. System.out.println(players.get(winnerA).getName()+ " has won with a FLUSH! (highcard)");
  1350. players.get(winnerA).addchips(table.getpot());
  1351. }
  1352. //multiple flush highcard2
  1353. else if(flushcount > 1 && countb==1 && players.get(winnerB).gethighcard() ==players.get(winnerA).gethighcard()){
  1354. System.out.println(players.get(winnerB).getName()+ " has won with a FLUSH!");
  1355. players.get(winnerB).addchips(table.getpot());
  1356. }
  1357. //multiple flush highcard3
  1358. else if(flushcount > 1 && countc==1 && players.get(winnerC).gethighcard() ==players.get(winnerA).gethighcard() && players.get(winnerC).getlowhighcard() == players.get(winnerB).getlowhighcard()){
  1359. System.out.println(players.get(winnerC).getName()+ " has won with a FLUSH!");
  1360. players.get(winnerC).addchips(table.getpot());
  1361. }
  1362. //multiple flush highcard4
  1363. else if(flushcount > 1 && countd==1 && players.get(winnerD).gethighcard() ==players.get(winnerA).gethighcard() && players.get(winnerD).getlowhighcard() == players.get(winnerB).getlowhighcard() && players.get(winnerD).getlowhighcardA() == players.get(winnerC).getlowhighcardA()){
  1364. System.out.println(players.get(winnerD).getName()+ " has won with a FLUSH!");
  1365. players.get(winnerD).addchips(table.getpot());
  1366. }
  1367. //multiple flush highcard5
  1368. else if(flushcount > 1 && counte==1 && players.get(winnerE).gethighcard() ==players.get(winnerA).gethighcard() && players.get(winnerE).getlowhighcard() == players.get(winnerB).getlowhighcard() && players.get(winnerE).getlowhighcardA() == players.get(winnerC).getlowhighcardA() && players.get(winnerE).getlowhighcardB() == players.get(winnerD).getlowhighcardB()){
  1369. System.out.println(players.get(winnerE)+ " has won with a FLUSH!");
  1370. players.get(winnerE).addchips(table.getpot());
  1371. }
  1372. //EXACT SAME FLUSH HAND
  1373. else if(flushcount>1 && counte>1){
  1374. System.out.println("The following players have identical FLUSHES, THE POT WILL BE SPLIT BETWEEN THEM!");
  1375. for(int p=0;p<narrowedlistD.size();p++){
  1376. reward = table.getpot()/narrowedlistD.size();
  1377. System.out.println(narrowedlistD.get(p).getName()+" has been awarded "+reward+" chips.");
  1378. narrowedlistD.get(p).addchips(reward);
  1379.  
  1380. }}
  1381.  
  1382. }
  1383. if(royalflushcount==0 && fourofakindcount==0 && fullhousecount ==0 && straightflushcount==0 && flushcount==0){
  1384.  
  1385.  
  1386. ArrayList<Player> narrowedlistX = new ArrayList<Player>();
  1387. reward = 0;
  1388. straightcount =0;
  1389. winner=0;
  1390. //hold value of highest straight
  1391. int highsf =0;
  1392.  
  1393. int changes =0;
  1394. int winnerA =0;
  1395. int maxstraight =0;
  1396. int winnerK =0;
  1397. int countL =0;
  1398. //look for straight flush
  1399. for(d=0;d<players.size();d++){
  1400. if(players.get(d).getstraight() > 1){
  1401. straightcount++;
  1402. winner=d;
  1403. }
  1404.  
  1405. //corrected here
  1406. if(players.get(d).getstraightflush() > maxstraight){
  1407. maxstraight=players.get(d).getstraight();
  1408. winnerK=d;
  1409. }
  1410.  
  1411. }
  1412.  
  1413.  
  1414. for(d=0;d<players.size();d++){
  1415. if(players.get(d).getstraight() == players.get(winnerK).getstraight()){
  1416. countL++;
  1417. narrowedlistX.add(players.get(d));
  1418. }
  1419.  
  1420. }
  1421.  
  1422.  
  1423.  
  1424. //if only 1 player has a straight & thats the highest
  1425. if(straightcount == 1){
  1426. System.out.print(players.get(winner).getName()+" has won with a STRAIGHT!");
  1427. players.get(winner).addchips(table.getpot());
  1428.  
  1429. }
  1430.  
  1431. //need to make sure the flushes arent
  1432.  
  1433. //case that there are multiple straight FLUSHES
  1434. //use high straightflush.. if equal split pot
  1435. else if(straightcount > 1 && countL==1){
  1436. System.out.println(players.get(winnerA).getName()+" has won with a STRAIGHT that is higher than the other straights.");
  1437. players.get(winnerK).addchips(table.getpot());
  1438. }
  1439.  
  1440. //case that there are multiple straight flushes that are all equal
  1441. else if(straightcount > 1 && countL>1){
  1442.  
  1443. System.out.println("The players below ALL have equivalent STRAIGHTS! Therefore the pot will be split between these players:\n");
  1444. for(int p=0;p<narrowedlistX.size();p++){
  1445. reward = (table.getpot())/narrowedlistX.size();
  1446. narrowedlistX.get(p).addchips(reward);
  1447. System.out.println(narrowedlistX.get(p).getName() +" was rewarded "+ reward+ " chips");
  1448. }
  1449. }
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.  
  1461. }
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467. if(royalflushcount==0 && fourofakindcount==0 && fullhousecount ==0 && flushcount ==0 && straightflushcount==0 && straightcount==0){
  1468. ///checking for three of a kind
  1469. threeofakindcount=0;
  1470. int threeofakindmax=0;
  1471. int highcard=0;
  1472. int highcardA=0;
  1473. int highcardB=0;
  1474. int highcardC=0;
  1475. int highcardD=0;
  1476. int winnerA=0;
  1477. int winnerB=0;
  1478. int winnerC=0;
  1479. int winnerD=0;
  1480. int winnerE=0;
  1481. int counta=0;
  1482. int countb=0;
  1483. int countc=0;
  1484. int countd=0;
  1485. int counte=0;
  1486. int lowhighcard =0;
  1487. int countJ =0;
  1488. reward=0;
  1489. ArrayList<Player> narrowedlistJ = new ArrayList<Player>();
  1490. for(int k=0; k<players.size();k++){
  1491. //max threeofakind
  1492. if(players.get(k).getthreeofakind() >1){
  1493. threeofakindcount++;
  1494. winner = k;
  1495. }
  1496.  
  1497. }
  1498.  
  1499.  
  1500. //check if the high value is repeated
  1501. for(d=0; d<players.size();d++){
  1502. if(players.get(d).getthreeofakind() == players.get(winner).getthreeofakind()){
  1503. counta++;
  1504.  
  1505. }
  1506. //find max higcard
  1507. if(players.get(d).gethighcard() > highcard && players.get(d).getthreeofakind() == players.get(winner).getthreeofakind()){
  1508. highcard = players.get(d).gethighcard();
  1509. winnerA=d;
  1510. }
  1511.  
  1512. }
  1513.  
  1514. for(d=0; d<players.size();d++){
  1515. //find maxlowhigh higcard
  1516. if(players.get(d).getlowhighcard() > lowhighcard && players.get(d).getthreeofakind() == players.get(winner).getthreeofakind() && players.get(d).gethighcard() == highcard){
  1517. lowhighcard = players.get(d).getlowhighcard();
  1518. winnerB=d;
  1519. }
  1520.  
  1521. //check for repeated highcard
  1522. if(players.get(d).gethighcard() == players.get(winnerA).gethighpair()){
  1523. countb++;
  1524. }
  1525.  
  1526. }
  1527.  
  1528. for(d=0; d<players.size();d++){
  1529. //check for repeated lowhigh cards
  1530. if(players.get(d).getlowhighcard() == lowhighcard && players.get(d).getthreeofakind() == players.get(winner).getthreeofakind() && players.get(d).gethighcard() == highcard){
  1531. narrowedlistJ.add(players.get(d));
  1532. countJ++;
  1533. }
  1534.  
  1535. }
  1536.  
  1537.  
  1538. //There is only one max three of a kind
  1539. if(counta == 1 && threeofakindcount == 1){
  1540. System.out.println(players.get(winner).getName()+ " has won with a THREE OF A KIND!");
  1541. players.get(winner).addchips(table.getpot());
  1542. }
  1543. //highcard tie breaker
  1544. else if(counta > 1 && countb == 1 && threeofakindcount > 1 && players.get(winnerA).getthreeofakind()==players.get(winner).getthreeofakind()){
  1545. System.out.println(players.get(winnerA).getName()+ " has won with a THREE OF A KIND! (using a high card)");
  1546. players.get(winnerA).addchips(table.getpot());
  1547. }
  1548. //case that a lowhighard breaks the tie
  1549. else if(counta > 1 && countb >1 && countJ==1 && threeofakindcount > 1 && players.get(winnerB).getthreeofakind()==players.get(winner).getthreeofakind() && players.get(winnerB).gethighcard()==players.get(winnerA).gethighcard()){
  1550. System.out.println(players.get(winnerA).getName()+ " has won with a THREE OF A KIND! (using a high card)");
  1551. players.get(winnerB).addchips(table.getpot());
  1552. }
  1553.  
  1554. //same hand
  1555. else if(flushcount>1 && counte>1){
  1556. System.out.println("The following players have identical THREE OF A KIND hands, THE POT WILL BE SPLIT BETWEEN THEM!");
  1557. for(int p=0;p<narrowedlistJ.size();p++){
  1558. reward = table.getpot()/narrowedlistJ.size();
  1559. System.out.println(narrowedlistJ.get(p).getName()+" has been awarded "+reward+" chips.");
  1560. narrowedlistJ.get(p).addchips(reward);
  1561.  
  1562. }
  1563. }
  1564.  
  1565.  
  1566. }
  1567.  
  1568. if(royalflushcount==0 && fourofakindcount==0 && fullhousecount ==0 && flushcount ==0 && straightflushcount==0 && straightcount==0 && threeofakindcount == 0){
  1569.  
  1570. //maxhighpair is 1 because if 0, paircount will add on
  1571. int maxhighpair = 1;
  1572. int maxlowpair =0;
  1573. paircount =0;
  1574. winner = 0;
  1575. int winnerA=0;
  1576. int maxhighpairB=0;
  1577. //check for pair
  1578. //find max values for pair, low pair, highcard, THEN IF THERE is not a low pair
  1579.  
  1580. int maxlowhigh=0;
  1581.  
  1582. int maxhighcard =0;
  1583. int maxlowhighA=0;
  1584. int countsame =0;
  1585. reward =0;
  1586. ArrayList<Player> narrowedlistH = new ArrayList<Player>();
  1587. //CAREFUL... SOMEONES LOWPAIR COULD BE HIGHER THAN SOMEONE ELSES LOW PAIR
  1588. for(int x=0;x<players.size();x++){
  1589. if(players.get(x).gethighpair() >= maxhighpair){
  1590. maxhighpair = players.get(x).gethighpair();
  1591. paircount++;
  1592. // winner =x; maybe the end winner will be the actual winner
  1593. }
  1594. }
  1595.  
  1596. for(int x=0;x<players.size();x++){
  1597. if(players.get(x).getlowpair() >= maxlowpair && players.get(x).gethighpair() == maxhighpair){
  1598. maxlowpair = players.get(x).getlowpair();
  1599. }
  1600. }
  1601.  
  1602. for(int x=0;x<players.size();x++){
  1603. if(players.get(x).gethighcard() >= maxhighcard && players.get(x).gethighpair() == maxhighpair && maxlowpair == players.get(x).getlowpair()){
  1604. maxhighcard = players.get(x).gethighcard();
  1605. }
  1606. }
  1607.  
  1608. for(int x=0;x<players.size();x++){
  1609. if(players.get(x).getlowhighcard() >= maxlowhigh && players.get(x).gethighcard() == maxhighcard && players.get(x).gethighpair() == maxhighpair && maxlowpair == players.get(x).getlowpair()){
  1610. maxlowhigh = players.get(x).getlowhighcard();
  1611. }
  1612. }
  1613. for(int x=0;x<players.size();x++){
  1614. if(players.get(x).getlowhighcardA() >= maxlowhighA && players.get(x).getlowhighcard() == maxlowhigh && players.get(x).gethighcard() == maxhighcard && players.get(x).gethighpair() == maxhighpair && maxlowpair == players.get(x).getlowpair()){
  1615. maxlowhighA = players.get(x).getlowhighcardA();
  1616. winner = x;
  1617. countsame ++;
  1618. narrowedlistH.add(players.get(x));
  1619. }
  1620. }
  1621.  
  1622. //maxhighpair is 1 for a reason
  1623. if(paircount >= 1 && countsame == 1){
  1624. System.out.println(players.get(winner).getName()+ " has won with a HIGH PAIR!");
  1625. players.get(winner).addchips(table.getpot());
  1626. }
  1627.  
  1628. else if(countsame>1 && paircount >=1){
  1629. System.out.println("The following players have identical PAIR hands, THE POT WILL BE SPLIT BETWEEN THEM!");
  1630. for(int p=0;p<narrowedlistH.size();p++){
  1631. reward = table.getpot()/narrowedlistH.size();
  1632. System.out.println(narrowedlistH.get(p).getName()+" has been awarded "+reward+" chips.");
  1633. narrowedlistH.get(p).addchips(reward);
  1634. }
  1635. }
  1636.  
  1637. }
  1638.  
  1639.  
  1640. if(royalflushcount==0 && fourofakindcount==0 && fullhousecount ==0 && flushcount ==0 && straightflushcount==0 && straightcount==0 && threeofakindcount == 0 && paircount ==0){
  1641. //determine winner with only highcards
  1642.  
  1643. ArrayList<Player> narrowedlistT = new ArrayList<Player>();
  1644. int highcard=1;
  1645. int highcardA=0;
  1646. winner = 0;
  1647. int count =0;
  1648. int k=0;
  1649.  
  1650. for(k=0; k<players.size();k++){
  1651.  
  1652. //find max of each card position
  1653. if(players.get(k).gethighcard() >= highcard){
  1654. highcard = players.get(k).gethighcard();
  1655. }
  1656. }
  1657.  
  1658.  
  1659.  
  1660. for(k=0; k<players.size();k++){
  1661. if(players.get(k).getlowhighcard() >= highcardA && players.get(k).gethighcard() == highcard){
  1662. highcardA = players.get(k).getlowhighcard();
  1663. winner=k;
  1664. }
  1665. }
  1666.  
  1667.  
  1668. for(k=0; k<players.size();k++){
  1669. if(players.get(k).getlowhighcard() == highcardA && players.get(k).gethighcard() == highcard){
  1670. narrowedlistT.add(players.get(k));
  1671. count++;
  1672. }
  1673. }
  1674.  
  1675.  
  1676. //only need to do two because the array will be narrowed and 3 cards are shared
  1677.  
  1678. if(count == 1){
  1679. System.out.println(players.get(winner).getName()+ " has won with a HIGH CARD!");
  1680. players.get(winner).addchips(table.getpot());
  1681. }
  1682.  
  1683. else if(count > 1){
  1684. System.out.println("The following players have identical HIGH CARD hands, THE POT WILL BE SPLIT BETWEEN THEM!");
  1685. for(int p=0;p<narrowedlistT.size();p++){
  1686. reward = table.getpot()/narrowedlistT.size();
  1687. System.out.println(narrowedlistT.get(p).getName()+" has been awarded "+reward+" chips.");
  1688. narrowedlistT.get(p).addchips(reward);
  1689. }
  1690.  
  1691. }
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706. }
  1707. //clear the pot at the end
  1708. table.clearpot();
  1709.  
  1710. }
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733. // clipped off this part so that it could be recursive rather than reusing the whole game start up
  1734. public static void gamecycle(ArrayList<Player> players, Table table1, ArrayList<String> deck){
  1735.  
  1736. //add cards back to the deck
  1737. for(int w=0; w<players.size();w++){
  1738. deck.addAll(players.get(w).returnhand());
  1739. }
  1740. deck.addAll(table1.gettablecards());
  1741.  
  1742. resetplayersandtable(players, table1);
  1743. //betting round should start at 1
  1744. table1.setbettinground();
  1745.  
  1746.  
  1747. deck = shuffle(deck);
  1748. deck = shuffle(deck);
  1749. System.out.println("The deck was just reset and shuffled thoroughly.");
  1750.  
  1751. //the ante is x chips
  1752. //set fold is reset
  1753. //previous bets are cleared
  1754. for(int t=0; t<players.size();t++){
  1755. players.get(t).removechips(table1.getante());
  1756. players.get(t).setrecentbet(0);
  1757. players.get(t).clearfold();
  1758. table1.addpotchips(table1.getante());
  1759. }
  1760.  
  1761. //2 cards are dealt
  1762. for(int x=0; x<players.size();x++){
  1763. deal(players.get(x), deck);
  1764. deal(players.get(x), deck);
  1765. //players.get(x).setrecentbet(0);
  1766. }
  1767.  
  1768. ArrayList<Player> nonfoldplayers = new ArrayList<Player>();
  1769. ArrayList<Player> foldplayers = new ArrayList<Player>();
  1770. nonfoldplayers.clear();
  1771.  
  1772. nonfoldplayers.addAll(betting(players, table1, deck, foldplayers));
  1773. table1.addbettinground();
  1774.  
  1775. if (nonfoldplayers.size() == 1){
  1776. //check if any players have zero chips and remove them
  1777. for(int kk=0; kk<players.size();kk++){
  1778.  
  1779. if(players.get(kk).getchips()==0){
  1780. System.out.println("\n"+players.get(kk).getName()+" has run out of chips and is therefore being removed from the table.\n Now.. if you'd kindly get the h*#! outta of here.. \n"+"I always knew people named "+players.get(kk).getName()+" had about three too many chromosomes.");
  1781. players.remove(players.get(kk));
  1782. }
  1783. }
  1784.  
  1785. System.out.println("\n\nA NEW ROUND IS STARTING SHORTLY, please make yourselves comfortable \nand remember to tell Adam how cool you think his virtual Poker lounge is.");
  1786. // 15 second delay and clear screen
  1787. try {
  1788. TimeUnit.SECONDS.sleep(6);
  1789. }catch (InterruptedException e){
  1790. //handle the exception
  1791. System.out.println("Please don't input while delaying");
  1792. }
  1793. // clearScreen();
  1794. for(int bp=0;bp<300;bp++){
  1795. System.out.println(" ");
  1796. }
  1797.  
  1798. // a player has won so start a new game
  1799. gamecycle(players, table1, deck);
  1800. }
  1801.  
  1802. //this is the case that you move on to laying 3 cards on the table
  1803. else{
  1804. dealtable(table1, deck);
  1805. dealtable(table1, deck);
  1806. dealtable(table1, deck);
  1807.  
  1808.  
  1809. ArrayList<Player> nonfoldplayersB = new ArrayList<Player>();
  1810.  
  1811. nonfoldplayersB.addAll(betting(nonfoldplayers, table1, deck, foldplayers));
  1812.  
  1813. //clearnonfold players
  1814. nonfoldplayers.clear();
  1815.  
  1816. table1.addbettinground();
  1817.  
  1818. //this could be called as a method to reduce space
  1819. if (nonfoldplayersB.size() == 1){
  1820. //check if any players have zero chips and remove them
  1821. for(int kk=0; kk<players.size();kk++){
  1822.  
  1823. if(players.get(kk).getchips()==0){
  1824. System.out.println("\n"+players.get(kk).getName()+" has run out of chips and is therefore being removed from the table.\nNow.. if you'd kindly get the h*#! outta of here.. \n"+"I always knew people named "+players.get(kk).getName()+" had about three too many chromosomes.");
  1825. players.remove(players.get(kk));
  1826. }
  1827. }
  1828. System.out.println("\n\nA NEW ROUND IS STARTING SHORTLY, please make yourselves comfortable \nand remember to tell Adam how cool you think his virtual Poker lounge is.");
  1829. // 15 second delay and clear screen
  1830. try {
  1831. TimeUnit.SECONDS.sleep(6);
  1832. }catch (InterruptedException e){
  1833. //handle the exception
  1834. System.out.println("Please don't input while delaying");
  1835. }
  1836. // clearScreen();
  1837. for(int bp=0;bp<300;bp++){
  1838. System.out.println(" ");
  1839. }
  1840.  
  1841. // a player has won so start a new game
  1842. gamecycle(players, table1, deck);
  1843. }
  1844. //1 more card dealt and another round of betting
  1845. else{
  1846. dealtable(table1, deck);
  1847.  
  1848.  
  1849. ArrayList<Player> nonfoldplayersC = new ArrayList<Player>();
  1850.  
  1851. nonfoldplayersC.addAll(betting(nonfoldplayersB, table1, deck, foldplayers));
  1852.  
  1853. nonfoldplayersB.clear();
  1854.  
  1855. table1.addbettinground();
  1856.  
  1857. if (nonfoldplayersC.size() == 1){
  1858. //check if any players have zero chips and remove them
  1859. for(int kk=0; kk<players.size();kk++){
  1860.  
  1861. if(players.get(kk).getchips()==0){
  1862. System.out.println("\n"+players.get(kk).getName()+" has run out of chips and is therefore being removed from the table.\nNow.. if you'd kindly get the h*#! outta of here.. \n"+"I always knew people named "+players.get(kk).getName()+" had about three too many chromosomes.");
  1863. players.remove(players.get(kk));
  1864. }
  1865. }
  1866. System.out.println("\n\nA NEW ROUND IS STARTING SHORTLY, please make yourselves comfortable \nand remember to tell Adam how cool you think his virtual Poker lounge is.");
  1867. // 15 second delay and clear screen
  1868. try {
  1869. TimeUnit.SECONDS.sleep(6);
  1870. }catch (InterruptedException e){
  1871. //handle the exception
  1872. System.out.println("Please don't input while delaying");
  1873. }
  1874. // clearScreen();
  1875. for(int bp=0;bp<300;bp++){
  1876. System.out.println(" ");
  1877. }
  1878.  
  1879. // a player has won so start a new game
  1880. gamecycle(players, table1, deck);
  1881. }
  1882.  
  1883. else{
  1884. //last card delt to the table
  1885. dealtable(table1, deck);
  1886.  
  1887. ArrayList<Player> nonfoldplayersD = new ArrayList<Player>();
  1888.  
  1889.  
  1890. nonfoldplayersD.addAll(betting(nonfoldplayersC, table1, deck, foldplayers));
  1891.  
  1892. nonfoldplayersC.clear();
  1893.  
  1894. table1.addbettinground();
  1895.  
  1896. if (nonfoldplayersD.size() == 1){
  1897. //check if any players have zero chips and remove them
  1898. for(int kk=0; kk<players.size();kk++){
  1899.  
  1900. if(players.get(kk).getchips()==0){
  1901. System.out.println("\n"+players.get(kk).getName()+" has run out of chips and is therefore being removed from the table.\nNow.. if you'd kindly get the h*#! outta of here.. \n"+"I always knew people named "+players.get(kk).getName()+" had about three too many chromosomes.");
  1902. players.remove(players.get(kk));
  1903. }
  1904. }
  1905. System.out.println("\n\nA NEW ROUND IS STARTING SHORTLY, please make yourselves comfortable \nand remember to tell Adam how cool you think his virtual Poker lounge is.");
  1906. // 15 second delay and clear screen
  1907. try {
  1908. TimeUnit.SECONDS.sleep(6);
  1909. }catch (InterruptedException e){
  1910. //handle the exception
  1911. System.out.println("Please don't input while delaying");
  1912. }
  1913. // clearScreen();
  1914. for(int bp=0;bp<300;bp++){
  1915. System.out.println(" ");
  1916. }
  1917.  
  1918.  
  1919.  
  1920. nonfoldplayersD.clear();
  1921. // a player has won so start a new game
  1922. gamecycle(players, table1, deck);
  1923. }
  1924.  
  1925. else{
  1926.  
  1927. // clearScreen();
  1928. for(int bp=0;bp<300;bp++){
  1929. System.out.println(" ");
  1930. }
  1931.  
  1932. System.out.println("All betting rounds and cycles are over.");
  1933. System.out.println("The remaining players hands are about to be shown and a winner will be determined.");
  1934.  
  1935. // 15 second delay and clear screen
  1936. try {
  1937. TimeUnit.SECONDS.sleep(10);
  1938. }catch (InterruptedException e){
  1939. //handle the exception
  1940. System.out.println("Please don't input while delaying");
  1941. }
  1942. // clearScreen();
  1943. for(int bp=0;bp<300;bp++){
  1944. System.out.println(" ");
  1945. }
  1946.  
  1947. //print the addtablecards
  1948. System.out.println("The table cards are:");
  1949. table1.printtablecards();
  1950. System.out.print("\n");
  1951.  
  1952. //print everyones hands
  1953. for(int i=0; i<nonfoldplayersD.size(); i++){
  1954. System.out.println(nonfoldplayersD.get(i).getName() + "'s hand is:");
  1955. nonfoldplayersD.get(i).gethand();
  1956. System.out.print("\n");
  1957. }
  1958.  
  1959.  
  1960. straightflush(table1, nonfoldplayersD);
  1961. //need to check for four of a kind and fullhouse here before clearing the cards array
  1962. flush(table1, nonfoldplayersD);
  1963. checkpair(table1, nonfoldplayersD);
  1964. straight(table1, nonfoldplayersD);
  1965. highcard(table1, nonfoldplayersD);
  1966.  
  1967. System.out.println("\n");
  1968. //THIS IS WHERE A WINNER MUST BE SESLECTED BASED ON CARDS
  1969. winnerselection(nonfoldplayersD, table1);
  1970.  
  1971. nonfoldplayersD.clear();
  1972.  
  1973. //check if any players have zero chips and remove them
  1974. for(int kk=0; kk<players.size();kk++){
  1975.  
  1976. if(players.get(kk).getchips()==0){
  1977. System.out.println("\n"+players.get(kk).getName()+" has run out of chips and is therefore being removed from the table.\nNow.. if you'd kindly get the h*#! outta of here.. \n"+"I always knew people named "+players.get(kk).getName()+" had about three too many chromosomes.");
  1978. players.remove(players.get(kk));
  1979. }
  1980. }
  1981.  
  1982. System.out.println("\n\nA NEW ROUND IS STARTING SHORTLY, please make yourselves comfortable \nand remember to tell Adam how cool you think his virtual Poker lounge is.");
  1983. // 15 second delay and clear screen
  1984. try {
  1985. TimeUnit.SECONDS.sleep(30);
  1986. }catch (InterruptedException e){
  1987. //handle the exception
  1988. System.out.println("Please don't input while delaying");
  1989. }
  1990. // clearScreen();
  1991. for(int bp=0;bp<300;bp++){
  1992. System.out.println(" ");
  1993. }
  1994.  
  1995. // a player has won so start a new game
  1996. gamecycle(players, table1, deck);
  1997.  
  1998. }
  1999.  
  2000.  
  2001. }
  2002.  
  2003.  
  2004. }
  2005.  
  2006.  
  2007.  
  2008.  
  2009. }
  2010. }
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019. public static void pokergame(){
  2020.  
  2021. ArrayList<String> deck = new ArrayList<>();
  2022. // deck.add("Jack"); adds to tail end
  2023. // deck.get(3); returns item at index 3
  2024. // length = deck.size();
  2025.  
  2026. deck.add("2 of Spades (black)");deck.add("2 of Clubs (black)");deck.add("2 of Diamonds (red)");deck.add("2 of Hearts (red)");
  2027. deck.add("3 of Spades (black)");deck.add("3 of Clubs (black)");deck.add("3 of Diamonds (red)");deck.add("3 of Hearts (red)");
  2028. deck.add("4 of Spades (black)");deck.add("4 of Clubs (black)");deck.add("4 of Diamonds (red)");deck.add("4 of Hearts (red)");
  2029. deck.add("5 of Spades (black)");deck.add("5 of Clubs (black)");deck.add("5 of Diamonds (red)");deck.add("5 of Hearts (red)");
  2030. deck.add("6 of Spades (black)");deck.add("6 of Clubs (black)");deck.add("6 of Diamonds (red)");deck.add("6 of Hearts (red)");
  2031. deck.add("7 of Spades (black)");deck.add("7 of Clubs (black)");deck.add("7 of Diamonds (red)");deck.add("7 of Hearts (red)");
  2032. deck.add("8 of Spades (black)");deck.add("8 of Clubs (black)");deck.add("8 of Diamonds (red)");deck.add("8 of Hearts (red)");
  2033. deck.add("9 of Spades (black)");deck.add("9 of Clubs (black)");deck.add("9 of Diamonds (red)");deck.add("9 of Hearts (red)");
  2034. deck.add("10 of Spades (black)");deck.add("10 of Clubs (black)");deck.add("10 of Diamonds (red)");deck.add("10 of Hearts (red)");
  2035. deck.add("Jack of Spades (black)");deck.add("Jack of Clubs (black)");deck.add("Jack of Diamonds (red)");deck.add("Jack of Hearts (red)");
  2036. deck.add("Queen of Spades (black)");deck.add("Queen of Clubs (black)");deck.add("Queen of Diamonds (red)");deck.add("Queen of Hearts (red)");
  2037. deck.add("King of Spades (black)");deck.add("King of Clubs (black)");deck.add("King of Diamonds (red)");deck.add("King of Hearts (red)");
  2038. deck.add("Ace of Spades (black)");deck.add("Ace of Clubs (black)");deck.add("Ace of Diamonds (red)");deck.add("Ace of Hearts (red)");
  2039.  
  2040.  
  2041. Table table1 = new Table();
  2042.  
  2043. //asking for number of players; creating number of player objects based on that input
  2044. //placing these objects in an arraylist
  2045. ArrayList<Player> players = new ArrayList<Player>();
  2046. // int numOfPlayers;
  2047. // System.out.println("Greetings gentlemen, how many players will be participating? ");
  2048. Scanner input = new Scanner(System.in);
  2049. // numOfPlayers = input.nextInt();
  2050.  
  2051. //catch input mismatch exception
  2052. int numOfPlayers=0;
  2053. do {
  2054. try {
  2055. System.out.print("Greetings gentlemen, how many players will be participating: ");
  2056. numOfPlayers = input.nextInt();
  2057. } catch (InputMismatchException e) {
  2058. System.out.print("Invalid number of players. ");
  2059. }
  2060. input.nextLine(); // clears the buffer
  2061. } while (numOfPlayers <= 0);
  2062.  
  2063.  
  2064. for(int i = 0; i < numOfPlayers; i++)
  2065. {
  2066. System.out.println("What is Player " + (i + 1) + "'s name? ");
  2067. String name = input.next();
  2068. // System.out.println("What is Player " + (i + 1) + "'s three digit password? ");
  2069. // int password = input.nextInt();
  2070.  
  2071. //catch input mismatch exception
  2072. int password=0;
  2073. do {
  2074. try {
  2075. System.out.print("What is Player " + (i + 1) + "'s three digit password? ");
  2076. password = input.nextInt();
  2077. } catch (InputMismatchException e) {
  2078. System.out.print("Invalid three digit passowrd. ");
  2079. }
  2080. input.nextLine(); // clears the buffer
  2081. } while (password <= 99 || password >= 1000);
  2082.  
  2083. Player plr = new Player();
  2084. plr.setName(name);
  2085. plr.setpassword(password);
  2086. players.add(plr);
  2087. // clearScreen();
  2088. for(int bp=0;bp<300;bp++){
  2089. System.out.println(" ");
  2090. }
  2091. }
  2092. // System.out.println("What is the ante for this poker game?");
  2093. // table1.setante(input.nextInt());
  2094.  
  2095. int ante=0;
  2096. do {
  2097. try {
  2098. System.out.print("What is the ante for this poker game?");
  2099. ante = input.nextInt();
  2100. } catch (InputMismatchException e) {
  2101. System.out.print("Invalid ante. Max ante is 30 chips. ");
  2102. }
  2103. input.nextLine(); // clears the buffer
  2104. } while (ante <= 1 || ante >= 30);
  2105.  
  2106. table1.setante(ante);
  2107.  
  2108.  
  2109.  
  2110.  
  2111. ///WHERE THE CHANGE HAPPENS
  2112.  
  2113.  
  2114. gamecycle(players, table1, deck);
  2115.  
  2116.  
  2117.  
  2118.  
  2119. }
  2120.  
  2121.  
  2122.  
  2123.  
  2124.  
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.  
  2132.  
  2133.  
  2134.  
  2135.  
  2136. public static void main(String[] args){
  2137.  
  2138. //Needs to handle all in
  2139. //same cards...
  2140. //ask inbetween games for players to be added or moved into an array list of paused players
  2141. //transform into executable?
  2142. //Null pointer exception?
  2143.  
  2144. //line 980 in four of a kind is wrong because only a max of five cards are compared before the pot is split
  2145. //check if works for allin allin fold or fold allin allin
  2146. pokergame();
  2147.  
  2148.  
  2149. //use arraylist becasue of variable length and ability to move things from the middle
  2150. //ArrayList<String> deck = new ArrayList<>();
  2151. // deck.add("Jack"); adds to tail end
  2152. // deck.get(3); returns item at index 3
  2153. // length = deck.size();
  2154.  
  2155. /*
  2156.  
  2157. deck.add("2 of Spades (black)");deck.add("2 of Clubs (black)");deck.add("2 of Diamonds (red)");deck.add("2 of Hearts (red)");
  2158. deck.add("3 of Spades (black)");deck.add("3 of Clubs (black)");deck.add("3 of Diamonds (red)");deck.add("3 of Hearts (red)");
  2159. deck.add("4 of Spades (black)");deck.add("4 of Clubs (black)");deck.add("4 of Diamonds (red)");deck.add("4 of Hearts (red)");
  2160. deck.add("5 of Spades (black)");deck.add("5 of Clubs (black)");deck.add("5 of Diamonds (red)");deck.add("5 of Hearts (red)");
  2161. deck.add("6 of Spades (black)");deck.add("6 of Clubs (black)");deck.add("6 of Diamonds (red)");deck.add("6 of Hearts (red)");
  2162. deck.add("7 of Spades (black)");deck.add("7 of Clubs (black)");deck.add("7 of Diamonds (red)");deck.add("7 of Hearts (red)");
  2163. deck.add("8 of Spades (black)");deck.add("8 of Clubs (black)");deck.add("8 of Diamonds (red)");deck.add("8 of Hearts (red)");
  2164. deck.add("9 of Spades (black)");deck.add("9 of Clubs (black)");deck.add("9 of Diamonds (red)");deck.add("9 of Hearts (red)");
  2165. deck.add("10 of Spades (black)");deck.add("10 of Clubs (black)");deck.add("10 of Diamonds (red)");deck.add("10 of Hearts (red)");
  2166. deck.add("Jack of Spades (black)");deck.add("Jack of Clubs (black)");deck.add("Jack of Diamonds (red)");deck.add("Jack of Hearts (red)");
  2167. deck.add("Queen of Spades (black)");deck.add("Queen of Clubs (black)");deck.add("Queen of Diamonds (red)");deck.add("Queen of Hearts (red)");
  2168. deck.add("King of Spades (black)");deck.add("King of Clubs (black)");deck.add("King of Diamonds (red)");deck.add("King of Hearts (red)");
  2169. deck.add("Ace of Spades (black)");deck.add("Ace of Clubs (black)");deck.add("Ace of Diamonds (red)");deck.add("Ace of Hearts (red)");
  2170.  
  2171. ArrayList<Player> players = new ArrayList<Player>();
  2172. int numOfPlayers=0;
  2173. //System.out.println("Greetings gentlemen, how many players will be participating? ");
  2174. Scanner input = new Scanner(System.in);
  2175. // numOfPlayers = input.nextInt();
  2176.  
  2177.  
  2178. //catch input mismatch exception
  2179. int numOfPlayers=0;
  2180. do {
  2181. try {
  2182. System.out.print("Greetings gentlemen, how many players will be participating: ");
  2183. numOfPlayers = input.nextInt();
  2184. } catch (InputMismatchException e) {
  2185. System.out.print("Invalid number of players. ");
  2186. }
  2187. input.nextLine(); // clears the buffer
  2188. } while (numOfPlayers <= 0);
  2189.  
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195. for(int i = 0; i < numOfPlayers; i++)
  2196. {
  2197. System.out.println("What is Player " + (i + 1) + "'s name? ");
  2198. String name = input.next();
  2199. Player plr = new Player();
  2200. plr.setName(name);
  2201. players.add(plr);
  2202.  
  2203. }
  2204. Table table1 = new Table();
  2205. deck=shuffle(deck);
  2206.  
  2207.  
  2208. //TEST checkpair method
  2209.  
  2210. deal(players.get(0), deck);
  2211. deal(players.get(0), deck);
  2212. // deal(players.get(1), deck);
  2213. // deal(players.get(1), deck);
  2214. deal(players.get(2), deck);
  2215. deal(players.get(2), deck);
  2216. deal(players.get(3), deck);
  2217. deal(players.get(3), deck);
  2218. System.out.println(" ");
  2219. System.out.println(" ");
  2220.  
  2221. dealtable(table1, deck);
  2222. dealtable(table1, deck);
  2223. dealtable(table1, deck);
  2224. dealtable(table1, deck);
  2225. dealtable(table1, deck);
  2226. players.get(1).addhand("3 of Diamonds (black)");
  2227. players.get(1).addhand("4 of Diamonds (black)");
  2228. // players.get(1).addhand("Jack of Diamonds (black)");
  2229. // players.get(1).addhand("8 of Diamonds (black)");
  2230. // table1.addtablecards("5 of Diamonds (black)");
  2231. // table1.addtablecards("6 of Diamonds (black)");
  2232. //table1.addtablecards("7 of Diamonds (black)");
  2233.  
  2234. //print hand
  2235. System.out.println(players.get(0).getName() +"'s hand/n");
  2236. players.get(0).gethand();
  2237. System.out.println(players.get(1).getName() +"'s hand/n");
  2238. players.get(1).gethand();
  2239. System.out.println(players.get(2).getName() +"'s hand/n");
  2240. players.get(2).gethand();
  2241. System.out.println(players.get(3).getName() +"'s hand/n");
  2242. players.get(3).gethand();
  2243. System.out.println(" ");
  2244. System.out.println("Table Cards");
  2245. table1.printtablecards();
  2246. System.out.println(" ");
  2247. System.out.println(" ");
  2248. checkpair(table1, players);
  2249. // flush(table1, players);
  2250. straightflush(table1, players);
  2251. straight(table1, players);
  2252. flush(table1, players);
  2253.  
  2254. //FULLHOUSE
  2255. highcard(table1, players);
  2256.  
  2257. winnerselection(players, table1);
  2258.  
  2259. //for(String obj:deck){
  2260. //System.out.println(obj);}
  2261.  
  2262.  
  2263.  
  2264. //*/
  2265. }
  2266.  
  2267. }
Add Comment
Please, Sign In to add comment