private void PerformAction(Game game) { var random = new Random(); var isHit = random.NextDouble() > 0.51; if (isHit) { var typePos = random.Next(0, _hitTypes.Length); var startPoint = 0; if (typePos == 3) startPoint = 6; var locationPos = random.Next(startPoint, _positions.Length); game.Hit(_hitTypes[typePos], _positions[locationPos]); } else { var typePos = random.Next(0, _outTypes.Length); var startPos = 0; var endPos = _positions.Length; if (typePos == 0 || typePos == 1) { endPos = 6; } else { startPos = 6; } var locationPos = random.Next(startPos, endPos); game.Out(_outTypes[typePos], _positions[locationPos]); } }
private bool TryUpdatingGame(Game game) { var r = _updateOrNotRandom.NextDouble(); if (r > 0.1) return false; if (game.CurrentAtBat.IsComplete) { game.CurrentAtBat.Reset(); return true; } var random = new Random(); var eventValue = random.NextDouble(); if (eventValue > 0.66) game.Ball(); else if (eventValue > 0.33) game.Strike(); else PerformAction(game); return true; }
private void BroadcastGame(Game game) { //var teams = game.Identifier.Split(new string[] { "vs" }, StringSplitOptions.RemoveEmptyEntries); //foreach (var team in teams) //{ // Clients.Group(team).updateGame(game); //} Clients.All.updateGame(game); }