Esempio n. 1
0
        /// <summary>
        /// Updates the statistics.
        /// </summary>
        /// <param name="result">The result.</param>
        private void UpdateStatistics(BattingResult result)
        {
            switch (result)
            {
            case BattingResult.Walk:
                this.PitcherStatistics.Walks++;
                break;

            case BattingResult.Strikeout:
                this.PitcherStatistics.Strikeouts++;
                break;

            case BattingResult.Single:
            case BattingResult.Double:
            case BattingResult.Triple:
            case BattingResult.Homerun:
                this.PitcherStatistics.Hits++;
                break;
                ////case BattingResult.FlyOut:
                ////case BattingResult.GroundOut:
                ////case BattingResult.LineOut:
                ////case BattingResult.PopOut:
                ////    this.PitcherStatistics.TotalOuts++;
                ////    break;
            }
        }
Esempio n. 2
0
    IEnumerator Throw()
    {
        while (true)
        {
            battingResult = BattingResult.WAIT;
            yield return(new WaitForSeconds(3f));

            pitcher.SendMessage("Throw");
            yield return(new WaitForSeconds(3f));
        }
    }
Esempio n. 3
0
    IEnumerator GameResult()
    {
        if (highScore < point)
        {
            highScore = point;
            PlayerPrefs.SetInt("HighScore", highScore);
        }
        yield return(new WaitForSeconds(1));

        battingResult = GameController.BattingResult.CHANGE;
    }
Esempio n. 4
0
 public PlayerObject(GameScene owner, Color defaultColor, Rectangle rectData, string drawKeyword)
 {
     this.owner = owner;
     this.textureList = new Dictionary<string, Texture2D>();
     this.color = defaultColor;
     this.rectData = rectData;
     this.drawKeyword = drawKeyword;
     this.playerLife = 3;
     this.strikeCount = 0;
     this.stageSelectUfoKey = 0;
     this.nowBateerState = PlayerActionState.Stand;
     this.battingHitTime = 0;
     this.stageUfoCount = 100;
     this.nowBattingResult = BattingResult.NoSwing;
     this.targetPos = new Vector2(10, 560);
 }
