コード例 #1
0
ファイル: TwoPersonZeroSumGame.cs プロジェクト: zzhi/Algs4Net
        public static void MainTest(string[] args)
        {
            TwoPersonZeroSumGame.test1();
            TwoPersonZeroSumGame.test2();
            TwoPersonZeroSumGame.test3();
            TwoPersonZeroSumGame.test4();
            TwoPersonZeroSumGame.test5();

            int M = 5, N = 5;

            if (args.Length == 3)
            {
                M = int.Parse(args[1]);
                N = int.Parse(args[2]);
            }
            double[,] payoff = new double[M, N];
            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    payoff[i, j] = StdRandom.Uniform(-0.5, 0.5);
                }
            }
            TwoPersonZeroSumGame.test("random " + M + "-by-" + N, payoff);
        }
コード例 #2
0
ファイル: TwoPersonZeroSumGame.cs プロジェクト: zzhi/Algs4Net
        internal static void test(string description, double[,] payoff)
        {
            Console.WriteLine();
            Console.WriteLine(description);
            Console.WriteLine("------------------------------------");
            int M = payoff.GetLength(0);
            int N = payoff.GetLength(1);
            TwoPersonZeroSumGame zerosum = new TwoPersonZeroSumGame(payoff);

            double[] x = zerosum.Row();
            double[] y = zerosum.Column();

            Console.Write("x[] = [");
            for (int j = 0; j < N - 1; j++)
            {
                Console.Write("{0:F4}, ", x[j]);
            }
            Console.Write("{0:F4}]\n", x[N - 1]);

            Console.Write("y[] = [");
            for (int i = 0; i < M - 1; i++)
            {
                Console.Write("{0:F4}, ", y[i]);
            }
            Console.Write("{0:F4}]\n", y[M - 1]);
            Console.WriteLine("value =  " + zerosum.Value());
        }