//if the discard pile has a card that is less than the cards the //computer can see of its hand or less than 5 then the computer picks up the card. //if the discard pile is larger than all of the computers cards or if it //is higher than 10, the computer picks a card from the deck public compPick(Vector deck, Vector discardPile, Vector computerHand) //<------- not sure if this actually works....in fact... // im sure it dosent..... { //int randcard = 0; for(int i = 3; i <= 4; i++) { //if the discard pile is less than //either of the cards the comp can see //then the comp switches the cards, effectivley //picking up and discarding if (discardPile.elementAt(0).getValue() < computerHand.elementAt(i).getValue()); { Card holder = new Card(); holder = discardPile.elementAt(0); discardPile.elementAt(0) = computerHand.elementAt(i); computerHand.elementAt(i) = holder; } while (randcard !<= 1)&&(randcard !>= size)&&(deck.elementAt(randcard).getvalue() == 0); { randcard = (Math.random() * 100); } //------------------------------------------------| THIS IS NOW THE TRADE METHOD|---------------------------------prepare------- //asks the user from where he wants to pick up a card //user gets a list of possible places and enters a corosponding int //the computer pulls the card and asks the user where he wants to put it //agian the user is presented with a list of places that he could be allowed to //put it and agian he enters the corosponding int //the computer then puts the card into that place in his hand //------------------------------------------------|KNOCK DICISION|-------------------------------------------------- //this method can be used for both the user and the computer (although i would let the user decide for himself when to knock) //it decides if a players cards are low enough that it has a good chance of winning if it knocks. if they are low it returns 'true' public boolean computerKnockDecide(Vector computerhand) { if (((computerhand.elementAt(1).getvalue()+2) + (computerhand.elementAt(2).getvalue()+2) + (computerhand.elementAt(3).getValue()) + (computerhand.elementAt(4).getvalue())) < 10) { return true; } } //-------------------------------------------------------|whereToPickUp|---------------------------------------------------------------------- //this method will decide where to pick up from (either the discard pile or the deck) then it will pick a card up from that place //and return it. public Card whereToPickUp(Vector computerhand,Vector deck, Vector discardPile) { Card temp = new Card(); //checks to mkae sure that discard pile is more than all of the computers cards before picking from the deck if ((discardPile.elementAt(0).getValue() > computerhand.elementAt(3).getValue()) && (discardPile.elementAt(0).getValue() >computerhand.elementAt(4).getValue() ) && (discardPile.elementAt(0).getValue() >computerhand.elementAt(1).getValue() + 2 ) && (discardPile.elementAt(0).getValue() >computerhand.elementAt(2).getValue() + 2 ) { temp = Card.dealCard(deck); } else { temp = discardPile.elementAt(0); } return temp; } //-----------------------------------| wincheck |----------------------------------------- // winCheck will check to see which player (comp or computer player) wins. // it compares the hands and sees which is lowest. then it returns 1 if // the human player wins and 0 if the human player looses (ie: the copmuter wins.) public int winCheck(Vector computerhand, Vector playerhand) { int accumulte = 0; int ptotal = 0; int ctotal = 0; int pwin = 0; //adds up the computers total for(int i = 0; i <= 3; i++) { accumulte = computerhand.elementAt(i).getValue(); ctotal = ctotal + accumulte; } //adds up the player's total for(int i = 0; i <= 3; i++) { accumulte = playerhand.elementAt(i).getValue(); ptotal = ptotal + accumulte; } //compares the totals if (ptotal = ctotal) { pwin = 0; } else if (ptotal < ctotal) { pwin = 1; } else { pwin = 0; } return pwin; } //-----------------------------------| replace |-------------------------------------------- //replaces the computers highest card with the one it recieves and takes the one that was ousted //and puts it into the discard pile public void replace(Vector discardPile, Vector computerhand, Card pickup) { int biggest = 0; int max = 0; Card temp = new Card; for(int i = 0; i < 3; i++) { if (computerhand.elementAt(i).getValue() > max) { max = computerhand.elementAt(i).getValue(); biggest = i; } } temp = computerhand.elementAt(biggest); computerhand.elementAt(biggest) = pickup; Discardpile.elementAt(0) = temp; } //-----------------------------------| playNewGame |------------------------------------------- //plays the frikken game... //loops one round of turns until boolean knock = true //then it decides who wins and outputs the winner... // goes back to main...or something....maybe its in a giant loop...i dunno... playNewGame(Vector computerhand,Vector deck,Vector discardPile, Vector playerhand) { //this is the arbiter of the method, if someone knocks then the game is over and we see who wins. boolean knock = false; int win = 0; //makes a temp card for the userdecide method...it needs one apperently Card cardholder = new Card; //deals cards out to the player and computer System.out.println("dealing, please wait..."); G1.deal while(knock == false) { //makes the user go, gives choices of pickup a card chose which card to discard ect. System.out.println(the user will go first, becuase humans rock"); userDecide(cardholder); //humanknowkdecision <<<----------FINISH!! //-----------------------------------------------------------------------------------NO FRATERNISING!!-------------------------------------------------------------------------------------------- //this makes the computer go: //decide where to pick up - //pick up - //replace. - //discard - System.out.println("now the lowly computer will go"); cardholder = G1.whereToPickUp(computerhand,deck,discardPile); G1.replace(discardPile,computerhand,cardholder); knock = G1.computerKnockDecide(computerhand); } //checks to see who wins! win = winCheck(computerhand,playerhand); if (win == 1) { System.out.println("THE HUMAN HAS TRIUMPHED OVER THE MACHINE, CONGRATULATIONS!!"); } else { System.out.println("THE MACHINE HAS TRIUMPHED OVER THE HUMAN, SORRY, YOU FAILED."); } }//end method