import com.mg.*; import java.util.*; public class AIDinoStone extends DinoStone{ public int maxscore = 0; public final int SCOREPERCLEAR = 5; public final int PENALTYPERHEIGHT = 5; public final int SCOREPERCOUPLE = 1; public int level = 0; //level: 0 - 4 public AIDinoStone(int totalx, int totaly, int color, DinoStone opponent, int level) { super(totalx, totaly, color, opponent); this.level = level+5; isComputer = true; } //return int[] includes 1. xposition 2. rotation public int[] calBestposition() { //for each column //System.out.println("abavc"); int[] returnint = {-1,-1}; int maxscore =-100; for (int i=0; i0) { // System.out.println("x: "+x+" y: "+y); //for each rotation for (int r=0; r<4; r++) { int score = calGetScore(x, y, r);//-calHeightPenalty(x, y, r); resetlayout(); // System.out.println("score: "+score); // System.out.println("maxscore: "+maxscore); if (score>maxscore) { maxscore = score; // System.out.println("newmaxscore: "+maxscore); returnint[0] = x; returnint[1] = r; } } //} } // System.out.println("return: "+returnint[0]+" " +returnint[1]); return returnint; } public int calGetScore(int x, int y, int r) { //return random(100); int returnscore = 0; // clearnumber = 0; currentx = x; currenty = y-1; currentposition = r; currentcolors = nextcolors; // System.out.println("check11"); loadlayout(); // System.out.println("check12"); roundfinish = false; while(!roundfinish) { //matchfinished = false; while (!dropfinished) { dropDown(); } while(!matchfinished){ //System.out.println("matching"); domatch(); } // //for display // for (int j=2; jleastclearBlock-1) { //System.out.println("couplescore: "+couplenumber); returnscore = returnscore+clearnumber*SCOREPERCLEAR+couplenumber*SCOREPERCOUPLE; //System.out.println("hscore: "+clearHlist.size()); } returnscore = returnscore - (getheight(layout) - getheight(c_layout))*PENALTYPERHEIGHT; // System.out.println(getheight(layout)+ " "+getheight(c_layout)); // System.out.println("penalty: "+(getheight(layout) - getheight(c_layout))*PENALTYPERHEIGHT); return returnscore; //} } // public int loadlayout() { // // } public int getheight(int[][] l) { int maxheight = 0; int height = 0; //System.out.println(l[0][totaly-1]); for (int i=0; imaxheight) { maxheight = height; j = totaly; // System.out.println("maxheight: "+maxheight); } } } } return maxheight; } int[] target = {-1,-1}; public void run() { long starttime = 0; long sleeptime = 0; genNextBlock(); while (!checkgameover()) { //initCurrentBlock(); // System.out.println("check1"); // if (random(10)==0) //for test // enemyturn = true; // else // enemyturn = false; if (enemyturn) { enemyinited = true; enemyturn = false; initblackstone(); } else { for (int i=0; ilevel) { target[0] = random(totalx-1); // System.out.println("handicap: "+target[0]); target[1] = random(4); }else { // System.out.println("non_handicap"); isCheckingAI = true; target = calBestposition(); isCheckingAI = false; } initCurrentBlock(); genNextBlock(); } roundfinish = false; while (!roundfinish) { starttime = System.currentTimeMillis(); if (!pause) { doAction(); } // for (int j=0; j 0) { try { AIDinoStone.sleep(sleeptime); } catch (Exception e) { System.out.println(e); } } // System.out.println("check12: "); } //System.out.println("check13: "); } gameover = true; } public void resetlayout() { for (int i=0; itarget[0]) move(LEFT); else if (currentposition!=target[1]) rotate(); else move(DOWN); dropDown(); } } if (dropfinished && !matchfinished){ domatch(); } if (matchfinished) { doclear(); // System.out.println(roundfinish); } } }