Exemple #1
0
        private static ProportionValue <string> checkIfFielded(double odds)
        {
            setHasItOrNotOdds(odds);

            ProportionValue <string> hasIt        = ProportionValue.Create(hasItOdds, null, "The fielder fielded the ball ", "hasIt");
            ProportionValue <string> doesntHaveIt = ProportionValue.Create(doesntHaveItOdds, null, "The fielder doesn't have the ball yet", "notYet");

            ProportionValue <string>[] hasItOrNot = new[] {
                hasIt,
                doesntHaveIt
            };

            checkIt = hasItOrNot.ChooseByRandom();

            if (checkIt.InsertValue == "hasIt")
            {
                return(hasIt);
            }

            if (checkIt.InsertValue == "notYet")
            {
                return(doesntHaveIt);
            }

            return(null);
        }
Exemple #2
0
        private static void runInfieldProgression(Fielder fielder)
        {
            frmBaseballSimulator.updateLblTest("infield");
            advanceRunners();

            ProportionValue <string> checkIT = checkIfFielded(1);

            if (checkIT.InsertValue == "hasIt")
            {
                frmBaseballSimulator.addToLblTest(" has it");
                infieldChallengeRunner(fielder);
            }
            else if (checkIT.InsertValue == "notYet")
            {
                frmBaseballSimulator.addToLblTest(" not yet");
                if (onBaseList.Count > 0)
                {
                    setRunnersNewBase();
                }

                Lists.playDescription = "";
                Lists.playDescription = "Error!";
                frmBaseballSimulator.addPlayDescription();

                frmBaseballSimulator.startAdvanceHalfTimer(1, true, 100);
            }
        }
Exemple #3
0
 private static void chooseInfielder(ProportionValue <string> fielderProp)
 {
     if (fielderProp.Value == "first baseman ")
     {
         inFielder = firstBaseman;
     }
     else if (fielderProp.Value == "second baseman ")
     {
         inFielder = secondBaseman;
     }
     else if (fielderProp.Value == "third baseman ")
     {
         inFielder = thirdBaseman;
     }
     else if (fielderProp.Value == "catcher ")
     {
         inFielder = catcher;
     }
     else if (fielderProp.Value == "short stop ")
     {
         inFielder = shortStop;
     }
     else if (fielderProp.Value == "pitcher ")
     {
         inFielder = pitcher;
     }
 }
Exemple #4
0
        private static ProportionValue <string> allChooseToRun()
        {
            ProportionValue <string> runOrNotRun = runnerDecision.ChooseByRandom();

            if (runOrNotRun == run)
            {
                return(run);
            }
            else
            {
                return(notRun);
            }
        }
Exemple #5
0
 private static void ChooseOutFielder(ProportionValue <string> fielderProp)
 {
     if (fielderProp.Value == "center fielder ")
     {
         outFielder = centerFielder;
     }
     else if (fielderProp.Value == "left fielder ")
     {
         outFielder = leftFielder;
     }
     else if (fielderProp.Value == "right fielder ")
     {
         outFielder = rightFielder;
     }
 }
Exemple #6
0
        public static void runPlay()
        {
            ProportionValue <string> fieldedBy   = infieldOrOutfield.ChooseByRandom();
            ProportionValue <string> caughtOrNot = caughtOrNotCaught.ChooseByRandom();

            chooseInfielder(infieldList.ChooseByRandom());

            ChooseOutFielder(outfieldList.ChooseByRandom());


            if (caughtOrNot.InsertValue == "caught")
            {
                advanceRunners();
                //determine the player who caught the ball
                if (fieldedBy.InsertValue == "outfield")
                {
                    Lists.playDescription  = "";
                    Lists.playDescription += "Caught by " + outFielder.Position + "\n\n";
                    frmBaseballSimulator.addPlayDescription();
                    removePlayerAfterOut(currentBatter);
                }

                if (fieldedBy.InsertValue == "infield")
                {
                    Lists.playDescription  = "";
                    Lists.playDescription += "Caught by " + inFielder.Position + "\n\n";
                    frmBaseballSimulator.addPlayDescription();
                    removePlayerAfterOut(currentBatter);
                }
                //return players to their original bases
            }

            if (caughtOrNot.InsertValue == "notCaught")
            {
                if (fieldedBy.InsertValue == "infield")
                {
                    runInfieldProgression(inFielder);
                }
                else if (fieldedBy.InsertValue == "outfield")
                {
                    advanceRunners();

                    runOutfieldProgression(outFielder);
                }
            }
        }
