public void False_ToNumber_IsZero() { var value = BoolValue.Create(false) as IValue; var result = value.ImplicitConversionToNumberValue(); Assert.AreEqual(0, result.Value); }
public void False_ToBool_IsFalse() { var value = BoolValue.Create(false) as IValue; var result = value.ImplicitConversionToBoolValue(); Assert.AreEqual(false, result.Value); }
public IValue Evaluate() { if (Operator == "+") { return(Operand.Evaluate().ImplicitConversionToNumberValue()); } if (Operator == "-") { return(NumberValue.Create(-Operand.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "~") { return(NumberValue.Create(~Operand.Evaluate().ImplicitConversionToNumberValue().BitwiseValue)); } if (Operator == "!") { return(BoolValue.Create(!Operand.Evaluate().ImplicitConversionToBoolValue().Value)); } if (Operator == "++") { return(NumberValue.Create(Operand.Evaluate().ImplicitConversionToNumberValue().Value + 1)); } if (Operator == "--") { return(NumberValue.Create(Operand.Evaluate().ImplicitConversionToNumberValue().Value - 1)); } throw new Exception("Internal error: no implementation for operator '" + Operator + "'"); // TODO: different exception type? }
public void True_ToBool_IsTrue() { var value = BoolValue.Create(true) as IValue; var result = value.ImplicitConversionToBoolValue(); Assert.AreEqual(true, result.Value); }
public override bool TryParse(string value, out Value val) { val = null; var match = ParseRegEx.Match(value); if (match.Success && bool.TryParse(match.Groups[1].Value, out var boolVal)) { val = BoolValue.Create(boolVal); return(true); } return(false); }
public IValue Evaluate() { if (Operator == "+") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().Value + Right.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "-") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().Value - Right.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "*") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().Value *Right.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "/") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().Value / Right.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "%") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().Value % Right.Evaluate().ImplicitConversionToNumberValue().Value)); } if (Operator == "@&") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().BitwiseValue & Right.Evaluate().ImplicitConversionToNumberValue().BitwiseValue)); } if (Operator == "@|") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().BitwiseValue | Right.Evaluate().ImplicitConversionToNumberValue().BitwiseValue)); } if (Operator == "@^") { return(NumberValue.Create(Left.Evaluate().ImplicitConversionToNumberValue().BitwiseValue ^ Right.Evaluate().ImplicitConversionToNumberValue().BitwiseValue)); } if (Operator == "&") { return(StringValue.Create(Left.Evaluate().ImplicitConversionToStringValue().Value + Right.Evaluate().ImplicitConversionToStringValue().Value)); } if (Operator == "&&") { return(BoolValue.Create(Left.Evaluate().ImplicitConversionToBoolValue().Value&& Right.Evaluate().ImplicitConversionToBoolValue().Value)); } if (Operator == "||") { return(BoolValue.Create(Left.Evaluate().ImplicitConversionToBoolValue().Value || Right.Evaluate().ImplicitConversionToBoolValue().Value)); } throw new Exception("Internal error: no implementation for operator '" + Operator + "'"); // TODO: different exception type? }
BoolValue s_Repetition() { return(BoolValue.Create(_phase2 && _board.Repetition())); }
TypedValue s_Stalemated() { return(BoolValue.Create(_phase2 && _board.Stalemated())); }
BoolValue s_TotalPieceCount(NumberValue quantity, PieceValue piece = null) { return(BoolValue.Create(_phase1 && _board.PiecesCount(PlayerKinds.Any, piece) == (int)quantity.Value)); }
BoolValue s_Checkmated(PieceValue[] pieces) { return(BoolValue.Create(_phase2 && _board.Checkmated(pieces))); }
BoolValue s_RelativeConfig(List <OccupierDef> occupiers) { return(BoolValue.Create(_phase1 && _board.PositionIter().Any(p => IsRelative(p, occupiers)))); }
BoolValue s_PiecesRemaining(NumberValue quantity, PieceValue piece = null) { return(BoolValue.Create(_phase1 && _board.PiecesCount(PlayerKinds.Friend, piece) == (int)quantity.Value)); }
BoolValue s__Attribute(AttributeValue attribute, PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsAttributeSet(attribute, ToPosition(posordir)))); }
BoolValue s_Enemy_(PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsEnemy(ToPosition(posordir)))); }
BoolValue s_Piece_(PieceValue piece, PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsPiece(piece, ToPosition(posordir)))); }
BoolValue s_Position_(PositionValue position, PositionOrDirection posordir = null) { return(BoolValue.Create(position == ToPosition(posordir))); }
BoolValue s_OnBoard_(PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsValid(ToPosition(posordir)))); }
BoolValue s_Neutral_(PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsNeutral(ToPosition(posordir)))); }
BoolValue s_Friend_(PositionOrDirection posordir = null) { return(BoolValue.Create(_board.IsFriend(ToPosition(posordir)))); }
// simple state enquiries BoolValue s_Marked_(PositionOrDirection posordir = null) { return(BoolValue.Create(_state.Mark == ToPosition(posordir))); }
// conditions codes BoolValue s_Flag_(IdentValue flag) { return(BoolValue.Create(_state.GetMoveFlag(flag))); }
protected BoolValue s_Not(BoolValue arg) { return(BoolValue.Create(!arg.Value)); }
// simple board enquiries BoolValue s_AdjacentToEnemy_(PositionOrDirection posordir = null) { return(BoolValue.Create(_board.AdjEnemy(ToPosition(posordir)))); }
BoolValue s_LastTo_(PositionOrDirection posordir = null) { return(BoolValue.Create(_state.LastTo == ToPosition(posordir))); }
BoolValue s_PositionFlag_(IdentValue flag, PositionOrDirection posordir = null) { return(BoolValue.Create(_state.GetPositionFlag(flag, ToPosition(posordir)))); }
BoolValue s_InZone_(ZoneValue zone, PositionOrDirection posordir = null) { return(BoolValue.Create(_board.InZone(zone, ToPosition(posordir)))); }
// sexpr api for goal evaluators // note: and/or/not in outer scope BoolValue s_AbsoluteConfig(List <OccupierDef> occupiers, PositionOrZone[] posorzones) { return(BoolValue.Create(_phase1 && occupiers.Any(o => IsAbsolute(o, posorzones)))); }
public AstLiteral Bool(string value) { return(LitValue(BoolValue.Create(value[0] == 't'))); }
public override Value GetValue(UserItem item) { if (item.TryGetUserItemData(out var userItemData)) return BoolValue.Create(userItemData.Played); return Value.None; }