Exemplo n.º 1
0
        private static bool isCollisionAffected(int[,] matrix, element targetElement)
        {
            UInt16 upElementCordinatesRow = (UInt16)(targetElement.Row - 1);
            UInt16 upElementCordinatesCol = targetElement.Col;
            UInt16 downElementCordinatesRow = (UInt16)(targetElement.Row + 1);
            UInt16 downElementCordinatesCol = targetElement.Col;
            UInt16 leftElementCordinatesRow = targetElement.Row;
            UInt16 leftElementCordinatesCol = (UInt16)(targetElement.Col - 1);
            UInt16 rightElementCordinatesRow = targetElement.Row;
            UInt16 rightElementCordinatesCol = (UInt16)(targetElement.Col + 1);

            if (matrix [targetElement.Row, targetElement.Col] == 0)
                return true;

            if (targetElement.Up)
                if (matrix [upElementCordinatesRow, upElementCordinatesCol] == 0)
                    return true;

            if (targetElement.Down)
                if (matrix [downElementCordinatesRow, downElementCordinatesCol] == 0)
                    return true;

            if (targetElement.Left)
                if (matrix [leftElementCordinatesRow, leftElementCordinatesCol] == 0)
                    return true;

            if (targetElement.Right)
                if (matrix [rightElementCordinatesRow, rightElementCordinatesCol] == 0)
                    return true;

            return false;
        }
Exemplo n.º 2
0
        private static element ElementAfterTurn(int[,] matrix, UInt16 row, UInt16 col, int Moves)
        {
            element elementPack = new element ();
            elementPack.Row = row;
            elementPack.Col = col;
            elementPack.Cost = (UInt16)Math.Abs(Moves);
            elementPack.Value = CalculateSum (matrix);
            elementPack.isRased = (Moves > 0);
            matrix [1, 1] += Moves;

            bool killLastTouchedTower = false;

            UInt16 i = 1 , j = 1;

            if (matrix [i, j] == matrix [i + 1, j] && matrix[i,j] != 0)
            {
                matrix [i + 1, j] = 0;
                killLastTouchedTower = true;
                elementPack.Down = true;
            }
            if (matrix[i, j] == matrix[i - 1, j] && matrix[i,j] != 0)
            {
                matrix[i - 1, j] = 0;
                killLastTouchedTower = true;
                elementPack.Up = true;
            }
            if (matrix[i, j] == matrix[i, j - 1] && matrix[i,j] != 0)
            {
                matrix[i, j - 1] = 0;
                killLastTouchedTower = true;
                elementPack.Left = true;
            }
            if (matrix[i, j] == matrix[i, j + 1] && matrix[i,j] != 0)
            {
                matrix[i, j + 1] = 0;
                killLastTouchedTower = true;
                elementPack.Right = true;
            }

            if (killLastTouchedTower == true)
                matrix[i, j] = 0;

            elementPack.Value -= CalculateSum(matrix);
            elementPack.ValueCoefficient = elementPack.Value/elementPack.Cost;

            return elementPack;
        }
Exemplo n.º 3
0
        private static void ExecuteTurn(int[,] matrix, element targetElement)
        {
            UInt16 upElementCordinatesRow = (UInt16)(targetElement.Row - 1);
            UInt16 upElementCordinatesCol = (UInt16)targetElement.Col;
            UInt16 downElementCordinatesRow = (UInt16)(targetElement.Row + 1);
            UInt16 downElementCordinatesCol = (UInt16)targetElement.Col;
            UInt16 leftElementCordinatesRow = (UInt16)targetElement.Row;
            UInt16 leftElementCordinatesCol = (UInt16)(targetElement.Col - 1);
            UInt16 rightElementCordinatesRow = (UInt16)targetElement.Row;
            UInt16 rightElementCordinatesCol = (UInt16)(targetElement.Col + 1);

            if (targetElement.Up == true)
                matrix [upElementCordinatesRow, upElementCordinatesCol] = 0;

            if (targetElement.Down == true)
                matrix [downElementCordinatesRow, downElementCordinatesCol] = 0;

            if (targetElement.Left == true)
                matrix [leftElementCordinatesRow, leftElementCordinatesCol] = 0;

            if (targetElement.Right == true)
                matrix [rightElementCordinatesRow, rightElementCordinatesCol] = 0;

            matrix[targetElement.Row, targetElement.Col] = 0;
        }
Exemplo n.º 4
0
        public static element[] ResultInMatrixForTurnsAtLocation(int[,] matrix, UInt16 turnsCount, UInt16 row, UInt16 col)
        {
            element rasePack = new element();
            element dropPack = new element();

            int midValue = matrix[1, 1];

            int leftSum = matrix[1, 0] - midValue;
            int rightSum = matrix[1, 2] - midValue;
            int upSum = matrix[0, 1] - midValue;
            int downSum = matrix[2, 1] - midValue;

            int[] localValues = new int []
            {
                rightSum,
                upSum,
                leftSum,
                downSum
            };

            int upValue = 0, downValue = 0;
            foreach (var el in localValues)
            {
                if (Math.Abs(el) > turns)
                    continue;

                if( el < 0 )
                {
                    if (Math.Abs(el) < downValue || downValue == 0)
                        downValue = Math.Abs(el);
                }
                else
                {
                    if (el < upValue || upValue == 0)
                        upValue = el;
                }
            }

            if(upValue != 0)
            {
                int [,] rasedMatrix = new int [3,3];
                Array.Copy(matrix, rasedMatrix, matrix.Length);

                rasePack = ElementAfterTurn(rasedMatrix, row, col, upValue);
            }

            if(downValue != 0)
            {
                int [,] dropMatrix = new int [3,3];
                Array.Copy(matrix, dropMatrix, matrix.Length);

                dropPack = ElementAfterTurn(dropMatrix, row, col, -downValue);
            }

            element[] result = new element [2];
            result[0] = rasePack;
            result[1] = dropPack;

            return result;
        }