private bool Any(JavaList <object> moves) { return(!moves.IsEmpty() && !((JavaList <object>)moves.peek_head()).IsEmpty()); }
private JavaList <object> FindAllLegalKingDiagonalAttackMoves(JavaList <object> lastPos, int currentPos, int playerColor, int enemyColor, int incX, int incY) { var x = PosToCol(currentPos); var y = PosToBoardLine(currentPos); var moves = new JavaList <object>(); var startPos = (int)lastPos.peek_head(); var i = x + incX; var j = y + incY; // Find enemy while (i > 0 && i < 7 && j > 0 && j < 7 && (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos)) { i += incX; j += incY; } if (i > 0 && i < 7 && j > 0 && j < 7 && (_pieces[ColLineToPos(i, j)] & ~King) == enemyColor && !lastPos.Contains(ColLineToPos(i, j))) { lastPos.push_back(ColLineToPos(i, j)); i += incX; j += incY; var saveI = i; var saveJ = j; JavaList <object> tempMoves; while (i >= 0 && i <= 7 && j >= 0 && j <= 7 && (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos)) { int dir; if (incX == 1 && incY == 1) { dir = LastDirectionLeftAbove; } else if (incX == -1 && incY == -1) { dir = LastDirectionRightBelow; } else if (incX == -1 && incY == 1) { dir = LastDirectionRightAbove; } else { dir = LastDirectionLeftBelow; } var tempPos = lastPos.Clone(); tempMoves = FindAllLegalKingAttackMoves(tempPos, ColLineToPos(i, j), dir, playerColor, enemyColor); if (Any(tempMoves)) { moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPos, ColLineToPos(i, j)), tempMoves)); } i += incX; j += incY; } lastPos.pop_back(); if (moves.IsEmpty()) { i = saveI; j = saveJ; while (i >= 0 && i <= 7 && j >= 0 && j <= 7 && (_pieces[ColLineToPos(i, j)] == EmptyPiece || ColLineToPos(i, j) == startPos)) { tempMoves = new JavaList <object>(); tempMoves.push_back(new PlayerMove(currentPos, ColLineToPos(i, j))); moves.push_back(tempMoves); i += incX; j += incY; } } } return(moves); }