PRivate ChessModel model[][][]; private StepStack stack; private Step step; private int layer; private int turn; protected GameRule gameRule;
public FirstAI(int t) { super(false); stack = new StepStack(); layer = 7; // layer = 3; turn = t; }
public String getName() { return "ColinRobot"; }
public Step getNextStep(ChessModel m[][][]) { //algo model = m; System.out.println("max="+getLayerValue(0)); stack.removeAll(); return step; }
//get largest value private int getLayerValue(int lay) { if(lay>layer) { //no recursion return -1*getModelValue(); } int value = 0; int max = -2000; int decision; for(int z=0;z<3;z++) { for(int y=0;y<3;y++) { for(int x=0;x<3;x++) { if((x==1&&y==1)model[z][y][x].isOccupied()) continue; //assume lay chessman here model[z][y][x].acceptChessman(Chessman.CHESS[(turn+lay)%2]); decision = gameRule.checkStep(model[z][y][x], model); switch(decision) { case 0://win stack.add(new Step(model[z][y][x],decision)); value = 1000; break; case 3://tiaodangan gameRule.checkDecision(model[z][y][x],1,model); stack.add(new Step(model[z][y][x],1)); value = 660; /* value = -1*getLayerValue(lay+1); //roll back gameRule.undoStep(stack.remove(),model); model[z][y][x].acceptChessman(Chessman.CHESS[(turn+lay)%2]); //another gameRule.checkDecision(model[z][y][x],2,model); stack.add(new Step(model[z][y][x],2)); int b = -1*getLayerValue(lay+1); //choose better if(value<b) { value = b; } else { //roll back gameRule.undoStep(stack.remove(),model); model[z][y][x].acceptChessman(Chessman.CHESS[(turn+lay)%2]); //redo first gameRule.checkDecision(model[z][y][x],1,model); stack.add(new Step(model[z][y][x],1)); } */ break; case 1://tiaodan