CPD Results

The following document contains the results of PMD's CPD 4.1.

Duplications

File Line
com/alonsoruibal/chess/evaluation/CompleteEvaluator.java 76
com/alonsoruibal/chess/evaluation/CompleteEvaluatorNew.java 88
	public final static int TEMPO          = 10; // Add to moving side score
	
	private final static int knightOutpost[] = {
	      0,   0,   0,   0,   0,   0,   0,   0,
		  0,   0,   0,   0,   0,   0,   0,   0,
		  0,   0,   7,   9,   9,   7,   0,   0,
		  0,   5,  10,  20,  20,  10,   5,   0,
		  0,   5,  10,  20,  20,  10,   5,   0,
		  0,   0,   7,   9,   9,   7,   0,   0,
		  0,   0,   0,   0,   0,   0,   0,   0,
		  0,   0,   0,   0,   0,   0,   0,   0
	};
	
	// The pair of values are {opening, endgame}
	private final static int PawnFileValue[]       = {5,0};
	private final static int KnightCenterValue[]   = {5,5};
	private final static int KnightRankValue[]     = {5,0};
	private final static int KnightBackRankValue[] = {0,0};
	private final static int KnightTrappedValue[]  = {-100,0};
	private final static int BishopCenterValue[]   = {2,3};
	private final static int BishopBackRankValue[] = {-10,0};
	private final static int BishopDiagonalValue[] = {4,0};
	private final static int RookFileValue[]       = {3,0};
	private final static int QueenCenterValue[]    = {0,4};
	private final static int QueenBackRankValue[]  = {-5,0};
	private final static int KingCenterValue[]     = {0,12};
	private final static int KingFileValue[]       = {10,0};
	private final static int KingRankValue[]       = {10,0};

	private final static int PawnFile[]   = {-3, -1, +0, +1, +1, +0, -1, -3};
	private final static int KnightLine[] = {-4, -2, +0, +1, +1, +0, -2, -4};
	private final static int KnightRank[] = {-2, -1, +0, +1, +2, +3, +2, +1};
	private final static int BishopLine[] = {-3, -1, +0, +1, +1, +0, -1, -3};
	private final static int RookFile[]   = {-2, -1, +0, +1, +1, +0, -1, -2};
	private final static int QueenLine[]  = {-3, -1, +0, +1, +1, +0, -1, -3};
	private final static int KingLine[]   = {-3, -1, +0, +1, +1, +0, -1, -3};
	private final static int KingFile[]   = {+3, +4, +2, +0, +0, +2, +4, +3};
	private final static int KingRank[]   = {+1, +0, -2, -3, -4, -5, -6, -7};
	
	// Values are rotated for whites, so when white is playing is like shown in the code
	private final static int pawnIndexValue[][] = new int[64][2];
	private final static int knightIndexValue[][] = new int[64][2];
	private final static int bishopIndexValue[][] = new int[64][2];
	private final static int rookIndexValue[][] = new int[64][2];
	private final static int queenIndexValue[][] = new int[64][2];
	private final static int kingIndexValue[][] = new int[64][2];
	
	static {
		// Initialize Piece square values Fruit/Toga style 
		int i;
		
		for (int phase = 0; phase<2; phase++) {
			for (i = 0; i < 64; i++) {
				int rank = i >> 3;
				int file = 7 - i & 7;
			
				pawnIndexValue[i][phase] = PawnFile[file] * PawnFileValue[phase];
				knightIndexValue[i][phase] = KnightLine[file] * KnightCenterValue[phase] + KnightLine[rank] * KnightCenterValue[phase] + KnightRank[rank] * KnightRankValue[phase];
				bishopIndexValue[i][phase] = BishopLine[file] * BishopCenterValue[phase] + BishopLine[rank] * BishopCenterValue[phase];
				rookIndexValue[i][phase] = RookFile[file] * RookFileValue[phase];
				queenIndexValue[i][phase] = QueenLine[file] * QueenCenterValue[phase] + QueenLine[rank] * QueenCenterValue[phase];
				kingIndexValue[i][phase] = KingFile[file] * KingFileValue[phase]  + KingRank[rank] * KingRankValue[phase] + KingLine[file] * KingCenterValue[phase] + KingLine[rank] * KingCenterValue[phase];
			}

			knightIndexValue[56][phase] += KnightTrappedValue[phase]; // H8 
			knightIndexValue[63][phase] += KnightTrappedValue[phase]; // A8
		
			for (i = 0; i < 8; i++) {
				queenIndexValue[i][phase] += QueenBackRankValue[phase];
				knightIndexValue[i][phase] += KnightBackRankValue[phase];
				bishopIndexValue[i][phase] += BishopBackRankValue[phase];
				bishopIndexValue[(i << 3) | i][phase] += BishopDiagonalValue[phase];
				bishopIndexValue[((i << 3) | i) ^ 070][phase] += BishopDiagonalValue[phase];
			}
		}
		// Pawn opening corrections
		pawnIndexValue[19][OPENING] += 10; // E3
		pawnIndexValue[20][OPENING] += 10; // D3
		pawnIndexValue[27][OPENING] += 25; // E4
		pawnIndexValue[28][OPENING] += 25; // D4
		pawnIndexValue[35][OPENING] += 10; // E5
		pawnIndexValue[36][OPENING] += 10; // D5
		
//		logger.debug("***PAWN");
//		printPcsq(pawnIndexValue);
//		logger.debug("***KNIGHT");
//		printPcsq(knightIndexValue);
//		logger.debug("***BISHOP");
//		printPcsq(bishopIndexValue);
//		logger.debug("***ROOK");
//		printPcsq(rookIndexValue);
//		logger.debug("***QUEEN");
//		printPcsq(queenIndexValue);
//		logger.debug("***KING");
//		printPcsq(kingIndexValue);
//		logger.debug("PCSQ tables generated");
	}
	
