請幫助迭代列表的索引與數組。這行代碼score + = SquareTable [index.get(i)];會產生一個錯誤,我不知道如何適應它。提前致謝。需要幫助迭代arrayList與數組
@Override
public int evaluatePieceScore() {
int score = 0;
List<Piece> index = chessgame.getPieces();
for (Piece piece : this.chessgame.getPieces()){
if(piece.getColor() == Piece.YELLOW_COLOR){
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_PAWN), PawnSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_KNIGHT), KnightSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_BISHOP), BishopSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_ROOK), RookSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_QUEEN), QueenSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_KING), KingMiddleGameSquareTable);
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_KING), KingEndGameSquareTable);
}else if(piece.getColor() == Piece.BROWN_COLOR){
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_PAWN), reverse(PawnSquareTable));
score += this.CalculateScore(index ,getPieceValue(Piece.TYPE_KNIGHT), reverse(KnightSquareTable));
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_BISHOP), reverse(BishopSquareTable));
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_ROOK), reverse(RookSquareTable));
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_QUEEN), reverse(QueenSquareTable));
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_KING), reverse(KingMiddleGameSquareTable));
score += this.CalculateScore(index, getPieceValue(Piece.TYPE_KING), reverse(KingEndGameSquareTable));
}else{
throw new IllegalStateException("Unknown piece color found: "+piece.getColor());
}
}
return score;
}
public int CalculateScore(List<Piece> index, int pieceValue, int[] SquareTable){
int score = pieceValue * index.size();
for(int i = 0; i < index.size(); i++){
score += SquareTable[index.get(i)];
}
return score;
}
需要錯誤堆棧跟蹤。 –
請您詳細說明 – user3816650
您收到的錯誤是什麼? –