Exemple #1
0
        public void AtBatIN(Player[] players, Pitcher pitcher)
        {
            Random rand = new Random();

            //print lineup
            printLineUp(players);

            //throw pitches until a hit happens
            while (Outs < 3)
            {
                //print scoreboard information
                PrintOutPut($"Score: {Score}\nOuts: {Outs}\nBalls: {Balls} Strikes: {Strikes}\n{WhoIsOn()}\nBatter: {players[Index].ToString()}");

                //get a random number representing pitch power
                //use the getChances method to return the chances for a strike and a ball based on the pitch power
                double ballChance;
                double strikeChance;
                var    pitch = pitcher.Pitch(rand);
                getChances(pitch, out ballChance, out strikeChance);

                WriteLine($"Pitch Power = {pitch}\nChance for ball = {ballChance:P}\nChance for Strike = {strikeChance:P}");


                //user interaction
                Write("Swing? (1 = yes/2 = no)");
                var swing = char.Parse(ReadLine());

                //if the user decided to swing
                if (swing == '1')
                {
                    //result of the swing represented by an int variable that will be passed into the swingOutcome Method to determine which actions should execute based on the result
                    var outcome = players[Index].swing(pitch, rand);
                    SwingOutcome(outcome);
                }
                //the user did not decide to swing
                else
                {
                    //check if the pitch was a ball or a strike
                    //might need to look at this logic in more depth soon
                    if (rand.Next(1, pitch) <= 15)
                    {
                        PrintOutPut("Ball");
                        Balls++;
                    }
                    else
                    {
                        PrintOutPut("Strike");
                        Strikes++;
                    }
                }
            }
            PrintOutPut("Inning over");
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Write("Play or Sim? (p for play and s for sim): ");
            var tempChar = char.Parse(ReadLine());

            if (tempChar == 's')
            {
                Write("How many innings? ");
                var tempInt = int.Parse(ReadLine());
                RunSim(tempInt);
            }
            Player[] playerArr = new Player[9];
            for (int i = 0; i < playerArr.Length; ++i)
            {
                playerArr[i] = new Player(i);
            }
            Pitcher pitcher = new Pitcher();
            AtBat   atbat   = new AtBat();

            atbat.AtBatIN(shuffleArray(playerArr), pitcher);
            Read();
        }
Exemple #3
0
        private static void RunSim(int iterations)
        {
            int totalRuns = 0;

            //add more data here

            Player[] playerArr = new Player[9];
            for (int i = 0; i < playerArr.Length; ++i)
            {
                playerArr[i] = new Player(i);
            }
            Pitcher pitcher = new Pitcher();

            for (int i = 0; i < iterations; ++i)
            {
                AtBat atbat = new AtBat();
                atbat.atBatSim(shuffleArray(playerArr), pitcher);
                //get values from the at bat object and add them to running totals
                totalRuns += atbat.Score;
            }
            WriteLine("Total number of runs scored in {0} innings is {1}", iterations, totalRuns);
            Read();
        }
Exemple #4
0
        public void atBatSim(Player[] players, Pitcher pitcher)
        {
            Random rand = new Random();

            while (Outs < 3)
            {
                double ballChance;
                double strikeChance;
                var    pitch = pitcher.Pitch(rand);
                getChances(pitch, out ballChance, out strikeChance);

                //logic for if to swing or not here
                bool swing = strikeChance >= ballChance ? true : false;

                if (swing)
                {
                    //result of the swing represented by an int variable that will be passed into the swingOutcome Method to determine which actions should execute based on the result
                    var outcome = players[Index].swing(pitch, rand);
                    SwingOutcomeSim(outcome);
                }
                //the user did not decide to swing
                else
                {
                    //check if the pitch was a ball or a strike
                    //might need to look at this logic in more depth soon
                    if (rand.Next(1, pitch) <= 15)
                    {
                        Balls++;
                    }
                    else
                    {
                        Strikes++;
                    }
                }
            }
        }