Oct 19, 2014

Online Poker 5 Card Draw Game Using JSP

This article will help you to develop an Online Poker 5 Card Draw Game using jsp. First of all make sure you have a good knowledge in Poker 5 Card Draw game including rules and all. 

In this article we are going to use jsp pages to develop the game. So first set up your environment for jsp development. If development environment is not set up Click Here to setup the environment. 

Step 01:
In side the webapps folder of tomcat create a folder and name it as Poker. Inside it create another folder and name it as WEB-INF.

Step 02:
Create a jsp file and name it as index.jsp inside the Poker folder. Include the following codes to test the environment setup.

<h3>Poker 5 Card Draw - by Easy Code Stuff</h3>

Now run and see if your getting the following output.




Step 03:
Create Card Class to store the information of all the 52 cards. Include the following codes.

<%  
  class Card {

    private int iCardIndex; //From 0 to 51
    private int iCardValue; //From 2 to 14 ( 11=Jack, 12=Queen, 13=King, 14=Ace)
    private int iCardType; //From 1 to 4 ( 1=Spades, 2=Hearts, 3=Clubs, 4=Diamonds)

    public Card() {
    }

    public Card(int _iCardIndex, int _iCardValue, int _iCardType) {
      iCardIndex = _iCardIndex;
      iCardValue = _iCardValue;
      iCardType = _iCardType;
    }

    public int getCardIndex() {
      return iCardIndex;
    }

    public int getCardValue() {
      return iCardValue;
    }

    public int getCardType() {
      return iCardType;
    }
  }
%>

<h3>Card Class Created</h3>

Now run and see if your getting the following output. 
Type The URL as localhost:8080/Poker/Card.jsp




Step 04:
Create another jsp file and name it as Deck.jsp. This jsp file used to create the deck with 52 cards and Deal cards to players. Include the following codes in the Deck.jsp file.

<%@ page import ="java.util.Arrays"%>
<%@ page import ="java.util.ArrayList" %>
<%@ page import ="java.util.Collections" %>

<%@ page import ="java.util.Comparator" %>

<%@ include file="Card.jsp" %>

<%
  class Deck {

    private ArrayList<Card> deck = new ArrayList<Card>();

    //Creating The Deck With 52 Cards
    public Deck() {
      int iIndex = 0;
      for (int iSuit=1; iSuit<5; iSuit++) { //Suits(1=Spades,2=Hearts,3=Clubs,4=Diamonds)
        for (int iValue=2; iValue<15; iValue++) {//Values(11=Jack,12=Queen,13=King,14=Ace)
          deck.add(new Card(iIndex, iValue, iSuit));//Adding Card Objects To The "deck" Array
          iIndex++;
        }
      }
    }

    public void shuffle() {
      Collections.shuffle(deck);
    }

    public Card getCard(int index) {
      return (Card) deck.get(index);
    }

    public int getDeckSize() {
      return deck.size();
    }

    public Card dealCard() {
      return (Card) deck.remove(0);
    }

    public String getHandCard() {
      String current_cards = "";
      for (Card c : deck) {
        current_cards += c.getCardIndex() + ",";
      }
      return current_cards;
    }

    public void addCard(Card c) {
      deck.add(c);
    }

    public ArrayList<Card> getDeckCards() {
      return deck;
    }
  }
%>

<h3>Deck Class Created</h3>

Now run and see if your getting the following output. 
Type The URL as localhost:8080/Poker/Deck.jsp



Step 05:
Create another jsp file and name it as Hand.jsp. This class contains each players cards. And also this class contains two imprtant methods to remove cards from hand and add cards to hand. Include the following codes in the Hand.jsp file.

<%@ include file="Deck.jsp" %>

<%
  class Hand {

    private ArrayList<Card> hand = new ArrayList<Card>();//Cards Available In The Hand

    public void addCard(Card c) {
      hand.add(c);
    }

    public Card removeCard(int iCardIndex) {
      Card x = new Card();
      for (Card c : hand) {
        if (c.getCardIndex() == iCardIndex) {
          x = c;
        }
      }
      hand.remove(x);
      return x;
    }

    public ArrayList<Card> getHandCard() {
      return hand;
    }
  }
%>

<h3>Hand Class Created</h3>

Now run and see if your getting the following output. 
Type The URL as localhost:8080/Poker/Hand.jsp



Step 06:
First target of this development is to develop a Single Player Vs Computer game. 
Create another jsp file and name it as PlayerVsComputerControl.jsp. This class contains all the controls of the game. This is our main class to control the whole game of Player Vs Computer game. Include the following codes in the PlayerVsComputerControl.jsp file. 

<%@ include file="Hand.jsp" %>

<h3>Board Is Created</h3>

<%
   Deck deck = new Deck(); //Creating The Deck Object
   Hand hand_1 = new Hand(); //Creating The Player Hand 1 Object
   Hand hand_2 = new Hand(); //Creating The Player Hand 2 Object
   deck.shuffle(); //Shuffling The Cards In The Deck Object

   //Adding 5 Cards To The Player Hands
   for (int i = 0; i < 5; i++) { 
      hand_1.addCard(deck.dealCard());
      hand_2.addCard(deck.dealCard());
   }

   ArrayList<Card> mydeck = deck.getDeckCards();
   ArrayList<Card> myhand1 = hand_1.getHandCard();
   ArrayList<Card> myhand2 = hand_2.getHandCard();

   //Creating printDeck String For Print The Deck
   String printDeck = "Deck";
   for (Card c : deck.getDeckCards()) {
      printDeck += "<br/>index : ";
      printDeck += "" + c.getCardIndex();
      printDeck += " , Type : ";
      printDeck += "" + c.getCardType();
      printDeck += " , value : ";
      printDeck += "" + c.getCardValue();
   }
   printDeck += "<br/><br/>";
    
   //Creating printHand1 String For Print The Hand1
   String printHand1 = "Hand1";
   for (Card c : hand_1.getHandCard()) {
      printHand1 += "<br/>index : ";
      printHand1 += "" + c.getCardIndex();
      printHand1 += " , Type : ";
      printHand1 += "" + c.getCardType();
      printHand1 += " , value : ";
      printHand1 += "" + c.getCardValue();
   }
   printHand1 += "<br/><br/>";

   //Creating printHand2 String For Print The Hand2
   String printHand2 = "Hand2";
   for (Card c : hand_2.getHandCard()) {
      printHand2 += "<br/>index : ";
      printHand2 += "" + c.getCardIndex();
      printHand2 += " , Type : ";
      printHand2 += "" + c.getCardType();
      printHand2 += " , value : ";
      printHand2 += "" + c.getCardValue();
   }
   printHand2 += "<br/><br/>";

   out.println(printHand1);
   out.println(printHand2);
   out.println(printDeck);

%>

Now run and see if your getting the following output. 
Type The URL as localhost:8080/Poker/PlayerVsComputerControl.jsp







Refresh and see the outputs. You will gets different output all the time. Because all the time you refreshed the page, this class will create the deck and deal cards to the players.

Before going further make sure you have the following file architecture.




Step 07:
Create another jsp file and name it as Rank.jsp. This class contains the check player rankings and all. Include the following codes in the Rank.jsp file.  


<%@ include file="Hand.jsp" %>

<%
  class Rank {
    private ArrayList<Card> handCards;
    private boolean chk = true;

    //Setting The Hand Cards
    public void setHand(ArrayList<Card> _handCards) {
      this.handCards = _handCards;
      sortHandCards();
    }

    //Sorting Hand Cards In Card Value Ascending Order
    public void sortHandCards() { 
      /**
      //Available From jdk 1.7
      Collections.sort(this.handCards, new Comparator<Card>() {
        @Override
        public int compare(Card c1, Card c2) {
          return Integer.compare(c1.getCardValue(),c2.getCardValue());
        }
      });**/
            
      //Copying The Hand Cards To An UnSorted Card Array 
      ArrayList<Card> unSortPlayerCards = new ArrayList<Card>();
      for (Card c : this.handCards) {
        unSortPlayerCards.add(c); 
      }
            
      //Creating An Integer Array Using Card Values & Sorting The Array
      int[] arr = new int[5];
      for(int i=0;i<5;i++){
        arr[i] = unSortPlayerCards.get(i).getCardValue();
      }
      Arrays.sort(arr);//Sorting Integer Array

      //Removing All The Cards From Player Hand & Copying The Sorted Cards
      this.handCards = new ArrayList<Card>();//Hand Cards Intialize
      Card x = new Card();
      for(int a : arr){
        for (Card c : unSortPlayerCards) {
          if(a == c.getCardValue()){
            x = c;
            break;
          }
        }
        this.handCards.add(x);
        unSortPlayerCards.remove(x);
      }
    }

    public ArrayList<Card> getRankCards() {
      return handCards;
    }

  }
%>

Remove all the comments("<h3>  </h3>") that are in the all the jsp files. 
Edit The PlayerVsComputerControl.jsp To Check Player Sorted Cards.


















Step 08:
Now we need to create rank functions to check the all 10 ranks. Following are the 10 ranks in poker 5 card draw and the ranking as priority. 

1. Royal Flush
2. Straight Flush
3. Four Of A Kind 
4. Full House
5. Flush
6. Straight
7. Three Of A Kind

8. Two Pair

9. One Pair
10. High Card


Step 09:
First of all we need to identify the different suits. If all the 5 cards in the same suits. Then ranking must be Royal Flush, Straight Flush or Flush. Following methods checks the Suits of all cards.

Now edit the PlayerVsComputerControl.jsp file. Top the class define some variables.

private int priority, rankcard , highCard;

Then add the methods.

public void checkRank(){


  //Checking For Different Suits

  int suit = 0 , i = 0;

  for (Card c : this.handCards) {

    if (i == 0) {

      suit = c.getCardType();//Saving First Card Suit

    } else if (suit == c.getCardType()) {

      continue;
    } else {
      suit = 0;//If Suit Is Different Suit is 0
      break;
    }
    i++;
  }

  if (suit != 0) { //Same Suit 
             
  } else { //Not Same Suit
                
  }
}

Now run and see the output. 
Type The URL as localhost:8080/Poker/PlayerVsComputerControl.jsp
You will get a error saying "Cannot refer to a non-final variable out inside an inner class defined in a different method". 






This is coming because "out.println();". This wont work here.
so use System.out.println and check the tomcat for output.

if (suit != 0) { //Same Suit 
   System.out.println("Same Suit");
} else { //Not Same Suit
   System.out.println("Not Same Suit");
}




Step 10:
From checkRank() method we are calling all the methods to check the rank. Mainly two scenarios. One is same suit and other one is different suits. If any of the methods gets true in order, that mean card has ranking value then all other methods won't check.

public void checkRank(){

  //Checking For Different Suits
int suit = 0 , i = 0;
   for (Card c : this.handCards) {
       if (i == 0) {
          suit = c.getCardType();//Saving First Card Suit
       } else if (suit == c.getCardType()) {
         continue;
       } else {
         suit = 0;//If Suit Is Different Suit is 0
         break;
       }
       i++;
   }

   if (suit != 0) {//Same Suit 
      if (chk) { 
        checkRoyalFlush();
      }if (chk) { 
        checkStraightFlush();
      }if (chk) { 
        checkFlush();
      }
   } else {//Not Same Suit
      if (chk) { 
        checkFourOfAKind();
      }if (chk) { 
        checkFullHouse();
      }if (chk) { 
        checkStraight();
      }if (chk) { 
        checkThreeOfAKind();
      }if (chk) { 
        checkTwoPair();
      }if (chk) { 
        checkOnePair();
      }if (chk) { 
        HighCard();
      }
   }
}


Step 11:
Creating a method to check the Royal Flush.
Royal flush cards are 10,Jack,Queen,King,Ace.
Card values according to our classes are 10,11,12,13,14
Following function will check the Royal Flush Ranking.
        
public void checkRoyalFlush() {
    if (handCards.get(0).getCardValue() == 10 &&  
        handCards.get(1).getCardValue() == 11 && 
        handCards.get(2).getCardValue() == 12 &&     
        handCards.get(3).getCardValue() == 13 && 
        handCards.get(4).getCardValue() == 14) {
          priority = 1;
          chk = false;
    }
}


Step 12:
Creating a  method to check the Straight Flush. In Straight Flush you need to test two scenarios. One is card values start with A and Ends with 5.In this card values are  A , 2 , 3 , 4 , 5. Second is start with value "n" and ends with with a card value "n+4".

public void checkStraightFlush() {
    int sum = handCards.get(0).getCardValue() + 3;
    int tot = handCards.get(0).getCardValue() + 4;
    
    //Checking For Straight Flush with A in 1st
    if (handCards.get(4).getCardValue() == 14 && 
        handCards.get(0).getCardValue() == 2 && 
        sum == handCards.get(3).getCardValue()) {
           priority = 2;
           rankcard = handCards.get(4).getCardValue();
           chk = false;
    }//Checking Straight Flush For Other values
    else if (tot == handCards.get(4).getCardValue()) {
           priority = 2;
           rankcard = handCards.get(4).getCardValue();
           chk = false;
    }
}


Step 13:
Creating a  method to check the Four Of A Kind rank. In Four Of A Kind cards values can be in two ways. One is "X,N,N,N,N" and the other is "N,N,N,N,X". In this X and N are card values. 

public void checkFourOfAKind() {
   if (handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() && 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() || 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() && 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue()) {
            priority = 3;
            rankcard = handCards.get(2).getCardValue();
            chk = false;
   }
}


Step 14:
Creating a  method to check the Full House rank. In Full House rank cards values can be in two ways. One is "X,X,N,N,N" and the other is "N,N,N,X,X". In this X and N are card values. 

public void checkFullHouse() {
   if (handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue() || 
       handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue()) {
         priority = 4;
         rankcard = handCards.get(2).getCardValue();
         chk = false;
   }
}


Step 15:
Creating a  method to check the Flush rank. In flush you don't need to check the card values. You only need to check for the same card suit.

public void checkFlush() {
    priority = 5;
    rankcard = handCards.get(4).getCardValue();
    chk = false;
}


Step 16:
Creating a  method to check the Straight rank. In Straight you need to test two scenarios. One is card values start with A and Ends with 5.In this card values are  A , 2 , 3 , 4 , 5. Second is start with value "n" and ends with with a card value "n+4". That mean cards with values "N,N+1,N+2,N+3,N+4". In this N is card values.

public void checkStraight() {
   if ((handCards.get(0).getCardValue() + 1) == handCards.get(1).getCardValue() && 
       (handCards.get(1).getCardValue() + 1) == handCards.get(2).getCardValue() && 
       (handCards.get(2).getCardValue() + 1) == handCards.get(3).getCardValue() && 
       (handCards.get(3).getCardValue() + 1) == handCards.get(4).getCardValue() || 
       handCards.get(4).getCardValue() == 14 && 
       handCards.get(0).getCardValue() == 2 && 
       (handCards.get(0).getCardValue() + 1) == handCards.get(1).getCardValue() && 
       (handCards.get(1).getCardValue() + 1) == handCards.get(2).getCardValue() && 
       (handCards.get(2).getCardValue() + 1) == handCards.get(3).getCardValue()) {
          priority = 6;
          rankcard = handCards.get(4).getCardValue();
          chk = false;
   }
}


Step 17:
Creating a  method to check the Three Of A Kind rank. In Three Of A Kind rank cards values can be in three ways. Either "X,X,X,Y,Z" or "Y,X,X,X,Z" or "Y,Z,X,X,X". In this X,Y and Z are card values and not in order.

public void checkThreeOfAKind() {
   if (handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() || 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() && 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() || 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue()) {
          priority = 7;
          rankcard = handCards.get(2).getCardValue();
          chk = false;
   }
}


Step 18:
Creating a  method to check the Two Pair. In Two Pair rank cards values can be in three ways. Either "X,X,Y,Y,Z" or "Z,X,X,Y,Y" or "X,X,Z,Y,Y". In this X,Y and Z are card values and not in order.

public void checkTwoPair() {
   if (handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(2).getCardValue() == handCards.get(3).getCardValue() || 
       handCards.get(1).getCardValue() == handCards.get(2).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue() || 
       handCards.get(0).getCardValue() == handCards.get(1).getCardValue() && 
       handCards.get(3).getCardValue() == handCards.get(4).getCardValue()) {
          priority = 8;
          rankcard = handCards.get(3).getCardValue();
          highCard = handCards.get(1).getCardValue();
          chk = false;
   }
}


Step 19:
Creating a  method to check the One Pair. In One Pair rank cards values can be in four ways. Either "X,X,W,Y,Z" or "W,X,X,Y,Z" or "W,Y,X,X,Z" or "W,Y,Z,X,X". In this W,X,Y and Z are card values and not in order.

