Пример #1
0
        public void Encode_DecodeTest()
        {
            //Arrange
            string sentMessage = "Message";

            byte[]       file        = Encoding.ASCII.GetBytes(sentMessage);
            IEncode      encoder     = new Encode(file);
            var          blocksCount = encoder.NumberOfBlocks;
            var          overHead    = 20;
            IList <Drop> drops       = new List <Drop>();

            for (int i = 0; i < blocksCount + overHead; i++)
            {
                var drop = encoder.Encode();
                drops.Add(drop);
            }
            IMatrixSolver matrixSolver = new MatrixSolver();
            IDecode       target       = new Decode(matrixSolver);

            //Act
            var actualByte      = target.Decode(drops, blocksCount, encoder.ChunkSize, encoder.FileSize);
            var receievdMessage = Encoding.ASCII.GetString(actualByte);

            //Assert
            Assert.AreEqual(sentMessage, receievdMessage);
        }
Пример #2
0
        // GET: /<controller>/
        public IActionResult Index(
            double l1, double l2, double l3,
            double x, double y, double z)
        {
            ViewData["x"]       = x;
            ViewData["y"]       = y;
            ViewData["z"]       = z;
            ViewData["l1"]      = l1;
            ViewData["l2"]      = l2;
            ViewData["l3"]      = l3;
            ViewData["runFast"] = _runFast;

            InitializeMatrixSolver(new double[3] {
                l1, l2, l3
            });

            if (Math.Abs(l1) > EPSILON &&
                Math.Abs(l2) > EPSILON &&
                Math.Abs(l3) > EPSILON)
            {
                return(View(MatrixSolver.RunPointSimulation(x, y, z)));
            }
            else
            {
                return(View(new List <FinalAngles>()));
            }
        }
Пример #3
0
        public void SolveTest()
        {
            //Arrange
            IMatrixSolver target = new MatrixSolver();
            var           matrix = new int[7, 7]
            {
                { 1, 0, 1, 0, 0, 0, 2 },
                { 0, 1, 0, 1, 0, 0, 3 },

                { 1, 0, 0, 0, 1, 0, 4 },
                { 0, 1, 0, 0, 0, 1, 8 },

                { 0, 0, 1, 0, 1, 0, 6 },
                { 1, 0, 0, 0, 0, 0, 5 },
                { 0, 1, 0, 0, 0, 0, 10 }
            };

            var expected = new int[7, 7]
            {
                { 1, 0, 0, 0, 0, 0, 5 },
                { 0, 1, 0, 0, 0, 0, 10 },
                { 0, 0, 1, 0, 0, 0, 7 },
                { 0, 0, 0, 1, 0, 0, 9 },
                { 0, 0, 0, 0, 1, 0, 1 },
                { 0, 0, 0, 0, 0, 1, 2 },
                { 0, 0, 0, 0, 0, 0, 0 }
            };

            //Act
            var result = target.Solve(matrix);

            //Assert
            Assert.IsTrue(result, "couldnt solve matrix");
            Common.CheckArraysAreEqual(matrix, expected);
        }
Пример #4
0
    static void testPrintMatrix()
    {
        string[,] testMatrix = { { "1C", "1D", "1E", "1D" }, { "1C", "1E", "1C", "1D" }, { "1C", "1F", "1C", "1D" } };
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix);

        matrixSolver.printMatrix();
    }
Пример #5
0
    static void test_getShortestPermutation()
    {
        string[,] testMatrix = { { "1C", "1C", "BD", "55", "1C" },
                                 { "1C", "55", "BD", "1D", "1C" },
                                 { "1C", "1F", "FF", "1D", "1C" },
                                 { "1C", "E9", "FF", "1C", "BD" },
                                 { "1C", "1F", "1C", "1D", "1C" } };
        List <string> hacks = new List <string>();

        hacks.Add("55 1C");
        hacks.Add("55 BD 1C");
        hacks.Add("55 1C E9");
        int                   bufferSize   = 7;
        MatrixSolver          matrixSolver = new MatrixSolver(testMatrix, hacks, bufferSize);
        List <List <string> > hackArrays   =
            new List <List <string> > {
            new List <string> {
                "1D", "1C"
            },
            new List <string> {
                "1D", "BD", "1C"
            },
            new List <string> {
                "1D", "1C", "E9"
            }
        };
        List <List <string> > shortestSuperStrings = matrixSolver.findShortestSuperStrings(hackArrays);

        matrixSolver.getShortestPermutation(shortestSuperStrings);
    }