Exemple #7
0
        //this method runs through an outcome of lists and returns their outcomes.
        public static void DoWorkSon(ProportionValue <string> propValue)
        {
            var newPropValueList = propValue.PropValueList;

            if (newPropValueList != null)
            {
                var newDescription = propValue.Value;
                playDescription += newDescription;

                var newChosenList = newPropValueList.ChooseByRandom();
                DoWorkSon(newChosenList);

                if (propValue.InsertValue != null)
                {
                    string switchInsertValue = propValue.InsertValue;

                    //receives the inserted values that will update scoreboard information and trigger methods
                    switch (switchInsertValue)
                    {
                    case "balls":
                        Play.recordBall();
                        break;

                    case "strikes":
                        Play.recordStrike();
                        break;

                    case "fouls":
                        Play.recordFoul();
                        break;

                    case "hits":
                        frmBaseballSimulator.startRunPlayTimer();
                        break;
                    }
                }
            }
            else
            {
                var newDescription = propValue.Value;
                playDescription += newDescription;

                Console.WriteLine(playDescription);

                if (propValue.InsertValue != null)
                {
                    string switchInsertValue = propValue.InsertValue;

                    //receives the inserted values that will update scoreboard information and trigger methods
                    switch (switchInsertValue)
                    {
                    case "balls":
                        Play.recordBall();
                        break;

                    case "strikes":
                        Play.recordStrike();
                        break;

                    case "fouls":
                        Play.recordFoul();
                        break;

                    case "hits":
                        frmBaseballSimulator.startRunPlayTimer();
                        break;
                    }
                }

                if (propValue.InsertValue != "hits")
                {
                    playDescription = string.Empty;
                }
            }
        }
Exemple #8
0
        private static void runOutfieldProgression(Fielder fielder)
        {
            frmBaseballSimulator.updateLblTest("outfield");
            ProportionValue <string> checkIT = checkIfFielded(hasItOdds);

            //determine if players are running
            foreach (Player element in onBaseList)
            {
                if (element.BaseLocation < 0)
                {
                    playersRunning = true;
                    break;
                }
                else
                {
                    playersRunning = false;
                }
            }

            //this is for a home run
            if (numToAdvance == 4)
            {
                frmBaseballSimulator.addToLblTest(" home run");
                frmBaseballSimulator.startAdvanceHalfTimer(numToAdvance, false, 100);
            }
            else if (playersRunning)
            {
                frmBaseballSimulator.addToLblTest(" Players Running");

                //fielder doesn't have it
                if (checkIT.InsertValue == "notYet")
                {
                    frmBaseballSimulator.addToLblTest(" not yet");
                    numToAdvance += 1;
                    if (onBaseList.Count > 0)
                    {
                        setRunnersNewBase();
                    }


                    hasItOdds      = .5;
                    playersRunning = false;

                    runOutfieldProgression(fielder);
                }

                //player fields it
                if (checkIT.InsertValue == "hasIt")
                {
                    frmBaseballSimulator.addToLblTest(" has it");
                    outFieldChallengeRunner(fielder);
                }
            }
            else if (!playersRunning)
            {
                frmBaseballSimulator.addToLblTest(" Players Running");
                if (checkIT.InsertValue == "notYet")
                {
                    frmBaseballSimulator.addToLblTest(" not yet");

                    hasItOdds += .1;
                    advanceRunners();
                    runOutfieldProgression(fielder);
                }
                else if (checkIT.InsertValue == "hasIt")
                {
                    frmBaseballSimulator.addToLblTest(" has it");
                    addHitPlayDescription();
                    frmBaseballSimulator.startAdvanceHalfTimer(numToAdvance, false, 100);
                }
            }
        }
Exemple #9
0
        private static ProportionValue <string> chooseInfieldOrOutfield()
        {
            ProportionValue <string> infieldOutfield = infieldOrOutfield.ChooseByRandom();

            return(infieldOutfield);
        }
Exemple #10
0
        private static void outFieldChallengeRunner(Fielder fielder)
        {
            frmBaseballSimulator.addToLblTest(" outfieldchallengerunner");
            Base priority = determineBasePriority();

            ProportionValue <string> outOrSafe = outSafe.ChooseByRandom();

            if (outOrSafe.InsertValue == "out")
            {
                frmBaseballSimulator.addToLblTest(" out");
                if (priority.baseNumber == 1)
                {
                    frmBaseballSimulator.addToLblTest(" priority.baseNumber == 1");
                    addHitPlayDescription();
                    Lists.playDescription += "Out at " + priority.name + "! (" + fielder.Position + ")\n\n";

                    removePlayerAfterOut(currentBatter, false, true);
                }
                else
                {
                    frmBaseballSimulator.addToLblTest(" else");
                    addHitPlayDescription();
                    for (int i = 0; i < onBaseList.Count; i++)
                    {
                        if (-onBaseList.ElementAt(i).BaseLocation == priority.baseNumber)
                        {
                            Lists.playDescription += "Out! (" + fielder.Position + " to " + priority.name + ")\n\n";

                            removePlayerAfterOut(onBaseList.ElementAt(i), false, true);

                            playerRemoved = true;
                        }
                    }

                    if (playerRemoved == false)
                    {
                        priority.baseNumber = onBaseList.ElementAt(0).BaseLocation;

                        Lists.playDescription += "Out! (" + fielder.Position + " to " + priority.name + ")\n\n";

                        removePlayerAfterOut(onBaseList.ElementAt(0), false, true);
                    }

                    playerRemoved = false;
                }
            }
            else if (outOrSafe.InsertValue == "safe")
            {
                frmBaseballSimulator.addToLblTest(" safe");
                if (onBaseList.Count > 0)
                {
                    setRunnersNewBase();
                }
                numToAdvance  += 1;
                playersRunning = false;

                Lists.playDescription = "";
                addHitPlayDescription();
                Lists.playDescription = "Safe! (" + fielder.Position + ")";

                frmBaseballSimulator.startAdvanceHalfTimer(numToAdvance, false, 100);
            }
        }