public void checkOnePair() {
   if (handCards.get(0).getCardValue() == handCards.get(1).getCardValue()) {
      priority = 9;
      rankcard = handCards.get(1).getCardValue();
      chk = false;
   }
   if (handCards.get(1).getCardValue() == handCards.get(2).getCardValue()) {
      priority = 9;
      rankcard = handCards.get(1).getCardValue();
      chk = false;
   }
   if (handCards.get(2).getCardValue() == handCards.get(3).getCardValue()) {
      priority = 9;
      rankcard = handCards.get(2).getCardValue();
      chk = false;
   }
   if (handCards.get(3).getCardValue() == handCards.get(4).getCardValue()) {
      priority = 9;
      rankcard = handCards.get(4).getCardValue();
      highCard = handCards.get(2).getCardValue();
      chk = false;
   }
}



Step 20:
Creating a  method to check the High Card. Simply High Cad rank mean player doesn't have any above 9 ranks. So rank select the high card of players hand.

public void HighCard() {
   priority = 10;
   rankcard = handCards.get(4).getCardValue();
   highCard = handCards.get(3).getCardValue();
   chk = false;
}


Step 21:
Now lets design the images need for Player Vs Computer page. These are the images I'm going to use.


 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 
 
 




Now lets finish it off with all the codes.

main.css
/*Common For All The Pages Start*/
*{
margin:0px;
padding:0px;
}
.style1 {
    font-size: 30px
}
.style2 {
    font-size: 40px
}
.style4 {
    font-size: 20px;
    font-weight: bold;
}
.style5 {
    color: #FFFFFF;
    text-shadow:1px 1px 3px #080808;
}
.style6 {
    display:block;
    font-size: 25px; 
    font-weight: bold; 
    color: #FFFFFF; 
}
.h3{ /*For Main titles*/
font-family:Arial;
font-size:35px;
font-weight:normal;
color:white;
text-shadow:1px 1px 3px #080808;
}
.h4{ /*For Sub titles*/
font-family:Arial;
font-size:16px;
font-weight:normal;
color:white;
margin-top:20px;
margin-bottom:10px;
margin-left:15px;
}
.h5{ /*For Sub Headings*/
font-family:Arial;
font-size:14px;
font-weight:bold;
color:white;
margin-top:13px;
margin-bottom:8px;
margin-left:25px;
}
/*Common For All The Pages End*/

/*Common For All Buttons Start*/

.button:hover {
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #d29105), color-stop(1, #f6b33d) );
background:-moz-linear-gradient( center top, #d29105 5%, #f6b33d 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#d29105', endColorstr='#f6b33d');
background-color:#d29105;
}
.button:active {
position:relative;
top:1px;
}
/*Common For All Buttons End*/

/*Signin and Registration Form Area Start*/

#signin_wrapper,#register_wrapper{
width:900px;
margin:10px auto 0px;
text-align:left;
}
#btnLogin,#btnRegister{
width:100px;
    height:25px;
-moz-box-shadow: 0px 1px 0px 0px #fed897;
-webkit-box-shadow: 0px 1px 0px 0px #fed897;
box-shadow: 0px 1px 0px 0px #fed897;
background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #f6b33d), color-stop(1, #d29105) );
background:-moz-linear-gradient( center top, #f6b33d 5%, #d29105 100% );
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f6b33d', endColorstr='#d29105');
-moz-border-radius:20px;
-webkit-border-radius:20px;
border-radius:20px;
border:1px solid #eda933;
display:inline-block;
color:#ffffff;
font-family:arial;
font-size:16px;
font-weight:bold;
padding:2px 10px;
    text-shadow: 1px 1px 5px #303030;
margin-top:10px;
margin-bottom:10px;
}
#mainbanner{
padding:20px;
}
label{
display:block;
font-weight:bold;
margin-right:10px;
text-align:right;
width:130px;
line-height:25px;
font-size:15px;
color:white;
text-shadow:1px 1px 3px #080808;
}
#Password,#Username,#RPassword,#RUsername,#RPlayerName{
font-size:15px;
padding:5px;
border:1px solid #b9bdc1;
color:#505050;
    width:250px;
}
.input{
width:300px;
}
.select{
width:312px;
}
.file{
color:white;
width:300px;
}
.hint{
display:none;
}
.field{
margin-bottom:7px;
}
.field:hover .hint{
position:absolute;
display:block;
margin:-30px 0 0 450px;
font-size:15px;
color:white;
padding:7px 10px;
background:rgba(0,0,0,0.6);
border-radius:7px;
-moz-border-radius:7px;
-webkit-border-radius:7px;
}
/*Signin and Registration Form Area End*/

/*Common Footer Area Start*/
#main_footer{
margin-top:20px;
margin-bottom:20px;
padding-top:30px;
clear:both;
font-size:14px;
text-align:center;
}
.fotter:link{
color:#006699;
text-decoration:none;
}
.fotter:visited{
color:#006699;
text-decoration:none;
}
.fotter:hover{
color:#CC6600;
text-decoration:underline;
}
.fotter:active{
color:#CC6600;
text-decoration:underline;
}
/*Common Footer Area End*/


PlayerVsComputer.js
jsonObj = [];
Xmlhttp = getxmlhttlp(); 
count = 0;
BoardCoin = 20;
PlayerBalanceCoin = 0;
PlayerBetCoin = 10;
ComputerBalanceCoin = 240;
ComputerBetCoin = 10;

function getxmlhttlp() {

    return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
}

//Starting Function

$(function() {
    $('#GameHint').html("Player Vs. Computer Game Loading...");
    loadGame();
});

//Loading The Game

function loadGame(){
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {  
            getPlayerBalanceCoin();
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=Load", true);
    xmlhttp.send();
}

//Gets Player Balance Coin

function getPlayerBalanceCoin(){
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { 
            PlayerBalanceCoin = parseInt(xmlhttp.responseText.trim());   
            setTimeout(function() {
                getPlayerCards();
            }, 4000);
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=GetBalanceCoin", true);
    xmlhttp.send();
}

//Control The Turns

function gameTimer() {
    displayCoins();
    RequestChecker = setInterval(function() {
        count++;
        if (count == 1) {
            $(".betting").removeClass("hidden");
            setTurnPicture("Player");
            getHint();
        }
        else if (count == 15) {
            setTurnPicture("Computer");
            $(".betting").addClass("hidden");
        }
        else if (count == 20) {
            controlComputerCoins();
            displayCoins();
            setTurnPicture("Player");
            $('#deal').removeClass("hidden");
        }
        else if (count == 35) {
            setTurnPicture("Computer");
            getFinalHint();
            $('#deal').addClass("hidden");
        }
        else if (count == 40) {
            doComputerDeal();
            setTurnPicture("Player");
            $(".betting").removeClass("hidden");
        }
        else if (count == 55) {
            setTurnPicture("Computer");
            $(".betting").addClass("hidden");
        }
        else if (count == 60) {
            setTurnPicture("GameEnd");
            controlComputerCoins();
            displayCoins();
        }
        else if (count == 61) {
            getComputerCards();
            getRanking();
        }
    }, 1000);
}

//Control The Turn GIF Image

function setTurnPicture(type){
    $(".turn").addClass("hidden");
    if (type == "Player"){
        $("#playerTurn").removeClass("hidden");
    }
    else if(type == "Computer"){
        $("#computerTurn").removeClass("hidden");
    } 
}

//Calling The Computer Turn Before Player Clock Ends

function setComputerTurn(){
    setTurnPicture("Computer");
    if (count < 16) {
        count = 15;
    }
    else if (count < 36) {
        count = 35;
    }else{
        count = 55;
    }
}

//Gets The Player Cards From PlayerVsComputerControl.jsp

function getPlayerCards() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            setPlayerCards(jQuery.parseXML(xmlhttp.responseText.trim()));
            gameTimer();
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=GetCards&playertype=Player", true);
    xmlhttp.send();
}

//Gets The Computer Cards From PlayerVsComputerControl.jsp

function getComputerCards() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            setComputerCards(jQuery.parseXML(xmlhttp.responseText.trim()));
            gameTimer();
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=GetCards&playertype=Computer", true);
    xmlhttp.send();
}

//Binding The Player Cards To The Layout

function setPlayerCards(result) {
    var x = result.getElementsByTagName("player");
    for (var i = 0; i < 5; i++) {
        if (jsonObj.length < 5) {
            item = {};
            item ["index"] = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            item ["value"] = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            item ["select"] = 0;
            jsonObj.push(item);
        }
        else {
            jsonObj[i].index = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            jsonObj[i].value = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            jsonObj[i].select = 0;
        }
        $("#card" + (i)).css('background-image', 'url(img/' + jsonObj[i].index + '.png)').show(1000);
        $("#card" + (i)).removeClass("selected_card");
        $("#card" + (i) + "_check").val(0);
    }
}

//Binding The Computer Cards To The Layout

function setComputerCards(result) {
    var x = result.getElementsByTagName("player");
    for (var i = 0; i < 5; i++) {
        if (jsonObj.length < 5) {
            item = {};
            item ["index"] = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            item ["value"] = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            item ["select"] = 0;
            jsonObj.push(item);
        }
        else {
            jsonObj[i].index = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            jsonObj[i].value = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            jsonObj[i].select = 0;
        }
        $("#card" + (i+5)).css('background-image', 'url(img/' + jsonObj[i].index + '.png)').show(1000);
        $("#card" + (i+5)).removeClass("selected_card");
        $("#card" + (i+5) + "_check").val(0);
    }
}

//Controls The Player Bet Coins

function controlPlayerCoins(type){
    if(type == "Call"){
        
    }else if(type == "Raise"){
        BoardCoin = BoardCoin + 10;
        PlayerBalanceCoin = PlayerBalanceCoin - 10;
        PlayerBetCoin = PlayerBetCoin + 10;
    }else if(type == "AllIn"){
        BoardCoin = BoardCoin + PlayerBalanceCoin;
        PlayerBetCoin = PlayerBetCoin + PlayerBalanceCoin;
        PlayerBalanceCoin = 0;
    }
}

//Controls The Computer Bet Coins(Only Call Works)

function controlComputerCoins(){
    if(PlayerBetCoin > ComputerBetCoin){
        if(PlayerBetCoin - ComputerBetCoin < ComputerBalanceCoin ){
            BoardCoin = BoardCoin + PlayerBetCoin - ComputerBetCoin;
            ComputerBalanceCoin = ComputerBalanceCoin - (PlayerBetCoin - ComputerBetCoin);
            ComputerBetCoin = PlayerBetCoin;
        }else{
            BoardCoin = BoardCoin + ComputerBalanceCoin;
            ComputerBalanceCoin = 0;
            ComputerBetCoin = 250;
        }
    }
}

//Displays The Coin Details In The Screen

function displayCoins(){
    $('#BoardAmount').html(BoardCoin);//Board Bet Amount
    $('#PlayerBalance').html(PlayerBalanceCoin);//Player Balance
    $('#PlayerCurrentBetAmount').html(PlayerBetCoin);//Player Currrent Bet
    $('#ComputerBalance').html(ComputerBalanceCoin);//Player Balance
    $('#ComputerCurrentBetAmount').html(ComputerBetCoin);//Player Currrent Bet
}

//Gets The Player Hint

function getHint() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $('#GameHint').html(xmlhttp.responseText);
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=Hint", true);
    xmlhttp.send();
}

//Gets The Player Final Hint

function getFinalHint() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $('#GameHint').html(xmlhttp.responseText);
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=FinalHint", true);
    xmlhttp.send();
}

//Do The Automatic Computer Deal

function doComputerDeal() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=ComputerDeal", true);
    xmlhttp.send();
}

//Select The Card For Remove From Player Hand

$(".card").on("click", function() {
    var no_of_cards = parseInt($('#number_of_selected_card').val()); // get number of selected card
    if (jsonObj[this.id.substring(4, 5)].select === 1) {
        jsonObj[this.id.substring(4, 5)].select = 0;
        $("#" + this.id).removeClass("selected_card");
        $('#number_of_selected_card').val(no_of_cards - 1); // if deselected the card then reduce no of selected card value by 1
    }
    else if (no_of_cards === 3) {
        for (var i = 0; i < 5; i++) {
            if (jsonObj[i].select !== 1 && i != this.id.substring(4, 5) && jsonObj[i].value == 14) {
                jsonObj[this.id.substring(4, 5)].select = 1;
                $("#" + this.id).addClass("selected_card");
                $('#number_of_selected_card').val(no_of_cards + 1);
            }
        }
    }
    else if (no_of_cards === 4) {

    }

    else {
        jsonObj[this.id.substring(4, 5)].select = 1;
        $("#" + this.id).addClass("selected_card");
        $('#number_of_selected_card').val(no_of_cards + 1); // if select the card the add no of card by one
    }
});

//Removes The Selected Cards and Gets New Cards From Deck

$("#deal").on("click", function() {
    $('#number_of_selected_card').val(0);
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $("#deal").addClass("hidden");
            setComputerTurn();
            setPlayerCards(jQuery.parseXML(xmlhttp.responseText.trim()));
            getFinalHint();
        }
    };
    var card1 = 53, card2 = 53, card3 = 53, card4 = 53, card5 = 53;

    if (jsonObj[0].select === 1)

        card1 = jsonObj[0].index;
    if (jsonObj[1].select === 1)
        card2 = jsonObj[1].index;
    if (jsonObj[2].select === 1)
        card3 = jsonObj[2].index;
    if (jsonObj[3].select === 1)
        card4 = jsonObj[3].index;
    if (jsonObj[4].select === 1)
        card5 = jsonObj[4].index;

    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=Deal&C1=" + card1 + "&C2=" + card2 + "&C3=" + card3 + "&C4=" + card4 + "&C5=" + card5, true);

    xmlhttp.send();
});

//If Player Click The Call

$("#call").on("click", function() {
    $(".betting").addClass("hidden");
    controlPlayerCoins("Call");
    displayCoins();
    setComputerTurn();
});

//If Player Click The Raise

$("#raise").on("click", function() {
    $(".betting").addClass("hidden");
    controlPlayerCoins("Raise");
    displayCoins();
    setComputerTurn();
    updateDatabase("Raise");
});

//If Player Click The Fold

$("#fold").on("click", function() {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $(".betting").addClass("hidden");
            flag = false;
        }
    };
    xmlhttp.open("GET", "PlayerVsComputer?reqtype=fold&player_id=" + PlayerId, true);
    xmlhttp.send();
});

//Get Ranking For The Game

function getRanking(){
    var xmlhttp = getxmlhttlp();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            printGameResults(jQuery.parseXML(xmlhttp.responseText.trim()));
        }
    };
    xmlhttp.open("GET", "PlayerVsComputerControl.jsp?reqtype=PokerRanking", true);
    xmlhttp.send();
}

//Printing The Game Results

function printGameResults(result){
    var PlayerRank = 53, ComputerRank = 53, PlayerRankCard = 53, ComputerRankCard = 53, PlayerHighCard = 53, ComputerHighCard = 53;
    var y = result.getElementsByTagName("result");
    PlayerRank = parseInt(y[0].getElementsByTagName("rank")[0].childNodes[0].nodeValue);
    ComputerRank = parseInt(y[0].getElementsByTagName("rank")[1].childNodes[0].nodeValue);
    PlayerRankCard = parseInt(y[0].getElementsByTagName("rankcard")[0].childNodes[0].nodeValue);
    ComputerRankCard = parseInt(y[0].getElementsByTagName("rankcard")[1].childNodes[0].nodeValue);
    PlayerHighCard = parseInt(y[0].getElementsByTagName("highcard")[0].childNodes[0].nodeValue);
    ComputerHighCard = parseInt(y[0].getElementsByTagName("highcard")[1].childNodes[0].nodeValue);
    
    if(PlayerRank < ComputerRank){
        $('#GameHint').html("You Won The Game");
        PlayerBalanceCoin = PlayerBalanceCoin + BoardCoin;
        displayCoins();
        updateDatabase("Win");
    }else if(PlayerRank > ComputerRank){
        $('#GameHint').html("Computer Won The Game");
    }else{
        if(PlayerRankCard > ComputerRankCard){
            $('#GameHint').html("You Won The Game");
            PlayerBalanceCoin = PlayerBalanceCoin + BoardCoin;
            displayCoins();
            updateDatabase("Win");
        }else if(PlayerRankCard < ComputerRankCard){
            $('#GameHint').html("Computer Won The Game");
        }else{
            if(PlayerHighCard > ComputerHighCard){
                $('#GameHint').html("You Won The Game");
                PlayerBalanceCoin = PlayerBalanceCoin + BoardCoin;
                displayCoins();
                updateDatabase("Win");
            }else if(PlayerHighCard < ComputerHighCard){
                $('#GameHint').html("Computer Won The Game");
            }else{
                $('#GameHint').html("You Won The Game");
                PlayerBalanceCoin = PlayerBalanceCoin + BoardCoin;
                displayCoins();
                updateDatabase("Win");
            }
        } 
    }
}

//Updating The Database For Player Wining

function updateDatabase(type) {
    var updateURL; 
    if (type == "Raise"){
        updateURL = "PlayerVsComputerControl.jsp?reqtype=PlayerRaise";
    }else{
        updateURL = "PlayerVsComputerControl.jsp?reqtype=UpdateRanking&Coins="+BoardCoin;
    }
    var xmlhttp = getxmlhttlp();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        }
    };
    xmlhttp.open("GET", updateURL , true);
    xmlhttp.send();

}


