public const double MULTIPLE = 1000.0; // it has to be power of ten public static bool TryParse(string s, out ProtocolDouble result) { bool success = int.TryParse(s, out int v); result = new ProtocolDouble(v / MULTIPLE); return(success); }
/// <summary> /// Try to convert every element at position defined in positions array to ProtocolDouble. If one of them cannot be converted return false. Otherwise it return true and in param is every element converted. /// </summary> /// <param name="positions"></param> /// <param name="sources"></param> /// <param name="param"></param> /// <returns></returns> public static bool TryParse(int[] positions, string[] sources, out ProtocolDouble[] param) { param = new ProtocolDouble[positions.Length]; for (int i = 0; i < positions.Length; i++) { if (!ProtocolDouble.TryParse(sources[positions[i]], out param[i])) { return(false); } } return(true); }
public override bool IsDeserializeable(string s) { string[] rest; if (ProtocolV1_0Utils.GetParams(s, NAME, out rest)) { ProtocolDouble angle, range; if (ProtocolDouble.TryParse(rest[0], out range) && ProtocolDouble.TryParse(rest[1], out angle)) { cache.Cached(s, new ShootCommandV10(range, angle)); return(true); } } return(false); }
/// <summary> /// Try to convert every element in source to ProtocolDouble. If one of them cannot be converted return false. Otherwise it return true and in param is every element converted. /// </summary> /// <param name="sources"></param> /// <param name="param"></param> /// <returns></returns> public static bool TryParse(ICollection <string> sources, out ProtocolDouble[] param) { param = new ProtocolDouble[sources.Count]; int i = 0; foreach (var source in sources) { if (!ProtocolDouble.TryParse(source, out param[i++])) { return(false); } } return(true); }
public override bool IsDeserializeable(string s) { s = s.Trim(); if (s.StartsWith(NAME + "(") && s.EndsWith(")")) { var rest = s.Substring(NAME.Length + 1, s.Length - 2 - NAME.Length).Trim().Split(';'); ProtocolDouble range; int enemyId; if (ProtocolDouble.TryParse(rest[0], out range) && int.TryParse(rest[1], out enemyId)) { cache.Cached(s, new ScanAnswerCommandV1_0(range, enemyId)); return(true); } } return(false); }
public bool Deserialize(string s, object[] commandsMore) { string[] basesString; if (ProtocolV1_0Utils.Deserialize(s, out basesString, ProtocolV1_0Utils.DEFAULT.NEXT.NEXT)) { List <Base> bases = new List <Base>(); foreach (var baseString in basesString) // parametrs are separated by DEFAULT.NEXT.NEXT.NEXT { string[] baseParam; if (ProtocolV1_0Utils.GetParams(baseString, COMMAND_BASE_NAME, ProtocolV1_0Utils.DEFAULT.NEXT.NEXT.NEXT, out baseParam)) { if (baseParam.Length == 6) { ProtocolDouble x, y; int maxProgress, teamId, progress, progressTeamId; if (ProtocolDouble.TryParse(baseParam[0], out x) && ProtocolDouble.TryParse(baseParam[1], out y) && int.TryParse(baseParam[2], out maxProgress) && int.TryParse(baseParam[3], out progress) && int.TryParse(baseParam[4], out teamId) && int.TryParse(baseParam[5], out progressTeamId)) { Base @base = new Base(x, y, maxProgress); @base.Progress = progress; @base.TeamId = teamId; @base.ProgressTeamId = progressTeamId; bases.Add(@base); } } } } commandsMore[POSITION_IN_ROBOT_STATE_COMMAND] = bases.ToArray(); } return(false); }
public ShotCommand(ProtocolDouble angle, ProtocolDouble range) : base() { ANGLE = angle; RANGE = range; }
public static DriveCommand GetInstance(ProtocolDouble speed, ProtocolDouble angle) { return(new DriveCommand(speed, angle)); }
public ProtocolDouble(ProtocolDouble d) { value = d.value; }
public ShotCommandV1_0(ProtocolDouble angle, ProtocolDouble range) : base(angle, range) { }