Пример #6
0
    static void testCombinationFinder()
    {
        string[,] testMatrix = {};
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix);

        int[]         hackIds    = { 1, 2, 3, 4 };
        IList <int[]> returnList = matrixSolver.findAllCombinationsPossible(hackIds);
    }
Пример #7
0
 static void testFindWordOverlap()
 {
     string[]     string1      = { "OM", "55", "ED", "UU" };
     string[]     string2      = { "55", "ED" };
     MatrixSolver matrixSolver = new MatrixSolver(new string[, ] {
     });
     int overlap = matrixSolver.findWordOverlap(string1, string2);
 }
Пример #8
0
        public void CalculatesTurnsForZeroAugmentColumnPriorToGaussianElimination()
        {
            const int nodeCount = 25;
            const int mineCount = 1;

            Span <Node> nodes = stackalloc Node[]
            {
                new(0, false, 0, NodeState.Revealed),
                new(1, false, 1, NodeState.Revealed),
                new(2, true, 0, NodeState.Flagged),
                new(3, false, 0, NodeState.Hidden),
                new(4, false, 0, NodeState.Hidden),

                new(5, false, 0, NodeState.Revealed),
                new(6, false, 1, NodeState.Revealed),
                new(7, false, 1, NodeState.Revealed),
                new(8, false, 0, NodeState.Hidden),
                new(9, false, 0, NodeState.Hidden),

                new(10, false, 1, NodeState.Revealed),
                new(11, false, 1, NodeState.Revealed),
                new(12, false, 1, NodeState.Revealed),
                new(13, false, 0, NodeState.Hidden),
                new(14, false, 0, NodeState.Hidden),

                new(15, false, 0, NodeState.Hidden),
                new(16, false, 0, NodeState.Hidden),
                new(17, false, 3, NodeState.Revealed),
                new(18, false, 0, NodeState.Hidden),
                new(19, false, 0, NodeState.Hidden),

                new(20, false, 0, NodeState.Hidden),
                new(21, false, 0, NodeState.Hidden),
                new(22, false, 0, NodeState.Hidden),
                new(23, false, 0, NodeState.Hidden),
                new(24, false, 0, NodeState.Hidden)
            };

            var buffs = new BufferKeeper
            {
                Turns          = stackalloc Turn[nodeCount],
                EdgeIndexes    = stackalloc int[Engine.MaxNodeEdges],
                Mines          = stackalloc int[mineCount],
                VisitedIndexes = stackalloc int[nodeCount - mineCount],
                RevealedMineCountNodeIndexes = stackalloc int[nodeCount - mineCount],
                AdjacentHiddenNodeIndexes    = stackalloc int[nodeCount],
                Grid = stackalloc float[nodeCount * nodeCount]
            };

            var matrix = new Matrix <Node>(nodes, 5);

            var turnCount = MatrixSolver.CalculateTurns(matrix, buffs, false);

            Assert.Equal(3, turnCount);
            Assert.Equal(new Turn(3, NodeOperation.Reveal), buffs.Turns[0]);
            Assert.Equal(new Turn(8, NodeOperation.Reveal), buffs.Turns[1]);
            Assert.Equal(new Turn(13, NodeOperation.Reveal), buffs.Turns[2]);
        }
Пример #9
0
 static void testConvertStringListToArrayList()
 {
     string[,] testMatrix = {};
     MatrixSolver  matrixSolver = new MatrixSolver(testMatrix);
     List <string> listOfHacks  = new List <string> {
         "1M 2E 55", "2E 4D 34", "RE 54 78"
     };
     List <List <string> > hackArrays = matrixSolver.convertStringsToStringLists(listOfHacks);
 }
Пример #10
0
        public static void RegisterMatrixSolver <T>(MatrixSolver <T> solver)
        {
            Type valueType = typeof(T);

            if (solver == null)
            {
                throw new ArgumentNullException("solver");
            }
            m_MatrixSolvers[valueType] = solver;
        }
Пример #11
0
        public void MatrixColumnZeroification(int index, int expected)
        {
            Span <float> data = stackalloc float[9];

            data.Fill(1);
            var matrix = new Matrix <float>(data, 3);

            MatrixSolver.ZeroifyColumn(matrix, 1);

            Assert.Equal(expected, data[index]);
        }
Пример #12
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var            decoderView         = new Views.DecoderView();
            IMatrixSolver  matrixSolver        = new MatrixSolver();
            IDecode        decoder             = new Decode(matrixSolver);
            IEncodeService encodeServiceClient = new EncodeService.EncodeServiceClient();
            var            decoderViewModel    = new DecoderViewModel(decoder, encodeServiceClient);

            decoderView.DataContext = decoderViewModel;
            decoderView.Show();
        }
