import java.applet.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; class intro extends Canvas { Font f; public intro() { f=new Font("SansSerif", Font.BOLD, 79); setBackground(Color.white); setSize(800, 145); show(); } public void paint(Graphics g) { g.drawString("", 0, 0); g.setFont(f); g.drawString("Welcome To Yahtzee", 3, 100); f=new Font("SansSerif", Font.BOLD, 20); g.setFont(f); g.drawString("Please select number of players :", 239, 140); } } class scorecard extends Panel { int scores[][], r, i, j; CheckboxGroup radio; Checkbox ones, twos, threes, fours, fives, sixes, threekind, fourkind, largestraight, smallstraight, fullhouse, yahtzee, chance; Label total1, total2, total3, total4, bonus, abovetotal, round, blank; TextField onescore, twoscore, threescore, fourscore, fivescore, sixscore, threekindscore, fourkindscore, largestraightscore, smallstraightscore, fullhousescore, yahtzeescore, chancescore, total1score, total2score, total3score, total4score, bonusscore, abovetotalscore; public scorecard() { int i, j; setLayout(new GridLayout(22, 2)); setBackground(Color.blue); setBounds(66, 10, 220, 462); r=1; blank = new Label(""); add(blank); round = new Label(" Round "+String.valueOf(r)); add(round); radio = new CheckboxGroup(); ones = new Checkbox("Ones", radio, true); add(ones); onescore = new TextField(); onescore.setBackground(Color.white); onescore.setEditable(false); add(onescore); twos = new Checkbox("Twos", radio, false); add(twos); twoscore = new TextField(); twoscore.setBackground(Color.white); twoscore.setEditable(false); add(twoscore); threes = new Checkbox("Threes", radio, false); add(threes); threescore = new TextField(); threescore.setBackground(Color.white); threescore.setEditable(false); add(threescore); fours = new Checkbox("Fours", radio, false); add(fours); fourscore = new TextField(); fourscore.setBackground(Color.white); fourscore.setEditable(false); add(fourscore); fives = new Checkbox("Fives", radio, false); add(fives); fivescore = new TextField(); fivescore.setBackground(Color.white); fivescore.setEditable(false); add(fivescore); sixes = new Checkbox("Sixes", radio, false); add(sixes); sixscore = new TextField(); sixscore.setBackground(Color.white); sixscore.setEditable(false); add(sixscore); total1 = new Label(" Total"); add(total1); total1score = new TextField(); total1score.setBackground(Color.white); total1score.setEditable(false); add(total1score); bonus = new Label(" Bonus"); add(bonus); bonusscore = new TextField(); bonusscore.setBackground(Color.white); add(bonusscore); total2 = new Label(" Total"); add(total2); total2score = new TextField(); total2score.setBackground(Color.white); total2score.setEditable(false); add(total2score); add(new Label("")); add(new Label("")); threekind = new Checkbox("Three of a Kind", radio, false); add(threekind); threekindscore = new TextField(); threekindscore.setBackground(Color.white); threekindscore.setEditable(false); add(threekindscore); fourkind = new Checkbox("Four of a Kind", radio, false); add(fourkind); fourkindscore = new TextField(); fourkindscore.setBackground(Color.white); fourkindscore.setEditable(false); add(fourkindscore); fullhouse = new Checkbox("Full House", radio, false); add(fullhouse); fullhousescore = new TextField(); fullhousescore.setBackground(Color.white); fullhousescore.setEditable(false); add(fullhousescore); smallstraight = new Checkbox("Small Straight", radio, false); add(smallstraight); smallstraightscore = new TextField(); smallstraightscore.setBackground(Color.white); smallstraightscore.setEditable(false); add(smallstraightscore); largestraight = new Checkbox("Large Straight", radio, false); add(largestraight); largestraightscore = new TextField(); largestraightscore.setBackground(Color.white); largestraightscore.setEditable(false); add(largestraightscore); yahtzee = new Checkbox("Yahtzee", radio, false); add(yahtzee); yahtzeescore = new TextField(); yahtzeescore.setBackground(Color.white); yahtzeescore.setEditable(false); add(yahtzeescore); chance = new Checkbox("Chance", radio, false); add(chance); chancescore = new TextField(); chancescore.setBackground(Color.white); chancescore.setEditable(false); add(chancescore); total3 = new Label(" Total"); add(total3); total3score = new TextField(); total3score.setBackground(Color.white); total3score.setEditable(false); add(total3score); abovetotal = new Label(" Above Total"); add(abovetotal); abovetotalscore = new TextField(); abovetotalscore.setBackground(Color.white); abovetotalscore.setEditable(false); add(abovetotalscore); total4 = new Label(" Total"); add(total4); total4score = new TextField(); total4score.setBackground(Color.white); total4score.setEditable(false); add(total4score); scores = new int[6][19]; for (i=0; i<6; i++) for (j=0; j<13; j++) { scores[i][j]=-1; // scores[i][11]=-1; } hide(); // show(); } public void reinit() { r=1; round.setText(String.valueOf(" Round "+String.valueOf(r))); onescore.setText(""); twoscore.setText(""); threescore.setText(""); fourscore.setText(""); fivescore.setText(""); sixscore.setText(""); total1score.setText(""); bonusscore.setText(""); total2score.setText(""); threekindscore.setText(""); fourkindscore.setText(""); fullhousescore.setText(""); largestraightscore.setText(""); smallstraightscore.setText(""); yahtzeescore.setText(""); chancescore.setText(""); total3score.setText(""); abovetotalscore.setText(""); total4score.setText(""); for (i=0; i<6; i++) for (j=0; j<13; j++) { scores[i][j]=-1; // scores[i][11]=-1; } // hide(); // show(); } public void nextround() { int j; r++; round.setText(String.valueOf(" Round "+String.valueOf(r))); onescore.setText(""); twoscore.setText(""); threescore.setText(""); fourscore.setText(""); fivescore.setText(""); sixscore.setText(""); total1score.setText(""); bonusscore.setText(""); total2score.setText(""); threekindscore.setText(""); fourkindscore.setText(""); fullhousescore.setText(""); largestraightscore.setText(""); smallstraightscore.setText(""); yahtzeescore.setText(""); chancescore.setText(""); total3score.setText(""); abovetotalscore.setText(""); total4score.setText(""); // System.out.println("r="+r); // for (j=0; j<13; j++) // scores[r-1][j]=-1; } public CheckboxGroup getradio() { return radio; } public boolean getonestate() { return ones.getState(); } public boolean gettwostate() { return twos.getState(); } public boolean getthreestate() { return threes.getState(); } public boolean getfourstate() { return fours.getState(); } public boolean getfivestate() { return fives.getState(); } public boolean getsixstate() { return sixes.getState(); } public boolean getthreekindstate() { return threekind.getState(); } public boolean getfourkindstate() { return fourkind.getState(); } public boolean getfullhousestate() { return fullhouse.getState(); } public boolean getlargestraightstate() { return largestraight.getState(); } public boolean getsmallstraightstate() { return smallstraight.getState(); } public boolean getyahtzeestate() { return yahtzee.getState(); } public boolean getchancestate() { return chance.getState(); } public void clearstates() { ones.setState(false); //System.out.println(""+getonestate()); twos.setState(false); threes.setState(false); fours.setState(false); fives.setState(false); sixes.setState(false); threekind.setState(false); fourkind.setState(false); fullhouse.setState(false); largestraight.setState(false); smallstraight.setState(false); yahtzee.setState(false); chance.setState(false); /*System.out.println(""+getonestate()); // System.out.println(""+gettwostate()); // System.out.println(""+getthreestate()); // System.out.println(""+getfourstate());*/ } public void enableones() { ones.setState(true); } public void enabletwos() { twos.setState(true); } public void enablethrees() { threes.setState(true); } public void enablefours() { fours.setState(true); } public void enablefives() { fives.setState(true); } public void enablesixes() { sixes.setState(true); } public void enablethreekind() { threekind.setState(true); } public void enablefourkind() { fourkind.setState(true); } public void enablefullhouse() { fullhouse.setState(true); } public void enablelargestraight() { largestraight.setState(true); } public void enablesmallstraight() { smallstraight.setState(true); } public void enableyahtzee() { yahtzee.setState(true); } public void enablechance() { chance.setState(true); } public int getscore(int round, int s) { //System.out.println("ok"); return scores[round-1][s]; } public void erase(int s, boolean bonusgiven[], int player, boolean computer) { if (roundover()) { scores[r-1][13]=-1; total1score.setText(""); scores[r-1][14]=-1; bonusscore.setText(""); scores[r-1][15]=-1; total2score.setText(""); scores[r-1][16]=-1; total3score.setText(""); scores[r-1][17]=-1; abovetotalscore.setText(""); scores[r-1][18]=-1; total4score.setText(""); } scores[r-1][s] = -1; if (bonusgiven[0]==true) { setyahtzeescore(scores[r-1][11]-100, player, computer); bonusgiven[0] = false; } switch (s) { case 0 : onescore.setText(""); break; case 1 : twoscore.setText(""); break; case 2 : threescore.setText(""); break; case 3 : fourscore.setText(""); break; case 4 : fivescore.setText(""); break; case 5 : sixscore.setText(""); break; case 6 : threekindscore.setText(""); break; case 7 : fourkindscore.setText(""); break; case 8 : fullhousescore.setText(""); break; case 9 : smallstraightscore.setText(""); break; case 10 : largestraightscore.setText(""); break; case 11 : yahtzeescore.setText(""); break; case 12 : chancescore.setText(""); break; } } public boolean roundover() { int i; for (i=0; i<13; i++) if (scores[r-1][i] == -1) return false; return true; } public void totalround(int player, boolean computer) { int i, grandtotal; int score=0, b=0; for (i=0; i<6; i++) score += scores[r-1][i]; scores[r-1][13] = score; // System.out.println("score="+score); //System.out.println("player="+player); // if ((player!=2)||(!computer)) total1score.setText(String.valueOf(score)); if (score >= 63) b=35; scores[r-1][14] = b; // if ((player!=2)||(!computer)) bonusscore.setText(String.valueOf(b)); scores[r-1][15] = score+b; // if ((player!=2)||(!computer)) total2score.setText(String.valueOf(score+b)); score=0; for (i=6; i<13; i++) score += scores[r-1][i]; scores[r-1][16] = score; // if ((player!=2)||(!computer)) total3score.setText(String.valueOf(score)); scores[r-1][17] = scores[r-1][15]; // if ((player!=2)||(!computer)) abovetotalscore.setText(String.valueOf(scores[r-1][15])); grandtotal = scores[r-1][16] + scores[r-1][17]; scores[r-1][18] = grandtotal; // if ((player!=2)||(!computer)) total4score.setText(String.valueOf(grandtotal)); } public void setonescore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) // System.out.println("score="+score); onescore.setText(String.valueOf(score)); // System.out.println(String.valueOf(onescore.getText())); scores[r-1][0] = score; } public void settwoscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) twoscore.setText(String.valueOf(score)); scores[r-1][1] = score; } public void setthreescore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) threescore.setText(String.valueOf(score)); scores[r-1][2] = score; } public void setfourscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) fourscore.setText(String.valueOf(score)); scores[r-1][3] = score; } public void setfivescore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) fivescore.setText(String.valueOf(score)); scores[r-1][4] = score; } public void setsixscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) sixscore.setText(String.valueOf(score)); scores[r-1][5] = score; } public void setthreekindscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) threekindscore.setText(String.valueOf(score)); scores[r-1][6] = score; } public void setfourkindscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) fourkindscore.setText(String.valueOf(score)); scores[r-1][7] = score; } public void setfullhousescore(int score, int player, boolean computer) { //System.out.println("setfullhousescoreok"); // if ((player!=2)||(!computer)) fullhousescore.setText(String.valueOf(score)); scores[r-1][8] = score; } public void setlargestraightscore(int score, int player, boolean computer) { //if ((player!=2)||(!computer)) largestraightscore.setText(String.valueOf(score)); scores[r-1][10] = score; } public void setsmallstraightscore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) smallstraightscore.setText(String.valueOf(score)); scores[r-1][9] = score; } public void setyahtzeescore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) yahtzeescore.setText(String.valueOf(score)); scores[r-1][11] = score; } public void setchancescore(int score, int player, boolean computer) { // if ((player!=2)||(!computer)) chancescore.setText(String.valueOf(score)); scores[r-1][12] = score; } } class scoreboard extends Panel { Label blank, p1, p2, p3, p4, c; TextField player1score, player2score, player3score, player4score; int playernum, round; // boolean computer; public scoreboard(int playernum, boolean computer) { setLayout(new GridLayout(1, 2*playernum)); setBackground(Color.red); this.playernum=playernum; // this.computer=computer; round=1; p1 = new Label(" Player 1"); p2 = new Label(" Player 2"); p3 = new Label(" Player 3"); p4 = new Label(" Player 4"); c = new Label(" Comp."); player1score = new TextField("0"); player2score = new TextField("0"); player3score = new TextField("0"); player4score = new TextField("0"); add(p1); add(player1score); if (playernum > 1) { if (!computer) add(p2); else add(c); add(player2score); } if (playernum > 2) { add(p3); add(player3score); } if (playernum > 3) { add(p4); add(player4score); } setBounds(57, 506, 116*playernum, 23); } public void reinit() { round=1; /* p1 = new Label(" Player 1"); p2 = new Label(" Player 2"); p3 = new Label(" Player 3"); p4 = new Label(" Player 4"); c = new Label(" Comp."); player1score = new TextField("0"); player2score = new TextField("0"); player3score = new TextField("0"); player4score = new TextField("0"); add(p1); add(player1score);*/ player1score.setText("0"); if (playernum > 1) { /* if (!computer) add(p2); else add(c); add(player2score);*/ player2score.setText("0"); } if (playernum > 2) { /* add(p3); add(player3score);*/ player3score.setText("0"); } if (playernum > 3) { /* add(p4); add(player4score);*/ player4score.setText("0"); } // setBounds(57, 546, 116*playernum, 23); } public void totalround(scorecard players[]) { int i, j, score; for (i=0; i0) newhits++; if (hits[i]>1) lowerhits(hits, 1, i); } if (hits[4]>0) lowerhits(hits, 0, 4); if (hits[5]>0) lowerhits(hits, 0, 5); oldhits=newhits; newhits=0; gethits(); for (i=2; i<6; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { selectnone(); if (hits[0]>0) lowerhits(hits, 0, 0); if (hits[1]>0) lowerhits(hits, 0, 1); for (i=2; i<6; i++) if (hits[i]>1) lowerhits(hits, 1, i); oldhits=newhits; } newhits=0; gethits(); for (i=1; i<5; i++) if (hits[i]>0) newhits++; if ((newhits>oldhits)||((newhits==oldhits)&& ((players[player-1].getscore(round, 10)==-1)|| (((oldhits<3)&&(hits[5]>0)&&((hits[2]>0)|| (hits[3]>0))))||((hits[2]>0)&&(hits[3]>0))))) { selectnone(); if (hits[0]>0) lowerhits(hits, 0, 0); for (i=1; i<5; i++) if (hits[i]>1) lowerhits(hits, 1, i); if (hits[5]>0) lowerhits(hits, 0, 5); oldhits=newhits; } done = true; } public void goforfullhouse() { int i, j, k; i=0; while ((i<6)&&(hits[i]<2)) i++; j=i+1; while ((j<6)&&(hits[j]<2)) j++; if ((i<6)&&(j<6)) { for (k=0; k<5; k++) if ((hand[k]!=i)&&(hand[k]!=j)) selected[k]=true; done=true; } } public void goforchance() { int i; for (i=0; i<5; i++) if (hand[i]<4) selected[i]=true; done=true; } public void initlookup() { int j, k, l, m, n; for (j=0; j<6; j++) for (k=j; k<6; k++) for (l=k; l<6; l++) for (m=l; m<6; m++) for (n=m; n<6; n++) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; // score=0; // bonusgiven[0]=false; // catnum=-1; pretendtoscoreroll(); gethits(); lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]][hits[5]]=score; score=0; bonusgiven[0]=false; catnum=-1; } } public void getavepayoutselected(int i) { int j, k, m, l, n; avepayoutselected=0; o=0; if ((!selected[0])&&(00) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); //System.out.println(paths); hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n;*/ // gethits(); /*for (j=0; j<6; j++) { catnum=-1; bonusgiven[0]=false; score=0;*/ gethits(); // pretendtoscoreroll(); score=lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]][hits[5]]; if ((hand[0]==originalhand[0])&&(0>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; // catnum=-1; bonusgiven[0]=false; // score=0; // } // } // System.out.println(o); /*if (i==0) { paths= // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==1) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==2) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==3) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); // catnum=-1; bonusgiven[0]=false; // score=0; }*/ } } public void getavepayoutnotselected(int i) { int j, k, m, l, n; avepayoutnotselected=0; o=0; if (i==0) { js=originalhand[i]; jf=js+1; } /*else { js=0; jf=6; }*/ if (i==1) { ks=originalhand[i]; kf=ks+1; } /* else { ks=0; kf=6; }*/ if (i==2) { ls=originalhand[i]; lf=ls+1; } /*else { ls=0; lf=6; }*/ if (i==3) { ms=originalhand[i]; mf=ms+1; } /* else { ms=0; mf=6; }*/ if (i==4) { ns=originalhand[i]; nf=ns+1; } /* else { ns=0; nf=6; }*/ for (j=js; j0) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight2*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); hits2[originalhand[i]]++; // for (j=js; ji)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight*score)/(o+weight); o+=weight; } avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; // System.out.println(o); // System.out.println(o); /* if (i==0) { if (j==originalhand[0]) { hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); // catnum=-1; bonusgiven[0]=false; // score=0; } } else if (i==1) { if (k==originalhand[1]) { hand[0]=j; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==2) { if (l==originalhand[2]) { hand[0]=j; hand[1]=k; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==3) { if (m==originalhand[3]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else { if (n==originalhand[4]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else*/ // getnextselected(i); // catnum=-1; bonusgiven[0]=false; // score=0; /* } }*/ } } public void goforupper() { int weight=4, weight2=4; int i, j, k, m, l, n, p, q, w;//, oldhits, newhits, //originalhand[], // paths; boolean found, streak; done=false; // System.out.println("go for upper"); // originalhand=new int[5]; // hits2=new int[6]; // lookup=new int[6][6][6][6][6][6]; if (((players[player-1].getscore(round, 9)==-1)|| (players[player-1].getscore(round, 10)==-1))&& (players[player-1].getscore(round, 0)>-1)&& (players[player-1].getscore(round, 1)>-1)&& (players[player-1].getscore(round, 2)>-1)&& (players[player-1].getscore(round, 3)>-1)&& (players[player-1].getscore(round, 4)>-1)&& (players[player-1].getscore(round, 5)>-1)&& (players[player-1].getscore(round, 6)>-1)) { weight=12; weight2=12; } /* if ((players[player-1].getscore(round, 9)==-1)|| (players[player-1].getscore(round, 10)==-1)) { weight=11; weight2=11; }*/ getkindscore(3); if (score>0) { if ((players[player-1].getscore(round, die-1)==-1) || (players[player-1].getscore(round, 6)==-1)|| (players[player-1].getscore(round, 7)==-1)) getselected(die-1); } if ((!done)&&(r==2)) { System.out.println("searching paths"); System.out.println(""+selected[0]+selected[1]+selected[2]+selected[3]+selected[4]); // sorthand(); //System.out.println(""+hand[0]+hand[1]+hand[2]+hand[3]+hand[4]); for (i=0; i<5; i++) originalhand[i]=hand[i]; initlookup(); for (i=0; i<5; i++) { //getavepayoutselected(i); // getavepayoutnotselected(i); avepayoutselected=0; o=0; if ((!selected[0])&&(00) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); //System.out.println(paths); hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n;*/ // gethits(); /*for (j=0; j<6; j++) { catnum=-1; bonusgiven[0]=false; score=0; if (i==0) { pretendtoscoreroll(); gethits(); lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]] [hits[5]]=score; } else {*/ gethits(); //pretendtoscoreroll(); score=lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]][hits[5]]; // } if ((hand[0]==originalhand[0])&&(0>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; catnum=-1; bonusgiven[0]=false; score=0; // } // } // System.out.println(o); /*if (i==0) { paths= // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==1) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==2) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==3) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; }*/ } for (p=0; p<5; p++) hand[p]=originalhand[p]; avepayoutnotselected=0; o=0; if (i==0) { js=originalhand[i]; jf=js+1; } /*else { js=0; jf=6; }*/ if (i==1) { ks=originalhand[i]; kf=ks+1; } /* else { ks=0; kf=6; }*/ if (i==2) { ls=originalhand[i]; lf=ls+1; } /*else { ls=0; lf=6; }*/ if (i==3) { ms=originalhand[i]; mf=ms+1; } /* else { ms=0; mf=6; }*/ if (i==4) { ns=originalhand[i]; nf=ns+1; } /* else { ns=0; nf=6; }*/ for (j=js; j0) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight2*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); hits2[originalhand[i]]++; // for (j=js; ji)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; // System.out.println(o); // System.out.println(o); /* if (i==0) { if (j==originalhand[0]) { hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==1) { if (k==originalhand[1]) { hand[0]=j; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==2) { if (l==originalhand[2]) { hand[0]=j; hand[1]=k; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==3) { if (m==originalhand[3]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else { if (n==originalhand[4]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else*/ // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; // } // } } // System.out.println("avepayoutselected="+avepayoutselected); // System.out.println("avepayoutnotselected="+avepayoutnotselected); // System.out.println("o="+o); if (avepayoutselected>avepayoutnotselected) { selected[i]=true; // weight2=0; // weight=weight2/2; } else { // weight2=weight2*2; // weight=weight*2; } for (p=0; p<5; p++) hand[p]=originalhand[p]; } done=true; } if (!done) {System.out.println("goingforupper"); /*getkindscore(3); if (score>0) { if ((players[player-1].getscore(round, die-1)==-1) || (players[player-1].getscore(round, 6)==-1)|| (players[player-1].getscore(round, 7)==-1)) getselected(die-1); }*/ if (!done) if (!taketwo()) if (players[player-1].getscore(round, 9)==-1) { getsmallstraightscore(); if (score==0) { if (((hits[1]>0)&&(hits[2]>0)&&(hits[3]>0))|| ((hits[2]>0)&&(hits[3]>0)&&(hits[4]>0))) goforsmallstraight(); else if (players[player-1].getscore(round, 10)==-1) { if (((hits[1]>0)&&(hits[2]>0)&&(hits[3]>0))|| ((hits[1]>0)&&(hits[3]>0)&&(hits[4]>0))|| ((hits[1]>0)&&(hits[2]>0)&&(hits[4]>0))|| ((hits[2]>0)&&(hits[3]>0)&&(hits[4]>0))) goforsmallstraight(); } } else if (players[player-1].getscore(round, 10)==-1) goforlargestraight(); else done = true; }/*{ i=5; if (r==1) { found = false; while ((i>-1)&&(!found)) { if ((hits[i]==2)&&((players[player-1].getscore(round, i)==-1) ||((players[player-1].getscore(round, 6)==-1)&&(i>=1))|| ((players[player-1].getscore(round, 7)==-1)&&(i>=1)))) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; done=true; } else i--; } } else if (r==2) { found = false; i=0; while ((i<6)&&(!found)) { if ((hits[i]==2)&&(players[player-1].getscore(round, i)==-1)) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; done=true; } else i++; } } if ((i==-1)||(i==6)) {/* found = false; i=0; while ((i<6)&&(!found)) { if ((hits[i]==1)&&(players[player-1].getscore(round, i)==-1)) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; done=true; } else i++; } if (i==6) {*/ if (players[player-1].getscore(round, 8)==-1) { getfullhousescore(); if (score>0) { done=true; } goforfullhouse(); } // } // } } if ((!done)&&(r==2)) { System.out.println("searching paths"); System.out.println(""+selected[0]+selected[1]+selected[2]+selected[3]+selected[4]); // sorthand(); //System.out.println(""+hand[0]+hand[1]+hand[2]+hand[3]+hand[4]); for (i=0; i<5; i++) originalhand[i]=hand[i]; initlookup(); for (i=0; i<5; i++) { //getavepayoutselected(i); // getavepayoutnotselected(i); avepayoutselected=0; o=0; if ((!selected[0])&&(00) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); //System.out.println(paths); hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n;*/ // gethits(); /*for (j=0; j<6; j++) { catnum=-1; bonusgiven[0]=false; score=0; if (i==0) { pretendtoscoreroll(); gethits(); lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]] [hits[5]]=score; } else {*/ gethits(); //pretendtoscoreroll(); score=lookup[hits[0]][hits[1]][hits[2]][hits[3]][hits[4]][hits[5]]; // } if ((hand[0]==originalhand[0])&&(0>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; catnum=-1; bonusgiven[0]=false; score=0; // } // } // System.out.println(o); /*if (i==0) { paths= // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==1) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==2) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else if (i==3) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[4]==originalhand[4]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; } else { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[1]==originalhand[1]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[2]==originalhand[2]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (hand[3]==originalhand[3]) { avepayoutselected=(float)(avepayoutselected*o+weight*score)/(o+weight); o+=weight; } if (r==2) { avepayoutselected=(float)(avepayoutselected*o+score)/(o+1); o++; } // else // getnextnotselected(i); catnum=-1; bonusgiven[0]=false; score=0; }*/ } for (p=0; p<5; p++) hand[p]=originalhand[p]; avepayoutnotselected=0; o=0; if (i==0) { js=originalhand[i]; jf=js+1; } /*else { js=0; jf=6; }*/ if (i==1) { ks=originalhand[i]; kf=ks+1; } /* else { ks=0; kf=6; }*/ if (i==2) { ls=originalhand[i]; lf=ls+1; } /*else { ls=0; lf=6; }*/ if (i==3) { ms=originalhand[i]; mf=ms+1; } /* else { ms=0; mf=6; }*/ if (i==4) { ns=originalhand[i]; nf=ns+1; } /* else { ns=0; nf=6; }*/ for (j=js; j0) for (p=0; p<6; p++) paths+=(int)(hits[p]*hits2[p]*weight2*combinations)/r; hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; paths=0; paths+=getcombinations2(); hits2[originalhand[i]]++; // for (j=js; ji)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[1]==originalhand[1])&&(1>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[2]==originalhand[2])&&(2>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[3]==originalhand[3])&&(3>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if ((hand[4]==originalhand[4])&&(4>i)) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; // System.out.println(o); // System.out.println(o); /* if (i==0) { if (j==originalhand[0]) { hand[1]=k; hand[2]=l; hand[3]=m; hand[4]=n; // System.out.println("hand="+hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); // System.out.println("scoreroll"); pretendtoscoreroll(); // System.out.println("catnum="+catnum); // System.out.println("o="+o); if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==1) { if (k==originalhand[1]) { hand[0]=j; hand[2]=l; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==2) { if (l==originalhand[2]) { hand[0]=j; hand[1]=k; hand[3]=m; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else if (i==3) { if (m==originalhand[3]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[4]=n; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[4]==originalhand[4]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; } } else { if (n==originalhand[4]) { hand[0]=j; hand[1]=k; hand[2]=l; hand[3]=m; pretendtoscoreroll(); if (hand[0]==originalhand[0]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[1]==originalhand[1]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[2]==originalhand[2]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (hand[3]==originalhand[3]) { avepayoutnotselected=(float)(avepayoutnotselected*o+weight2*score)/(o+weight2); o+=weight2; } if (r==2) { avepayoutnotselected=(float)(avepayoutnotselected*o+score)/(o+1); o++; } // else*/ // getnextselected(i); catnum=-1; bonusgiven[0]=false; score=0; // } // } } // System.out.println("avepayoutselected="+avepayoutselected); // System.out.println("avepayoutnotselected="+avepayoutnotselected); // System.out.println("o="+o); if (avepayoutselected>avepayoutnotselected) { selected[i]=true; // weight2=0; // weight=weight2/2; } else { // weight2=weight2*2; // weight=weight*2; } for (p=0; p<5; p++) hand[p]=originalhand[p]; } done=true; } /* getkindscore(3); if (score>0) { if ((players[player-1].getscore(round, die-1)==-1) || (players[player-1].getscore(round, 6)==-1)|| (players[player-1].getscore(round, 7)==-1)) { for (i=0; i<5; i++) if ((hand[i]+1)!=die) selected[i]=true; done = true; } } if (!done) { i=5; if (r==1) { found = false; while ((i>-1)&&(!found)) { if ((hits[i]==2)&&((players[player-1].getscore(round, i)==-1) ||((players[player-1].getscore(round, 6)==-1)&&(i>=1))|| ((players[player-1].getscore(round, 7)==-1)&&(i>=1)))) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; done=true; } else i--; } } else if (r==2) { found = false; i=0; while ((i<6)&&(!found)) { if ((hits[i]==2)&&(players[player-1].getscore(round, i)==-1)) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; } else i++; } if ((i==6)&&(players[player-1].getscore(round, 6)==-1)) { found = false; i=5; while ((i>-1)&&(!found)) { if (hits[i]==2) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; } else i--; } } } if ((i==-1)||(i==6)) { found = false; i=0; while ((i<6)&&(!found)) { if ((hits[i]==1)&&(players[player-1].getscore(round, i)==-1)) { for (j=0; j<5; j++) if (hand[j]!=i) selected[j]=true; found = true; } else i++; } if (i==6) { if (players[player-1].getscore(round, 8)==-1) { getfullhousescore(); if (score>0) { done=true; } else { i=0; while ((i<6)&&(hits[i]<2)) i++; j=i+1; while ((j<6)&&(hits[j]<2)) j++; if ((i<6)&&(j<6)) { for (k=0; k<5; k++) if ((hand[k]!=i)&&(hand[k]!=j)) selected[k]=true; done=true; } } } */ if ((!done)&&(players[player-1].getscore(round, 6)==-1)) goforexpensivethreeofakind(); if (!done) if (!takeone()) if (players[player-1].getscore(round, 9)==-1) goforsmallstraight(); else if (players[player-1].getscore(round, 10)==-1) goforlargestraight(); /*{ if (players[player-1].getscore(round, 10)==-1) { oldhits=0; newhits=0; for (i=0; i<5; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { for (i=0; i<5; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } for (i=0; i<5; i++) if (hand[i]==5) selected[i]=true; oldhits=newhits; } newhits=0; gethits(); for (i=1; i<6; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { for (i=0; i<5; i++) selected[i]=false; for (i=1; i<6; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } for (i=0; i<5; i++) if (hand[i]==0) selected[i]=true; } done=true; } else if (players[player-1].getscore(round, 9)==-1) { oldhits=0; newhits=0; for (i=0; i<4; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { for (i=0; i<4; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } for (i=0; i<5; i++) if ((hand[i]==4)||(hand[i]==5)) selected[i]=true; oldhits=newhits; } newhits=0; gethits(); for (i=1; i<5; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { for (i=0; i<5; i++) selected[i]=false; for (i=1; i<5; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } for (i=0; i<5; i++) if ((hand[i]==0)||(hand[i]==5)) selected[i]=true; oldhits=newhits; } newhits=0; gethits(); for (i=2; i<6; i++) if (hits[i]>0) newhits++; if (newhits>=oldhits) { for (i=0; i<5; i++) selected[i]=false; for (i=2; i<6; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } for (i=0; i<5; i++) if ((hand[i]==0)||(hand[i]==1)) selected[i]=true; oldhits=newhits; newhits=0; } if (oldhits==4) for (i=0; i<5; i++) selected[i]=false; done=true; }*/ if (!done) if (players[player-1].getscore(round, 6)==-1) goforcheapthreeofakind(); if (!done) if ((players[player-1].getscore(round, 7)==-1)|| (players[player-1].getscore(round, 8)==-1)|| (players[player-1].getscore(round, 11)==-1)) goforleftovers(); if (!done) if ((hits[0]>=1)&&(players[player-1].getscore(round, 0)==-1)) getselected(0); if (!done) { i=0; while ((i<6)&&(!done)) if (players[player-1].getscore(round, i)==-1) getselected(i); else i++; } if (!done) goforchance(); /* } } } } }*/ for (i=0; i<5; i++) if (selected[i]==true) break; if (i==5) {// roll.setEnabled(false); // players[player-1].clearstates(); scoreroll(); } } public void getmove() { int i, j; //System.out.println("getmove"); //if (r==1) //{ //getyahtzeescore(); getkindscore(5); //if (score==50) if (score>0) { roll.setEnabled(false); //players[player-1].clearstates(); scoreroll(); // System.out.println("score="+players[player-1].getscore(round, 11) ); } else { getlargestraightscore(); if (score==40) if ((players[player-1].getscore(round, 9) == -1)|| (players[player-1].getscore(round, 10) == -1)) { roll.setEnabled(false); // players[player-1].clearstates(); scoreroll(); } else goforupper(); else { getfullhousescore(); if (score>0) if ((players[player-1].getscore(round, 8)==-1) &&(r==2)) scoreroll(); else goforupper(); else { if ((players[player-1].getscore(round, 10)==-1)&&(hits[1]>=1)&&(hits[2]>=1)&& (hits[3]>=1)&&(hits[4]>=1)) { goforlargestraight(); /* for (i=0; i<5; i++) { j=0; while (hits[i]>1) { if (hand[j]==i) { selected[j]=true; hits[i]--; } j++; } } if ((hand[0]==0)||(hand[0]==5)) selected[0]=true; if ((hand[1]==0)||(hand[1]==5)) selected[1]=true; if ((hand[2]==0)||(hand[2]==5)) selected[2]=true; if ((hand[3]==0)||(hand[3]==5)) selected[3]=true; if ((hand[4]==0)||(hand[4]==5)) selected[4]=true;*/ } else goforupper(); } } } //}else // goforupper(); repaint(); } public boolean handleEvent(Event e) { /* if (e.id == Event.WINDOW_DESTROY) { hide(); dispose(); System.exit(0); } else*/ if (e.id == Event.ACTION_EVENT) action(e, e.arg); else if ((e.id == Event.MOUSE_DOWN)&&((!computer)||(player==1))&&(roll.isEnabled())&& (r>1)) { if ((e.y >= 260) && (e.y <= 331)) { if ((e.x >= 409) && (e.x <= 480)) { selected[0] = !selected[0]; dice[0][hand[0]].select(); dice[0][hand[0]].repaint(); } else if ((e.x >= 509) && (e.x <= 580)) { selected[1] = !selected[1]; dice[1][hand[1]].select(); dice[1][hand[1]].repaint(); } else if ((e.x >= 609) && (e.x <= 680)) { selected[2] = !selected[2]; dice[2][hand[2]].select(); dice[2][hand[2]].repaint(); } } if ((e.y >= 360) && (e.y <= 431)) { if ((e.x >= 459) && (e.x <= 531)) { selected[3] = !selected[3]; dice[3][hand[3]].select(); dice[3][hand[3]].repaint(); } else if ((e.x >= 559) && (e.x <= 631)) { selected[4] = !selected[4]; dice[4][hand[4]].select(); dice[4][hand[4]].repaint(); } } repaint(); } return true; } public boolean scorecheapest(int olddeficit) { int i, j=6, newdeficit; gethits(); for (i=0; i<6; i++) { newdeficit = (i+1)*3 - hits[i]*(i+1); if ((newdeficit=50) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else { if (players[player-1].getscore(round, die-1)==-1) if (die==1) catnum=0;//players[player-1].enableones(); else if (die==2) catnum=1;//players[player-1].enabletwos(); else if (die==3) catnum=2;//players[player-1].enablethrees(); else if (die==4) catnum=3;//players[player-1].enablefours(); else if (die==5) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); else if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else { for (i=0; i<6; i++) if (players[player-1].getscore(round, i)==-1) break; if (i==0) catnum=0;//players[player-1].enableones(); else if (i==1) catnum=1;//players[player-1].enabletwos(); else if (i==2) catnum=2;//players[player-1].enablethrees(); else if (i==3) catnum=3;//players[player-1].enablefours(); else if (i==4) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); } }*/ else { getfullhousescore(); if ((score>0)&&(players[player-1].getscore(round, 8)==-1)) catnum=8;//players[player-1].enablefullhouse(); else { getkindscore(3); if (score>0) if (players[player-1].getscore(round, die-1)==-1) if (die==1) catnum=0;//players[player-1].enableones(); else if (die==2) catnum=1;//players[player-1].enabletwos(); else if (die==3) catnum=2;//players[player-1].enablethrees(); else if (die==4) catnum=3;//players[player-1].enablefours(); else if (die==5) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); else { getkindscore(4); if ((score>0)&&(players[player-1].getscore(round, 7)==-1)) catnum=7;//players[player-1].enablefourkind(); else { if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); } } else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); } } } } if (catnum>-1) enterscore(); } public void pretendtoscoreroll() { //System.out.println("round="+round); boolean done; done=false; getkindscore(5); if (score>0) { if (players[player-1].getscore(round, 11)==-1) { catnum=11; done=true; } else if (((hits[0]==5)&&(players[player-1].getscore(round, 0)>-1))|| ((hits[1]==5)&&(players[player-1].getscore(round, 1)>-1))|| ((hits[2]==5)&&(players[player-1].getscore(round, 2)>-1))|| ((hits[3]==5)&&(players[player-1].getscore(round, 3)>-1))|| ((hits[4]==5)&&(players[player-1].getscore(round, 4)>-1))|| ((hits[5]==5)&&(players[player-1].getscore(round, 5)>-1))) { pretendtoscorejoker(); //done=true; } } if (!done) { getlargestraightscore(); if (score==40) { if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); } else { getsmallstraightscore(); if (score==30) { if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); } /*else { getyahtzeescore(); //System.out.println("all is ok"); if (score>=50) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else { if (players[player-1].getscore(round, die-1)==-1) if (die==1) catnum=0;//players[player-1].enableones(); else if (die==2) catnum=1;//players[player-1].enabletwos(); else if (die==3) catnum=2;//players[player-1].enablethrees(); else if (die==4) catnum=3;//players[player-1].enablefours(); else if (die==5) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); else if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else { for (i=0; i<6; i++) if (players[player-1].getscore(round, i)==-1) break; if (i==0) catnum=0;//players[player-1].enableones(); else if (i==1) catnum=1;//players[player-1].enabletwos(); else if (i==2) catnum=2;//players[player-1].enablethrees(); else if (i==3) catnum=3;//players[player-1].enablefours(); else if (i==4) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); } }*/ else { getfullhousescore(); if ((score>0)&&(players[player-1].getscore(round, 8)==-1)) catnum=8;//players[player-1].enablefullhouse(); else { getkindscore(3); if (score>0) if (players[player-1].getscore(round, die-1)==-1) if (die==1) catnum=0;//players[player-1].enableones(); else if (die==2) catnum=1;//players[player-1].enabletwos(); else if (die==3) catnum=2;//players[player-1].enablethrees(); else if (die==4) catnum=3;//players[player-1].enablefours(); else if (die==5) catnum=4;//players[player-1].enablefives(); else catnum=5;//players[player-1].enablesixes(); else { getkindscore(4); if ((score>0)&&(players[player-1].getscore(round, 7)==-1)) catnum=7;//players[player-1].enablefourkind(); else { if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); } } else if (!scorecheapest(3)) if (players[player-1].getscore(round, 12)==-1) catnum=12;//players[player-1].enablechance(); else if (!scorecheapest(5)) if (players[player-1].getscore(round, 11)==-1) catnum=11;//players[player-1].enableyahtzee(); else if (players[player-1].getscore(round, 10)==-1) catnum=10;//players[player-1].enablelargestraight(); else if (players[player-1].getscore(round, 7)==-1) catnum=7;//players[player-1].enablefourkind(); else if (players[player-1].getscore(round, 8)==-1) catnum=8;//players[player-1].enablefullhouse(); else if (!scorecheapest(19)) if (players[player-1].getscore(round, 9)==-1) catnum=9;//players[player-1].enablesmallstraight(); else if (players[player-1].getscore(round, 6)==-1) catnum=6;//players[player-1].enablethreekind(); } } } } if (catnum>-1) pretendtoenterscore(); } /*public void computestandings(Vector filescores, Vector filescores2) { byte buf1[], buf2[]; int player1total=0, computertotal=0, player1score, computerscore, available, x=0; player1wins=0; computerwins=0; player1average=0; computeraverage=0; try { available = inf.available(); while (available>0) { try { buf1 = new byte[4]; buf2 = new byte[4]; inf.read(buf1); filescores.addElement(buf1); inf2.read(buf2); filescores2.addElement(buf2); available = inf.available(); player1score = Integer.parseInt(new String(buf1, 0, 4)); computerscore = Integer.parseInt(new String(buf2, 0, 4)); if (player1score > computerscore) player1wins++; else computerwins++; player1total+=player1score; computertotal+=computerscore; } catch(Exception e) {} x++; } } catch(Exception e) {} player1average = (float)(float)Math.floor(10*(float)player1total/(player1wins+computerwins))/10; computeraverage = (float)(float)Math.floor(10*(float)computertotal/(player1wins+computerwins))/10; }*/ public void enterscore() { /*System.out.println(""+players[player-1].getonestate()); // System.out.println(""+players[player-1].gettwostate()); // System.out.println(""+players[player-1].getthreestate()); // System.out.println(""+players[player-1].getfourstate());*/ // System.out.println("computer="+computer); if (entered) players[player-1].erase(scorenum, bonusgiven, player, computer); if ((players[player-1].getonestate()&&((player!=2)||(!computer)))||(catnum==0)) { //System.out.println("bad"); if (players[player-1].getscore(round, 0) != -1) tryagain = true; else { getupperscore(1); // System.out.println("player="+player); players[player-1].setonescore(score, player, computer); scorenum = 0; entered = true; // System.out.println("ok"); } } else if ((players[player-1].gettwostate()&&((player!=2)||(!computer)))||(catnum==1)) { if (players[player-1].getscore(round, 1) != -1) tryagain = true; else { getupperscore(2); players[player-1].settwoscore(score, player, computer); scorenum = 1; entered = true; } // System.out.println("ok"); } else if ((players[player-1].getthreestate()&&((player!=2)||(!computer)))||(catnum==2)) { if (players[player-1].getscore(round, 2) != -1) tryagain = true; else { getupperscore(3); players[player-1].setthreescore(score, player, computer); scorenum = 2; entered = true; } } else if ((players[player-1].getfourstate()&&((player!=2)||(!computer)))||(catnum==3)) { if (players[player-1].getscore(round, 3) != -1) tryagain = true; else { getupperscore(4); players[player-1].setfourscore(score, player, computer); scorenum = 3; entered = true; } } else if ((players[player-1].getfivestate()&&((player!=2)||(!computer)))||(catnum==4)) { if (players[player-1].getscore(round, 4) != -1) tryagain = true; else { getupperscore(5); players[player-1].setfivescore(score, player, computer); scorenum = 4; entered = true; } } else if ((players[player-1].getsixstate()&&((player!=2)||(!computer)))||(catnum==5)) { if (players[player-1].getscore(round, 5) != -1) tryagain = true; else { getupperscore(6); players[player-1].setsixscore(score, player, computer); scorenum = 5; entered = true; } } else if ((players[player-1].getthreekindstate()&&((player!=2)||(!computer)))||(catnum==6)) { if (players[player-1].getscore(round, 6) != -1) tryagain = true; else { getkindscore(3); players[player-1].setthreekindscore(score, player, computer); scorenum = 6; entered = true; } } else if ((players[player-1].getfourkindstate()&&((player!=2)||(!computer)))||(catnum==7)) { if (players[player-1].getscore(round, 7) != -1) tryagain = true; else { getkindscore(4); // System.out.println("scored"); players[player-1].setfourkindscore(score, player, computer); scorenum = 7; entered = true; } } else if ((players[player-1].getfullhousestate()&&((player!=2)||(!computer)))||(catnum==8)) { if (players[player-1].getscore(round, 8) != -1) tryagain = true; else { // System.out.println("fullhouseok"); getfullhousescore(); players[player-1].setfullhousescore(score, player, computer); scorenum = 8; entered = true; } } else if ((players[player-1].getlargestraightstate()&&((player!=2)||(!computer)))||(catnum==10)) { //System.out.println("all is ok10"); if (players[player-1].getscore(round, 10) != -1) tryagain = true; else { getlargestraightscore(); players[player-1].setlargestraightscore(score, player, computer); scorenum = 10; entered = true; } } else if ((players[player-1].getsmallstraightstate()&&((player!=2)||(!computer)))||(catnum==9)) { // System.out.println("all is ok0"); // System.out.println(hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); if (players[player-1].getscore(round, 9) != -1) tryagain = true; else { getsmallstraightscore(); players[player-1].setsmallstraightscore(score, player, computer); scorenum = 9; entered = true; } } else if ((players[player-1].getyahtzeestate()&&((player!=2)||(!computer)))||(catnum==11)) { if (players[player-1].getscore(round, 11) != -1) tryagain = true; else { getyahtzeescore(); players[player-1].setyahtzeescore(score, player, computer); scorenum = 11; entered = true; //System.out.println("entered yahtzee"); } } else if ((players[player-1].getchancestate()&&((player!=2)||(!computer)))||(catnum==12)) { if (players[player-1].getscore(round, 12) != -1) tryagain = true; else { getchancescore(); players[player-1].setchancescore(score, player, computer); scorenum = 12; entered = true; } } //System.out.println("tryagain="+tryagain); if (((!players[player-1].getyahtzeestate()&&((player!=2)||(!computer)))|| ((player==2)&&(computer)&&(catnum!=11)))&&(!tryagain)) {// System.out.println("ok"); // System.out.println("yatzee="+players[player-1].getscore(round, 11)); getyahtzeescore(); // System.out.println("consideredok"); if (score>50) { //System.out.println("score>50"); /*if ((catnum==0)||(catnum==1)||(catnum==2)||(catnum==3)||(catnum==4)|| (catnum==5)||players[player-1].getonestate()||players[player-1].gettwostate() ||players[player-1].getthreestate()||players[player-1].getfourstate()|| players[player-1].getfivestate()||players[player-1].getsixstate()) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==1)&&(players[player-1].getscore(round, die-1)!=-1)) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==2)&&(players[player-1].getscore(round, die-1)!=-1)) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==3)&&(players[player-1].getscore(round, die-1)!=-1)) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==4)&&(players[player-1].getscore(round, die-1)!=-1)) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==5)&&(players[player-1].getscore(round, die-1)!=-1)) { players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; } else if ((die==6)&&(players[player-1].getscore(round, die-1)!=-1)) { */ players[player-1].setyahtzeescore(score, player, computer); bonusgiven[0] = true; // } } //System.out.println("ok"); } /*if ((!computer)||(player!=2)) roll.setEnabled(!tryagain);*/ if (players[player-1].roundover()) players[player-1].totalround(player, computer); scored=true; repaint(); // System.out.println("ok"); } public void pretendtoenterscore() { int oldscore; if ((players[player-1].getonestate()&&((player!=2)||(!computer)))||(catnum==0)) { if (players[player-1].getscore(round, 0) != -1) tryagain = true; else { getupperscore(1); score-=2; } } else if ((players[player-1].gettwostate()&&((player!=2)||(!computer)))||(catnum==1)) { if (players[player-1].getscore(round, 1) != -1) tryagain = true; else { getupperscore(2); score-=4; } } else if ((players[player-1].getthreestate()&&((player!=2)||(!computer)))||(catnum==2)) { if (players[player-1].getscore(round, 2) != -1) tryagain = true; else { getupperscore(3); score-=7; } } else if ((players[player-1].getfourstate()&&((player!=2)||(!computer)))||(catnum==3)) { if (players[player-1].getscore(round, 3) != -1) tryagain = true; else { getupperscore(4); score-=9; } } else if ((players[player-1].getfivestate()&&((player!=2)||(!computer)))||(catnum==4)) { if (players[player-1].getscore(round, 4) != -1) tryagain = true; else { getupperscore(5); score-=11; } } else if ((players[player-1].getsixstate()&&((player!=2)||(!computer)))||(catnum==5)) { if (players[player-1].getscore(round, 5) != -1) tryagain = true; else { getupperscore(6); score-=13; } } else if ((players[player-1].getthreekindstate()&&((player!=2)||(!computer)))||(catnum==6)) { if (players[player-1].getscore(round, 6) != -1) tryagain = true; else { getkindscore(3); score-=15; } } else if ((players[player-1].getfourkindstate()&&((player!=2)||(!computer)))||(catnum==7)) { if (players[player-1].getscore(round, 7) != -1) tryagain = true; else { getkindscore(4); score-=5; } } else if ((players[player-1].getfullhousestate()&&((player!=2)||(!computer)))||(catnum==8)) { if (players[player-1].getscore(round, 8) != -1) tryagain = true; else { getfullhousescore(); score-=6; } } else if ((players[player-1].getlargestraightstate()&&((player!=2)||(!computer)))||(catnum==10)) { if (players[player-1].getscore(round, 10) != -1) tryagain = true; else { getlargestraightscore(); score-=10; } } else if ((players[player-1].getsmallstraightstate()&&((player!=2)||(!computer)))||(catnum==9)) { if (players[player-1].getscore(round, 9) != -1) tryagain = true; else { getsmallstraightscore(); score-=18; } } else if ((players[player-1].getyahtzeestate()&&((player!=2)||(!computer)))||(catnum==11)) { if (players[player-1].getscore(round, 11) != -1) tryagain = true; else { getyahtzeescore(); score-=2; } } else if ((players[player-1].getchancestate()&&((player!=2)||(!computer)))||(catnum==12)) { if (players[player-1].getscore(round, 12) != -1) tryagain = true; else { getchancescore(); score-=23; } } oldscore=score; if (((!players[player-1].getyahtzeestate()&&((player!=2)||(!computer)))|| ((player==2)&&(computer)&&(catnum!=11)))&&(!tryagain)) // if (((!players[player-1].getyahtzeestate()&&((player!=2)||(!computer)))||(catnum!=11))&&(!tryagain)) { getyahtzeescore(); if (score>50) { /* if ((catnum==0)||(catnum==1)||(catnum==2)||(catnum==3)||(catnum==4)|| (catnum==5)||players[player-1].getonestate()||players[player-1].gettwostate() ||players[player-1].getthreestate()||players[player-1].getfourstate()|| players[player-1].getfivestate()||players[player-1].getsixstate()) { bonusgiven[0] = true; } else if ((die==1)&&(players[player-1].getscore(round, die-1)!=-1)) { bonusgiven[0] = true; } else if ((die==2)&&(players[player-1].getscore(round, die-1)!=-1)) { bonusgiven[0] = true; } else if ((die==3)&&(players[player-1].getscore(round, die-1)!=-1)) { bonusgiven[0] = true; } else if ((die==4)&&(players[player-1].getscore(round, die-1)!=-1)) { bonusgiven[0] = true; } else if ((die==5)&&(players[player-1].getscore(round, die-1)!=-1)) { bonusgiven[0] = true; } else if ((die==6)&&(players[player-1].getscore(round, die-1)!=-1)) {*/ bonusgiven[0] = true; // } // oldscore=score; } } /* if ((!computer)||(player!=2)) roll.setEnabled(!tryagain); if (players[player-1].roundover()) players[player-1].totalround(player, computer);*/ score=oldscore; if (bonusgiven[0]) score+=100; repaint(); } public void rolldice() { System.out.println("about to roll dice"); System.out.println(""+selected[0]+selected[1]+selected[2]+selected[3]+selected[4]); if (r>1) System.out.println(dice[0][hand[0]].selected+","+dice[1][hand[1]].selected+","+ dice[2][hand[2]].selected+","+dice[3][hand[3]].selected+","+dice[4][hand[4]].selected); for (i=0; i<5; i++) {// System.out.println(selected[i]); if (selected[i]) { if ((r>1))//&&((!computer)||(player!=2))) { dice[i][hand[i]].select(); dice[i][hand[i]].hide(); } if (r>1) System.out.println(r+""+dice[0][hand[0]].selected+","+dice[1][hand[1]].selected+","+ dice[2][hand[2]].selected+","+dice[3][hand[3]].selected+","+dice[4][hand[4]].selected); hand[i] = (int)Math.floor(Math.random()*6); // if (((!computer)||(player!=2))) // System.out.println("showing dice"); dice[i][hand[i]].show(); selected[i] = false; rolled=true; } } } public void resetmove() { r=1; catnum=-1; bonusgiven[0]=false; entered=false; for (i=0; i<5; i++) { dice[i][hand[i]].hide(); hand[i]=-1; selected[i] = true; } } public void playround() { int i;//System.out.println("ok"); //for (i=0;i<7;i++) while (!players[player-1].roundover()) { // System.out.println("ok7"); //System.out.println("catnum="+catnum+","+hand); rolldice(); // System.out.println(hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+hand[4]); // System.out.println(players[player-1].getscore(1,11)); scored=false; if (r<3) { getmove(); for (i=0; i<5; i++) { if (selected[i]) { dice[i][hand[i]].select(); dice[i][hand[i]].repaint(); } } // System.out.println("catnum="+catnum+","+hand); if (!scored) r++; else { // System.out.println("players[playernum-1].getscore(round, catnum)="+ // players[playernum-1].getscore(round, catnum)); if (!entered) { System.out.println("error"); // System.out.println("catnum="+catnum); // System.out.println("tryagain="+tryagain); // System.out.println("scored="+scored); // System.out.println("entered="+entered); // System.out.println("players[playernum-1].getscore(round, catnum)="+ // players[playernum-1].getscore(round, catnum)); // System.out.println(hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); } if (!players[player-1].roundover()) resetmove(); } } else { // players[player-1].clearstates(); scoreroll(); // System.out.println("catnum="+catnum+","+hand); if ((!scored)||(!entered)) { System.out.println("error"); // System.out.println("catnum="+catnum); // System.out.println("tryagain="+tryagain); // System.out.println("scored="+scored); // System.out.println("entered="+entered); // System.out.println("players[playernum-1].getscore(round, catnum)="+ // players[playernum-1].getscore(round, catnum)); // System.out.println(hand[0]+","+hand[1]+","+hand[2]+","+hand[3]+","+ // hand[4]); } if (!players[player-1].roundover()) /*{ r=1; entered=false; }*/ //System.out.println("catnum="+catnum); resetmove(); } repaint(); } for (i=0; i<5; i++) dice[i][hand[i]].show(); } public boolean action2(Event e, Object o) { int i, j, l, z, y, w, checked, total, player0grandtotal; byte buf1[], buf2[]; //System.out.print("ok"); if ((e.target==player1) || (e.target==player2) || (e.target==player3) || (e.target==player4)) { welcome.hide(); buttonpanel.hide(); setBackground(Color.white); setLayout(null); // System.out.print("ok"); // roll = new Button("Roll"); add(roll); roll.show(); show(); repaint(); } return true; } public boolean action(Event e, Object o) { int i, j, l, z, y, w, checked, total, player0grandtotal; byte buf1[], buf2[]; boolean justended=false; //System.out.print("ok"); if ((e.target==player1) || (e.target==player2) || (e.target==player3) || (e.target==player4)) {// System.out.println("ok"); /* reset.setEnabled(true); help.setEnabled(true); quit.setEnabled(true); next.setEnabled(false);*/ welcome.hide(); buttonpanel.hide(); started = true; setLayout(null); // add(roll); // roll.show(); setBackground(Color.white); if (e.target==player1) { playernum = 2; scoreboardnum=0; computer = true; // resetgame(); // System.out.println("ok"); /*try { inf = new FileInputStream("averages.dat"); inf2 = new FileInputStream("averages2.dat"); } catch(Exception ex) {} computestandings(filescores, filescores2); winslosses = new standings(String.valueOf(player1wins), String.valueOf(computerwins), String.valueOf(player1average), String.valueOf(computeraverage), 317); add(winslosses);*/ } else if (e.target==player2) { playernum = 2; scoreboardnum=1; } else if (e.target==player3) { playernum = 3; scoreboardnum=2; } else { playernum = 4; scoreboardnum=3; } // players = new scorecard[playernum]; for (i=0; i1)) begin=0; else begin=2; if ((player==2)&&(computer)) { byroll.show(); byturn.show(); byround.show(); } else { byroll.hide(); byturn.hide(); byround.hide(); } if (byroll.isEnabled()==false) next.setEnabled(false); justended=true; } // if (players[player-1].roundover()) // scores.nextround(players); if ((players[player-1].roundover())&&(player==1)) { if (round==6) { player=playernum; players[player-1].show(); roll.hide(); next.hide(); reset.show(); main.show(); //next.setEnabled(false); } if (round<6) { // System.out.println("ok"); for (i=0; i-1) { if (selected[i]) dice[i][hand[i]].select(); selected[i] = true; dice[i][hand[i]].hide(); hand[i]=-1; } // scores=new scoreboard[4]; // scores[0] = new scoreboard(2, true); // add(scores[0]); // scores[scoreboardnum].reinit(); /* for (i=1; i<4; i++) { scores[i] = new scoreboard(i+1, false); add(scores[i]); scores[i].hide(); }*/ //scores = new scoreboard(playernum, computer); //add(scores); r=1; round=1; catnum=-1; bonusgiven[0] = false; player=1; tryagain=false; entered=false; show(); repaint(); } else if (e.target==main) { players[playernum-1].hide(); for (i=0;i-1) { if (selected[i]) dice[i][hand[i]].select(); selected[i] = true; // System.out.println(selected[0]); // System.out.println("ok"); dice[i][hand[i]].hide(); hand[i]=-1; } setBackground(Color.yellow); welcome.show(); buttonpanel.show(); r=1; round=1; catnum=-1; // System.out.println("catnum="+catnum); bonusgiven[0] = false; player=1; tryagain=false; entered=false; started=false; show(); repaint(); } else if (e.target==byroll) { byroll.setEnabled(false); byturn.setEnabled(true); byround.setEnabled(true); if (!players[player-1].roundover()) { roll.setEnabled(true); next.setEnabled(false); } } else if (e.target==byturn) { byroll.setEnabled(true); byturn.setEnabled(false); byround.setEnabled(true); roll.setEnabled(false); next.setEnabled(true); } else if (e.target==byround) { byroll.setEnabled(true); byturn.setEnabled(true); byround.setEnabled(false); roll.setEnabled(false); next.setEnabled(true); } /*else if (e.target == instructionsitem) { instructionsdialog = new instructions(this); setinstructionstate(false); } else if (e.target == yahtzeerulesitem) { yahtzeerulesdialog = new yahtzeerules(this); setyahtzeerulestate(false); } else if (e.target == scoringrulesitem) { scoringrulesdialog = new scoringrules(this); setscoringrulestate(false); } else { hide(); dispose(); System.exit(0); }*/ return true; } /* public void setinstructionstate(boolean state) { if (state==true) instructionsitem.enable(); else instructionsitem.disable(); } public void setyahtzeerulestate(boolean state) { if (state==true) yahtzeerulesitem.enable(); else yahtzeerulesitem.disable(); } public void setscoringrulestate(boolean state) { if (state==true) scoringrulesitem.enable(); else scoringrulesitem.disable(); }*/ public void paint(Graphics g) { f = new Font("SansSerif", Font.BOLD, 35); g.setFont(f); g.drawString("", 0, 0); g.drawImage(img, 300, 90, this); g.drawImage(img, 400, 90, this); g.drawImage(img, 500, 90, this); g.drawImage(img, 600, 90, this); g.drawImage(img, 700, 90, this); g.drawImage(img, 300, 190, this); g.drawImage(img, 400, 190, this); g.drawImage(img, 500, 190, this); g.drawImage(img, 600, 190, this); g.drawImage(img, 700, 190, this); if (started) { if ((computer)&&(player==2)) g.drawString("Computer, roll #"+r, 402, 40); else g.drawString("Player #"+player+", roll #"+r, 403, 40); g.drawLine(402, 50, 683, 50); if (tryagain) { g.drawString("Try again", 470, 150); tryagain = false; } if ((begin==1)&&((!computer)||(player==1))) { f = new Font("SansSerif", Font.BOLD, 22); g.setFont(f); g.drawString("Click on dice to be rolled.", 417, 225); g.drawString("Double click to deselect.", 421, 245); g.drawLine(402, 250, 683, 250); } f = new Font("SansSerif", Font.BOLD, 15); g.setFont(f); if (round<7) if (round!=2) g.drawString("Scoreboard though "+(round-1)+" rounds", 53+(116*playernum+16-204)/2, 492); else g.drawString("Scoreboard though 1 round", 75, 492); else g.drawString("Game over, final score", 53+(116*playernum+16-204), 492); g.setColor(Color.blue); g.fillRect(53, 10, 248, 462); g.setColor(Color.red); g.fillRect(53, 496, 116*playernum+16, 43); g.setColor(Color.red); if (r>1) { if (selected[0]) g.fillRect(401, 252, 88, 88); if (selected[1]) g.fillRect(501, 252, 88, 88); if (selected[2]) g.fillRect(601, 252, 88, 88); if (selected[3]) g.fillRect(451, 352, 88, 88); if (selected[4]) g.fillRect(551, 352, 88, 88); } } } }
Make your own free website on Tripod.com