//	private static void printPcsq(int pcsq[][]) {
//		StringBuffer sb = new StringBuffer();
//		for (int k=0; k<2; k++) {
//			if (k==0) sb.append("Opening:\n");
//			else sb.append("Endgame:\n");
//			for (int i = 0; i<64; i++) {
//				String aux = "     " + pcsq[i][k];
//				aux = aux.substring(aux.length()-5);
//				sb.append(aux);
//				if (i%8 != 7) {
//					sb.append(",");
//				} else {
//					sb.append("\n");
//				}
//			}
//		}
//		logger.debug(sb.toString());
//	}
	
	public int evaluateBoard(Board board) {
		int pieces = 0;

		long attacks[] = {0,0}; // Squares attacked by each side

File Line
com/alonsoruibal/chess/evaluation/CompleteEvaluator.java 198
com/alonsoruibal/chess/evaluation/CompleteEvaluatorNew.java 212
		int auxInt;
		int bishopCount[] = {0,0};
		
		int materialValue[] = {0,0};
		int pawnMaterialValue[] = {0,0};
		int mobilityOpeningValue[] = {0,0};
		int mobilityEndgameValue[] = {0,0};
		int positionalOpeningValue[] = {0,0};
		int positionalEndgameValue[] = {0,0};
		int kingSafetyValue[] = {0,0};
		int pawnsValue[] = {0,0};
		
		// Squares surrounding King
		long squaresNearKing[] = {BitboardAttacks.king[BitboardUtils.square2Index(board.whites & board.kings)],
								BitboardAttacks.king[BitboardUtils.square2Index(board.blacks & board.kings)]};

		// From material imbalances (Larry Kaufmann):
		// A further refinement would be to raise the knight's value by 1/16 and lower the rook's value by 1/8
		// for each pawn above five of the side being valued, with the opposite adjustment for each pawn short of five
		int whitePawnsCount = BitboardUtils.popCount(board.pawns & board.whites);
		int blackPawnsCount = BitboardUtils.popCount(board.pawns & board.blacks);
		int knightKaufBonus[] = {KNIGHT_KAUF_BONUS * (whitePawnsCount-5), KNIGHT_KAUF_BONUS * (blackPawnsCount-5)};
		int rookKaufBonus[] = {ROOK_KAUF_BONUS * (whitePawnsCount-5), ROOK_KAUF_BONUS * (blackPawnsCount-5)};
		
		long square = 1;
		byte index = 0;
		while (square != 0) {
			boolean isWhite = ((board.whites & square) != 0);
			int color = (isWhite ? 0 : 1);
			long mines = (isWhite ? board.whites : board.blacks);
			long others = (isWhite ? board.blacks : board.whites);
			int pcsqIndex = (isWhite ? index : 63 - index);
			
			if ((square & all) != 0) {
				pieces++;
				int rank = index >> 3;
				int file = 7 - index & 7;
			
				if ((square & board.pawns  ) != 0) {
					pawnMaterialValue[color] += PAWN;
					positionalOpeningValue[color] += pawnIndexValue[pcsqIndex][OPENING];
					positionalEndgameValue[color] += pawnIndexValue[pcsqIndex][ENDGAME];

File Line
com/alonsoruibal/chess/tt/MultiprobeTranspositionTable.java 60
com/alonsoruibal/chess/tt/TwoTierTranspositionTable.java 62
		}
		return false;
	}

	public int getBestMove() {
		return (int)(info & 0x1fffff);
	}

	public int getNodeType() {
		return (int)((info >>> 21) & 0xf);
	}

	public byte getGeneration() {
		return (byte)((info >>> 32) & 0xff);
	}
	
	public byte getDepthAnalyzed() {
		return (byte)((info >>> 40) & 0xff);
	}
	
	public int getScore() {
		return (short)((info >>> 48) & 0xffff);
	}	
	
	public void set(Board board, int nodeType, int bestMove, int score, byte depthAnalyzed) {
		long key2 =  board.getKey2();

File Line
com/alonsoruibal/chess/movegen/MagicMoveGenerator.java 58
com/alonsoruibal/chess/movesort/MoveIterator.java 150
								| ((square & BitboardUtils.b2_u) != 0 && (((square >>> 8) | (square >>> 16)) & all) == 0 ? (square >>> 16) : 0));
					}
				}
			}
			square <<= 1;
			index++;
		} 

		square = board.kings & mines; // my king
		Byte myKingIndex = null;
		// Castling: disabled when in check or squares attacked
		if ((((all & (board.getTurn() ? 0x06L : 0x0600000000000000L)) == 0  &&
			  (board.getTurn() ? board.getWhiteKingsideCastling() : board.getBlackKingsideCastling())))) {
			myKingIndex = BitboardUtils.square2Index(square);
			if (!board.getCheck() &&
				!BitboardAttacks.isIndexAttacked(board, (byte) (myKingIndex-1), board.getTurn()) &&
				!BitboardAttacks.isIndexAttacked(board, (byte) (myKingIndex-2), board.getTurn()))

File Line
com/alonsoruibal/chess/evaluation/CompleteEvaluator.java 277
com/alonsoruibal/chess/evaluation/CompleteEvaluatorNew.java 303
					if ((( BitboardUtils.FILE_ADJACENTS[file] &
						(isWhite ? BitboardUtils.RANKS_UPWARDS[rank] : BitboardUtils.RANKS_DOWNWARDS[rank])
						& board.pawns & others) == 0) &&
						(((isWhite ? BitboardAttacks.pawnDownwards[index] : BitboardAttacks.pawnUpwards[index]) & board.pawns & mines) !=0))
						positionalOpeningValue[color] += knightOutpost[pcsqIndex];
				
				} else if ((square & board.bishops) != 0) {
					materialValue[color] += BISHOP;
					positionalOpeningValue[color] += bishopIndexValue[pcsqIndex][OPENING];
					positionalEndgameValue[color] += bishopIndexValue[pcsqIndex][ENDGAME];

File Line
com/alonsoruibal/chess/movegen/MagicMoveGenerator.java 75
com/alonsoruibal/chess/movesort/MoveIterator.java 167
				addNonCapturesAndBadPromos(Move.KING, myKingIndex, myKingIndex-2, 0, false, Move.TYPE_KINGSIDE_CASTLING);	
		}
		if ((((all & (board.getTurn() ? 0x70L : 0x7000000000000000L)) == 0 &&
				(board.getTurn() ? board.getWhiteQueensideCastling() : board.getBlackQueensideCastling())))) {
			if (myKingIndex == null) myKingIndex = BitboardUtils.square2Index(square);
			if (!board.getCheck() &&
				!BitboardAttacks.isIndexAttacked(board, (byte) (myKingIndex+1), board.getTurn()) &&
				!BitboardAttacks.isIndexAttacked(board, (byte) (myKingIndex+2), board.getTurn()))

File Line
com/alonsoruibal/chess/search/SearchEngine.java 260
com/alonsoruibal/chess/search/SearchEngine.java 420
	public int zwsearch(byte depth, byte depthRemaining, int beta) throws TimeExceedException {
		if (System.currentTimeMillis() > thinkTo && foundOneMove) throw new TimeExceedException();
		positionCounter++;

		// checks draw by treefold rep. and fifty moves rule
		if (board.isDraw()) return 0;
				
		int ttMove = 0;
		int bestMove = 0;
		int bestScore = -Evaluator.VICTORY;
		int score = 0;

		ttProbe++;
		if (tt.search(board)) {
			if (tt.getDepthAnalyzed() >= depthRemaining && tt.isMyGeneration()) {
				switch(tt.getNodeType()) {
					case TranspositionTable.TYPE_EXACT_SCORE: ttPvHit++; return tt.getScore();
					case TranspositionTable.TYPE_FAIL_LOW: ttLBHit++; if (tt.getScore() <= beta-1) return beta-1;

File Line
com/alonsoruibal/chess/evaluation/CompleteEvaluator.java 350
com/alonsoruibal/chess/evaluation/CompleteEvaluatorNew.java 382
		value += kingSafetyValue[0] - kingSafetyValue[1];
		// Ponder opening and Endgame value: opening=> gamephase = 255 / ending => gamephase ~=0
		int gamePhase = (256 * ((materialValue[0] + materialValue[1])) / 5000);
		if (gamePhase > 256) gamePhase = 256; // Security
		value += (gamePhase * (positionalOpeningValue[0] - positionalOpeningValue[1]
				+ mobilityOpeningValue[0] - mobilityOpeningValue[1])) >> 8; // divide by 256
		value += ((256 - gamePhase) * (positionalEndgameValue[0] - positionalEndgameValue[1]
		        + mobilityEndgameValue[0] - mobilityEndgameValue[1])) >> 8;
		// Piece attacks
//		value += BitboardUtils.popCount(attacks[0]&~attacks[1]) - BitboardUtils.popCount(attacks[1]&~attacks[0]);
		// Tempo
		value += (board.getTurn() ? TEMPO : -TEMPO);

//	    logger.debug("materialValue          = " + (materialValue[OPENING] - materialValue[ENDGAME]));
//		logger.debug("pawnMaterialValue      = " + (pawnMaterialValue[OPENING] - pawnMaterialValue[ENDGAME]));
//		logger.debug("mobilityOpeningValue   = " + (mobilityOpeningValue[OPENING] - mobilityOpeningValue[ENDGAME]));
//		logger.debug("mobilityEndgameValue   = " + (mobilityEndgameValue[OPENING] - mobilityEndgameValue[ENDGAME]));
//		logger.debug("pawnsValue             = " + (pawnsValue[OPENING] - pawnsValue[ENDGAME]));
//		logger.debug("kingSafetyValue        = " + (kingSafetyValue[OPENING] - kingSafetyValue[ENDGAME]));
//		logger.debug("positionalOpeningValue = " + (positionalOpeningValue[OPENING] - positionalOpeningValue[ENDGAME]));
//		logger.debug("positionalEndgameValue = " + (positionalEndgameValue[OPENING] - positionalEndgameValue[ENDGAME]));
//		logger.debug("gamePhase              = " + gamePhase);
//		logger.debug("tempo                  = " + (board.getTurn() ? TEMPO : -TEMPO));
//		logger.debug("value                  = " + value);
		return value;
	}
}

File Line
com/alonsoruibal/chess/tt/MultiprobeTranspositionTable.java 128
com/alonsoruibal/chess/tt/TwoTierTranspositionTable.java 98
		}
		
		keys[index] = key2;
		info = (bestMove & 0x1fffff) |
		       ((nodeType & 0xf) << 21) |
		       (((long)(generation & 0xff)) << 32) |
			   (((long)(depthAnalyzed & 0xff)) << 40) |
			   (((long)(score & 0xffff)) << 48);

		infos[index] = info;
	}

	// called at the start of each search
	public void newGeneration() {
		generation++;
	}

	@Override
	public boolean isMyGeneration() {
		return getGeneration() == generation;
	}
}