ComputerVsComputer.js
jsonObj = [];
Xmlhttp = getxmlhttlp(); 
count = 0;
BoardCoin = 20;
Computer1BalanceCoin = 240;
Computer1BetCoin = 10;
Computer2BalanceCoin = 240;
Computer2BetCoin = 10;

function getxmlhttlp() {
    return window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
}

//Starting Function
$(function() {
    $('#GameHint').html("Computer Vs. Computer Game Loading...");
    loadGame();
});

//Loading The Game
function loadGame(){
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            $('#GameHint').html("Demo Game Loading");
            setTimeout(function() {
                getComputerCards("Computer1");
            }, 2500);
            setTimeout(function() {
                getComputerCards("Computer2");          
            }, 3500);
            setTimeout(function() {
                displayCoins();
                $('#GameHint').html("Game Started");
                gameTimer();
            }, 3600);
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=Load", true);
    xmlhttp.send();
}

//Gets The Player Cards From ComputerVsComputerControl.jsp
function getComputerCards(type) {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            if(type == "Computer1"){ 
                setComputer1Cards(jQuery.parseXML(xmlhttp.responseText.trim()));
            }else{
                setComputer2Cards(jQuery.parseXML(xmlhttp.responseText.trim()));
            }
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=GetCards&playertype="+type, true);
    xmlhttp.send();
}

//Binding The Computer 1 Cards To The Layout
function setComputer1Cards(result) {
    var x = result.getElementsByTagName("player");
    for (var i = 0; i < 5; i++) {
        if (jsonObj.length < 5) {
            item = {};
            item ["index"] = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            item ["value"] = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            item ["select"] = 0;
            jsonObj.push(item);
        }
        else {
            jsonObj[i].index = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            jsonObj[i].value = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            jsonObj[i].select = 0;
        }
        $("#card" + (i)).css('background-image', 'url(img/' + jsonObj[i].index + '.png)').show(1000);
        $("#card" + (i)).removeClass("selected_card");
        $("#card" + (i) + "_check").val(0);
    }
}

//Binding The Computer 2 Cards To The Layout
function setComputer2Cards(result) {
    var x = result.getElementsByTagName("player");
    for (var i = 0; i < 5; i++) {
        if (jsonObj.length < 5) {
            item = {};
            item ["index"] = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            item ["value"] = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            item ["select"] = 0;
            jsonObj.push(item);
        }
        else {
            jsonObj[i].index = x[0].getElementsByTagName("index")[i].childNodes[0].nodeValue;
            jsonObj[i].value = x[0].getElementsByTagName("value")[i].childNodes[0].nodeValue;
            jsonObj[i].select = 0;
        }
        $("#card" + (i+5)).css('background-image', 'url(img/' + jsonObj[i].index + '.png)').show(1000);
        $("#card" + (i+5)).removeClass("selected_card");
        $("#card" + (i+5) + "_check").val(0);
    }
}

//Displays The Coin Details In The Screen
function displayCoins(){
    $('#BoardAmount').html(BoardCoin);//Board Bet Amount
    $('#Computer_1_Balance').html(Computer1BalanceCoin);//Computer 1 Balance
    $('#Computer_1_Current_Bet_Amount').html(Computer1BetCoin);//Computer 1 Currrent Bet
    $('#Computer_2_Balance').html(Computer2BalanceCoin);//Computer 2 Balance
    $('#Computer_2_Current_Bet_Amount').html(Computer2BetCoin);//Computer 2 Currrent Bet
}

//Control The Turns
function gameTimer() {
    RequestChecker = setInterval(function() {
        count++;
        if (count == 1) {
            $('#GameHint').html("Round 1 : ANTE Round Goes Automatically.Each Player Put Same Bet Amount");
        }
        else if (count == 5) {
            $('#GameHint').html("Round 2 : Initial Betting");
        }
        else if (count == 7) {
            $('#GameHint').html("Round 2 : Computer 1 Turn");
            setTurnPicture("Computer1");
            $(".betting").removeClass("hidden");
        }
        else if (count == 9) {
            $('#GameHint').html("Round 2 : Computer 1 Gets 15 Seconds For Initial Betting.");
        }
        else if (count == 16) {
            $('#GameHint').html("Round 2 : Computer 1 Can Call For Same Bet Amount Or Raise The Bet Amount Or Fold The Cards");
        }
        else if (count == 23) {
            $('#GameHint').html("Round 2 : Computer 1 Raised The Bet Amount");
            $(".betting").addClass("hidden");
            controlComputerCoins("Computer1");
        }
        else if (count == 27) {
            $('#GameHint').html("Round 2 : Computer 2 Turn");
            setTurnPicture("Computer2");       
        }
        else if (count == 31) {
            $('#GameHint').html("Round 2 : Computer 2 Can Call For Same Bet Amount Or Raise The Bet Amount Or Fold The Cards");
        }
        else if (count == 38) {
            $('#GameHint').html("Round 2 : Computer 2 Raised The Bet Amount");
            controlComputerCoins("Computer2");
            setTurnPicture("Round2End");
        }
        else if (count == 42) {
            $('#GameHint').html("Round 2 : Initial Betting Round Over");      
        }
        else if (count == 44) {
            $('#GameHint').html("Round 3 : Deal");      
        }
        else if (count == 46) {
            setTurnPicture("Computer1");
            $('#GameHint').html("Round 3 : Computer 1 Turn");      
        }
        else if (count == 48) {
            $('#GameHint').html("Round 3 : Computer 1 Gets 15 Seconds To Deal Cards From Deck");      
        }
        else if (count == 51) {
            $('#GameHint').html("Round 3 : Computer 1 Will Get A Hint Automatically.");
        }
        else if (count == 54) {
            getHint("Computer1");
        }
        else if (count == 60) {
            $('#GameHint').html("Round 3 : Computer 1 Will Deal Cards For Better Hand");
            doComputerDeal("Computer1");
        }
        else if (count == 63) {
            $('#GameHint').html("Round 3 : Computer 1 Will Get New Cards");
        }
        else if (count == 67) {
            setTurnPicture("Computer2");
            $('#GameHint').html("Round 3 : Computer 2 Turn");      
        }
        else if (count == 69) {
            $('#GameHint').html("Round 3 : Computer 2 Gets 15 Seconds To Deal Cards From Deck");      
        }
        else if (count == 72) {
            $('#GameHint').html("Round 3 : Computer 2 Will Get A Hint Automatically.");
        }
        else if (count == 75) {
            getHint("Computer2");
        }
        else if (count == 81) {
            $('#GameHint').html("Round 3 : Computer 2 Will Deal Cards For Better Hand");
            doComputerDeal("Computer2");
        }
        else if (count == 84) {
            $('#GameHint').html("Round 3 : Computer 2 Will Get New Cards");
            setTurnPicture("Round3End");
        }
        else if (count == 87) {
            $('#GameHint').html("Round 3 : Deal Round Over");
        }
        else if (count == 90) {
            $('#GameHint').html("Round 4 : Betting");
        }
        else if (count == 92) {
            $('#GameHint').html("Round 4 : Computer 1 Turn");
            setTurnPicture("Computer1");
            $(".betting").removeClass("hidden");
        }
        else if (count == 94) {
            $('#GameHint').html("Round 4 : Computer 1 Gets 15 Seconds For Betting.");
        }
        else if (count == 101) {
            $('#GameHint').html("Round 4 : Computer 1 Gets The Final Hint As Per Ranking");
        }
        else if (count == 105) {
            getFinalHint("Computer1");
        }
        else if (count == 111) {
            $('#GameHint').html("Round 4 : Computer 1 Can Call For Same Bet Amount Or Raise The Bet Amount Or Fold The Cards");
        }
        else if (count == 118) {
            $('#GameHint').html("Round 4 : Computer 1 Raised The Bet Amount");
            $(".betting").addClass("hidden");
            controlComputerCoins("Computer1");
        }
        else if (count == 122) {
            $('#GameHint').html("Round 4 : Computer 2 Turn");
            setTurnPicture("Computer2");       
        }
        else if (count == 124) {
            $('#GameHint').html("Round 4 : Computer 2 Gets 15 Seconds For Betting.");
        }
        else if (count == 128) {
            getFinalHint("Computer2");
        }
        else if (count == 134) {
            $('#GameHint').html("Round 4 : Computer 2 Can Call For Same Bet Amount Or Raise The Bet Amount Or Fold The Cards");
        }
        else if (count == 141) {
            $('#GameHint').html("Round 4 : Computer 2 Raised The Bet Amount");
            controlComputerCoins("Computer2");
            setTurnPicture("Round4End");
        }
        else if (count == 144) {
            $('#GameHint').html("Round 4 : Betting Round Over");      
        }
        else if (count == 146) {
            $('#GameHint').html("Calculating Ranking Results...");      
        }
        else if (count == 148) {
            getRanking();      
        }
    }, 1000);
}

//Control The Turn GIF Image
function setTurnPicture(type){
    $(".turn").addClass("hidden");
    if (type == "Computer1"){
        $("#computer_1_Turn").removeClass("hidden");
    }
    else if(type == "Computer2"){
        $("#computer_2_Turn").removeClass("hidden");
    } 
}

//Controls The Computer Bet Coins
function controlComputerCoins(type){
    if(type == "Computer1"){ 
        BoardCoin = BoardCoin + 10;
        Computer1BalanceCoin = Computer1BalanceCoin - 10;
        Computer1BetCoin = Computer1BetCoin + 10;
        displayCoins();
    }else{
        BoardCoin = BoardCoin + 10;
        Computer2BalanceCoin = Computer2BalanceCoin - 10;
        Computer2BetCoin = Computer2BetCoin + 10;
        displayCoins();
    }
}

//Gets The Computer Hint
function getHint(type) {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            if (type == "Computer1"){
                $('#GameHint').html("Round 3 : Computer 1 Hint: "+xmlhttp.responseText);
            }else{
                $('#GameHint').html("Round 3 : Computer 2 Hint: "+xmlhttp.responseText);
            }
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=Hint&playertype="+type, true);
    xmlhttp.send();
}

//Gets The Computer Final Hint
function getFinalHint(type) {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            if (type == "Computer1"){
                $('#GameHint').html("Round 4 : Computer 1 Ranking: "+xmlhttp.responseText);
            }else{
                $('#GameHint').html("Round 4 : Computer 2 Ranking: "+xmlhttp.responseText);
            }
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=FinalHint&playertype="+type, true);
    xmlhttp.send();
}

//Do The Automatic Computer Deal
function doComputerDeal(type) {
    var xmlhttp = Xmlhttp;
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            getComputerCards(type);
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=ComputerDeal&playertype="+type, true);
    xmlhttp.send();
}

//Get Ranking For The Game
function getRanking(){
    var xmlhttp = getxmlhttlp();
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            calculateGameResults(jQuery.parseXML(xmlhttp.responseText.trim()));
        }
    };
    xmlhttp.open("GET", "ComputerVsComputerControl.jsp?reqtype=PokerRanking", true);
    xmlhttp.send();
}

//Calculating The Game Results
function calculateGameResults(result){
    var Player1Rank = 53, Player2Rank = 53, Player1RankCard = 53, Player2RankCard = 53, Player1HighCard = 53, Player2HighCard = 53;
    var y = result.getElementsByTagName("result");
    Player1Rank = parseInt(y[0].getElementsByTagName("rank")[0].childNodes[0].nodeValue);
    Player2Rank = parseInt(y[0].getElementsByTagName("rank")[1].childNodes[0].nodeValue);
    Player1RankCard = parseInt(y[0].getElementsByTagName("rankcard")[0].childNodes[0].nodeValue);
    Player2RankCard = parseInt(y[0].getElementsByTagName("rankcard")[1].childNodes[0].nodeValue);
    Player1HighCard = parseInt(y[0].getElementsByTagName("highcard")[0].childNodes[0].nodeValue);
    Player2HighCard = parseInt(y[0].getElementsByTagName("highcard")[1].childNodes[0].nodeValue);
    
    if(Player1Rank < Player2Rank){
        printGameResults("Computer1"); 
    }else if(Player1Rank > Player2Rank){
        printGameResults("Computer2"); 
    }else{
        if(Player1RankCard > Player2RankCard){
            printGameResults("Computer1");   
        }else if(Player1RankCard < Player2RankCard){
            printGameResults("Computer2"); 
        }else{
            if(Player1HighCard > Player2HighCard){
                printGameResults("Computer1"); 
            }else if(Player1HighCard < Player2HighCard){
                printGameResults("Computer2"); 
            }else{
                printGameResults("Computer1"); 
            }
        } 
    }
}

//Printing The Game Results
function printGameResults(type){
    if(type == "Computer1"){
        $('#GameHint').html("Computer 1 Won The Game");
        Computer1BalanceCoin = Computer1BalanceCoin + BoardCoin;
        displayCoins(); 
    }else{
        $('#GameHint').html("Computer 2 Won The Game");
        Computer2BalanceCoin = Computer2BalanceCoin + BoardCoin;
        displayCoins();
    }

}


dbconfig.jsp
<%
    class DBConfig{
        public String host = "jdbc:mysql://localhost:3306";
        public String db   = "Poker";
        public String user = "root";
        public String pass = "";
    }
%>


DBConnection.jsp
<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%
    String sType = request.getParameter("Type");
    String sUserId = (String)session.getAttribute("suserid");
 
    Connection mysqlCon = null;
    Statement stmt = null;
    ResultSet rs = null;
    String query = "";

    try {
        DBConfig db = new DBConfig();
                Class.forName("com.mysql.jdbc.Driver");
                mysqlCon = DriverManager.getConnection(db.host+"/"+db.db, db.user, db.pass);
                stmt = mysqlCon.createStatement();
     
        if(sType.equals("getBalance")){
            query = "SELECT `Coins` FROM `user` WHERE `UserId` = " + sUserId;
            rs = stmt.executeQuery(query);
            int coins = 0;
            if (rs.next()){
                coins = rs.getInt(1);
            }
            out.print(coins);
        }
    }
    catch (Exception e) {
        System.out.println("Error Poker DBConnection"+e);
    }
    finally {
        stmt.close();
        mysqlCon.close();
    }
%>


SigninDB.jsp
<html>
    <body>
        <%@ page language="java" session="true"%>
        <%@ page import ="java.sql.*" %>
        <%@ page import ="javax.sql.*" %>
        <%@ include file="dbconfig.jsp" %>
     
        <%
            String username = request.getParameter("Username");
            String password = request.getParameter("Password");

            Connection mysqlCon = null;
            Statement stmt = null;
         
            try {
                DBConfig db = new DBConfig();
                Class.forName("com.mysql.jdbc.Driver");
                mysqlCon = DriverManager.getConnection(db.host+"/"+db.db, db.user, db.pass);
                stmt = mysqlCon.createStatement();
             
                String query = "SELECT `UserId`,`Password`,`Name` FROM `user` WHERE `UserName` = '"+username+"'";
                ResultSet rs = stmt.executeQuery(query);
             
                if (rs.next()){
                    String dbUserId = rs.getString(1);
                    String dbPassword = rs.getString(2);
                    String dbName = rs.getString(3);

                    if(password.equals(dbPassword)){
                        query = "UPDATE `user` SET `Coins` = `Coins`+50 ,`LastLog`= CURRENT_DATE WHERE `LastLog` < CURRENT_DATE AND `UserId`="+dbUserId;
                        stmt.executeUpdate(query);//Daily Bonus
                        session.setAttribute("susername", username);//Username
                        session.setAttribute("spassword", password);//Password
                        session.setAttribute("suserid", dbUserId);//UserId
                        session.setAttribute("sname", dbName);//Name
                        response.sendRedirect("PokerHome.jsp");
                    }
                    else{
session.setAttribute("sattempt","incorrect");
                        response.sendRedirect("index.jsp");
                    }
}
else{
                    response.sendRedirect("index.jsp");
                    session.setAttribute("sattempt","incorrect");
}
            }
            catch (Exception e) {
                System.out.println(e);
            }
            finally {
                stmt.close();
mysqlCon.close();
            }
        %>
    </body>
</html>


RegisterDB.jsp
<html>
    <body>
        <%@ page language="java" session="true"%>
        <%@ page import ="java.sql.*" %>
        <%@ page import ="javax.sql.*" %>
        <%@ include file="dbconfig.jsp" %>

        <%
            String playername = request.getParameter("RPlayerName");
            String username = request.getParameter("RUsername");
            String password = request.getParameter("RPassword");

            Connection mysqlCon = null;
            Statement stmt = null;
         
            try {
                DBConfig db = new DBConfig();
                Class.forName("com.mysql.jdbc.Driver");
                mysqlCon = DriverManager.getConnection(db.host+"/"+db.db, db.user, db.pass);
                stmt = mysqlCon.createStatement();
             
                String query = "INSERT INTO `user`(`UserName`, `Password`, `Name`, `Coins`, `GamesPlayed`, `GamesWon`) VALUES ('"+username+"','"+password+"','"+playername+"',250,0,0)";
                int i = stmt.executeUpdate(query);
             
                if (i==0){
                    response.sendRedirect("index.jsp");
                    session.setAttribute("sattempt","registersuccessful");
}
else{
                    response.sendRedirect("index.jsp");
                    session.setAttribute("sattempt","registerfail");
}
            }
            catch (Exception e) {
                System.out.println(e);
            }
            finally {
                stmt.close();
mysqlCon.close();
            }
        %>
    </body>