Esempio n. 5
0
        /// <summary>
        /// Handles the base runners.
        /// </summary>
        /// <param name="result">The result.</param>
        /// <param name="batter">The batter.</param>
        private void HandleBaseRunners(BattingResult result, Player batter)
        {
            switch (result)
            {
            case BattingResult.Walk:
                this.HandleWalk(batter);
                break;

            case BattingResult.Single:
                this.HandleSingle(batter);
                break;

            case BattingResult.Double:
                this.HandleDouble(batter);
                break;

            case BattingResult.Triple:
                this.HandleTriple(batter);
                break;

            case BattingResult.Homerun:
                this.HandleHomerun();
                break;

            case BattingResult.GroundOut:
                this.HandleGroundOut();
                break;

            case BattingResult.PopOut:
            case BattingResult.LineOut:
            case BattingResult.FlyOut:
            case BattingResult.Strikeout:
            case BattingResult.Out:
                this.AddOuts(1);
                break;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Updates the batter statistics.
        /// </summary>
        /// <param name="batter">The batter.</param>
        /// <param name="result">The result.</param>
        private void UpdateBatterStatistics(Player batter, BattingResult result)
        {
            Int32 index = Game.HomeTeam;

            if (this.scoreboard.HalfInning == HalfInningEnum.Top)
            {
                index = Game.VisitorTeam;
            }

            Player stats;

            if (this.gameResults.PlayerStatsDictionary[index].TryGetValue(batter.Identifier, out stats) == false)
            {
                stats            = new Player();
                stats.Identifier = batter.Identifier;
                stats.FirstName  = batter.FirstName;
                stats.LastName   = batter.LastName;
                this.gameResults.PlayerStatsDictionary[index].Add(batter.Identifier, stats);
            }

            switch (result)
            {
            case BattingResult.Walk:
                stats.BattingStats.Walks++;
                break;

            case BattingResult.Strikeout:
                stats.BattingStats.AtBats++;
                stats.BattingStats.Strikeouts++;
                break;

            case BattingResult.Single:
                stats.BattingStats.AtBats++;
                stats.BattingStats.Hits++;
                break;

            case BattingResult.Double:
                stats.BattingStats.AtBats++;
                stats.BattingStats.Hits++;
                stats.BattingStats.Doubles++;
                break;

            case BattingResult.Triple:
                stats.BattingStats.AtBats++;
                stats.BattingStats.Hits++;
                stats.BattingStats.Triples++;
                break;

            case BattingResult.Homerun:
                stats.BattingStats.AtBats++;
                stats.BattingStats.Hits++;
                stats.BattingStats.Homeruns++;
                break;

            case BattingResult.FlyOut:
            case BattingResult.GroundOut:
            case BattingResult.LineOut:
            case BattingResult.PopOut:
                stats.BattingStats.AtBats++;
                break;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the batting result.
        /// </summary>
        /// <param name="batter">The batter.</param>
        /// <param name="pitcher">The pitcher.</param>
        /// <returns>
        /// The result.
        /// </returns>
        private BattingResult GetBattingResult(Player batter, Player pitcher)
        {
            var result = new BattingResult();

            Boolean isStarter = true;

            if (this.scoreboard.HalfInning == HalfInningEnum.Top)
            {
                if (this.gameResults.Pitchers[Game.HomeTeam].Count > 1)
                {
                    isStarter = false;
                }
            }
            else
            {
                if (this.gameResults.Pitchers[Game.VisitorTeam].Count > 1)
                {
                    isStarter = false;
                }
            }

            // Calculate pitcher's fatigue adjustment
            var pitchCount         = Utilities.GetPitchCount(this.PitcherStatistics);
            var expectedPitchCount = Utilities.CalculateExpectedPitchCount(this.Pitcher.PitchingStats, isStarter);

            var fatigueFactor     = (Double)((Double)pitchCount / (Double)expectedPitchCount);
            var fatigueAdjustment = (Double)((0.175 * fatigueFactor) - 0.0965);

            var overallAdjustment = 1 + fatigueAdjustment;

            var dictionary = new System.Collections.Generic.Dictionary <BattingResult, Double>();

            Int32 plateAppearances = batter.BattingStats.AtBats + batter.BattingStats.Walks;

            // Walks
            Double pitcherPercent = (Double)pitcher.PitchingStats.Walks / (Double)pitcher.PitchingStats.BattersFaced;
            Double batterPercent  = (Double)batter.BattingStats.Walks / (Double)plateAppearances;
            Double percent        = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Walks);

            dictionary.Add(BattingResult.Walk, percent);
            Double baseline = percent;

            // Singles
            pitcherPercent = (Double)pitcher.PitchingStats.Singles / (Double)pitcher.PitchingStats.BattersFaced;
            Int32 singles = batter.BattingStats.Hits - (batter.BattingStats.Doubles + batter.BattingStats.Triples + batter.BattingStats.Homeruns);

            batterPercent = (Double)singles / (Double)plateAppearances;
            percent       = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Singles) + baseline;
            percent      *= (1 - this.parameters.LeagueAverages.Singles) * (1 - overallAdjustment);
            dictionary.Add(BattingResult.Single, percent);
            baseline = percent;

            // Doubles
            pitcherPercent = (Double)pitcher.PitchingStats.Doubles / (Double)pitcher.PitchingStats.BattersFaced;
            batterPercent  = (Double)batter.BattingStats.Doubles / (Double)plateAppearances;
            percent        = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Doubles) + baseline;
            percent       *= (1 - this.parameters.LeagueAverages.Doubles) * (1 - overallAdjustment);
            dictionary.Add(BattingResult.Double, percent);
            baseline = percent;

            // Triples
            pitcherPercent = (Double)pitcher.PitchingStats.Triples / (Double)pitcher.PitchingStats.BattersFaced;
            batterPercent  = (Double)batter.BattingStats.Triples / (Double)plateAppearances;
            percent        = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Triples) + baseline;
            percent       *= (1 - this.parameters.LeagueAverages.Triples) * (1 - overallAdjustment);
            dictionary.Add(BattingResult.Triple, percent);
            baseline = percent;

            // Homeruns
            pitcherPercent = (Double)pitcher.PitchingStats.Homeruns / (Double)pitcher.PitchingStats.BattersFaced;
            batterPercent  = (Double)batter.BattingStats.Homeruns / (Double)plateAppearances;
            percent        = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Homeruns) + baseline;
            percent       *= (1 - this.parameters.LeagueAverages.Homeruns) * (1 - overallAdjustment);
            dictionary.Add(BattingResult.Homerun, percent);
            baseline = percent;

            // Strikeouts
            pitcherPercent = (Double)pitcher.PitchingStats.Strikeouts / (Double)pitcher.PitchingStats.BattersFaced;
            batterPercent  = (Double)batter.BattingStats.Strikeouts / (Double)plateAppearances;
            percent        = this.CalculateLog5(batterPercent, pitcherPercent, this.parameters.LeagueAverages.Strikeouts) + baseline;
            dictionary.Add(BattingResult.Strikeout, percent);
            baseline = percent;

            // Get a random number
            Double randomeValue = this.random.NextDouble();

            result = BattingResult.Out;
            foreach (var key in dictionary.Keys)
            {
                percent = dictionary[key];
                if (randomeValue < percent)
                {
                    result = key;
                    break;
                }
            }

            if (result == BattingResult.Out)
            {
                randomeValue = this.random.NextDouble();
                if (randomeValue < 0.55)
                {
                    result = BattingResult.GroundOut;
                }
                else if (randomeValue < 0.6)
                {
                    result = BattingResult.LineOut;
                }
                else if (randomeValue < 0.75)
                {
                    result = BattingResult.PopOut;
                }
                else
                {
                    result = BattingResult.FlyOut;
                }

                // Handle errors
                randomeValue = this.random.NextDouble();
                if (randomeValue >= 0.90)
                {
                    if (result == BattingResult.FlyOut)
                    {
                        randomeValue = this.random.NextDouble();
                        if (randomeValue <= 0.5)
                        {
                            result = BattingResult.Double;
                        }
                        else if (randomeValue <= 0.9)
                        {
                            result = BattingResult.Triple;
                        }
                        else
                        {
                            result = BattingResult.Homerun;
                        }
                    }
                    else
                    {
                        result = BattingResult.Single;
                    }
                }
            }

            return(result);
        }
Esempio n. 8
0
 public void damageUfo(int getStageUfoKey, int ufoTargetNumber, int ufoPartsNumber, bool extraFlg, BattingResult battingResult)
 {
 }
Esempio n. 9
0
 private void buttingSwing()
 {
     if (this.nowGameState == GameMainState.BallAction && this.nowBateerState == PlayerActionState.Swing)
     {
         this.battingHitTime++;
         if (this.battingHitTime >= 15)
         {
             this.nowBateerState = PlayerActionState.SwingResult;
             this.battingHitTime = 0;
             this.strikeCheck();
             this.nowBattingResult = BattingResult.NoSwing;
         }
     }
 }