Пример #13
0
    static void testFindHackPath1()
    {
        string[,] testMatrix = { { "1C", "BD", "55", "E9", "55" },
                                 { "1C", "BD", "1C", "55", "E9" },
                                 { "55", "E9", "E9", "BD", "BD" },
                                 { "55", "FF", "FF", "1C", "1C" },
                                 { "FF", "E9", "1C", "BD", "FF" } };
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix);

        matrixSolver.findHackPath(new List <string> {
            "E9", "BD", "FF", "1C"
        });
    }
Пример #14
0
        public void BuildMatrixTest()
        {
            //Arrange
            IMatrixSolver   matrixSolver = new MatrixSolver();
            Decode_Accessor target       = new Decode_Accessor(matrixSolver);
            IList <Drop>    drops        = new Drop[3]
            {
                new Drop()
                {
                    SelectedParts = new int[2] {
                        0, 1
                    }, Data = new byte[2] {
                        1, 2
                    }
                },
                new Drop()
                {
                    SelectedParts = new int[2] {
                        0, 2
                    }, Data = new byte[2] {
                        3, 4
                    }
                },
                new Drop()
                {
                    SelectedParts = new int[2] {
                        1, 2
                    }, Data = new byte[2] {
                        5, 6
                    }
                }
            };
            var expected = new int[6, 7]
            {
                { 1, 0, 1, 0, 0, 0, 1 },
                { 0, 1, 0, 1, 0, 0, 2 },

                { 1, 0, 0, 0, 1, 0, 3 },
                { 0, 1, 0, 0, 0, 1, 4 },

                { 0, 0, 1, 0, 1, 0, 5 },
                { 0, 0, 0, 1, 0, 1, 6 }
            };
            int blocksCount = 3;
            int chunkSize   = 2;
            //Act
            var actual = target.BuildMatrix(drops, blocksCount, chunkSize);

            //Assert
            Common.CheckArraysAreEqual(expected, actual);
        }
Пример #15
0
    static void testFindHackPath_sameSquareBypass()
    {
        string[,] testMatrix = { { "1C", "BD", "55", "E9", "55" },
                                 { "1C", "BD", "1C", "55", "E9" },
                                 { "55", "E9", "E9", "BD", "BD" },
                                 { "55", "FF", "FF", "1C", "1C" },
                                 { "FF", "E9", "1C", "BD", "FF" } };
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix);

        List <Tuple <int, int> > expectedPath = null;

        Assert.Equal(expectedPath, matrixSolver.findHackPath(new List <string> {
            "1C", "BD", "BD", "1C", "1C"
        }));
    }
Пример #16
0
        /// <summary>
        /// Natural Spline data interpolator
        /// </summary>
        public NaturalSpline(double[] xs, double[] ys, int resolution = 10) : base(xs, ys, resolution)
        {
            m     = new Matrix(n - 2);
            gauss = new MatrixSolver(n - 2, m);

            a = new double[n];
            b = new double[n];
            c = new double[n];
            d = new double[n];
            h = new double[n - 1];

            CalcParameters();
            Integrate();
            Interpolate();
        }
Пример #17
0
        public FullMatrix(int m, int n, T[] values = null, MatrixSolver <T> solver = null)
        {
            int size = m * n;

            m_RowsCount    = m;
            m_ColumnsCount = n;
            m_Values       = new T[size];
            if (values != null)
            {
                if (values.Length != size)
                {
                    throw new IndexOutOfRangeException("values");
                }
                Array.Copy(values, m_Values, size);
            }
        }
Пример #18
0
    static void test_findAllPathsForHacks()
    {
        string[,] testMatrix = { { "1C", "1C", "BD", "55", "1C" },
                                 { "1C", "E9", "55", "BD", "1C" },
                                 { "55", "55", "55", "E9", "1C" },
                                 { "1C", "1C", "55", "BD", "BD" },
                                 { "55", "1C", "BD", "1C", "1C" } };
        List <string> hacks = new List <string>();

        hacks.Add("55 1C");
        hacks.Add("55 BD 1C");
        hacks.Add("55 1C E9");
        int          bufferSize   = 7;
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix, hacks, bufferSize);

        matrixSolver.findAllHackPaths();
    }