</html>


index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta name="keywords" />
        <title>Code Hunters - 5 Card Draw</title>
        <link rel="stylesheet" href="css/main.css">
        <link rel="icon" href="img/icon.jpg">
        <style>
            #myfoter{
                text-align: center;
                position: absolute;
                top: 615px;
                left: 490px;
                color: white;
            }
        </style>
    </head>
        <body background="img/LoginBackground.jpg">
            <center>
                <table border="0" >
                    <tr>
                        <td>&nbsp;</td>
                        <td align="center" >
                            <div id="screenMidView">
                                <div align="center" class="style5">
                                    <p>&nbsp;</p>
                                    <span class="style2"><img src="img/Five_Card_Draw_Poker_logo.jpg" width="151" height="151" /></span>
                                    <p><font face="Bernard MT Condensed" ><span class="style2">WELCOME TO POKER - 5 CARD DRAW </span></font></p>
                                </div>
                                <br/>
                             
                                <table border="0"> <!--start of LOGIN FORM -->
                                    <tr>
                                        <td>
                                            <form action="SigninDB.jsp" name="LoginForm" id="LoginForm" method="post">
                                                <div align="center">
                                                    <table border="0">
                                                        <tr>
                                                            <th width="100%" colspan="3"><span class="style6">LOGIN&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></th>
                                                        </tr>
                                                        <tr>
                                                            <td width="3%" class="style5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                                            <td width="30%" class="style5"><div align="right"><span class="style4">Username&nbsp;&nbsp;</span></div>
                                                            <td><input type="text" name="Username" id="Username" placeholder="Username" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td class="style5">&nbsp;</td>
                                                            <td class="style5"><div align="right"><span class="style4">Password&nbsp;&nbsp;</span></div></td>
                                                            <td><input type="Password" name="Password" id="Password" placeholder="Password" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td></td>
                                                            <td></td>
                                                            <td></td>
                                                            <td><input type="submit" name="btnLogin" id="btnLogin" value="Sign In"/></td>
                                                        </tr>
                                                    </table>
                                                </div>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                             
                                <br/>
                             
                                <table border="0"> <!--start of Register FORM -->
                                    <tr>
                                        <td>
                                            <form action="RegisterDB.jsp" name="RegisterForm" id="RegisterForm" method="post">
                                                <div align="center">
                                                    <table border="0">
                                                        <tr>
                                                            <th width="100%" colspan="3"><span class="style6">REGISTER&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></th>
                                                        </tr>
                                                        <tr>
                                                            <td width="3%" class="style5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                                            <td width="30%" class="style5"><div align="right"><span class="style4">PlayerName&nbsp;&nbsp;</span></div>
                                                            <td><input type="text" name="RPlayerName" id="RPlayerName" placeholder="Player Name" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="3%" class="style5">&nbsp;</td>
                                                            <td width="30%" class="style5"><div align="right"><span class="style4">Username&nbsp;&nbsp;</span></div>
                                                            <td><input type="text" name="RUsername" id="RUsername" placeholder="Username" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td width="3%" class="style5">&nbsp;</td>
                                                            <td width="30%" class="style5"><div align="right"><span class="style4">Password&nbsp;&nbsp;</span></div>
                                                            <td><input type="text" name="RPassword" id="RPassword" placeholder="Password" /></td>
                                                        </tr>
                                                        <tr>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                            <td>&nbsp;</td>
                                                            <td><input type="submit" name="btnRegister" id="btnRegister" value="Register"/></td>
                                                            <td></td>
                                                        </tr>
                                                     
                                                    </table>
                                                </div>
                                            </form>
                                        </td>
                                    </tr>
                                </table>
                                       
                            </div>
                        </td>          
                    </tr>
                </table>
                <div id="myfoter">&#169; 2014 Code Hunters - 5 Card Draw. All Rights Reserved.</div>
            </center>

            <script type="text/javascript" src="js/jquery.js"></script>
            <script type="text/javascript" >
                $(document).ready(function() {
                    $('#LoginForm').submit(function() {
                        if (!$('#Username').val()) {
                            alert("Please Enter The Username");
                            return false;
                        }
                        else if (!$('#Password').val()) {
                            alert("Please Enter The Password");
                            return false;
                        }
                    });
                });
            </script>
            <script type="text/javascript" >
                $(document).ready(function() {
                    $('#RegisterForm').submit(function() {
                        if (!$('#RPlayerName').val()) {
                            alert("Please Enter The Player Name");
                            return false;
                        }
                        if (!$('#RUsername').val()) {
                            alert("Please Enter The Username");
                            return false;
                        }
                        else if (!$('#RPassword').val()) {
                            alert("Please Enter The Password");
                            return false;
                        }
                    });
                });
            </script>
        </body>
</html>


SaveRankingDB.jsp
<%@ page import="org.omg.CORBA.Current"%>
<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%
    String TableId = (String) session.getAttribute("stableid");//TableId Of Game Played
    String Rank1 = request.getParameter("Rank1");//Rank 1's UserId
    String Rank2 = request.getParameter("Rank2");//Rank 2's UserId
    //String Rank3 = request.getParameter("Rank3");//Rank 3's UserId
    //String Rank4 = request.getParameter("Rank4");//Rank 4's UserId
    //String Rank5 = request.getParameter("Rank5");//Rank 5's UserId
    //String Rank6 = request.getParameter("Rank6");//Rank 6's UserId
    int Rank1Bet = Integer.parseInt( request.getParameter("Rank1BetAmount"));//Rank 1's Bet Amount
    int Rank2Bet = Integer.parseInt( request.getParameter("Rank2BetAmount"));//Rank 2's Bet Amount
    //int Rank3Bet = Integer.parseInt( request.getParameter("Rank3BetAmount"));//Rank 3's Bet Amount
    //int Rank4Bet = Integer.parseInt( request.getParameter("Rank4BetAmount"));//Rank 4's Bet Amount
    //int Rank5Bet = Integer.parseInt( request.getParameter("Rank5BetAmount"));//Rank 5's Bet Amount
    //int Rank6Bet = Integer.parseInt( request.getParameter("Rank6BetAmount"));//Rank 6's Bet Amount
    int WiningCoins = Rank2Bet ;//+ Rank3Bet + Rank4Bet + Rank5Bet + Rank6Bet;//Total Wining Bet Amount

    Connection mysqlCon = null;
    Statement stmt = null;
    ResultSet rs = null;
    String query;
    Timestamp LastUpdated = null;
    Boolean chk = false;
    int RoundId = 0;

    try {
        java.util.Date date = new java.util.Date();

        DBConfig db = new DBConfig();
                Class.forName("com.mysql.jdbc.Driver");
                mysqlCon = DriverManager.getConnection(db.host+"/"+db.db, db.user, db.pass);
                stmt = mysqlCon.createStatement();

        query = "SELECT Chk,RoundId FROM `resultranking` WHERE `TableId` = " + TableId;
        rs = stmt.executeQuery(query);
        if (rs.next()) {
            LastUpdated = rs.getTimestamp(1);
            RoundId = rs.getInt(2);
            chk = true;
        }

   //     if (chk) {

        //    if (LastUpdated.getTime() > date.getTime()) {
   //             RoundId++;
//                query = "INSERT INTO `resultranking`(`TableId`, `RoundId`, `UserId1`, `UserId2`, `UserId3`, `UserId4`, `UserId5`, `UserId6`) VALUES (" + TableId + "," + RoundId + "," + Rank1 + "," + Rank2 + "," + Rank3 + "," + Rank4 + "," + Rank5 + "," + Rank6 + ")";
//                stmt.executeUpdate(query);
 ///               query = "UPDATE `user` SET `GamesWon`=`GamesWon`+1 , `Coins` = `Coins` + " + WiningCoins + " WHERE `UserId` = " + Rank1;
    //            stmt.executeUpdate(query);
      //          query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank2Bet + " WHERE `UserId` = " + Rank2;
        //        stmt.executeUpdate(query);
          //      query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank3Bet + " WHERE `UserId` = " + Rank3;
            //    stmt.executeUpdate(query);
  //              query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank4Bet + " WHERE `UserId` = " + Rank4;
    //            stmt.executeUpdate(query);
      //          query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank5Bet + " WHERE `UserId` = " + Rank5;
        //        stmt.executeUpdate(query);
          //      query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank6Bet + " WHERE `UserId` = " + Rank6;
            //    stmt.executeUpdate(query);
        //    }
    //    } else {
//            query = "INSERT INTO `resultranking`(`TableId`, `RoundId`, `UserId1`, `UserId2`, `UserId3`, `UserId4`, `UserId5`, `UserId6`) VALUES (" + TableId + ",1," + Rank1 + "," + Rank2 + "," + Rank3 + "," + Rank4 + "," + Rank5 + "," + Rank6 + ")";
//            stmt.executeUpdate(query);
            query = "UPDATE `user` SET `GamesWon`=`GamesWon`+1 , `Coins` = `Coins` + " + WiningCoins + " WHERE `UserId` = " + Rank1;
            stmt.executeUpdate(query);
            query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank2Bet + " WHERE `UserId` = " + Rank2;
            stmt.executeUpdate(query);
        /**    query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank3Bet + " WHERE `UserId` = " + Rank3;
            stmt.executeUpdate(query);
            query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank4Bet + " WHERE `UserId` = " + Rank4;
            stmt.executeUpdate(query);
            query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank5Bet + " WHERE `UserId` = " + Rank5;
            stmt.executeUpdate(query);
            query = "UPDATE `user` SET `Coins` = `Coins` - " + Rank6Bet + " WHERE `UserId` = " + Rank6;
            stmt.executeUpdate(query);  **/
      //  }

        query = "UPDATE  `tournment` SET  `UserId` =  `PlayerId` WHERE  `TableId` = " + TableId;
        stmt.executeUpdate(query);
        query = "UPDATE  `poker`.`tables` SET  `PlayerCount` =  '0' WHERE  `tables`.`TableId` = " + TableId;
        stmt.executeUpdate(query);

    } catch (Exception e) {
        System.out.println(e);
    } finally {
        stmt.close();
        mysqlCon.close();
    }
%>


PokerHome.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta name="keywords" />
        <title>Code Hunters - 5 Card Draw</title>
        <link href="5CardDraw.css" rel="stylesheet" type="text/css" />
        <link rel="icon" href="img/icon.jpg">
        <style type="text/css">
            <!--
            .style1 {font-size: 30px}
            .style2 {font-size: 40px}
            .style5 {color: #FFFFFF}
            -->
            #myfoter{
                text-align: center;
                position: absolute;
                top: 615px;
                left: 490px;
                color: white;
            }
        </style>
    </head>

    <body background="img/LoginBackground.jpg">
        <center>
            <table width="80%" border="0">
                <tr>
                    <td width="5%" ></td>
                    <td width="90%" align="center" background="img/Background.png">
                        <div id="gameTypeMidScreen">
                            <p><img src="img/Five_Card_Draw_Poker_logo.jpg" width="151" height="151" /></p>
                            <p><font face="Bernard MT Condensed" ><span class="style1 style5">Select The Table To Join The Game</span></font></p>
                            <table width="70%" height="244" border="0">
                                <tr>
                                    <td align="center">
                                        <img src="img/demo.png"  onclick="table(888)" width="140" height="135" />
                                        <img src="img/PvsV.png"  onclick="table(999)" width="140" height="135" />        
                                        <img src="img/PvsP.png"  width="140" height="135" />
                                        <img src="img/multi.png" width="140" height="135" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </td>
                    <td width="5%"></td>
                </tr>
            </table>
            <div id="myfoter">&#169; 2014 Code Hunters - 5 Card Draw. All Rights Reserved.</div>
        </center>
    </body>
</html>

<script>
    function table(table_id) {
        var form = document.createElement("form");
        var hiddenField = document.createElement("input");
        form.setAttribute("method", "post"),
        form.setAttribute("action", "EnterToTable.jsp"),
        hiddenField.setAttribute("type", "hidden"),
        hiddenField.setAttribute("name", "tableid"),
        hiddenField.setAttribute("value", table_id),
        form.appendChild(hiddenField),
        document.body.appendChild(form),
        form.submit();
    }
</script>


EnterToTable.jsp
<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%  String sUserId = (String) session.getAttribute("suserid");
    String sTableId = request.getParameter("tableid");
 
    Connection mysqlCon = null;
    Statement stmt = null;
    ResultSet rs = null;
    String query = "";
    int iPlayerCount = 0;
    int iPlayerId = 0;

    try {
        DBConfig db = new DBConfig();
        Class.forName("com.mysql.jdbc.Driver");
        mysqlCon = DriverManager.getConnection(db.host + "/" + db.db, db.user, db.pass);
        stmt = mysqlCon.createStatement();

        if ( Integer.parseInt(sTableId) ==888) {
            session.setAttribute("splayerid", "1");
            session.setAttribute("stableid", "888");
            response.sendRedirect("ComputerVsComputer.jsp");
        }
        else if ( Integer.parseInt(sTableId) ==999) {
            query = "UPDATE `user` SET `GamesPlayed`=`GamesPlayed`+1 WHERE `UserId` = " + sUserId;
            stmt.executeUpdate(query);
            out.print(sTableId);
            session.setAttribute("splayerid", "1");
            session.setAttribute("stableid", "999");
            response.sendRedirect("PlayerVsComputer.jsp");
        }
        else {

            query = "SELECT PlayerCount FROM tables WHERE TableId = " + sTableId;
            rs = stmt.executeQuery(query);
            if (rs.next()) {
                iPlayerCount = rs.getInt(1);
            } else {
                session.setAttribute("sboardselection", "selectionerror");
                response.sendRedirect("PokerHome.jsp");
            }

            if (iPlayerCount < 6) {//Less Than 6 Physical Users In the Table
                iPlayerCount++;
                query = "SELECT MIN(`PlayerId`) FROM `tournment` WHERE `UserId` < 7 AND TableId = " + sTableId;
                rs = stmt.executeQuery(query);
                if (rs.next()) {
                    iPlayerId = rs.getInt(1);
                }
                query = "UPDATE `tables` SET `PlayerCount` = " + iPlayerCount + " WHERE `TableId` = " + sTableId;
                stmt.executeUpdate(query);//Increasing Player Count By One In The Relavant Table
                query = "UPDATE `tournment` SET `UserId` = " + sUserId + " WHERE  `PlayerId` = " + iPlayerId + " AND TableId = " + sTableId;
                stmt.executeUpdate(query);//Assigning Relavent UserId To Player Hand
                session.setAttribute("splayerid", iPlayerId + "");
                session.setAttribute("stableid", sTableId + "");
                response.sendRedirect("Board.jsp");
            } else {
                session.setAttribute("sboardselection", "tablefull");
                response.sendRedirect("PokerHome.jsp");
            }
        }
    } catch (Exception e) {
        System.out.println("Error Poker Enter To Table ::" + e);
        session.setAttribute("sboardselection", "tablefull");
        response.sendRedirect("PokerHome.jsp");
    } finally {
        stmt.close();
        mysqlCon.close();
    }

%>


ExitFromTable.jsp
<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%
    Connection mysqlCon = null;
    Statement stmt = null;
    String query = "";

    try {
        String sPlayerId = (String) session.getAttribute("splayerid");
        String sTableId = (String) session.getAttribute("stableid");
     
        DBConfig db = new DBConfig();
                Class.forName("com.mysql.jdbc.Driver");
                mysqlCon = DriverManager.getConnection(db.host+"/"+db.db, db.user, db.pass);
                stmt = mysqlCon.createStatement();
                
        //Reducing The Player Count From Selected Table
        query = "UPDATE tables SET PlayerCount = PlayerCount - 1 WHERE TableId = " + sTableId;
        stmt.executeUpdate(query);
        
        //Removing The UserId From Table And Assigning A Computer Player
        query = "UPDATE `tournment` SET `UserId` = " + sPlayerId + " WHERE  `PlayerId` = " + sPlayerId + " AND TableId = " + sTableId;
        stmt.executeUpdate(query);
        session.setAttribute("sboardselection", "exitfromtable");
        session.setAttribute("splayerid", "Exit");
        session.setAttribute("stableid", "Exit");
    } 
    catch (Exception e) {
        System.out.println("Error Poker Exit From Table ::" + e);
        session.setAttribute("sboardselection", "tablefull");
    } 
    finally {
        stmt.close();
        mysqlCon.close();
        response.sendRedirect("PokerHome.jsp");
    }
%>


