public IChallenge InitializeChallenge(ChallengeConfiguration configuration) { IChallenge challenge = ChallengeFactory.CreateChallenge(configuration.ChallengeGuid); if (challenge != null) { List <IRobot> robots = RobotFactory.CreateRobots(configuration.Robots); challenge.Initialize(robots, configuration.ChallengeMatDetails, configuration.IsSinglePlayer); } return(challenge); }
private static void ManageChallenge(Socket listener) { Console.WriteLine("Setting up a new Challenge..."); var config = ChallengeConfiguration.GetChallengeConfiguration(_configPath); var state = ChallengeState.GetStateFromConfiguration(config); var name = state.GetPlayerNames(); for (var i = 0; i < state.Players.Count; i++) { listener.Listen(100); var connection = listener.Accept(); var task = ManageConnection(connection, state, name[i]); } state.Flags.AddOrUpdate("Ready", true, (x, y) => true); Console.WriteLine("Begin the challenge!"); }
/// <summary> /// Processes the parameters. /// </summary> /// <exception cref="System.Exception"> /// </exception> private void ProcessParams() { try { _configurationFilePath = ""; bool pass = true; if (CommandParams == null) { pass = false; } else if (CommandParams.Length < 1) { pass = false; } if (!pass) { _errMsg = "Invalid parameters applied to this command."; throw new Exception(_errMsg); } string commandParams = ""; for (int i = 0; i < CommandParams.Length; i++) { commandParams += CommandParams[i] + " "; } string[] commandParamsArray = commandParams.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < commandParamsArray.Length; i++) { try { if (commandParamsArray[i].ToUpper().StartsWith(CONFIG_FILE_SWITCH) && commandParamsArray[i].ToString().ElementAt(1) == ' ') { _configurationFilePath = commandParamsArray[i].Remove(0, CONFIG_FILE_SWITCH.Length); FileInfo sFileInfo = new FileInfo(_configurationFilePath); if (!sFileInfo.Exists) { _errMsg = "Invalid configuration file name provided: " + _configurationFilePath; throw new Exception(_errMsg); } } if (commandParamsArray[i].ToUpper().StartsWith(INPUT_FILE_SWITCH) && commandParamsArray[i].ToString().ElementAt(1) == ' ') { _inputCommandFilePath = commandParamsArray[i].Remove(0, INPUT_FILE_SWITCH.Length); FileInfo sFileInfo = new FileInfo(_inputCommandFilePath); if (!sFileInfo.Exists) { _errMsg = "Invalid input commmands file name provided: " + _configurationFilePath; throw new Exception(_errMsg); } } } catch (Exception d) { _errMsg = "Invalid parameters provided."; throw d; } } OnReportMessageSet(this, new EventArgs.HandlerEventArgs(this, "Checking config file...", false)); _challengeConfiguration = JsonConvert.DeserializeObject <ChallengeConfiguration>(File.ReadAllText(_configurationFilePath)); if (_challengeConfiguration == null) { throw new Exception("Unable to parse the given configuration file due to an error"); } } catch (Exception ex) { throw ex; } }