Пример #19
0
    static void test_findSpecificPathForHacks()
    {
        string[,] testMatrix = { { "1C", "1C", "BD", "55", "1C" },
                                 { "55", "E9", "55", "BD", "1C" },
                                 { "1C", "55", "55", "E9", "1C" },
                                 { "1C", "1C", "55", "BD", "BD" },
                                 { "1C", "1C", "BD", "1C", "1C" } };
        List <string> hacks = new List <string>();

        hacks.Add("55 1C");
        hacks.Add("55 BD 1C");
        hacks.Add("55 1C E9");
        int          bufferSize   = 20;
        MatrixSolver matrixSolver = new MatrixSolver(testMatrix, hacks, bufferSize);

        int[] hackIds = new int[] { 0 };
        matrixSolver.findSpecificHackPath(hackIds);
    }
Пример #20
0
        private void StandardTest(string testName, int correctCount)
        {
            Console.WriteLine("Test name: " + testName);

            var grammarFileDot    = "Resources\\Grammars\\" + testName + ".dot";
            var grammarFileSimple = "Resources\\Grammars\\" + testName + ".txt";
            var graphFile         = "Resources\\Automata\\" + testName + ".dot";

            var graphDot      = File.ReadAllText(graphFile, Encoding.Default);
            var grammarDot    = File.ReadAllText(grammarFileDot, Encoding.Default);
            var grammarSimple = File.ReadAllText(grammarFileSimple, Encoding.Default);

            var graph            = new Graph(graphDot);
            var grammar          = Grammar.FromDot(grammarDot);
            var grammarForMatrix = Grammar.FromSimpleFormat(grammarSimple);

            var gllSolver      = new GLLSolver();
            var matrixSolver   = new MatrixSolver();
            var bottomUpSolver = new BottomUpSolver();

            var resultGll      = gllSolver.Solve(graph, grammar);
            var resultMatrix   = matrixSolver.Solve(graph, grammarForMatrix);
            var resultBottomUp = bottomUpSolver.Solve(graph, grammar);

            var all = new List <string>()
            {
                resultBottomUp, resultMatrix, resultGll
            };

            foreach (var result in all)
            {
                var count = result.Split('S').Length - 1;  // count of triplets (i,S,j)
                if (count != correctCount)
                {
                    Console.WriteLine("Test failed: " + testName + Environment.NewLine);
                    return;
                }
            }
            Console.WriteLine("Test passed: " + testName);
            Console.WriteLine();
        }
Пример #21
0
    static void testFindShortestSuperString()
    {
        List <List <string> > hackArrays =
            new List <List <string> > {
            new List <string> {
                "1C", "1C", "55"
            },
            new List <string> {
                "55", "FF", "1C"
            },
            new List <string> {
                "BD", "E9", "BD", "55"
            },
            new List <string> {
                "55", "1C", "FF", "BD"
            }
        };
        MatrixSolver matrixSolver = new MatrixSolver(new string[, ] {
        });

        matrixSolver.findShortestSuperStrings(hackArrays);
    }
Пример #22
0
        public void MatrixSolverTest()
        {
            var sudoku = new Sudoku(new ICell[, ] {
                { new Cell(6), new Cell(4), new Cell(0), new Cell(2), new Cell(9), new Cell(8), new Cell(5), new Cell(0), new Cell(7) },
                { new Cell(0), new Cell(5), new Cell(2), new Cell(1), new Cell(0), new Cell(6), new Cell(9), new Cell(8), new Cell(4) },
                { new Cell(7), new Cell(9), new Cell(8), new Cell(0), new Cell(4), new Cell(5), new Cell(0), new Cell(6), new Cell(2) },

                { new Cell(9), new Cell(0), new Cell(3), new Cell(6), new Cell(1), new Cell(4), new Cell(8), new Cell(7), new Cell(0) },
                { new Cell(0), new Cell(8), new Cell(6), new Cell(5), new Cell(3), new Cell(0), new Cell(4), new Cell(2), new Cell(9) },
                { new Cell(5), new Cell(7), new Cell(4), new Cell(0), new Cell(8), new Cell(2), new Cell(6), new Cell(0), new Cell(3) },

                { new Cell(8), new Cell(3), new Cell(0), new Cell(7), new Cell(6), new Cell(9), new Cell(2), new Cell(4), new Cell(1) },
                { new Cell(4), new Cell(1), new Cell(9), new Cell(8), new Cell(0), new Cell(3), new Cell(7), new Cell(5), new Cell(6) },
                { new Cell(2), new Cell(0), new Cell(7), new Cell(4), new Cell(5), new Cell(1), new Cell(3), new Cell(0), new Cell(8) }
            });

            var solver = new MatrixSolver(sudoku);

            solver.Solve();

            //TODO: check if result is correct
        }