ComputerVsComputer.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Code Hunters - 5 Card Draw</title>
        <link href="css/bootstrap.css" rel="stylesheet" >
        <link rel="icon" href="img/icon.jpg">
        <style>
            #wrapper{
                width: 1000px;
                height: 600px;
                background-image: url(img/PlayerVsComputer.jpg);
            }
            #Computer_Menu_1{
                position: absolute;
                top: 485px;
                left: 600px;
                font-weight: bold;
                color: white;
                text-align: center;
            }
            #Computer_Menu_2{
                position: absolute;
                top: 40px;
                left: 600px;
                font-weight: bold;
                color: white;
            }
            #computer_1_hand{
                position: absolute;
                top: 335px;
                left: 400px;
            }
            #computer_2_hand{
                position: absolute;
                top: 115px;
                left: 400px;
            }
            .card{
                float: left;
                margin: 5px;
                min-width:  104px;
                min-height:  130px;
                background-color: #ffffff;
                border-radius: 8px;
                color: #62c462;
                font-size: 15px;
                font-weight: bold;
                background-image : url(img/back_side.png);
            }
            #GameHint{
                position: absolute;
                top: 260px;
                left: 410px;
                color: white;
                font-size: 18px;
                font-style: italic;
                max-width: 550px;
                text-align: center;
            }
            #BoardAmount{
                position: absolute;
                top: 280px;
                left: 1020px;
                color: blue;
                font-size: 50px;
                font-weight: bold;
            }
            .hidden{
                display: none;
            }
            input[type="button"]{
                width: 100px;
                height: 40px;
            }
            .img{
                width: 80px;
            }
            #computer_1_Turn{
                position: absolute;
                top: 500px;
                left: 480px;
            }
            #computer_2_Turn{
                position: absolute;
                top: 50px;
                left: 480px;
            }
            #Computer_1_Betting_Button{
                position: absolute;
                top: 550px;
                left: 550px;
            }
            #Computer_1_Deal_Button{
                position: absolute;
                top: 550px;
                left: 650px;
            }
            .turn{
                z-index: 99999;
            }
            #myfoter{
                text-align: center;
                position: absolute;
                top: 615px;
                left: 490px;
                color: white;
            }
            #mytopic{
                text-align: center;
                position: absolute;
                top: 5px;
                left: 522px;
                color: white;
                font-size: 18px;
            }
            #mylink{
                text-align: center;
                position: absolute;
                top: 5px;
                left: 1000px;
                color: white;
                font-size: 12px;
            }
        </style>
    </head>

    <body background="img/LoginBackground.jpg">
    <center>
        <div id="wrapper">
            
            <div id="mytopic">POKER Demo- Computer vs. Computer</div>
            
            <a id="mylink" href="PokerHome.jsp">Go To Home</a>
            
            <div id="Computer_Menu_1">
                <div> Balance : <span id="Computer_1_Balance" > </span> </div>
                <div> Current Bet Amount : <span id="Computer_1_Current_Bet_Amount" > </span> </div>
                <div> Player Name : Computer 1</div>   
            </div>
            
            <div id="Computer_Menu_2">
                <div> Balance : <span id="Computer_2_Balance" > </span> </div>
                <div> Current Bet Amount : <span id="Computer_2_Current_Bet_Amount" > </span> </div>
                <div> Player Name : Computer 2</div>   
            </div>
            
            <div id="computer_1_hand">
                <div class="card" id="card0" >  </div>
                <div class="card" id="card1" >  </div>
                <div class="card" id="card2" >  </div>
                <div class="card" id="card3" >  </div>
                <div class="card" id="card4" >  </div>
            </div>
            
            <div id="computer_2_hand">
                <div class="card" id="card5" >  </div>
                <div class="card" id="card6" >  </div>
                <div class="card" id="card7" >  </div>
                <div class="card" id="card8" >  </div>
                <div class="card" id="card9" >  </div>
            </div>
            
            <div id="Computer_1_Betting_Button" >
                <img src="img/call.PNG"  id="call"  class="betting hidden img"/>
                <img src="img/raise.PNG" id="raise" class="betting hidden img "/>
                <img src="img/fold.PNG"  id="fold"  class="betting hidden img "/>
            </div>
            
            <div id="Computer_1_Deal_Button" >
                <img src="img/deal.PNG"  id="deal"  class="hidden img" />
            </div>
            
            <div id="GameHint"></center>
            <div id="BoardAmount" > </div>
            <div id="myfoter">&#169; 2014 Code Hunters - 5 Card Draw. All Rights Reserved.</div>
           
        </div>
    </center>

    <img src="img/loader.gif" id="computer_1_Turn" class="turn hidden "/>
    <img src="img/loader.gif" id="computer_2_Turn" class="turn hidden "/>

    <script type="text/javascript" src="js/bootstrap.min.js" ></script>
    <script type="text/javascript" src="js/jquery.js" ></script>
    <script type="text/javascript" src="js/ComputerVsComputer.js" ></script>
</body>
</html>


ComputerVsComputerControl.jsp
<%@ page language="java" session="true"%>

<%@ page import ="java.util.Arrays"%>
<%@ page import ="java.util.ArrayList" %>
<%@ page import ="java.util.Collections" %>

<%@ page import ="java.util.Comparator" %>

<%@ page import ="java.io.IOException" %>
<%@ page import ="java.io.PrintWriter" %>
<%@ page import ="javax.servlet.ServletContext" %>
<%@ page import ="javax.servlet.ServletException" %>
<%@ page import ="javax.servlet.http.HttpServlet" %>
<%@ page import ="javax.servlet.http.HttpServletRequest" %>
<%@ page import ="javax.servlet.http.HttpServletResponse" %>
<%@ page import ="javax.servlet.http.HttpSession" %>

<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%    
    class MyCard {

        private int iCardIndex; //Index Of The Card, Vary From 0 to 51
        private int iCardValue; //Value Of The Card, Vary From 2 to 14 ( 11=Jack, 12=Queen, 13=King, 14=Ace)
        private int iCardType; //Type Of The Card, Vary From 1 to 4 ( 1=Spades, 2=Hearts, 3=Clubs, 4=Diamonds)
        
        public MyCard() {
        }

        public MyCard(int iCardIndex_, int iCardValue_, int iCardType_) {
            iCardIndex = iCardIndex_;
            iCardValue = iCardValue_;
            iCardType = iCardType_;
        }

        public int getCardIndex() {
            return iCardIndex;
        }

        public int getCardValue() {
            return iCardValue;
        }

        public int getCardType() {
            return iCardType;
        }
    }
%>

<%
    class MyDeck {

        private ArrayList<MyCard> mydeck = new ArrayList<MyCard>();

        public MyDeck() {
            int iIndex = 0;
            for (int iSuit = 1; iSuit < 5; iSuit++) { //Suits ( 1=Spades, 2=Hearts, 3=Clubs, 4=Diamonds)
                for (int iValue = 2; iValue < 15; iValue++) { //Value ( 11=Jack, 12=Queen, 13=King, 14=Ace)
                    mydeck.add(new MyCard(iIndex, iValue, iSuit));
                    iIndex++;
                }
            }
        }

        public MyCard getCard(int index) {
            return (MyCard) mydeck.get(index);
        }

        public int getDeckSize() {
            return mydeck.size();
        }

        public void shuffle() {
            Collections.shuffle(mydeck);
        }

        public MyCard dealCard() {
            return (MyCard) mydeck.remove(0);
        }

        public String getHandCard() {
            String current_cards = "";
            for (MyCard c : mydeck) {
                current_cards += c.getCardIndex() + ",";
            }
            return current_cards;
        }

        public void addCard(MyCard c) {
            mydeck.add(c);
        }

        public ArrayList<MyCard> getDeckCards() {
            return mydeck;
        }
    }
%>

<%
    class MyHand {

        private ArrayList<MyCard> myhand = new ArrayList<MyCard>();//Cards Available In The Hand
        int UserId = 0, roundPlay = -1;

        public void addCard(MyCard c) {
            myhand.add(c);
        }

        public void setUserId(int UserId) {
            this.UserId = UserId;
        }

        public int getUserId() {
            return UserId;
        }

        public MyCard removeCard(int iCardIndex) {
            MyCard x = new MyCard();
            for (MyCard c : myhand) {
                if (c.getCardIndex() == iCardIndex) {
                    x = c;
                }
            }
            myhand.remove(x);
            return x;
        }

        public ArrayList<MyCard> getHandCard() {
            return myhand;
        }
        
    }
%>

<%
    class MyHint {
        private int suit;
        private String message,finalmessage;
        private boolean chk = true;
        private ArrayList<MyCard> HandCards;
        int[] indexArray = new int[5];
        
        public MyHint(){
        }    
                
        public MyHint(ArrayList<MyCard> mycard) {
            this.HandCards = mycard;
        }
        
        public void checkHint() {
            this.indexArray[0] = 53;
            this.indexArray[1] = 53;
            this.indexArray[2] = 53;
            this.indexArray[3] = 53;
            this.indexArray[4] = 53;
            sortHandCards();
            getRank();
            getRankHint();
        }

        public String getHint() {
            return message;
        }
        
        public String getFinalHint() {
            return finalmessage;
        }

        public int[] getIndexArray() {
            return indexArray;
        }

        public void sortHandCards() { //Sorting The Hands in Asending Order Using Card Value
            
            //Copying The Hand Cards To Unsorted Card Array AND Removing All The Cards From Hand
            ArrayList<MyCard> unsortCards = new ArrayList<MyCard>();
            for (MyCard c : this.HandCards) {
                unsortCards.add(c); 
            }
            this.HandCards = new ArrayList<MyCard>();
            
            //Sorting The Card Values
            int[] arr = new int[5];
            for(int i=0;i<5;i++){
                arr[i] = unsortCards.get(i).getCardValue();
            }
            Arrays.sort(arr);

            //Copying The Sorted Cards To The Hand
            MyCard x = new MyCard();
            for(int a : arr){
                for (MyCard c : unsortCards) {
                    if(a == c.getCardValue()){
                        x = c;
                        break;
                    }
                }
                this.HandCards.add(x);
                unsortCards.remove(x);
            }
            
            /**
            //Available In jdk 1.7
            Collections.sort(this.HandCards, new Comparator<MyCard>() {
                @Override
                public int compare(MyCard c1, MyCard c2) {
                    return Integer.compare(c1.getCardValue(), c2.getCardValue());
                }
            });**/
        }

        private void getRank() {
            int i = 0;
            for (MyCard c : HandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }
            if (suit != 0) { //Same Suit 
                if (chk) { checkRoyalFlush(); }
                if (chk) { checkStraightFlush(); }
                if (chk) { checkFlush(); }
            } 
            else { //Not Same Suit
                if (chk) { checkFourOfAKind(); }
                if (chk) { checkFullHouse(); }
                if (chk) { checkStraight(); }
                if (chk) { checkThreeOfAKind(); }
                if (chk) { checkTwoPair(); }
                if (chk) { checkOnePair(); }
            }
        }
        
        private void getRankHint() {
            int suit = 5, i = 0;
            for (MyCard c : HandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }

            if (suit != 0) {
                if (chk) { checkRoyalFlushHint(); }
                if (chk) { checkStraightFlushHint(); }
            } 
            else {
                if (chk) { checkFourOfKindHint(); }
                if (chk) { checkFlushHint(); }
                if (chk) { checkStraightHint(); }
                if (chk) { checkHighCardHint(); }
            }
        }

        public void checkRoyalFlush() {
            if (HandCards.get(0).getCardValue() == 10 && HandCards.get(1).getCardValue() == 11 && HandCards.get(2).getCardValue() == 12 && HandCards.get(3).getCardValue() == 13 && HandCards.get(4).getCardValue() == 14) {
                message = "Hurray!!! You've Royal Flush";
                finalmessage = "Hurray!!! You've Royal Flush";
                chk = false;
            }
        }

        public void checkStraightFlush() {
            int sum = HandCards.get(0).getCardValue() + 3;
            int tot = HandCards.get(0).getCardValue() + 4;

            //Checking For Straight Flush with A in 1st
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && sum == HandCards.get(3).getCardValue()) {
                message = "You've Straight Flush";
                finalmessage = "You've Straight Flush";
                chk = false;
            }//Checking Straight Flush For Other values
            else if (tot == HandCards.get(4).getCardValue()) {
                message = "You've Straight Flush";
                finalmessage = "You've Straight Flush";
                chk = false;
            }
        }

        public void checkFourOfAKind() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Four Of A Kind";
                finalmessage = "You've Four Of A Kind";
                chk = false;
            }
        }

        public void checkFullHouse() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()
                    || HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Full House";
                finalmessage = "You've Full House";
                chk = false;
            }
        }

        public void checkFlush() {
            message = "You've Flush";
            finalmessage = "You've Flush";
            chk = false;
        }

        public void checkStraight() {
            if ((HandCards.get(0).getCardValue() + 1) == HandCards.get(1).getCardValue() && (HandCards.get(1).getCardValue() + 1) == HandCards.get(2).getCardValue() && (HandCards.get(2).getCardValue() + 1) == HandCards.get(3).getCardValue() && (HandCards.get(3).getCardValue() + 1) == HandCards.get(4).getCardValue()
                    || HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && (HandCards.get(0).getCardValue() + 1) == HandCards.get(1).getCardValue() && (HandCards.get(1).getCardValue() + 1) == HandCards.get(2).getCardValue() && (HandCards.get(2).getCardValue() + 1) == HandCards.get(3).getCardValue()) {
                message = "You've Straight";
                finalmessage = "You've Straight";
                chk = false;
            }
        }

        public void checkThreeOfAKind() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Three Of A Kind";
                finalmessage = "You've Three Of A Kind";
                chk = false;
            }
        }

        public void checkTwoPair() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()
                    || HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Two Pair";
                finalmessage = "You've Two Pair";
                chk = false;
            }
        }

        public void checkOnePair() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()
                    || HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've One Pair";
                finalmessage = "You've One Pair";
                chk = false;
            }
        }

        private void checkRoyalFlushHint() { //Royal Flush (10,J,Q,K,A)       
            String Message = "You Already Have Flush & You Can Try For A Royal Flush If You Remove ";
            String RemoveValues = "";

            int i = 0;
            int val = 0;
            for (MyCard c : HandCards) {
                if (c.getCardValue() == 10 || c.getCardValue() == 11 || c.getCardValue() == 12 || c.getCardValue() == 13 || c.getCardValue() == 14) {
                } else {
                    val++;
                    RemoveValues += c.getCardValue() + ",";
                    indexArray[i] = c.getCardIndex();
                    i++;
                }
                
            }

            if (val < 3) {
                if (val == 0) {
                    Message = "";
                }
                message = Message + " " + RemoveValues;
                finalmessage = "You've Flush";
                chk = false;
            }else{
                this.indexArray[0] = 53;
                this.indexArray[1] = 53;
                this.indexArray[2] = 53;
                this.indexArray[3] = 53;
                this.indexArray[4] = 53;
            }
        }

        private void checkStraightFlushHint() {
            String Message = "You Already Have Flush & You Can Try A Straight Flush If You Remove : ";
            finalmessage = "You've Flush";
            String RemoveValues = "";

            //Straight Flush (14,2,3,4,5)    
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && HandCards.get(1).getCardValue() == 3) {
                if (HandCards.get(2).getCardValue() == 4 || HandCards.get(2).getCardValue() == 5) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() == 4 || HandCards.get(3).getCardValue() == 5) {
                    RemoveValues = HandCards.get(2).getCardValue() + " ";
                    indexArray[0] = HandCards.get(2).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(2).getCardValue() + " , " + HandCards.get(3).getCardValue();
                    indexArray[0] = HandCards.get(2).getCardIndex();
                    indexArray[1] = HandCards.get(3).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight Flush (x,x+1,x+2,y,z)              
            else if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()) {
                if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() || HandCards.get(2).getCardValue() + 2 == HandCards.get(3).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() + 2 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(3).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(3).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;

            }//Straight Flush (y,x,x+1,x+2,z) 
            else if (HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()) {
                if (HandCards.get(1).getCardValue() - 1 == HandCards.get(0).getCardValue()) {
                    RemoveValues += HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                    RemoveValues += HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight Flush (y,z,x,x+1,x+2) 
            else if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                if (HandCards.get(2).getCardValue() - 2 == HandCards.get(0).getCardValue()) {
                    RemoveValues += HandCards.get(1).getCardValue() + " ";
                    indexArray[0] = HandCards.get(1).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() - 1 == HandCards.get(1).getCardValue() || HandCards.get(2).getCardValue() - 2 == HandCards.get(1).getCardValue()) {
                    RemoveValues += HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(1).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(1).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }
        }

        private void checkFlushHint() {
            int i = 0;
            int suit1 = 0, suit2 = 0, suit3 = 0, suit4 = 0;
            String Message = "";
            finalmessage = "You've High Card";

            for (MyCard c : HandCards) {
                if (c.getCardType() == 1) {
                    suit1++;
                } else if (c.getCardType() == 2) {
                    suit2++;
                } else if (c.getCardType() == 3) {
                    suit3++;
                } else if (c.getCardType() == 4) {
                    suit4++;
                }
                i++;
            }

            if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue()
                    && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()
                    && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()
                    && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                Message = "You Already Have Straight & ";
                finalmessage = "You've Straight";
            }

            if (suit1 == 3 || suit1 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Spades.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 1) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }

            } else if (suit2 == 3 || suit2 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Hearts.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 2) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }

            } else if (suit3 == 3 || suit3 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Clubs.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 3) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }
            } else if (suit4 == 3 || suit4 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Diamonds.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 4) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }
            }
        }

        private void checkStraightHint() {
            String Message = "You Can Try A Straight If You Remove : ";
            finalmessage = "You've A High Card";
            String RemoveValues = "";

            //Straight (8,9,11,12,13)    
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && HandCards.get(1).getCardValue() == 3) {
                if (HandCards.get(2).getCardValue() == 4 || HandCards.get(2).getCardValue() == 5) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() == 4 || HandCards.get(3).getCardValue() == 5) {
                    RemoveValues = HandCards.get(2).getCardValue() + " ";
                    indexArray[0] = HandCards.get(2).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(2).getCardValue() + " , " + HandCards.get(3).getCardValue();
                    indexArray[0] = HandCards.get(2).getCardIndex();
                    indexArray[1] = HandCards.get(3).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight (x,x+1,x+2,y,z)          
            else if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()) {
                if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() || HandCards.get(2).getCardValue() + 2 == HandCards.get(3).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() + 2 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(3).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(3).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;

            }//Straight (y,x,x+1,x+2,z) 
            else if (HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()) {
                if (HandCards.get(1).getCardValue() - 1 == HandCards.get(0).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight(y,z,x,x+1,x+2)Straight (8,9,11,12,13) 
            else if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                if (HandCards.get(2).getCardValue() - 2 == HandCards.get(0).getCardValue()) {
                    RemoveValues = HandCards.get(1).getCardValue() + " ";
                    indexArray[0] = HandCards.get(1).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() - 1 == HandCards.get(1).getCardValue() || HandCards.get(2).getCardValue() - 2 == HandCards.get(1).getCardValue()) {
                    RemoveValues = HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(1).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(1).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }
        }

        private void checkHighCardHint() {
            String Message = "";
            finalmessage = "You've A High Card";

            if (HandCards.get(2).getCardValue() < 10) {
                Message = "You Already Have A High Card of " + HandCards.get(4).getCardValue() +"& You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                chk = false;
            } else if (HandCards.get(4).getCardValue() == 14) {
                Message = "You Already Have A High Card of " + HandCards.get(4).getCardValue() +"& You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue() + "," + HandCards.get(3).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                indexArray[3] = HandCards.get(3).getCardIndex();
                chk = false;
            } else {
                Message = "You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                chk = false;
            }
            message = Message;
        }

        private void checkFourOfKindHint() {
            String Message = "";
            finalmessage = "You've A High Card";

            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove: " + HandCards.get(3).getCardValue() + "," + HandCards.get(4).getCardValue();
                indexArray[0] = HandCards.get(3).getCardIndex();
                indexArray[1] = HandCards.get(4).getCardIndex();
                chk = false;
            } else if (HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove " + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                chk = false;
            } else if (HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove " + HandCards.get(0).getCardValue() + " " + HandCards.get(4).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(4).getCardIndex();
                chk = false;
            }
            if (Message != "") {
                message = Message;
            }
        }

    }
