?? bitboardanalyzerimpl.java
字號:
/* BitBoardAnalyzerImpl - A class to analyze the game position on a BitBoard type chessbaord. Copyright (C) 2003 The Java-Chess team <info@java-chess.de> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/package de.java_chess.javaChess.engine;import de.java_chess.javaChess.*;import de.java_chess.javaChess.bitboard.*;import de.java_chess.javaChess.game.*;import de.java_chess.javaChess.piece.*;import de.java_chess.javaChess.position.*;/** * The class implements the functionality to analyze * a game position, stored as a bitboard. */public class BitBoardAnalyzerImpl implements BitBoardAnalyzer { // Static variables // A minus for pieces that block the development of the own pawns. static final short _pawnBlocker = 10; // The position value of pawns on all the squares, in the // opening stage and in the middle game. static final short [] [] _pawnPositionalValue = { { 0, 0, 0, 0, 0, 0, 0, 0, // Opening stage 0, 0, 3, 6, 6, 8, 8, 8, 0, 0, 2, 7, 7, 6, 6, 0, 0, 0, 1, 8, 8, 4, 4, 0, 0, 0, 8, 10, 10, 2, 2, 0, 0, 0, 8, 12, 12, 0, 0, 0, 0, 0, 9, 13, 13, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, // Middle game 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 5, 4, 3, 2, 3, 4, 5, 6, 6, 5, 4, 3, 4, 5, 6, 7, 7, 6, 5, 4, 5, 6, 7, 8, 8, 7, 6, 5, 6, 7, 8, 9, 9, 8, 8, 7, 7, 8, 9, 10, 10, 9, 8, 7 } }; // The positional value of knights on the various squares. static final short [] [] _knightPositionalValue = { { 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 5, 1, 0, 0, 1, 3, 5, 6, 6, 5, 3, 1, 1, 3, 5, 6, 6, 5, 3, 1, 0, 0, 1, 6, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0 } }; // The positional values of bishops on the various squares. static final short [] [] _bishopPositionalValue = { { 0, 0, 2, 0, 0, 2, 0, 0, // Opening stage 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 3, 5, 3, 3, 5, 3, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 3, 5, 3, 3, 5, 3, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}; // The positional value of rooks on the various squares. static final short [] [] _rookPositionalValue = { { 1, 1, 2, 2, 2, 2, 1, 1, // Opening stage 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, // Middle game 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 5, 1, 0, 0, 1, 3, 5, 6, 6, 5, 3, 1, 1, 3, 5, 6, 6, 5, 3, 1, 0, 0, 1, 6, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0 } }; // The positional value of queens on the various squares. static final short [] [] _queenPositionalValue = { { 0, 0, 5, 6, 6, 5, 0, 0, // Opening stage 0, 0, 2, 3, 3, 2, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, // Middle game 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 5, 5, 1, 0, 0, 1, 3, 5, 6, 6, 5, 3, 1, 1, 3, 5, 6, 6, 5, 3, 1, 0, 0, 1, 6, 6, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0 } }; // The position value of the king static final short [] _kingPositionalValue = { 6, 5, 2, 1, 1, 2, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Instance variables /** * The currently analyzed board. */ private BitBoard _board; /** * The current game. */ private Game _game; /** * The flag to indicate, if white moves next. */ private boolean _whiteMoves; /** * A ply generator instance to simulate moves. */ PlyGenerator _plyGenerator; // Constructors /** * Create a new bitboard analyzer. * * @param plyGenerator A PlyGenerator instance to simulate moves. */ public BitBoardAnalyzerImpl( Game game, PlyGenerator plyGenerator) { setGame( game); setPlyGenerator( plyGenerator); } // Methods /** * Get the currently analyzed board. * * @return The currently analyzed board. */ public final BitBoard getBoard() { return _board; } /** * Set a new board to be analyzed. * * @param board The new board. */ public final void setBoard( BitBoard board) { _board = board; } /** * Get the current game. * * @return The current game. */ public final Game getGame() { return _game; } /** * Set the current game. * * @param The current game. */ public final void setGame( Game game) { _game = game; } /** * Check, if white moves next. * * @return true, if white moves next, false otherwise. */ private final boolean whiteHasMoveRight() { return _whiteMoves; } /** * Set the flag, if white is about to move. * * @param white Flag to indicate, if white has the * next move. */ public final void setMoveRight( boolean white) { _whiteMoves = white; } /** * Get the ply generator. * * @return The PlyGenerator. */ private final PlyGenerator getPlyGenerator() { return _plyGenerator; } /** * Set a new PlyGenerator instance. * * @param plyGenerator The new PlyGenerator instance. */ private final void setPlyGenerator( PlyGenerator plyGenerator) { _plyGenerator = plyGenerator; } /** * Analyze the current board. */ public final short analyze() { // A check thread has a value, too. short checkValue = 0; // Start with the tests, if one of the players is in check.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -