private JavaList <object> FindAllLegalAttackMovesForCurrentPlayer(int currentPlayerColor, int enemyColor) { var moves = new JavaList <object>(); for (var k = 0; k < 32; k++) { if ((_pieces[k] & ~King) == _currentPlayer) { JavaList <object> tempMoves; if ((_pieces[k] & King) == 0) { tempMoves = FindAllLegalSimpleAttackMoves(k, currentPlayerColor, enemyColor); } else // KING { var lastPos = new JavaList <object>(); lastPos.push_back(k); tempMoves = FindAllLegalKingAttackMoves(lastPos, k, LastDirectionNone, currentPlayerColor, enemyColor); } if (Any(tempMoves)) { moves.AppendToTail(tempMoves); } } } return(moves); }
private JavaList <object> AddNewGameMovement(PlayerMove playerMove, JavaList <object> moves) { if (playerMove == null) { return(moves); } JavaList <object> temp = new JavaList <object>(); while (!moves.IsEmpty()) { var current = (JavaList <object>)moves.pop_front(); current.push_front(playerMove); temp.push_back(current); } return(temp); }
private JavaList <object> FindAllLegalSimpleAttackMoves(int currentPiecePos, int currentPlayerColor, int enemyColor) { var x = PosToCol(currentPiecePos); var y = PosToBoardLine(currentPiecePos); var moves = new JavaList <object>(); JavaList <object> tempMoves; int enemyPos, nextPos; var i = currentPlayerColor == WhitePiece ? -1 : 1; // Diagonals UPR e DNR if (x < 6 && y + i > 0 && y + i < 7) { enemyPos = ColLineToPos(x + 1, y + i); nextPos = ColLineToPos(x + 2, y + 2 * i); if ((_pieces[enemyPos] & ~King) == enemyColor && _pieces[nextPos] == EmptyPiece) { tempMoves = FindAllLegalSimpleAttackMoves(nextPos, currentPlayerColor, enemyColor); moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPiecePos, nextPos), tempMoves)); } } // Diagonals DNR e UPL if (x > 1 && y + i > 0 && y + i < 7) { enemyPos = ColLineToPos(x - 1, y + i); nextPos = ColLineToPos(x - 2, y + 2 * i); if ((_pieces[enemyPos] & ~King) == enemyColor && _pieces[nextPos] == EmptyPiece) { tempMoves = FindAllLegalSimpleAttackMoves(nextPos, currentPlayerColor, enemyColor); moves.AppendToTail(AddNewGameMovement(new PlayerMove(currentPiecePos, nextPos), tempMoves)); } } if (moves.IsEmpty()) { moves.push_back(new JavaList <object>()); } return(moves); }
private JavaList <object> FindAllNonAttackMoves(int currentPlayerColor) { var moves = new JavaList <object>(); for (var k = 0; k < 32; k++) { if ((_pieces[k] & ~King) == _currentPlayer) { var x = PosToCol(k); var y = PosToBoardLine(k); int i, j; JavaList <object> tempMove; if ((_pieces[k] & King) == 0) { // Simple piece i = currentPlayerColor == WhitePiece ? -1 : 1; // Diagonal UPR e DNR if (x < 7 && y + i >= 0 && y + i <= 7 && _pieces[ColLineToPos(x + 1, y + i)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(x + 1, y + i))); moves.push_back(tempMove); } // Diagonal UPL e DNL if (x > 0 && y + i >= 0 && y + i <= 7 && _pieces[ColLineToPos(x - 1, y + i)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(x - 1, y + i))); moves.push_back(tempMove); } } else // KING { // Diagonal DNR i = x + 1; j = y + 1; while (i <= 7 && j <= 7 && _pieces[ColLineToPos(i, j)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(i, j))); moves.push_back(tempMove); i++; j++; } // Diagonal UPL i = x - 1; j = y - 1; while (i >= 0 && j >= 0 && _pieces[ColLineToPos(i, j)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(i, j))); moves.push_back(tempMove); i--; j--; } // Diagonal UPR i = x + 1; j = y - 1; while (i <= 7 && j >= 0 && _pieces[ColLineToPos(i, j)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(i, j))); moves.push_back(tempMove); i++; j--; } // Diagonal DNL i = x - 1; j = y + 1; while (i >= 0 && j <= 7 && _pieces[ColLineToPos(i, j)] == EmptyPiece) { tempMove = new JavaList <object>(); tempMove.push_back(new PlayerMove(k, ColLineToPos(i, j))); moves.push_back(tempMove); i--; j++; } } } } return(moves); }
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); }