Пример #23
0
        public static void Simulation(Matrix <Node> matrix, Span <Turn> turns, int firstTurnNodeIndex, int mineCount)
        {
            var nodeCount = matrix.Nodes.Length;
            var buffs     = new BufferKeeper
            {
                Turns          = stackalloc Turn[nodeCount],
                EdgeIndexes    = stackalloc int[Engine.MaxNodeEdges],
                Mines          = stackalloc int[mineCount],
                VisitedIndexes = stackalloc int[nodeCount - mineCount],
                RevealedMineCountNodeIndexes = stackalloc int[nodeCount - mineCount],
                AdjacentHiddenNodeIndexes    = stackalloc int[nodeCount],
                Grid = stackalloc float[nodeCount * nodeCount]
            };

            Engine.FillCustomBoard(matrix, buffs.Mines, firstTurnNodeIndex);

            var firstTurn = new Turn(firstTurnNodeIndex, NodeOperation.Reveal);

            Engine.ComputeBoard(matrix, firstTurn, buffs.VisitedIndexes);

            while (true)
            {
                var turnCount = MatrixSolver.CalculateTurns(matrix, buffs, false);
                if (turnCount == 0)
                {
                    turnCount = MatrixSolver.CalculateTurns(matrix, buffs, true);
                    if (turnCount == 0)
                    {
                        break;
                    }
                }
                foreach (var turn in turns.Slice(0, turnCount))
                {
                    Engine.ComputeBoard(matrix, turn, buffs.VisitedIndexes);
                }
            }
        }
    }
Пример #24
0
    static void test_findAllPermutationsOfStrings()
    {
        List <List <string> > hackArrays = new List <List <string> >();

        hackArrays.Add(new List <string> {
            "ED", "OM", "FF", "UF", "PP"
        });
        hackArrays.Add(new List <string> {
            "ED", "OM", "FF", "UF"
        });
        hackArrays.Add(new List <string> {
            "ED", "OM", "FF"
        });
        hackArrays.Add(new List <string> {
            "ED", "OM"
        });
        hackArrays.Add(new List <string> {
            "ED"
        });
        MatrixSolver matrixSolver = new MatrixSolver(new string[, ] {
        });

        matrixSolver.findAllPermutationsOfStrings(hackArrays);
    }
Пример #25
0
        public void CalculatesTurnsWhenGaussianEliminationProducesNonIntegers()
        {
            const int nodeCount = 64;
            const int mineCount = 10;

            Span <Node> nodes = stackalloc Node[]
            {
                new(0, false, 1, NodeState.Revealed),
                new(1, false, 1, NodeState.Revealed),
                new(2, false, 1, NodeState.Revealed),
                new(3, true, 1, NodeState.Flagged),
                new(4, false, 2, NodeState.Revealed),
                new(5, false, 1, NodeState.Revealed),
                new(6, false, 1, NodeState.Revealed),
                new(7, false, 1, NodeState.Hidden),

                new(8, true, 1, NodeState.Flagged),
                new(9, false, 2, NodeState.Revealed),
                new(10, false, 3, NodeState.Revealed),
                new(11, false, 3, NodeState.Revealed),
                new(12, true, 2, NodeState.Hidden),
                new(13, false, 1, NodeState.Hidden),
                new(14, false, 1, NodeState.Revealed),
                new(15, true, 0, NodeState.Hidden),

                new(16, false, 2, NodeState.Revealed),
                new(17, true, 1, NodeState.Flagged),
                new(18, false, 2, NodeState.Revealed),
                new(19, true, 2, NodeState.Flagged),
                new(20, false, 3, NodeState.Hidden),
                new(21, false, 2, NodeState.Revealed),
                new(22, false, 1, NodeState.Revealed),
                new(23, false, 1, NodeState.Revealed),

                new(24, false, 1, NodeState.Revealed),
                new(25, false, 1, NodeState.Revealed),
                new(26, false, 3, NodeState.Revealed),
                new(27, false, 3, NodeState.Revealed),
                new(28, true, 2, NodeState.Hidden),
                new(29, false, 1, NodeState.Hidden),
                new(30, false, 0, NodeState.Hidden),
                new(31, false, 0, NodeState.Hidden),

                new(32, false, 0, NodeState.Revealed),
                new(33, false, 0, NodeState.Revealed),
                new(34, false, 1, NodeState.Revealed),
                new(35, true, 1, NodeState.Flagged),
                new(36, false, 2, NodeState.Revealed),
                new(37, false, 1, NodeState.Hidden),
                new(38, false, 0, NodeState.Hidden),
                new(39, false, 0, NodeState.Hidden),

                new(40, false, 0, NodeState.Revealed),
                new(41, false, 0, NodeState.Revealed),
                new(42, false, 1, NodeState.Revealed),
                new(43, false, 1, NodeState.Revealed),
                new(44, false, 2, NodeState.Revealed),
                new(45, false, 2, NodeState.Revealed),
                new(46, false, 2, NodeState.Hidden),
                new(47, false, 1, NodeState.Hidden),

                new(48, false, 0, NodeState.Revealed),
                new(49, false, 0, NodeState.Revealed),
                new(50, false, 0, NodeState.Revealed),
                new(51, false, 0, NodeState.Revealed),
                new(52, false, 1, NodeState.Revealed),
                new(53, true, 1, NodeState.Hidden),
                new(54, true, 1, NodeState.Hidden),
                new(55, false, 1, NodeState.Hidden),

                new(56, false, 0, NodeState.Revealed),
                new(57, false, 0, NodeState.Revealed),
                new(58, false, 0, NodeState.Revealed),
                new(59, false, 0, NodeState.Revealed),
                new(60, false, 1, NodeState.Revealed),
                new(61, false, 2, NodeState.Hidden),
                new(62, false, 2, NodeState.Hidden),
                new(63, false, 1, NodeState.Hidden)
            };

            var buffs = new BufferKeeper
            {
                Turns          = stackalloc Turn[nodeCount],
                EdgeIndexes    = stackalloc int[Engine.MaxNodeEdges],
                Mines          = stackalloc int[mineCount],
                VisitedIndexes = stackalloc int[nodeCount - mineCount],
                RevealedMineCountNodeIndexes = stackalloc int[nodeCount - mineCount],
                AdjacentHiddenNodeIndexes    = stackalloc int[nodeCount],
                Grid = stackalloc float[nodeCount * nodeCount]
            };

            var matrix    = new Matrix <Node>(nodes, 8);
            var turnCount = MatrixSolver.CalculateTurns(matrix, buffs, false);

            Assert.Equal(2, turnCount);

            // changing float to sbyte will cause our solver to generate incorrect turns
            Assert.NotEqual(6, turnCount);

            Assert.Equal(new Turn(29, NodeOperation.Reveal), buffs.Turns[0]);
            Assert.Equal(new Turn(61, NodeOperation.Reveal), buffs.Turns[1]);
        }