%>

<%
    class PokerRanking {
        private int priority, rankcard , highCard, suit;
        private ArrayList<MyCard> myHandCards;
        private boolean chk = true;

        public PokerRanking() {
        }

        public void setHand(ArrayList<MyCard> card) {
            this.myHandCards = card;
            sortHandCards();
            getRank();
        }

        public int getPriority() {
            return priority;
        }
        
        public int getRankCard() {
            return rankcard;
        }

        public int getHighCard() {
            return highCard;
        }

        public int getSuit() {
            return suit;
        }

        public void sortHandCards() { 
            
            //Copying The Hand Cards To Unsorted Card Array AND Removing All The Cards From Hand
            ArrayList<MyCard> unsortCards = new ArrayList<MyCard>();
            for (MyCard c : this.myHandCards) {
                unsortCards.add(c); 
            }
            this.myHandCards = new ArrayList<MyCard>();
            
            //Sorting The Card Values
            int[] arr = new int[5];
            for(int i=0;i<5;i++){
                arr[i] = unsortCards.get(i).getCardValue();
            }
            Arrays.sort(arr);

            //Copying The Sorted Cards To The Hand
            MyCard x = new MyCard();
            for(int a : arr){
                for (MyCard c : unsortCards) {
                    if(a == c.getCardValue()){
                        x = c;
                        break;
                    }
                }
                this.myHandCards.add(x);
                unsortCards.remove(x);
            }

            /**
            //Available In jdk 1.7
            Collections.sort(this.myHandCards, new Comparator<MyCard>() {
                @Override
                public int compare(MyCard c1, MyCard c2) {
                    return Integer.compare(c1.getCardValue(), c2.getCardValue());
                }
            });**/
            
            highCard = myHandCards.get(4).getCardValue();
            rankcard = 53;
        }
        
        

        private void getRank() {
            int i = 0;
            for (MyCard c : myHandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }
            if (suit != 0) {//Same Suit 
                if (chk) { checkRoyalFlush();
                }if (chk) { checkStraightFlush();
                }if (chk) { checkFlush();
                }
            } else {//Not Same Suit
                if (chk) { checkFourOfAKind();
                }if (chk) { checkFullHouse();
                }if (chk) { checkStraight();
                }if (chk) { checkThreeOfAKind();
                }if (chk) { checkTwoPair();
                }if (chk) { checkOnePair();
                }if (chk) { HighCard();
                }
            }
        }

        public void checkRoyalFlush() {
            if (myHandCards.get(0).getCardValue() == 10 && myHandCards.get(1).getCardValue() == 11 && myHandCards.get(2).getCardValue() == 12 && myHandCards.get(3).getCardValue() == 13 && myHandCards.get(4).getCardValue() == 14) {
                priority = 1;
                chk = false;
            }
        }

        public void checkStraightFlush() {
            int sum = myHandCards.get(0).getCardValue() + 3;
            int tot = myHandCards.get(0).getCardValue() + 4;

            //Checking For Straight Flush with A in 1st
            if (myHandCards.get(4).getCardValue() == 14 && myHandCards.get(0).getCardValue() == 2 && sum == myHandCards.get(3).getCardValue()) {
                priority = 2;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }//Checking Straight Flush For Other values
            else if (tot == myHandCards.get(4).getCardValue()) {
                priority = 2;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }
        }

        public void checkFourOfAKind() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 3;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkFullHouse() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()
                    || myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 4;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkFlush() {
            priority = 5;
            rankcard = myHandCards.get(4).getCardValue();
            chk = false;
        }

        public void checkStraight() {
            if ((myHandCards.get(0).getCardValue() + 1) == myHandCards.get(1).getCardValue() && (myHandCards.get(1).getCardValue() + 1) == myHandCards.get(2).getCardValue() && (myHandCards.get(2).getCardValue() + 1) == myHandCards.get(3).getCardValue() && (myHandCards.get(3).getCardValue() + 1) == myHandCards.get(4).getCardValue()
                    || myHandCards.get(4).getCardValue() == 14 && myHandCards.get(0).getCardValue() == 2 && (myHandCards.get(0).getCardValue() + 1) == myHandCards.get(1).getCardValue() && (myHandCards.get(1).getCardValue() + 1) == myHandCards.get(2).getCardValue() && (myHandCards.get(2).getCardValue() + 1) == myHandCards.get(3).getCardValue()) {
                priority = 6;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }
        }

        public void checkThreeOfAKind() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 7;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkTwoPair() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()
                    || myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 8;
                rankcard = myHandCards.get(3).getCardValue();
                highCard = myHandCards.get(1).getCardValue();
                chk = false;
            }
        }

        public void checkOnePair() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(1).getCardValue();
                chk = false;
            }
            if (myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(1).getCardValue();
                chk = false;
            }
            if (myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
            if (myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(4).getCardValue();
                highCard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void HighCard() {
            priority = 10;
            rankcard = myHandCards.get(4).getCardValue();
            highCard = myHandCards.get(3).getCardValue();
            chk = false;
        }

    }
%>

<%
    String sReqType = request.getParameter("reqtype");
    
    if (sReqType.equals("Load")) {
        MyDeck deck = new MyDeck();
        MyHand hand_1 = new MyHand();
        MyHand hand_2 = new MyHand();
        deck.shuffle();
        for (int i = 0; i < 5; i++) {
            hand_1.addCard(deck.dealCard());
            hand_2.addCard(deck.dealCard());
        }
        session.setAttribute("sdeck", deck);
        session.setAttribute("shand1", hand_1);
        session.setAttribute("shand2", hand_2);
    }
    else if (sReqType.equals("GetCards")) {
        String sPlayerType = request.getParameter("playertype");
        MyHand player_hand;
        if (sPlayerType.equals("Computer1")) {
            player_hand = (MyHand)session.getAttribute("shand1");
        }else{
            player_hand = (MyHand)session.getAttribute("shand2");
        }
        String playerhand = "<player>";
        for (MyCard c : player_hand.getHandCard()) {
            playerhand += "<index>";
            playerhand += "" + c.getCardIndex();
            playerhand += "</index>";
            playerhand += "<value>";
            playerhand += "" + c.getCardValue();
            playerhand += "</value>";
        }
        playerhand += "</player>";
        out.println(playerhand);
    }
    else if (sReqType.equals("Hint")) {
        String sPlayerType = request.getParameter("playertype");
        if (sPlayerType.equals("Computer1")) {
            MyHand hand_1 = (MyHand)session.getAttribute("shand1");
            MyHint myhint = new MyHint(hand_1.getHandCard());
            myhint.checkHint();
            out.print(myhint.getHint());
        }else{
            MyHand hand_2 = (MyHand)session.getAttribute("shand2");
            MyHint myhint = new MyHint(hand_2.getHandCard());
            myhint.checkHint();
            out.print(myhint.getHint());
        }
    }
    else if (sReqType.equals("FinalHint")) {
        String sPlayerType = request.getParameter("playertype");
        if (sPlayerType.equals("Computer1")) {
            MyHand hand_1 = (MyHand)session.getAttribute("shand1");
            MyHint myhint = new MyHint(hand_1.getHandCard());
            myhint.checkHint();
            out.print(myhint.getFinalHint());
        }else{
            MyHand hand_2 = (MyHand)session.getAttribute("shand2");
            MyHint myhint = new MyHint(hand_2.getHandCard());
            myhint.checkHint();
            out.print(myhint.getFinalHint());
        }
    }
    else if (sReqType.equals("ComputerDeal")) {
        String sPlayerType = request.getParameter("playertype");
        MyDeck deck =  (MyDeck)session.getAttribute("sdeck");
        if (sPlayerType.equals("Computer1")) {
            MyHand hand_1 = (MyHand)session.getAttribute("shand1");
            MyHint myhint = new MyHint(hand_1.getHandCard());
            myhint.checkHint();
            for (int c : myhint.getIndexArray()) {
                if (c < 53) {
                    deck.addCard(hand_1.removeCard(c));
                    hand_1.addCard(deck.dealCard());
                }
            }
            session.setAttribute("sdeck", deck);
            session.setAttribute("shand1", hand_1);
        }else{
            MyHand hand_2 = (MyHand)session.getAttribute("shand2");
            MyHint myhint = new MyHint(hand_2.getHandCard());
            myhint.checkHint();
            for (int c : myhint.getIndexArray()) {
                if (c < 53) {
                    deck.addCard(hand_2.removeCard(c));
                    hand_2.addCard(deck.dealCard());
                }
            }
            session.setAttribute("sdeck", deck);
            session.setAttribute("shand2", hand_2);
        }
    }
    else if (sReqType.equals("PokerRanking")) {
        String rankXML = "<result>";
        
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");
        PokerRanking player1 = new PokerRanking();
        player1.setHand(hand_1.getHandCard());
        rankXML += "<rank>" + player1.getPriority() + "</rank>";
        rankXML += "<rankcard>" + player1.getRankCard()+ "</rankcard>";
        rankXML += "<highcard>" + player1.getHighCard() + "</highcard>";
        
        MyHand hand_2 = (MyHand)session.getAttribute("shand2");
        PokerRanking player2 = new PokerRanking();
        player2.setHand(hand_2.getHandCard());
        rankXML += "<rank>" + player2.getPriority() + "</rank>";
        rankXML += "<rankcard>" + player2.getRankCard()+ "</rankcard>";
        rankXML += "<highcard>" + player2.getHighCard() + "</highcard>";
        
        rankXML += "</result>";
        out.println(rankXML);
    }
%>



PlayerVsComputer.jsp
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Code Hunters - 5 Card Draw</title>
        <link href="css/bootstrap.css" rel="stylesheet" >
        <link rel="icon" href="img/icon.jpg">
        <style>
            #wrapper{
                width: 1000px;
                height: 600px;
                background-image: url(img/PlayerVsComputer.jpg);
            }
            #computer_hand{
                position: absolute;
                top: 115px;
                left: 400px;
            }
            #player_hand{
                position: absolute;
                top: 335px;
                left: 400px;
            }
            #ComputerMenu{
                position: absolute;
                top: 40px;
                left: 600px;
                font-weight: bold;
                color: white;
            }
            #PlayerMenu{
                position: absolute;
                top: 485px;
                left: 600px;
                font-weight: bold;
                color: white;
                text-align: center;
            }
            #ButtonMenu{
                position: absolute;
                top: 550px;
                left: 550px;
            }
            #BoardAmount{
                position: absolute;
                top: 280px;
                left: 1020px;
                color: blue;
                font-size: 50px;
                font-weight: bold;
            }
            #GameHint{
                position: absolute;
                top: 260px;
                left: 410px;
                color: white;
                font-size: 18px;
                font-style: italic;
                max-width: 550px;
                text-align: center;
            }
            .card{
                float: left;
                margin: 5px;
                min-width:  104px;
                min-height:  130px;
                background-color: #ffffff;
                border-radius: 8px;
                color: #62c462;
                font-size: 15px;
                font-weight: bold;
                background-image : url(img/back_side.png);
            }
            .selected_card{
                margin-top: -50px;
            }          
            .hidden{
                display: none;
            }
            #PlayerMenu  div {
                color: white;
            }
            input[type="button"]{
                width: 100px;
                height: 40px;
            }
            #hint{
                position: absolute;
                left: 162px;
                top: 500px;
            }
            .img{
                width: 80px;
            }
            #playerTurn{
                position: absolute;
                top: 500px;
                left: 480px;
            }
            #computerTurn{
                position: absolute;
                top: 50px;
                left: 480px;
            }
            .turn{
                z-index: 99999;
            }
            #myfoter{
                text-align: center;
                position: absolute;
                top: 615px;
                left: 490px;
                color: white;
            }
            #mytopic{
                text-align: center;
                position: absolute;
                top: 5px;
                left: 560px;
                color: white;
                font-size: 18px;
            }
            #mylink{
                text-align: center;
                position: absolute;
                top: 5px;
                left: 1000px;
                color: white;
                font-size: 12px;
            }
        </style>
    </head>

    <body background="img/LoginBackground.jpg">
    <center>
        <div id="wrapper">
            
            <div id="mytopic">POKER - Player vs. Computer</div>
            
            <a id="mylink" href="PokerHome.jsp">Go To Home</a>
            
            <div id="ComputerMenu">
                <div> Balance : <span id="ComputerBalance" > </span> </div>
                <div> Current Bet Amount : <span id="ComputerCurrentBetAmount" > </span> </div>
                <div> Player Name : Computer </div>   
            </div>
            
            <div id="computer_hand">
                <div class="card" id="card5" >  </div>
                <div class="card" id="card6" >  </div>
                <div class="card" id="card7" >  </div>
                <div class="card" id="card8" >  </div>
                <div class="card" id="card9" >  </div>
            </div>
            
            <div id="player_hand">
                <div class="card" id="card0" >  </div>
                <div class="card" id="card1" >  </div>
                <div class="card" id="card2" >  </div>
                <div class="card" id="card3" >  </div>
                <div class="card" id="card4" >  </div>
                <input type="hidden" value="0" id="number_of_selected_card" />
            </div>

            <div id="GameHint"></center>
            <div id="BoardAmount" > </div>
            
            <div id="PlayerMenu">
                <div> Balance : <span id="PlayerBalance" > </span> </div>
                <div> Current Bet Amount : <span id="PlayerCurrentBetAmount" > </span> </div>
                <div> Player Name : <% out.print(session.getAttribute("sname"));%> </div>   
            </div>
            
            <div id="ButtonMenu" >
                <img src="img/deal.PNG"  id="deal"  class="hidden img" />
                <img src="img/call.PNG"  id="call"  class="betting hidden img"/>
                <img src="img/raise.PNG" id="raise" class="betting hidden img "/>
                <img src="img/fold.PNG"  id="fold"  class="betting hidden img "/>
            </div>
            
            <div id="myfoter">&#169; 2014 Code Hunters - 5 Card Draw. All Rights Reserved.</div>
            
        </div>
    </center>

    <img src="img/loader.gif" id="playerTurn" class="turn hidden "/>
    <img src="img/loader.gif" id="computerTurn" class="turn hidden "/>

    <script type="text/javascript" src="js/bootstrap.min.js" ></script>
    <script type="text/javascript" src="js/jquery.js" ></script>
    <script type="text/javascript" src="js/PlayerVsComputer.js" ></script>
