對不起,這可能已經回答了一些地方,但我對Java很新,我不能將我發現的其他答案應用到我正在做的工作中。如何排序我的ArrayList?並選擇最好的一個
所以我有一個ArrayList,它存儲了它可以在特定的回合上可以採取的塊的位置。
ArrayList<Move> legalTakes = new ArrayList<Move>();
一招具有從(X1,Y1)和座標對(X2,Y2),這是其將被取片處於座標。
moveInput = new Move(pieceToMove, x1, y1, x2, y2, false);
從調用方法(getPiece)我可以採取X2,Y2和查看哪些部分是在該位置處,並發現片的值。
for (Move m : legalTakes) { //for all of the possible takes that turn...
Piece occPieceToTake = this.getBoard().getPiece(m.getX2(),m.getY2());
int pieceValue = this.getBoard().getPiece(m.getX2(),m.getY2()).getValue(occPieceToTake.getChar());
System.err.println("-- WORTH : "+pieceValue);
}
從這個是有可能基於由pieceValue返回值整理我的ArrayList?所以如果一個國王返回值爲6,我可以選擇一個將返回值爲1的棋子?
希望這是足夠的信息..如果不是請讓我知道。
'Collections.sort(list,Comparator);' –