Java Game Fold (2)

xiaoxiao2021-03-06  19

This part is the artificial intelligence of the computer.

In order to accelerate the calculation speed of AI, a small amount of modifications must be performed on the previous design, and finally transfer to the VC platform. In the game implemented with VC, the chessboard will use Bitboard technology, and the display of the pieces will be completely and logically separated. At present, the Java version still adopts an array to represent a chessboard, mainly for logic analysis and design.

First summarize the first AI. 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 "colorobot";} 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) {f (lay> layer) {/ / no recuty 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] .oscupied ()) Continue; // Assume Lay Chessman Here Model [Z] [Y] .acceptchessman (Chessman.chess [(TURN LAY)% 2]); Decision = GAMERULE.CHECKSTEP (Model [Z] [Y] [x], model Switch (decision) {cas 0: // Win Stack.a DD (New Stel [Z] [Y], Value = 1000; Break; Case 3: // Tiaodan | Ga GameRule.CheckDecision (Model [Z] [Y] [x], 1 , Model; Stack.Add (New Stel [Z] [Y] [x], 1)); value = 660; / * value = -1 * getLayerValue (lay 1); // roll back gameerule. Undostep (stack.remove (), model; model [z] [y] .acceptchessman (chessman.chess [(turn lay)% 2]); // another gamerule.checkdecision (Model [z] [ y] [x], 2, model; stack.add (New Stel [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] .accept; chessman.chess [(Turn Lay)% 2]); // redo first Gameerule.checkDecision (Model [z] [y] [x], 1, model); stack.add (New Step (Model [z] [Y] [x], 1)); } * / Break; case 1: // Tiaodan Stack.Add (New Stel [z] [y] [x], division); value = 660; break; case 2: // gan stack.add (New Step (Model [Z] [Y], Value = 320; Break; Default: // Tiaodan, GaN, None Stack.Add (New Stel [Z] [Y], Decision); value = -1 * getLayerValue (lay 1);} if (value> max) {max = value; if (lay == 0) {// first layer, save system.out.println (" MAX = " max); step = stack.gettop ();}} // remove chessman gamerule.undostep (stack.remove (), model; if (max == 1000) returnem;}}} returnem PRIVATE INT GETMODELVALUE () {return 3;} public voi D setgameRule (GameRule rule) {gameule = rule;}} firstai directly inherits ChessPlayer, will be converted to indirect inheritance. Using the largest minimum depth priority search, two conditions for the search for a certain branch (only current level) are: a. This level of players win. B. The deepest search level. When the deepest search level will return to the overall evaluation value (not designed, return 3, indicating that the fall is 3 points.).

The back is designed, in addition to Bitboard, you need to consider several questions: 1) Search. For the first step, forced removal of the part independent branch (x y> 2), set the search level to 7 to obtain the correct method. Therefore, it is estimated that the largest search level is set to 7. 2) Improvement of the algorithm. Even if the search level is only 7, the calculation is calculated to consider the possibility of 46 billion, assuming that each possibility requires 60 operations, and it takes three minutes by the configuration of my book. Whether it is designed to open the library (calculation shows that some of the falling "will only consider taking other search skills; there will be additional rewards (Surface values> 3); consider whether the can be single, or not Bar is advantageous. 3) The estimate of the situation. More complex, consider.

转载请注明原文地址:https://www.9cbs.com/read-46096.html

New Post(0)