</body>
</html>



PlayerVsComputerControl.jsp
<%@ page language="java" session="true"%>

<%@ page import ="java.util.Arrays"%>
<%@ page import ="java.util.ArrayList" %>
<%@ page import ="java.util.Collections" %>

<%@ page import ="java.util.Comparator" %>

<%@ page import ="java.io.IOException" %>
<%@ page import ="java.io.PrintWriter" %>
<%@ page import ="javax.servlet.ServletContext" %>
<%@ page import ="javax.servlet.ServletException" %>
<%@ page import ="javax.servlet.http.HttpServlet" %>
<%@ page import ="javax.servlet.http.HttpServletRequest" %>
<%@ page import ="javax.servlet.http.HttpServletResponse" %>
<%@ page import ="javax.servlet.http.HttpSession" %>

<%@ page language="java" session="true"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%@ include file="dbconfig.jsp" %>

<%  
    class MyCard {

        private int iCardIndex; //Index Of The Card, Vary From 0 to 51
        private int iCardValue; //Value Of The Card, Vary From 2 to 14 ( 11=Jack, 12=Queen, 13=King, 14=Ace)
        private int iCardType; //Type Of The Card, Vary From 1 to 4 ( 1=Spades, 2=Hearts, 3=Clubs, 4=Diamonds)

        public MyCard() {
        }

        public MyCard(int iCardIndex_, int iCardValue_, int iCardType_) {
            iCardIndex = iCardIndex_;
            iCardValue = iCardValue_;
            iCardType = iCardType_;
        }

        public int getCardIndex() {
            return iCardIndex;
        }

        public int getCardValue() {
            return iCardValue;
        }

        public int getCardType() {
            return iCardType;
        }
    }
%>

<%
    class MyDeck {

        private ArrayList<MyCard> mydeck = new ArrayList<MyCard>();

        public MyDeck() {
            int iIndex = 0;
            for (int iSuit = 1; iSuit < 5; iSuit++) { //Suits ( 1=Spades, 2=Hearts, 3=Clubs, 4=Diamonds)
                for (int iValue = 2; iValue < 15; iValue++) { //Value ( 11=Jack, 12=Queen, 13=King, 14=Ace)
                    mydeck.add(new MyCard(iIndex, iValue, iSuit));
                    iIndex++;
                }
            }
        }

        public MyCard getCard(int index) {
            return (MyCard) mydeck.get(index);
        }

        public int getDeckSize() {
            return mydeck.size();
        }

        public void shuffle() {
            Collections.shuffle(mydeck);
        }

        public MyCard dealCard() {
            return (MyCard) mydeck.remove(0);
        }

        public String getHandCard() {
            String current_cards = "";
            for (MyCard c : mydeck) {
                current_cards += c.getCardIndex() + ",";
            }
            return current_cards;
        }

        public void addCard(MyCard c) {
            mydeck.add(c);
        }

        public ArrayList<MyCard> getDeckCards() {
            return mydeck;
        }
    }
%>

<%
    class MyHand {

        private ArrayList<MyCard> myhand = new ArrayList<MyCard>();//Cards Available In The Hand
        int UserId = 0, roundPlay = -1;

        public void addCard(MyCard c) {
            myhand.add(c);
        }

        public void setUserId(int UserId) {
            this.UserId = UserId;
        }

        public int getUserId() {
            return UserId;
        }

        public MyCard removeCard(int iCardIndex) {
            MyCard x = new MyCard();
            for (MyCard c : myhand) {
                if (c.getCardIndex() == iCardIndex) {
                    x = c;
                }
            }
            myhand.remove(x);
            return x;
        }

        public ArrayList<MyCard> getHandCard() {
            return myhand;
        }
        
    }
%>

<%
    class MyHint {
        private int suit;
        private String message,finalmessage;
        private boolean chk = true;
        private ArrayList<MyCard> HandCards;
        int[] indexArray = new int[5];
        
        public MyHint(){
        }    
                
        public MyHint(ArrayList<MyCard> mycard) {
            this.HandCards = mycard;
        }
        
        public void checkHint() {
            this.indexArray[0] = 53;
            this.indexArray[1] = 53;
            this.indexArray[2] = 53;
            this.indexArray[3] = 53;
            this.indexArray[4] = 53;
            sortHandCards();
            getRank();
            getRankHint();
        }

        public String getHint() {
            return message;
        }
        
        public String getFinalHint() {
            return finalmessage;
        }

        public int[] getIndexArray() {
            return indexArray;
        }

        public void sortHandCards() { //Sorting The Hands in Asending Order Using Card Value 
            
            //Copying The Hand Cards To Unsorted Card Array AND Removing All The Cards From Hand
            ArrayList<MyCard> unsortCards = new ArrayList<MyCard>();
            for (MyCard c : this.HandCards) {
                unsortCards.add(c); 
            }
            this.HandCards = new ArrayList<MyCard>();
            
            //Sorting The Card Values
            int[] arr = new int[5];
            for(int i=0;i<5;i++){
                arr[i] = unsortCards.get(i).getCardValue();
            }
            Arrays.sort(arr);

            //Copying The Sorted Cards To The Hand
            MyCard x = new MyCard();
            for(int a : arr){
                for (MyCard c : unsortCards) {
                    if(a == c.getCardValue()){
                        x = c;
                        break;
                    }
                }
                this.HandCards.add(x);
                unsortCards.remove(x);
            }
            
            /**
            //Available In jdk 1.7
            Collections.sort(this.HandCards, new Comparator<MyCard>() {
                @Override
                public int compare(MyCard c1, MyCard c2) {
                    return Integer.compare(c1.getCardValue(), c2.getCardValue());
                }
            });**/
        }

        private void getRank() {
            int i = 0;
            for (MyCard c : HandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }
            if (suit != 0) { //Same Suit 
                if (chk) { checkRoyalFlush(); }
                if (chk) { checkStraightFlush(); }
                if (chk) { checkFlush(); }
            } 
            else { //Not Same Suit
                if (chk) { checkFourOfAKind(); }
                if (chk) { checkFullHouse(); }
                if (chk) { checkStraight(); }
                if (chk) { checkThreeOfAKind(); }
                if (chk) { checkTwoPair(); }
                if (chk) { checkOnePair(); }
            }
        }
        
        private void getRankHint() {
            int suit = 5, i = 0;
            for (MyCard c : HandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }

            if (suit != 0) {
                if (chk) { checkRoyalFlushHint(); }
                if (chk) { checkStraightFlushHint(); }
            } 
            else {
                if (chk) { checkFourOfKindHint(); }
                if (chk) { checkFlushHint(); }
                if (chk) { checkStraightHint(); }
                if (chk) { checkHighCardHint(); }
            }
        }

        public void checkRoyalFlush() {
            if (HandCards.get(0).getCardValue() == 10 && HandCards.get(1).getCardValue() == 11 && HandCards.get(2).getCardValue() == 12 && HandCards.get(3).getCardValue() == 13 && HandCards.get(4).getCardValue() == 14) {
                message = "Hurray!!! You've Royal Flush";
                finalmessage = "Hurray!!! You've Royal Flush";
                chk = false;
            }
        }

        public void checkStraightFlush() {
            int sum = HandCards.get(0).getCardValue() + 3;
            int tot = HandCards.get(0).getCardValue() + 4;

            //Checking For Straight Flush with A in 1st
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && sum == HandCards.get(3).getCardValue()) {
                message = "You've Straight Flush";
                finalmessage = "You've Straight Flush";
                chk = false;
            }//Checking Straight Flush For Other values
            else if (tot == HandCards.get(4).getCardValue()) {
                message = "You've Straight Flush";
                finalmessage = "You've Straight Flush";
                chk = false;
            }
        }

        public void checkFourOfAKind() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Four Of A Kind";
                finalmessage = "You've Four Of A Kind";
                chk = false;
            }
        }

        public void checkFullHouse() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()
                    || HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Full House";
                finalmessage = "You've Full House";
                chk = false;
            }
        }

        public void checkFlush() {
            message = "You've Flush";
            finalmessage = "You've Flush";
            chk = false;
        }

        public void checkStraight() {
            if ((HandCards.get(0).getCardValue() + 1) == HandCards.get(1).getCardValue() && (HandCards.get(1).getCardValue() + 1) == HandCards.get(2).getCardValue() && (HandCards.get(2).getCardValue() + 1) == HandCards.get(3).getCardValue() && (HandCards.get(3).getCardValue() + 1) == HandCards.get(4).getCardValue()
                    || HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && (HandCards.get(0).getCardValue() + 1) == HandCards.get(1).getCardValue() && (HandCards.get(1).getCardValue() + 1) == HandCards.get(2).getCardValue() && (HandCards.get(2).getCardValue() + 1) == HandCards.get(3).getCardValue()) {
                message = "You've Straight";
                finalmessage = "You've Straight";
                chk = false;
            }
        }

        public void checkThreeOfAKind() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Three Of A Kind";
                finalmessage = "You've Three Of A Kind";
                chk = false;
            }
        }

        public void checkTwoPair() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()
                    || HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've Two Pair";
                finalmessage = "You've Two Pair";
                chk = false;
            }
        }

        public void checkOnePair() {
            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue()
                    || HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()
                    || HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()
                    || HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                message = "You've One Pair";
                finalmessage = "You've One Pair";
                chk = false;
            }
        }

        private void checkRoyalFlushHint() { //Royal Flush (10,J,Q,K,A)       
            String Message = "You Already Have Flush & You Can Try For A Royal Flush If You Remove ";
            String RemoveValues = "";

            int i = 0;
            int val = 0;
            for (MyCard c : HandCards) {
                if (c.getCardValue() == 10 || c.getCardValue() == 11 || c.getCardValue() == 12 || c.getCardValue() == 13 || c.getCardValue() == 14) {
                } else {
                    val++;
                    RemoveValues += c.getCardValue() + ",";
                    indexArray[i] = c.getCardIndex();
                    i++;
                }
                
            }

            if (val < 3) {
                if (val == 0) {
                    Message = "";
                }
                message = Message + " " + RemoveValues;
                finalmessage = "You've Flush";
                chk = false;
            }else{
                this.indexArray[0] = 53;
                this.indexArray[1] = 53;
                this.indexArray[2] = 53;
                this.indexArray[3] = 53;
                this.indexArray[4] = 53;
            }
        }

        private void checkStraightFlushHint() {
            String Message = "You Already Have Flush & You Can Try A Straight Flush If You Remove : ";
            finalmessage = "You've Flush";
            String RemoveValues = "";

            //Straight Flush (14,2,3,4,5)    
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && HandCards.get(1).getCardValue() == 3) {
                if (HandCards.get(2).getCardValue() == 4 || HandCards.get(2).getCardValue() == 5) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() == 4 || HandCards.get(3).getCardValue() == 5) {
                    RemoveValues = HandCards.get(2).getCardValue() + " ";
                    indexArray[0] = HandCards.get(2).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(2).getCardValue() + " , " + HandCards.get(3).getCardValue();
                    indexArray[0] = HandCards.get(2).getCardIndex();
                    indexArray[1] = HandCards.get(3).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight Flush (x,x+1,x+2,y,z)              
            else if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()) {
                if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() || HandCards.get(2).getCardValue() + 2 == HandCards.get(3).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() + 2 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(3).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(3).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;

            }//Straight Flush (y,x,x+1,x+2,z) 
            else if (HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()) {
                if (HandCards.get(1).getCardValue() - 1 == HandCards.get(0).getCardValue()) {
                    RemoveValues += HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                    RemoveValues += HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight Flush (y,z,x,x+1,x+2) 
            else if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                if (HandCards.get(2).getCardValue() - 2 == HandCards.get(0).getCardValue()) {
                    RemoveValues += HandCards.get(1).getCardValue() + " ";
                    indexArray[0] = HandCards.get(1).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() - 1 == HandCards.get(1).getCardValue() || HandCards.get(2).getCardValue() - 2 == HandCards.get(1).getCardValue()) {
                    RemoveValues += HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(1).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(1).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }
        }

        private void checkFlushHint() {
            int i = 0;
            int suit1 = 0, suit2 = 0, suit3 = 0, suit4 = 0;
            String Message = "";
            finalmessage = "You've High Card";

            for (MyCard c : HandCards) {
                if (c.getCardType() == 1) {
                    suit1++;
                } else if (c.getCardType() == 2) {
                    suit2++;
                } else if (c.getCardType() == 3) {
                    suit3++;
                } else if (c.getCardType() == 4) {
                    suit4++;
                }
                i++;
            }

            if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue()
                    && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()
                    && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()
                    && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                Message = "You Already Have Straight & ";
                finalmessage = "You've Straight";
            }

            if (suit1 == 3 || suit1 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Spades.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 1) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }

            } else if (suit2 == 3 || suit2 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Hearts.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 2) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }

            } else if (suit3 == 3 || suit3 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Clubs.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 3) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }
            } else if (suit4 == 3 || suit4 == 4) {
                message = Message + "You Can Try A Flush If You Remove The Cards Other Than Diamonds.";
                chk = false;
                int z = 0;
                for (MyCard c : HandCards) {
                    if (c.getCardType() != 4) {
                        indexArray[z] = c.getCardIndex();
                    } 
                    z++;
                }
            }
        }

        private void checkStraightHint() {
            String Message = "You Can Try A Straight If You Remove : ";
            finalmessage = "You've A High Card";
            String RemoveValues = "";

            //Straight (8,9,11,12,13)    
            if (HandCards.get(4).getCardValue() == 14 && HandCards.get(0).getCardValue() == 2 && HandCards.get(1).getCardValue() == 3) {
                if (HandCards.get(2).getCardValue() == 4 || HandCards.get(2).getCardValue() == 5) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() == 4 || HandCards.get(3).getCardValue() == 5) {
                    RemoveValues = HandCards.get(2).getCardValue() + " ";
                    indexArray[0] = HandCards.get(2).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(2).getCardValue() + " , " + HandCards.get(3).getCardValue();
                    indexArray[0] = HandCards.get(2).getCardIndex();
                    indexArray[1] = HandCards.get(3).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight (x,x+1,x+2,y,z)          
            else if (HandCards.get(0).getCardValue() + 1 == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue()) {
                if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() || HandCards.get(2).getCardValue() + 2 == HandCards.get(3).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() + 2 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(3).getCardValue() + " ";
                    indexArray[0] = HandCards.get(3).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(3).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(3).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;

            }//Straight (y,x,x+1,x+2,z) 
            else if (HandCards.get(1).getCardValue() + 1 == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue()) {
                if (HandCards.get(1).getCardValue() - 1 == HandCards.get(0).getCardValue()) {
                    RemoveValues = HandCards.get(4).getCardValue() + " ";
                    indexArray[0] = HandCards.get(4).getCardIndex();
                }
                else if (HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                    RemoveValues = HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(4).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(4).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }//Straight(y,z,x,x+1,x+2)Straight (8,9,11,12,13) 
            else if (HandCards.get(2).getCardValue() + 1 == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() + 1 == HandCards.get(4).getCardValue()) {
                if (HandCards.get(2).getCardValue() - 2 == HandCards.get(0).getCardValue()) {
                    RemoveValues = HandCards.get(1).getCardValue() + " ";
                    indexArray[0] = HandCards.get(1).getCardIndex();
                }
                else if (HandCards.get(2).getCardValue() - 1 == HandCards.get(1).getCardValue() || HandCards.get(2).getCardValue() - 2 == HandCards.get(1).getCardValue()) {
                    RemoveValues = HandCards.get(0).getCardValue() + " ";
                    indexArray[0] = HandCards.get(0).getCardIndex();
                }
                else{
                    RemoveValues = HandCards.get(0).getCardValue() + " , " + HandCards.get(1).getCardValue();
                    indexArray[0] = HandCards.get(0).getCardIndex();
                    indexArray[1] = HandCards.get(1).getCardIndex();
                }
                message = Message + " " + RemoveValues;
                chk = false;
            }
        }

        private void checkHighCardHint() {
            String Message = "";
            finalmessage = "You've A High Card";

            if (HandCards.get(2).getCardValue() < 10) {
                Message = "You Already Have A High Card of " + HandCards.get(4).getCardValue() +"& You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                chk = false;
            } else if (HandCards.get(4).getCardValue() == 14) {
                Message = "You Already Have A High Card of " + HandCards.get(4).getCardValue() +"& You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue() + "," + HandCards.get(3).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                indexArray[3] = HandCards.get(3).getCardIndex();
                chk = false;
            } else {
                Message = "You Can Try A Good Suit If You Remove:" + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue() + "," + HandCards.get(2).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                indexArray[2] = HandCards.get(2).getCardIndex();
                chk = false;
            }
            message = Message;
        }

        private void checkFourOfKindHint() {
            String Message = "";
            finalmessage = "You've A High Card";

            if (HandCards.get(0).getCardValue() == HandCards.get(1).getCardValue() && HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove: " + HandCards.get(3).getCardValue() + "," + HandCards.get(4).getCardValue();
                indexArray[0] = HandCards.get(3).getCardIndex();
                indexArray[1] = HandCards.get(4).getCardIndex();
                chk = false;
            } else if (HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue() && HandCards.get(3).getCardValue() == HandCards.get(4).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove " + HandCards.get(0).getCardValue() + "," + HandCards.get(1).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(1).getCardIndex();
                chk = false;
            } else if (HandCards.get(1).getCardValue() == HandCards.get(2).getCardValue() && HandCards.get(2).getCardValue() == HandCards.get(3).getCardValue()) {
                Message = "You Can Try For A Four A Kind, If You Remove " + HandCards.get(0).getCardValue() + " " + HandCards.get(4).getCardValue();
                indexArray[0] = HandCards.get(0).getCardIndex();
                indexArray[1] = HandCards.get(4).getCardIndex();
                chk = false;
            }
            if (Message != "") {
                message = Message;
            }
        }

    }
%>

<%
    class PokerRanking {
        private int priority, rankcard , highCard, suit;
        private ArrayList<MyCard> myHandCards;
        private boolean chk = true;

        public PokerRanking() {
        }

        public void setHand(ArrayList<MyCard> card) {
            this.myHandCards = card;
            sortHandCards();
            getRank();
        }

        public int getPriority() {
            return priority;
        }
        
        public int getRankCard() {
            return rankcard;
        }

        public int getHighCard() {
            return highCard;
        }

        public int getSuit() {
            return suit;
        }

        public void sortHandCards() { 
            
            //Copying The Hand Cards To Unsorted Card Array AND Removing All The Cards From Hand
            ArrayList<MyCard> unsortCards = new ArrayList<MyCard>();
            for (MyCard c : this.myHandCards) {
                unsortCards.add(c); 
            }
            this.myHandCards = new ArrayList<MyCard>();
            
            //Sorting The Card Values
            int[] arr = new int[5];
            for(int i=0;i<5;i++){
                arr[i] = unsortCards.get(i).getCardValue();
            }
            Arrays.sort(arr);

            //Copying The Sorted Cards To The Hand
            MyCard x = new MyCard();
            for(int a : arr){
                for (MyCard c : unsortCards) {
                    if(a == c.getCardValue()){
                        x = c;
                        break;
                    }
                }
                this.myHandCards.add(x);
                unsortCards.remove(x);
            }

            /**
            //Available In jdk 1.7
            Collections.sort(this.myHandCards, new Comparator<MyCard>() {
                @Override
                public int compare(MyCard c1, MyCard c2) {
                    return Integer.compare(c1.getCardValue(), c2.getCardValue());
                }
            });**/
            
            highCard = myHandCards.get(4).getCardValue();
            rankcard = 53;
        }

        private void getRank() {
            int i = 0;
            for (MyCard c : myHandCards) {
                if (i == 0) {
                    suit = c.getCardType();
                } else if (suit == c.getCardType()) {
                    continue;
                } else {
                    suit = 0;
                    break;
                }
                i++;
            }
            if (suit != 0) {//Same Suit 
                if (chk) { checkRoyalFlush();
                }if (chk) { checkStraightFlush();
                }if (chk) { checkFlush();
                }
            } else {//Not Same Suit
                if (chk) { checkFourOfAKind();
                }if (chk) { checkFullHouse();
                }if (chk) { checkStraight();
                }if (chk) { checkThreeOfAKind();
                }if (chk) { checkTwoPair();
                }if (chk) { checkOnePair();
                }if (chk) { HighCard();
                }
            }
        }

        public void checkRoyalFlush() {
            if (myHandCards.get(0).getCardValue() == 10 && myHandCards.get(1).getCardValue() == 11 && myHandCards.get(2).getCardValue() == 12 && myHandCards.get(3).getCardValue() == 13 && myHandCards.get(4).getCardValue() == 14) {
                priority = 1;
                chk = false;
            }
        }

        public void checkStraightFlush() {
            int sum = myHandCards.get(0).getCardValue() + 3;
            int tot = myHandCards.get(0).getCardValue() + 4;

            //Checking For Straight Flush with A in 1st
            if (myHandCards.get(4).getCardValue() == 14 && myHandCards.get(0).getCardValue() == 2 && sum == myHandCards.get(3).getCardValue()) {
                priority = 2;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }//Checking Straight Flush For Other values
            else if (tot == myHandCards.get(4).getCardValue()) {
                priority = 2;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }
        }

        public void checkFourOfAKind() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 3;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkFullHouse() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()
                    || myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 4;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkFlush() {
            priority = 5;
            rankcard = myHandCards.get(4).getCardValue();
            chk = false;
        }

        public void checkStraight() {
            if ((myHandCards.get(0).getCardValue() + 1) == myHandCards.get(1).getCardValue() && (myHandCards.get(1).getCardValue() + 1) == myHandCards.get(2).getCardValue() && (myHandCards.get(2).getCardValue() + 1) == myHandCards.get(3).getCardValue() && (myHandCards.get(3).getCardValue() + 1) == myHandCards.get(4).getCardValue()
                    || myHandCards.get(4).getCardValue() == 14 && myHandCards.get(0).getCardValue() == 2 && (myHandCards.get(0).getCardValue() + 1) == myHandCards.get(1).getCardValue() && (myHandCards.get(1).getCardValue() + 1) == myHandCards.get(2).getCardValue() && (myHandCards.get(2).getCardValue() + 1) == myHandCards.get(3).getCardValue()) {
                priority = 6;
                rankcard = myHandCards.get(4).getCardValue();
                chk = false;
            }
        }

        public void checkThreeOfAKind() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 7;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void checkTwoPair() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()
                    || myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()
                    || myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue() && myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 8;
                rankcard = myHandCards.get(3).getCardValue();
                highCard = myHandCards.get(1).getCardValue();
                chk = false;
            }
        }

        public void checkOnePair() {
            if (myHandCards.get(0).getCardValue() == myHandCards.get(1).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(1).getCardValue();
                chk = false;
            }
            if (myHandCards.get(1).getCardValue() == myHandCards.get(2).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(1).getCardValue();
                chk = false;
            }
            if (myHandCards.get(2).getCardValue() == myHandCards.get(3).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(2).getCardValue();
                chk = false;
            }
            if (myHandCards.get(3).getCardValue() == myHandCards.get(4).getCardValue()) {
                priority = 9;
                rankcard = myHandCards.get(4).getCardValue();
                highCard = myHandCards.get(2).getCardValue();
                chk = false;
            }
        }

        public void HighCard() {
            priority = 10;
            rankcard = myHandCards.get(4).getCardValue();
            highCard = myHandCards.get(3).getCardValue();
            chk = false;
        }

    }
