Java Game straight chess (ii)

Source: Internet
Author: User
This part is the artificial intelligence of the computer.

In order to speed up the calculation of AI, it is necessary to make a small number of modifications to the previous design, and eventually transfer to the VC platform. In the game with VC, the chessboard will adopt Bitboard technology, the display of the pieces will be completely and logically separate. The current Java version still uses arrays to represent the chessboard, mainly for logical analysis and design.

The first AI is summarized first. Firstai:

Package nicholas.game.chess;

Class Firstai extends Chessplayer {

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://tiaodan|gan
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
Gamerule.checkdecision (Model[z][y][x],1,model);
Stack.add (New Step (model[z][y][x],1));
}
* * BREAK;
Case 1://tiaodan
Stack.add (New Step (model[z][y][x],decision));
value = 660;
Break
Case 2://gan
Stack.add (New Step (model[z][y][x],decision));
Value = 320;
Break
Default://tiaodan,gan,none
Stack.add (New Step (model[z][y][x],decision));
Value = -1*getlayervalue (lay+1);
}
if (Value>max) {
max = value;
if (lay==0) {
Layer, Save step
System.out.println ("max=" +max);
Step = Stack.gettop ();
}
}
Remove Chessman
Gamerule.undostep (Stack.remove (), model);
if (max==1000) return Max;
}
}
}
return Max;
}

private int Getmodelvalue () {
return 3;
}

public void Setgamerule (Gamerule rule) {
gamerule = rule;
}
}

Firstai directly inherits Chessplayer and will later be converted to indirect inheritance. With a maximum minimum depth first search, the two criteria for ending a search for a branch (only the current level) are: a. This level of player wins. B. Deepest search level. The deepest search level will return the evaluation value of the situation (not designed, all return 3, said drop 3 points.) )。

Behind the design, in addition to bitboard implementation of the chessboard need to consider several issues:
1 The level of the search. For the first step, forcibly remove part of the independent branch (X+Y&GT;2), and then set the search level to 7, you can get the correct way. So the estimated maximum search level is set to 7.
2) The improvement of the algorithm. Even if the search level is only 7, compute one step to consider 4.6 billion possibilities, assuming that each of the possibilities requires 60 operations, with the configuration of my computer for three minutes. Whether to design the opening library (the calculations show that some drop have only a single should also launch), and other search techniques will be considered; the break will have an additional bonus (the local value of >3); Consider whether the bar can be a single, if the bar is necessarily better.
3) The valuation of the situation. More complex, in consideration.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.