Пример #26
0
        static void Main(string[] args)
        {
            int    choose;
            double a = 0;
            double b = 0;
            double c = 0;

            string pathFile = ConfigurationManager.AppSettings["log"];

            StreamWriter writer = new StreamWriter(pathFile, true);


            while (true)
            {
                Console.WriteLine(" Выберите действие");
                Console.WriteLine("0. Линейное уравнение");
                Console.WriteLine("1. Квадратное уравнение");
                Console.WriteLine("2. Перемножить матрицу (данные из файла)");
                Console.WriteLine("3. Выход");


                while (true)
                {
                    if (Int32.TryParse(Console.ReadLine(), out choose))
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Введите пожалуйста цифру из предложенных");
                    }
                }


                switch (choose)
                {
                case 0:
                    Console.WriteLine("Ax + B = 0");
                    Console.WriteLine("Введите коэффиценты А и В");

                    while (true)
                    {
                        Console.WriteLine("Введите A");

                        if (Double.TryParse(Console.ReadLine(), out a))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Введите пожалуйста цифру");
                            writer.WriteLine($"Линейное уравнение (ВВОД НЕКОРРЕКТНЫХ ДАННЫХ : А={a} ");
                        }
                    }

                    while (true)
                    {
                        Console.WriteLine("Введите B");

                        if (Double.TryParse(Console.ReadLine(), out b))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Введите пожалуйста цифру");
                            writer.WriteLine($"Линейное уравнение (ВВОД НЕКОРРЕКТНЫХ ДАННЫХ : B={b} ");
                        }
                    }


                    LinearSolver linearEquation = new LinearSolver(a, b);
                    Console.WriteLine("Корень уравнения: " + linearEquation.solve());


                    writer.WriteLine($"Линейное уравнение : {a}x+{b} = 0" + "\tКорень уравнения : " + linearEquation.solve());


                    Console.ReadLine();
                    break;

                case 1:

                    Console.WriteLine("Ax^2 + Bx + C = 0");
                    Console.WriteLine("Введите коэффиценты А,B и С");

                    while (true)
                    {
                        Console.WriteLine("Введите A");

                        if (Double.TryParse(Console.ReadLine(), out a))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Введите пожалуйста цифру");
                            writer.WriteLine($"Квадратное уравнение (ВВОД НЕКОРРЕКТНЫХ ДАННЫХ : А={a} ");
                        }
                    }

                    while (true)
                    {
                        Console.WriteLine("Введите B");

                        if (Double.TryParse(Console.ReadLine(), out b))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Введите пожалуйста цифру");
                            writer.WriteLine($"Квадратное уравнение (ВВОД НЕКОРРЕКТНЫХ ДАННЫХ : B={b} ");
                        }
                    }

                    while (true)
                    {
                        Console.WriteLine("Введите C");

                        if (Double.TryParse(Console.ReadLine(), out c))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Введите пожалуйста цифру");
                            writer.WriteLine($"Квадратное уравнение (ВВОД НЕКОРРЕКТНЫХ ДАННЫХ : C={c} ");
                        }
                    }



                    QuadraticSolver quadriticEquation = new QuadraticSolver(a, b, c);
                    double[]        result            = quadriticEquation.solve();
                    Console.WriteLine($" Корни уравнения :  x1= {result[1]}  x2= {result[2]}");
                    writer.WriteLine($"Квадратное уравнение : {a}x^2 + {b}x + c = 0 " + $" Корни уравнения :  x1= {result[1]}  x2= {result[2]}");



                    Console.ReadLine();
                    break;



                case 2:

                    string matrix1 = ConfigurationManager.AppSettings["matrix1"];
                    string matrix2 = ConfigurationManager.AppSettings["matrix2"];


                    double[,] A = MatrixSolver.readMatrix(matrix1);
                    double[,] B = MatrixSolver.readMatrix(matrix1);



                    Console.WriteLine();
                    Console.WriteLine("Матрицв А");
                    MatrixSolver.printMatrix(A);
                    Console.WriteLine();
                    Console.WriteLine("Матрицв B");
                    MatrixSolver.printMatrix(B);
                    Console.WriteLine();

                    double[,] answer = MatrixSolver.Multuply(A, B);

                    if (answer == null)
                    {
                        Console.WriteLine("Перемножение невозможно");
                    }
                    else
                    {
                        Console.WriteLine("Результат");
                        MatrixSolver.printMatrix(answer);
                    }


                    Console.ReadKey();

                    break;


                case 3:
                    writer.Close();
                    Environment.Exit(0);
                    break;
                }
            }
        }
