public override string Solve(Bomb bomb) { int number1 = 0, number2 = 0, number3 = 0; //Number 1 if (!string.IsNullOrEmpty(TwoFactor1)) { number1 += InternalFunctions.GetNumber(TwoFactor1[5].ToString()); } if (!string.IsNullOrEmpty(TwoFactor2)) { number1 += InternalFunctions.GetNumber(TwoFactor2[5].ToString()); } number1 += bomb.GetBatteries(); //Number 2 if (!string.IsNullOrEmpty(TwoFactor1)) { number2 += InternalFunctions.GetNumber(TwoFactor1[0].ToString()); } if (!string.IsNullOrEmpty(TwoFactor2)) { number2 += InternalFunctions.GetNumber(TwoFactor2[0].ToString()); } number2 += bomb.GetSolvedModules(); //Number 3 number3 += number1 + number2; Solved = true; return($"The numbers are {number1%20}, {number2 % 20}, {number3 % 20}."); }
public override string Command(Bomb bomb, string command) { var connection = new Connection(); foreach (var word in command.Split(' ')) { if (InternalFunctions.IsNumber(word)) { connection.LeftSide = word[0].ToString(); connection.RightSide = word[1].ToString(); } if (connection.IsComplete()) { Connections.Add(connection); connection = new Connection(); } } if (Connections.Count == 4) { return(Solve(bomb)); } else { return("Not enought connections."); } }
public override string Command(Bomb bomb, string command) { var row = -1; var column = -1; foreach (var word in command.Split(' ')) { if (InternalFunctions.GetLetterFromPhoneticLetter(word) != "") { column = InternalFunctions.GetNumberFromLetter(InternalFunctions.GetLetterFromPhoneticLetter(word)) - 1; } if (InternalFunctions.IsNumber(word)) { row = int.Parse(word) - 1; } if (row != -1 && column != -1) { Positions.Add(InternalFunctions.GetPhoneticLetterFromLetter(InternalFunctions.GetLetterFromNumber(column + 1)) + '-' + (row + 1)); row = -1; column = -1; } } return(Solve(bomb)); }
public override string Solve(Bomb bomb) { if (Letters.Count != 12) { return("Not enough letters."); } Solved = true; var message = "Press: "; string[,] grid = new string[3, 4]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { grid[i, j] = Letters[i * 4 + j]; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { if (PressLetter(grid, i, j)) { var letter = InternalFunctions.GetPhoneticLetterFromLetter(grid[i, j]) + ". "; message += letter.ToUpper()[0] + letter.Substring(1); } } } return(message.Trim()); }
public void DefinePosition3() { int column = InternalFunctions.GetNumberFromLetter(InternalFunctions.GetLetterFromPhoneticLetter(Positions[2].Split('-')[0])) - 1; int row = int.Parse(Positions[2].Split('-')[1]) - 1; int count = 0; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { if (Chessboard[i, j].Piece == "rook") { count++; } } } if (count < 2) { Chessboard[row, column].Piece = "queen"; } else { Chessboard[row, column].Piece = "king"; } ChangeOtherTiles(row, column, Chessboard[row, column].Piece); }
public override string Command(Bomb bomb, string command) { if (command.Contains("color")) { foreach (var word in command.Split(' ')) { if (InternalFunctions.IsColor(word)) { Colors.Add(word); } } return("Sequence saved."); } Stage++; ColorsFlashed.Clear(); foreach (var word in command.Split(' ')) { if (InternalFunctions.IsColor(word)) { ColorsFlashed.Add(word); } } return(Solve(bomb)); }
public override string Command(Bomb bomb, string command) { var color = ""; var number = ""; foreach (var word in command.Split(' ')) { if (InternalFunctions.IsNumber(word)) { number = word; } if (InternalFunctions.IsColor(word)) { color = word; } if (!string.IsNullOrWhiteSpace(number) && !string.IsNullOrWhiteSpace(word)) { Numbers.Add(color, number); color = ""; number = ""; } } if (Numbers.Count != 3) { return("Could not find enought numbers."); } return(Solve(bomb)); }
public override string Command(Bomb bomb, string command) { foreach (var word in command.Split(' ')) { if (PossibleSuspects.Keys.Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).Count() > 0) { Suspects.Add(PossibleSuspects.Keys.Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).First()); continue; } if (PossibleWeapons.Keys.Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).Count() > 0) { Weapons.Add(PossibleWeapons.Keys.Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).First()); continue; } if (PossibleSuspects["Scarlett"].Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).Count() > 0) { LocationBody = PossibleSuspects["Scarlett"].Where(x => x.StartsWith(InternalFunctions.ToPascalCase(word))).First(); continue; } } if (Suspects.Count > 0 && Weapons.Count > 0 && !string.IsNullOrEmpty(LocationBody)) { return(Solve(bomb)); } return("Not enought information."); }
public string TextToLetters(int start) { string TextToInform = ""; foreach (var word in Text.GetRange(start, Numbers.Count)) { TextToInform += word; } var result = "Order is "; List <int> indexList = new List <int>() { TextToInform.IndexOf(Letters[0]), TextToInform.IndexOf(Letters[1]), TextToInform.IndexOf(Letters[2]), TextToInform.IndexOf(Letters[3]), TextToInform.IndexOf(Letters[4]) }; indexList.Sort(); foreach (var index in indexList) { result += InternalFunctions.GetPhoneticLetterFromLetter(TextToInform[index]) + ", "; } Solved = true; return(result.Substring(0, result.Length - 2) + "."); }
public string WhatToDoWithTheButton(Bomb bomb) { if (Color == "blue" && bomb.BatteryAA > bomb.BatteryD) { return(TextPressOrHold(1)); } if (Color == "blue" || Color == "yellow" || Text.Count() >= bomb.GetBiggestSerialDigit()) { return(TextPressOrHold(2)); } if (Color == "blue" || Color == "yellow" || InternalFunctions.IsColor(Text)) { return(TextPressOrHold(1)); } if (string.IsNullOrWhiteSpace(Text)) { return(TextPressOrHold(1)); } if (Text != "dark grey" && Text.Count() > bomb.GetLitIndicators()) { return(TextPressOrHold(2)); } if (bomb.GetUnlitIndicators() <= 2 && bomb.HasSerialVowel()) { return(TextPressOrHold(2)); } return(TextPressOrHold(1)); }
/// <summary> /// Append a resource's properties to the xml text writer /// </summary> /// <param name="davResource"></param> /// <param name="xmlWriter"></param> private static void AppendResourceNodeProperties(DavResourceBase davResource, XmlTextWriter xmlWriter) { //Open the response element xmlWriter.WriteStartElement("response", "DAV:"); //Load the valid items HTTP/1.1 200 OK xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath); //Open the propstat element section xmlWriter.WriteStartElement("propstat", "DAV:"); //Open the prop element section xmlWriter.WriteStartElement("prop", "DAV:"); //Load the valid properties foreach (DavProperty _davProperty in davResource.ResourceProperties) { _davProperty.ToXML(xmlWriter); } //Close the prop element section xmlWriter.WriteEndElement(); //Write the status record xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok)); //Close the propstat element section xmlWriter.WriteEndElement(); //END Load the valid items HTTP/1.1 200 OK //Close the response element xmlWriter.WriteEndElement(); }
/// <summary> /// Append a resource to the xml text writer /// </summary> /// <param name="davResource"></param> /// <param name="requestedProperties"></param> /// <param name="xmlWriter"></param> private static void AppendResourceNode(DavResourceBase davResource, DavPropertyCollection requestedProperties, XmlTextWriter xmlWriter) { DavPropertyCollection _validProperties = new DavPropertyCollection(); DavPropertyCollection _invalidProperties = new DavPropertyCollection(); davResource.GetPropertyValues(requestedProperties, _validProperties, _invalidProperties); //Open the response element xmlWriter.WriteStartElement("response", "DAV:"); //Load the valid items HTTP/1.1 200 OK xmlWriter.WriteElementString("href", "DAV:", davResource.ResourcePath); //Open the propstat element section xmlWriter.WriteStartElement("propstat", "DAV:"); //Open the prop element section xmlWriter.WriteStartElement("prop", "DAV:"); //Load the valid properties foreach (DavProperty _davProperty in _validProperties) { _davProperty.ToXML(xmlWriter); } //Close the prop element section xmlWriter.WriteEndElement(); //Write the status record xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.Ok)); //Close the propstat element section xmlWriter.WriteEndElement(); //END Load the valid items HTTP/1.1 200 OK //Load the invalid items HTTP/1.1 404 Not Found if (_invalidProperties.Count > 0) { xmlWriter.WriteStartElement("propstat", "DAV:"); xmlWriter.WriteElementString("status", "DAV:", InternalFunctions.GetEnumHttpResponse(ServerResponseCode.NotFound)); //Open the prop element section xmlWriter.WriteStartElement("prop", "DAV:"); //Load all the invalid properties foreach (DavProperty _davProperty in _invalidProperties) { _davProperty.ToXML(xmlWriter); } //Close the prop element section xmlWriter.WriteEndElement(); //Close the propstat element section xmlWriter.WriteEndElement(); } //END Load the invalid items HTTP/1.1 404 Not Found //Close the response element xmlWriter.WriteEndElement(); }
public override string Command(Bomb bomb, string command) { if (command == "combination locks") { return(Solve(bomb)); } foreach (var word in command.Split(' ')) { if (InternalFunctions.IsNumber(word)) { if (TwoFactor1.Length < 6) { TwoFactor1 += InternalFunctions.GetNumber(word); } else { TwoFactor2 += InternalFunctions.GetNumber(word); } } } if (TwoFactor1.Length != 6 || TwoFactor2.Length != 6) { return("Could not get two factors."); } return(Solve(bomb)); }
protected override ICode VisitBox(ExprBox e) { var ctx = e.Ctx; var expr = (Expr)this.Visit(e.Expr); if (e.Type.IsUnsignedInteger() && expr.Type.IsSignedInteger()) { expr = new ExprConv(ctx, expr, e.Type, false); } if (!e.Type.IsValueType) { // For ref-types 'box' does nothing return(this.Visit(e.Expr)); } var eType = new ExprJsTypeVarName(ctx, e.Type); if (e.Type.IsNullable()) { var exprIsVar = expr.IsVar(); var innerType = e.Type.GetNullableInnerType(); var temp = exprIsVar ? null : new ExprVarLocal(ctx, e.Type); var box = new ExprBox(ctx, temp ?? expr, innerType).Named("box"); var nullableJs = exprIsVar ? "(expr !== null ? box : null)" : "((temp = expr) !== null ? box : null)"; var nullableExpr = new ExprJsExplicit(ctx, nullableJs, innerType, temp.Named("temp"), expr.Named("expr"), box); return(nullableExpr); } else { var deepCopyExpr = InternalFunctions.ValueTypeDeepCopyIfRequired(e.Type, () => (Expr)this.Visit(expr)); var int2bool = e.Type.IsBoolean() && expr.Type.IsInteger() ? "!!" : ""; var js = "{v:" + int2bool + "expr,_:type}"; var ret = new ExprJsExplicit(ctx, js, e.Type, (deepCopyExpr ?? expr).Named("expr"), eType.Named("type")); return(ret); } }
private ICode HandleCall(ICall call, Func <Expr, IEnumerable <Expr>, ICode> fnNew) { if (call.CallMethod.Name == "DeepCopyValueType") { // HACK return(call); } var obj = (Expr)this.Visit(call.Obj); var argsInfo = call.Args.Select((arg, i) => new { arg, parameterType = call.CallMethod.Parameters[i].ParameterType }).ToArray(); var args = this.HandleList(argsInfo, argInfo => { if (!argInfo.parameterType.IsValueType) { return(argInfo); } var arg = argInfo.arg; var type = arg.Type; if (type.IsNonPrimitiveValueType() && !type.IsRuntimeHandle() && !type.IsEnum()) { return(new { arg = InternalFunctions.ValueTypeDeepCopyIfRequired(arg.Type, () => arg) ?? arg, parameterType = argInfo.parameterType }); } else { return(argInfo); } }).NullThru(x => x.Select(y => y.arg).ToArray()); if (obj != call.Obj || args != null) { return(fnNew(obj, args ?? call.Args)); } else { return(call); } }
internal void Initialize(string ammeterValues) { InternalFunctions.ParseStringToIntArray(ammeterValues, ref NotchValues, "ammetervalues"); if (NotchValues.Length == 0 || NotchValues == null) { NotchValues = new int[] { 0 }; } }
public void Can_render_internal_functions(string source, string expected) { InternalFunctions.Register(); Template template = Template.Parse(source); string actual = template.Render(); Assert.Equal(expected, actual); }
public void DefinePosition4() { int column = InternalFunctions.GetNumberFromLetter(InternalFunctions.GetLetterFromPhoneticLetter(Positions[3].Split('-')[0])) - 1; int row = int.Parse(Positions[3].Split('-')[1]) - 1; Chessboard[row, column].Piece = "rook"; ChangeOtherTiles(row, column, Chessboard[row, column].Piece); }
/// <summary> /// Aborts the current request processing /// </summary> /// <param name="responseCode">HttpResponse status code</param> protected internal void AbortRequest(int responseCode) { if (responseCode >= 200 && responseCode < 300) { throw new WebDavException(InternalFunctions.GetResourceString("InvalidResponseCode")); } this.__abortStatusCode = responseCode; }
public override string Command(Bomb bomb, string command) { bool?NumberInTheFront = null; var splitCommand = command.Split(' ').ToList(); foreach (var word in command.Split(' ')) { if (word.Contains("dollar")) { var itemIndex = splitCommand.FindIndex(x => x == word); ValuePaid = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture); continue; } if (word == "sunday" || word == "monday" || word == "tuesday" || word == "wednesday" || word == "thursday" || word == "friday" || word == "saturday") { Day = word; continue; } if (!PossibleItems.Select(x => x.Name).Contains(word)) { continue; } ItemsBought.Add(PossibleItems.Where(x => x.Name == word).First()); if (ItemsBought.Last().BuyPerPound) { var itemIndex = splitCommand.FindIndex(x => x == ItemsBought.Last().Name); switch (NumberInTheFront) { case true: { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture); break; } case false: { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex + 1], CultureInfo.InvariantCulture); break; } default: { NumberInTheFront = InternalFunctions.IsNumber(splitCommand[itemIndex - 1]); if (NumberInTheFront.Value) { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex - 1], CultureInfo.InvariantCulture); } else { ItemsBought.Last().Quantity = double.Parse(splitCommand[itemIndex + 1], CultureInfo.InvariantCulture); } break; } } } else { ItemsBought.Last().Quantity = 1; } } return(Solve(bomb)); }
/// <summary> /// Add a resource /// </summary> /// <param name="resource"></param> /// <param name="errorCode"></param> /// <exception cref="WebDavException">Throw exception if the errorCode value is not a valid Int32</exception> internal void Add(DavResourceBase resource, Enum errorCode) { if (InternalFunctions.ValidateEnumType(errorCode)) { if (base.Dictionary[errorCode] == null) { base.Dictionary[errorCode] = new ArrayList(); } ((ArrayList)base.Dictionary[errorCode]).Add(resource); } }
public override string Command(Bomb bomb, string command) { foreach (var word in command.Split(' ')) { if (InternalFunctions.GetLetterFromPhoneticLetter(word) != "") { Letters.Add(InternalFunctions.GetLetterFromPhoneticLetter(word).ToLower()); } } return(Solve(bomb)); }
public override string Command(Bomb bomb, string command) { if (command.Contains("serial")) { foreach (var word in command.Split(' ')) { Serial += InternalFunctions.GetLetterFromPhoneticLetter(word).ToUpper(); Serial += InternalFunctions.GetNumber(word) == -1 ? "" : InternalFunctions.GetNumber(word).ToString(); } return("Serial added."); } if (command.Contains("type")) { if (command.Contains("strk")) { Type = "STRK"; } if (command.Contains("leds")) { Type = "LEDS"; } if (command.Contains("cntd")) { Type = "CNTD"; } if (command.Contains("expl")) { Type = "EXPL"; } if (Type != "") { return("Type added."); } } foreach (var word in command.Split(' ')) { if (InternalFunctions.IsNumber(word)) { if (command.Contains("pins")) { PinQuantity = InternalFunctions.GetNumber(word); return("Pin quantity added."); } else { PinNumber = InternalFunctions.GetNumber(word); return(Solve(bomb)); } } } return("Cannot resolve, try again."); }
public override string Command(Bomb bomb, string command) { if (command.Contains("reset")) { Stages.Clear(); return("Moduled reseted"); } var op = 0; var numberDisplayed = 0; var value1 = ""; var value2 = ""; var value3 = ""; var value4 = ""; foreach (var word in command.Split(' ')) { if (word == "display" || word == "monitor" || word == "show") { op = 1; } if (word == "numbers") { op = 2; } if (InternalFunctions.GetNumber(word) != -1) { if (op == 1) { numberDisplayed = InternalFunctions.GetNumber(word); } else { if (string.IsNullOrEmpty(value1)) { value1 = word; continue; } if (string.IsNullOrEmpty(value2)) { value2 = word; continue; } if (string.IsNullOrEmpty(value3)) { value3 = word; continue; } if (string.IsNullOrEmpty(value4)) { value4 = word; continue; } } } } return(StageOption(numberDisplayed.ToString(), value1, value2, value3, value4)); }
private int DavPropFindBase_ValidateDavRequest(object sender, EventArgs e) { int _returnCode = (int)ServerResponseCode.Ok; //Clear out all the collection resources base.FileResources.Clear(); base.CollectionResources.Clear(); //NOTE: An empty PROPFIND request body MUST be treated as a request for the names // and values of all properties. if (base.RequestXml == null) { this.RequestPropertyType = PropertyRequestType.AllProperties; } else { XPathNodeIterator _propFindNodeIterator = base.RequestXml.SelectDescendants("propfind", "DAV:", false); if (_propFindNodeIterator.MoveNext()) { if (_propFindNodeIterator.Current.MoveToFirstChild()) { switch (_propFindNodeIterator.Current.LocalName.ToLower(CultureInfo.InvariantCulture)) { case "propnames": this.RequestPropertyType = PropertyRequestType.PropertyNames; break; case "allprop": this.RequestPropertyType = PropertyRequestType.AllProperties; break; default: this.RequestPropertyType = PropertyRequestType.NamedProperties; break; } } else { _returnCode = (int)ServerResponseCode.BadRequest; } } else { _returnCode = (int)ServerResponseCode.BadRequest; } } //Write to the debug log InternalFunctions.WriteDebugLog("DavPropFindBase: PropertyRequestType - " + this.RequestPropertyType); return(_returnCode); }
private int DavDeleteBase_InternalProcessDavRequest(object sender, EventArgs e) { int _responseCode = (int)DavDeleteResponseCode.NoContent; //Check to see if there were any process errors... Enum[] _errorResources = this.ProcessErrorResources; if (_errorResources.Length > 0) { base.SetResponseXml(InternalFunctions.ProcessErrorRequest(this.ProcessErrors)); _responseCode = (int)ServerResponseCode.MultiStatus; } return(_responseCode); }
/// <summary> /// Retrieve all the resources with a particular errorCode /// </summary> /// <exception cref="WebDavException">Throw exception if the errorCode value is not a valid Int32</exception> internal DavResourceBase[] this[Enum errorCode] { get { DavResourceBase[] _davResources = null; if (InternalFunctions.ValidateEnumType(errorCode)) { ArrayList _errorResources = new ArrayList((ArrayList)base.Dictionary[errorCode]); _davResources = (DavResourceBase[])_errorResources.ToArray(typeof(DavResourceBase)); } return(_davResources); } }
private int DavGetBase_ValidateDavRequest(object sender, EventArgs e) { if (base.RequestLength != 0) { return((int)ServerResponseCode.BadRequest); } try { //Try to set the content type based on the requested extension this.ContentType = InternalFunctions.GetMimeType(Path.GetExtension(this.RelativeRequestPath)); } catch (Exception) { } return((int)ServerResponseCode.Ok); }
/// <summary> /// Copy an existing property collection /// </summary> /// <param name="propertyCollection"></param> public void Copy(DavPropertyCollection propertyCollection) { if (propertyCollection == null) { throw new ArgumentNullException("propertyCollection", InternalFunctions.GetResourceString("ArgumentNullException", "PropertyCollection")); } base.Clear(); foreach (DavProperty _davProperty in propertyCollection) { if (_davProperty.Name != null) { this.Add(_davProperty.Clone()); } } }
/// <summary> /// Check to see if this object is read only /// </summary> /// <returns></returns> private bool IsReadOnly(bool throwError) { bool _isReadOnly = false; if (this.__readOnly) { _isReadOnly = true; if (throwError) { throw new WebDavException(InternalFunctions.GetResourceString("ReadOnlyException")); } } return(_isReadOnly); }