%>

<%
    String sReqType = request.getParameter("reqtype");
    
    if (sReqType.equals("Load")) {
        MyDeck deck = new MyDeck();
        MyHand hand_1 = new MyHand();
        MyHand hand_2 = new MyHand();
        deck.shuffle();
        for (int i = 0; i < 5; i++) {
            hand_1.addCard(deck.dealCard());
            hand_2.addCard(deck.dealCard());
        }
        session.setAttribute("sdeck", deck);
        session.setAttribute("shand1", hand_1);
        session.setAttribute("shand2", hand_2);
    }
    else if (sReqType.equals("GetBalanceCoin")) {
        String sUserId = (String) session.getAttribute("suserid");
        int dbCoins = 0;
        Connection mysqlCon = null;
        Statement stmt = null;
        try {
            DBConfig db = new DBConfig();
            Class.forName("com.mysql.jdbc.Driver");
            mysqlCon = DriverManager.getConnection(db.host + "/" + db.db, db.user, db.pass);
            stmt = mysqlCon.createStatement();
            String query = "UPDATE `user` SET `Coins` = `Coins` - 10 WHERE `UserId` = " + sUserId;
            stmt.executeUpdate(query);
            query = "SELECT `Coins` FROM `user` WHERE `UserId` = " + sUserId;
            ResultSet rs = stmt.executeQuery(query);
            if (rs.next()) {
                dbCoins = rs.getInt(1);
            }
        } catch (Exception e) {
        } finally {
            stmt.close();
            mysqlCon.close();
        }
        out.print(dbCoins);
    }
    else if (sReqType.equals("GetCards")) {
        String sPlayerType = request.getParameter("playertype");
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");
        if (sPlayerType.equals("Computer")) {
            hand_1 = (MyHand)session.getAttribute("shand2");
        }
        String playerhand = "<player>";
        for (MyCard c : hand_1.getHandCard()) {
            playerhand += "<index>";
            playerhand += "" + c.getCardIndex();
            playerhand += "</index>";
            playerhand += "<value>";
            playerhand += "" + c.getCardValue();
            playerhand += "</value>";
        }
        playerhand += "</player>";
        out.println(playerhand);
    }
    else if (sReqType.equals("Hint")) {
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");
        MyHint myhint = new MyHint(hand_1.getHandCard());
        myhint.checkHint();
        out.print(myhint.getHint());
    }
    else if (sReqType.equals("FinalHint")) {
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");
        MyHint myhint = new MyHint(hand_1.getHandCard());
        myhint.checkHint();
        out.print(myhint.getFinalHint());
    }
    else if (sReqType.equals("Deal")) {
        int CC[] = new int[5];
        CC[0] = Integer.parseInt(request.getParameter("C1"));
        CC[1] = Integer.parseInt(request.getParameter("C2"));
        CC[2] = Integer.parseInt(request.getParameter("C3"));
        CC[3] = Integer.parseInt(request.getParameter("C4"));
        CC[4] = Integer.parseInt(request.getParameter("C5"));
                
        MyDeck deck =  (MyDeck)session.getAttribute("sdeck");
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");

        for (int c : CC) {
            if (c < 53) {
                deck.addCard(hand_1.removeCard(c));
                hand_1.addCard(deck.dealCard());
            }
        }
        
        session.setAttribute("sdeck", deck);
        session.setAttribute("shand1", hand_1);
        
        String playerhand = "<player>";
        for (MyCard c : hand_1.getHandCard()) {
            playerhand += "<index>";
            playerhand += "" + c.getCardIndex();
            playerhand += "</index>";
            playerhand += "<value>";
            playerhand += "" + c.getCardValue();
            playerhand += "</value>";
        }
        playerhand += "</player>";
        out.println(playerhand);
    }
    else if (sReqType.equals("ComputerDeal")) {
        MyDeck deck =  (MyDeck)session.getAttribute("sdeck");
        MyHand hand_2 = (MyHand)session.getAttribute("shand2");
        MyHint myhint = new MyHint(hand_2.getHandCard());
        myhint.checkHint();
        for (int c : myhint.getIndexArray()) {
            if (c < 53) {
                deck.addCard(hand_2.removeCard(c));
                hand_2.addCard(deck.dealCard());
            }
        }
        session.setAttribute("sdeck", deck);
        session.setAttribute("shand2", hand_2);
    }
    else if (sReqType.equals("PokerRanking")) {
        String rankXML = "<result>";
        
        MyHand hand_1 = (MyHand)session.getAttribute("shand1");
        PokerRanking player1 = new PokerRanking();
        player1.setHand(hand_1.getHandCard());
        rankXML += "<rank>" + player1.getPriority() + "</rank>";
        rankXML += "<rankcard>" + player1.getRankCard()+ "</rankcard>";
        rankXML += "<highcard>" + player1.getHighCard() + "</highcard>";
        
        MyHand hand_2 = (MyHand)session.getAttribute("shand2");
        PokerRanking player2 = new PokerRanking();
        player2.setHand(hand_2.getHandCard());
        rankXML += "<rank>" + player2.getPriority() + "</rank>";
        rankXML += "<rankcard>" + player2.getRankCard()+ "</rankcard>";
        rankXML += "<highcard>" + player2.getHighCard() + "</highcard>";
        
        rankXML += "</result>";
        out.println(rankXML);
    }
    else if (sReqType.equals("PlayerRaise")) {
        String sUserId = (String) session.getAttribute("suserid");
        Connection mysqlCon = null;
        Statement stmt = null;
        try {
            DBConfig db = new DBConfig();
            Class.forName("com.mysql.jdbc.Driver");
            mysqlCon = DriverManager.getConnection(db.host + "/" + db.db, db.user, db.pass);
            stmt = mysqlCon.createStatement();
            String query = "UPDATE `user` SET `Coins` = `Coins` - 10  WHERE `UserId` = " + sUserId;
            stmt.executeUpdate(query);
        } catch (Exception e) {
        } finally {
            stmt.close();
            mysqlCon.close();
        }
    }
    else if (sReqType.equals("UpdateRanking")) {
        String sWinCoin = request.getParameter("Coins");
        String sUserId = (String) session.getAttribute("suserid");
        Connection mysqlCon = null;
        Statement stmt = null;
        try {
            DBConfig db = new DBConfig();
            Class.forName("com.mysql.jdbc.Driver");
            mysqlCon = DriverManager.getConnection(db.host + "/" + db.db, db.user, db.pass);
            stmt = mysqlCon.createStatement();
            String query = "UPDATE `user` SET `GamesWon` = `GamesWon` + 1 , `Coins` = `Coins` + " + sWinCoin + " WHERE `UserId` = " + sUserId;
            stmt.executeUpdate(query);
        } catch (Exception e) {
        } finally {
            stmt.close();
            mysqlCon.close();
        }
    }
%>



poker.sql
-- phpMyAdmin SQL Dump
-- version 4.0.9
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 19, 2014 at 07:38 AM
-- Server version: 5.6.14
-- PHP Version: 5.5.6

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `poker`
--

-- --------------------------------------------------------

--
-- Table structure for table `tables`
--

CREATE TABLE IF NOT EXISTS `tables` (
  `TableId` int(11) NOT NULL AUTO_INCREMENT,
  `PlayerCount` int(11) NOT NULL,
  PRIMARY KEY (`TableId`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

--
-- Dumping data for table `tables`
--

INSERT INTO `tables` (`TableId`, `PlayerCount`) VALUES
(1, 0),
(2, 0),
(3, 0),
(4, 0),
(5, 0),
(6, 0),
(7, 0),
(8, 0),
(9, 0),
(10, 0);

-- --------------------------------------------------------

--
-- Table structure for table `tournment`
--

CREATE TABLE IF NOT EXISTS `tournment` (
  `TableId` int(11) NOT NULL,
  `PlayerId` int(11) NOT NULL,
  `UserId` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `tournment`
--

INSERT INTO `tournment` (`TableId`, `PlayerId`, `UserId`) VALUES
(1, 1, 1),
(1, 2, 2),
(1, 3, 3),
(1, 4, 4),
(1, 5, 5),
(1, 6, 6),
(3, 1, 1),
(3, 2, 2),
(3, 4, 4),
(3, 3, 3),
(3, 5, 5),
(3, 6, 6),
(4, 1, 1),
(4, 2, 2),
(4, 4, 4),
(4, 3, 3),
(4, 5, 5),
(4, 6, 6),
(5, 1, 1),
(5, 2, 2),
(5, 4, 4),
(5, 3, 3),
(5, 5, 5),
(5, 6, 6),
(2, 1, 1),
(2, 2, 2),
(2, 4, 4),
(2, 3, 3),
(2, 5, 5),
(2, 6, 6);

-- --------------------------------------------------------

--
-- Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
  `UserId` int(11) NOT NULL AUTO_INCREMENT,
  `UserName` varchar(20) NOT NULL,
  `Password` varchar(20) NOT NULL,
  `Name` varchar(50) NOT NULL,
  `Coins` int(11) NOT NULL,
  `GamesPlayed` int(11) NOT NULL,
  `GamesWon` int(11) NOT NULL,
  `LastLog` date NOT NULL,
  PRIMARY KEY (`UserId`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1008 ;

--
-- Dumping data for table `user`
--

INSERT INTO `user` (`UserId`, `UserName`, `Password`, `Name`, `Coins`, `GamesPlayed`, `GamesWon`, `LastLog`) VALUES
(1, '1', '1', 'Computer 1', 250, 0, 0, '0000-00-00'),
(2, '2', '2', 'Computer 2', 250, 0, 0, '0000-00-00'),
(3, '3', '3', 'Computer 3', 250, 0, 0, '0000-00-00'),
(4, '4', '4', 'Computer 4', 250, 0, 0, '0000-00-00'),
(5, '5', '5', 'Computer 5', 250, 0, 0, '0000-00-00'),
(6, '6', '6', 'Computer 6', 250, 0, 0, '0000-00-00'),
(1001, 'Nifal', '123', 'Nifal Nizar', 530, 72, 20, '2014-09-08'),
(1002, 's', 's', 'sss', 300, 0, 0, '2014-09-08');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;





ENJOY THE CODING....GOOD LUCK....

No comments:

JWT Token Decode Using Jquery

When it come to authentication we use many mechanism. Ones the user authenticated we must keep these details somewhere safe. So we can share...