Пример #27
0
 private static void InitializeMatrixSolver(double[] lengths)
 {
     MatrixSolver.lengths = lengths;
     MatrixSolver.SetRadius();
     MatrixSolver.runFastFlag = _runFast;
 }
Пример #28
0
        public void CalculatesTurnsForVectorSumEqualsAugmentColumnPriorToGaussianElimination()
        {
            const int nodeCount = 64;
            const int mineCount = 4;

            Span <Node> nodes = stackalloc Node[]
            {
                new(0, false, 0, NodeState.Revealed),
                new(1, false, 0, NodeState.Revealed),
                new(2, false, 0, NodeState.Revealed),
                new(3, false, 0, NodeState.Revealed),
                new(4, false, 1, NodeState.Revealed),
                new(5, false, 0, NodeState.Hidden),
                new(6, false, 1, NodeState.Revealed),
                new(7, false, 0, NodeState.Revealed),

                new(8, false, 1, NodeState.Revealed),
                new(9, false, 1, NodeState.Revealed),
                new(10, false, 2, NodeState.Revealed),
                new(11, false, 1, NodeState.Revealed),
                new(12, false, 2, NodeState.Revealed),
                new(13, false, 0, NodeState.Hidden),
                new(14, false, 1, NodeState.Revealed),
                new(15, false, 0, NodeState.Revealed),

                new(16, false, 1, NodeState.Revealed),
                new(17, true, 0, NodeState.Flagged),
                new(18, false, 2, NodeState.Revealed),
                new(19, true, 0, NodeState.Flagged),
                new(20, false, 2, NodeState.Revealed),
                new(21, false, 1, NodeState.Revealed),
                new(22, false, 1, NodeState.Revealed),
                new(23, false, 0, NodeState.Revealed),

                new(24, false, 2, NodeState.Revealed),
                new(25, false, 2, NodeState.Revealed),
                new(26, false, 3, NodeState.Revealed),
                new(27, false, 1, NodeState.Revealed),
                new(28, false, 2, NodeState.Revealed),
                new(29, false, 0, NodeState.Hidden),
                new(30, false, 1, NodeState.Revealed),
                new(31, false, 0, NodeState.Revealed),

                new(32, false, 2, NodeState.Revealed),
                new(33, true, 0, NodeState.Flagged),
                new(34, false, 2, NodeState.Revealed),
                new(35, false, 0, NodeState.Revealed),
                new(36, false, 1, NodeState.Revealed),
                new(37, false, 0, NodeState.Hidden),
                new(38, false, 3, NodeState.Revealed),
                new(39, false, 2, NodeState.Revealed),

                new(40, false, 3, NodeState.Revealed),
                new(41, true, 0, NodeState.Flagged),
                new(42, false, 3, NodeState.Revealed),
                new(43, false, 1, NodeState.Revealed),
                new(44, false, 1, NodeState.Revealed),
                new(45, false, 2, NodeState.Revealed),
                new(46, false, 0, NodeState.Hidden),
                new(47, false, 0, NodeState.Hidden),

                new(48, false, 0, NodeState.Hidden),
                new(49, false, 0, NodeState.Hidden),
                new(50, false, 0, NodeState.Hidden),
                new(51, false, 0, NodeState.Hidden),
                new(52, false, 0, NodeState.Hidden),
                new(53, false, 0, NodeState.Hidden),
                new(54, false, 0, NodeState.Hidden),
                new(55, false, 0, NodeState.Hidden),

                new(56, false, 0, NodeState.Hidden),
                new(57, false, 0, NodeState.Hidden),
                new(58, false, 0, NodeState.Hidden),
                new(59, false, 0, NodeState.Hidden),
                new(60, false, 0, NodeState.Hidden),
                new(61, false, 0, NodeState.Hidden),
                new(62, false, 0, NodeState.Hidden),
                new(63, false, 0, NodeState.Hidden)
            };

            var buffs = new BufferKeeper
            {
                Turns          = stackalloc Turn[nodeCount],
                EdgeIndexes    = stackalloc int[Engine.MaxNodeEdges],
                Mines          = stackalloc int[mineCount],
                VisitedIndexes = stackalloc int[nodeCount - mineCount],
                RevealedMineCountNodeIndexes = stackalloc int[nodeCount - mineCount],
                AdjacentHiddenNodeIndexes    = stackalloc int[nodeCount],
                Grid = stackalloc float[nodeCount * nodeCount]
            };
            var matrix = new Matrix <Node>(nodes, 8);

            var turnCount = MatrixSolver.CalculateTurns(matrix, buffs, false);

            Assert.Equal(2, turnCount);
            Assert.Equal(new Turn(46, NodeOperation.Flag), buffs.Turns[0]);
            Assert.Equal(new Turn(47, NodeOperation.Flag), buffs.Turns[1]);
        }
