コード例 #1
0
ファイル: ImplicitConversions.cs プロジェクト: nomada2/ARC
        public void False_ToNumber_IsZero()
        {
            var value  = BoolValue.Create(false) as IValue;
            var result = value.ImplicitConversionToNumberValue();

            Assert.AreEqual(0, result.Value);
        }
コード例 #2
0
ファイル: ImplicitConversions.cs プロジェクト: nomada2/ARC
        public void False_ToBool_IsFalse()
        {
            var value  = BoolValue.Create(false) as IValue;
            var result = value.ImplicitConversionToBoolValue();

            Assert.AreEqual(false, result.Value);
        }
コード例 #3
0
 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?
 }
コード例 #4
0
ファイル: ImplicitConversions.cs プロジェクト: nomada2/ARC
        public void True_ToBool_IsTrue()
        {
            var value  = BoolValue.Create(true) as IValue;
            var result = value.ImplicitConversionToBoolValue();

            Assert.AreEqual(true, result.Value);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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?
 }
コード例 #7
0
 BoolValue s_Repetition()
 {
     return(BoolValue.Create(_phase2 && _board.Repetition()));
 }
コード例 #8
0
 TypedValue s_Stalemated()
 {
     return(BoolValue.Create(_phase2 && _board.Stalemated()));
 }
コード例 #9
0
 BoolValue s_TotalPieceCount(NumberValue quantity, PieceValue piece = null)
 {
     return(BoolValue.Create(_phase1 && _board.PiecesCount(PlayerKinds.Any, piece) == (int)quantity.Value));
 }
コード例 #10
0
 BoolValue s_Checkmated(PieceValue[] pieces)
 {
     return(BoolValue.Create(_phase2 && _board.Checkmated(pieces)));
 }
コード例 #11
0
 BoolValue s_RelativeConfig(List <OccupierDef> occupiers)
 {
     return(BoolValue.Create(_phase1 && _board.PositionIter().Any(p => IsRelative(p, occupiers))));
 }
コード例 #12
0
 BoolValue s_PiecesRemaining(NumberValue quantity, PieceValue piece = null)
 {
     return(BoolValue.Create(_phase1 && _board.PiecesCount(PlayerKinds.Friend, piece) == (int)quantity.Value));
 }
コード例 #13
0
 BoolValue s__Attribute(AttributeValue attribute, PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsAttributeSet(attribute, ToPosition(posordir))));
 }
コード例 #14
0
 BoolValue s_Enemy_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsEnemy(ToPosition(posordir))));
 }
コード例 #15
0
 BoolValue s_Piece_(PieceValue piece, PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsPiece(piece, ToPosition(posordir))));
 }
コード例 #16
0
 BoolValue s_Position_(PositionValue position, PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(position == ToPosition(posordir)));
 }
コード例 #17
0
 BoolValue s_OnBoard_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsValid(ToPosition(posordir))));
 }
コード例 #18
0
 BoolValue s_Neutral_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsNeutral(ToPosition(posordir))));
 }
コード例 #19
0
 BoolValue s_Friend_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.IsFriend(ToPosition(posordir))));
 }
コード例 #20
0
 // simple state enquiries
 BoolValue s_Marked_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_state.Mark == ToPosition(posordir)));
 }
コード例 #21
0
 // conditions codes
 BoolValue s_Flag_(IdentValue flag)
 {
     return(BoolValue.Create(_state.GetMoveFlag(flag)));
 }
コード例 #22
0
 protected BoolValue s_Not(BoolValue arg)
 {
     return(BoolValue.Create(!arg.Value));
 }
コード例 #23
0
 // simple board enquiries
 BoolValue s_AdjacentToEnemy_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.AdjEnemy(ToPosition(posordir))));
 }
コード例 #24
0
 BoolValue s_LastTo_(PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_state.LastTo == ToPosition(posordir)));
 }
コード例 #25
0
 BoolValue s_PositionFlag_(IdentValue flag, PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_state.GetPositionFlag(flag, ToPosition(posordir))));
 }
コード例 #26
0
 BoolValue s_InZone_(ZoneValue zone, PositionOrDirection posordir = null)
 {
     return(BoolValue.Create(_board.InZone(zone, ToPosition(posordir))));
 }
コード例 #27
0
        // 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))));
        }
コード例 #28
0
 public AstLiteral Bool(string value)
 {
     return(LitValue(BoolValue.Create(value[0] == 't')));
 }
コード例 #29
0
        public override Value GetValue(UserItem item)
        {
            if (item.TryGetUserItemData(out var userItemData)) return BoolValue.Create(userItemData.Played);

            return Value.None;
        }