public IList<IPosition> GetKingPossibleMoves()
        {
            var movementStrategy = this.figuresInPlay['K'].GetMovements();
            var currentPostion = this.figuresInPlay['K'].Position;
            var possibleMoves = new List<IPosition>();

            foreach (var m in movementStrategy)
            {
                bool isOnBoard = this.IsOnBoard(currentPostion.Row + m.ByRow, currentPostion.Col + m.ByCol);
                if (!isOnBoard)
                {
                    continue;
                }

                var possiblePosition = new Position(currentPostion.Row + m.ByRow, currentPostion.Col + m.ByCol);
                bool isUnoccupied = this.board.PositionIsUnoccupied(possiblePosition);
                if (isUnoccupied)
                {
                    possibleMoves.Add(possiblePosition);
                }
            }

            return possibleMoves;
        }
 public void MethodShoudReturnsTrueWhenIsPassedValidPosition()
 {
     var position = new Position(4, 4);
     var expected = Validator.IsPositionOnTheBoard(position);
     Assert.IsTrue(expected);
 }
 public void MethodShoudReturnsFalseWhenIsPassedInvalidPositionWithPositiveCoordinates()
 {
     var position = new Position(100, 100);
     var expected = Validator.IsPositionOnTheBoard(position);
     Assert.IsFalse(expected);
 }
        public static IPosition CheckNextKingPosition(IPosition currentCoordinates, char firstDirection, char secondDirection)
        {
            int[] displacementDownLeft = { 1, -2 };
            int[] displacementDownRight = { 1, 2 };
            int[] displacementUpLeft = { -1, -2 };
            int[] displacementUpRight = { -1, 2 };
            var newCoordinates = new Position();

            if (firstDirection == 'U')
            {
                if (secondDirection == 'L')
                {
                    newCoordinates.Row = currentCoordinates.Row + displacementUpLeft[0];
                    newCoordinates.Col = currentCoordinates.Col + displacementUpLeft[1];

                    bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                    if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                    {
                        MoveFigure(currentCoordinates, newCoordinates);

                        BaseGame.Counter++;
                        for (int i = 0; i < 4; i++)
                        {
                            GameConstants.KingExistingMoves[i] = true;
                        }

                        CheckForKingExit(newCoordinates.Row);
                        return newCoordinates;
                    }
                    else
                    {
                        bool allAreFalse = KingExistingMovesMethod(0);
                        if (allAreFalse)
                        {
                            gameOver = true;
                            CommandPrintKingLosing();

                            return null;
                        }

                        Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                        Thread.Sleep(400);
                        return null;
                    }
                }
                else
                {
                    newCoordinates.Row = currentCoordinates.Row + displacementUpRight[0];
                    newCoordinates.Col = currentCoordinates.Col + displacementUpRight[1];

                    bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                    if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                    {
                        MoveFigure(currentCoordinates, newCoordinates);

                        BaseGame.Counter++;
                        for (int i = 0; i < 4; i++)
                        {
                            GameConstants.KingExistingMoves[i] = true;
                        }

                        CheckForKingExit(newCoordinates.Row);
                        return newCoordinates;
                    }
                    else
                    {
                        bool allAreFalse = KingExistingMovesMethod(1);
                        if (allAreFalse)
                        {
                            gameOver = true;
                            CommandPrintKingLosing();

                            return null;
                        }

                        Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                        Thread.Sleep(400);
                        return null;
                    }
                }
            }
            else
            {
                if (secondDirection == 'L')
                {
                    newCoordinates.Row = currentCoordinates.Row + displacementDownLeft[0];
                    newCoordinates.Col = currentCoordinates.Col + displacementDownLeft[1];

                    bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                    if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                    {
                        MoveFigure(currentCoordinates, newCoordinates);

                        BaseGame.Counter++;
                        for (int i = 0; i < 4; i++)
                        {
                            GameConstants.KingExistingMoves[i] = true;
                        }

                        CheckForKingExit(newCoordinates.Row);
                        return newCoordinates;
                    }
                    else
                    {
                        bool allAreFalse = KingExistingMovesMethod(2);
                        if (allAreFalse)
                        {
                            gameOver = true;
                            CommandPrintKingLosing();

                            return null;
                        }

                        Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                        Thread.Sleep(400);
                        return null;
                    }
                }
                else
                {
                    newCoordinates.Row = currentCoordinates.Row + displacementDownRight[0];
                    newCoordinates.Col = currentCoordinates.Col + displacementDownRight[1];

                    bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                    if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                    {
                        MoveFigure(currentCoordinates, newCoordinates);

                        BaseGame.Counter++;
                        for (int i = 0; i < 4; i++)
                        {
                            GameConstants.KingExistingMoves[i] = true;
                        }

                        CheckForKingExit(newCoordinates.Row);
                        return newCoordinates;
                    }
                    else
                    {
                        bool allAreFalse = KingExistingMovesMethod(3);
                        if (allAreFalse)
                        {
                            gameOver = true;
                            CommandPrintKingLosing();

                            return null;
                        }

                        Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                        Thread.Sleep(400);
                        return null;
                    }
                }
            }
        }
        public static void PrintBoard()
        {
            Console.WriteLine();
            for (int row = 0; row < GetField.GetLength(0); row++)
            {
                for (int col = 0; col < GetField.GetLength(1); col++)
                {
                    Position coordinates = new Position(row, col);
                    bool isCellIn = Validator.IsPositionOnTheBoard(coordinates);
                    if (isCellIn)
                    {
                        if (row % 2 == 0)
                        {
                            if (col % 4 == 0)
                            {
                                ConsoleColor backgroundColor = ConsoleColor.Green;
                                BaseGame.SetConsoleColor(backgroundColor, row, col);
                            }
                            else if (col % 2 == 0)
                            {
                                ConsoleColor backgroundColor = ConsoleColor.Blue;
                                BaseGame.SetConsoleColor(backgroundColor, row, col);
                            }
                            else if (col % 2 != 0)
                            {
                                Console.Write(BaseGame.GetField[row, col]);
                            }
                        }
                        else if (col % 4 == 0)
                        {
                            ConsoleColor backgroundColor = ConsoleColor.Blue;
                            BaseGame.SetConsoleColor(backgroundColor, row, col);
                        }
                        else if (col % 2 == 0)
                        {
                            ConsoleColor backgroundColor = ConsoleColor.Green;
                            BaseGame.SetConsoleColor(backgroundColor, row, col);
                        }
                        else if (col % 2 != 0)
                        {
                            Console.Write(BaseGame.GetField[row, col]);
                        }
                    }
                    else
                    {
                        Console.Write(BaseGame.GetField[row, col]);
                    }
                }

                Console.WriteLine();
                Console.ResetColor();
            }

            Console.WriteLine();
        }
        public static void KingDirection(char downUpDirection, char leftRightDirection)
        {
            var oldCoordinates = new Position(KingPosition.Row, KingPosition.Col);

            var coords = CheckNextKingPosition(oldCoordinates, downUpDirection, leftRightDirection);
            if (coords != null)
            {
                BaseGame.KingPosition = coords;
            }
        }
        public static IPosition CheckNextPawnPosition(IPosition currentCoordinates, char checkDirection, char currentPawn)
        {
            int[] displacementDownLeft = { 1, -2 };
            int[] displacementDownRight = { 1, 2 };
            var newCoordinates = new Position();
            if (checkDirection == 'L')
            {
                newCoordinates.Row = currentCoordinates.Row + displacementDownLeft[0];
                newCoordinates.Col = currentCoordinates.Col + displacementDownLeft[1];

                bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                {
                    MoveFigure(currentCoordinates, newCoordinates);

                    BaseGame.Counter++;

                    SwitchCurrentPawnExistingMoves(currentPawn);

                    return newCoordinates;
                }
                else
                {
                    bool allAreFalse = true;
                    switch (currentPawn)
                    {
                        case 'A':
                            GameConstants.PawnExistingMoves[0, 0] = false;
                            break;

                        case 'B':
                            GameConstants.PawnExistingMoves[1, 0] = false;
                            break;

                        case 'C':
                            GameConstants.PawnExistingMoves[2, 0] = false;
                            break;

                        case 'D':
                            GameConstants.PawnExistingMoves[3, 0] = false;
                            break;

                        default:
                            Console.WriteLine(MessageConstants.ErrorMessage);
                            break;
                    }

                    allAreFalse = CheckingAllPawnMoves();

                    if (allAreFalse)
                    {
                        gameOver = true;
                        Console.WriteLine(MessageConstants.KingVictoryMessage, BaseGame.Counter / 2);
                        gameOver = true;
                        return null;
                    }

                    Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                    Thread.Sleep(400);
                    return null;
                }
            }
            else
            {
                newCoordinates.Row = currentCoordinates.Row + displacementDownRight[0];
                newCoordinates.Col = currentCoordinates.Col + displacementDownRight[1];

                bool isEmptyCurrentCell = GetField[newCoordinates.Row, newCoordinates.Col] == ' ';
                if (Validator.IsPositionOnTheBoard(newCoordinates) && isEmptyCurrentCell)
                {
                    MoveFigure(currentCoordinates, newCoordinates);

                    BaseGame.Counter++;

                    SwitchCurrentPawnExistingMoves(currentPawn);

                    return newCoordinates;
                }
                else
                {
                    bool allAreFalse = true;
                    switch (currentPawn)
                    {
                        case 'A':
                            GameConstants.PawnExistingMoves[0, 1] = false;
                            break;

                        case 'B':
                            GameConstants.PawnExistingMoves[1, 1] = false;
                            break;

                        case 'C':
                            GameConstants.PawnExistingMoves[2, 1] = false;
                            break;

                        case 'D':
                            GameConstants.PawnExistingMoves[3, 1] = false;
                            break;

                        default:
                            Console.WriteLine(MessageConstants.ErrorMessage);
                            break;
                    }

                    allAreFalse = CheckingAllPawnMoves();

                    if (allAreFalse)
                    {
                        gameOver = true;
                        Console.WriteLine(MessageConstants.KingVictoryMessage, BaseGame.Counter / 2);
                        gameOver = true;
                        return null;
                    }

                    Printer.PrintMessage(ConsoleColor.DarkYellow, MessageConstants.WrongDirectionMessage);
                    Thread.Sleep(400);

                    return null;
                }
            }
        }