Пример #29
0
        static void Main(string[] args)
        {
            var options = new ChromeOptions();

            //options.AddArgument("-headless");
            using var driver = new ChromeDriver(options);

            // some key aspects have been omitted from this bot
            // also, performance is purposefully degraded
            driver.Navigate().GoToUrl("");

            var squares = driver
                          .FindElementById("game")
                          .FindElements(By.ClassName("square"))
                          .Where(x => x.Displayed)
                          .ToList();

            Debug.Assert(squares.Count == nodeCount);

            LeftClickNode(squares, 93);

            var buffs = new BufferKeeper
            {
                Turns          = stackalloc Turn[nodeCount],
                EdgeIndexes    = stackalloc int[Engine.MaxNodeEdges],
                Mines          = stackalloc int[mineCount],
                VisitedIndexes = stackalloc int[nodeCount - mineCount],
                RevealedMineCountNodeIndexes = stackalloc int[nodeCount - mineCount],
                AdjacentHiddenNodeIndexes    = stackalloc int[nodeCount],
                Grid = stackalloc float[nodeCount * nodeCount]
            };

            while (IsGamePending(driver))
            {
                var nodes = squares
                            .Select(x => x.GetAttribute("class"))
                            .Select((x, i) => new Node(i, false, GetMineCount(x), GetNodeState(x)))
                            .ToArray()
                            .AsSpan();

                var matrix    = new Matrix <Node>(nodes, columns);
                var turnCount = MatrixSolver.CalculateTurns(matrix, buffs, true);

                if (turnCount == 0)
                {
                    break;
                }

                // ignore the other turns for now
                var turn = buffs.Turns[0];

                if (turn.Operation == NodeOperation.Reveal)
                {
                    LeftClickNode(squares, turn.NodeIndex);
                }
                else
                {
                    RightClickNode(squares, turn.NodeIndex, driver);
                }

                Console.WriteLine(turn);
            }

            Console.WriteLine("finished");
            Console.ReadLine();
        }