Example #1
0
 public View AddField(string tableName, Type tableType, AbstractField field, string name = null)
 {
     if (!string.IsNullOrEmpty(tableName) && field != null)
     {
         Table table = null;
         if (Tables != null && Tables.Any() && Tables.Any(x => x.Name == tableName))
         {
             table = Tables.FirstOrDefault(x => x.Name == tableName);
         }
         else
         {
             table = new Table()
             {
                 Name = tableName,
                 Type = tableType
             };
             Tables = (Tables == null) ? new[] { table } : Tables.Concat(new[] { table });
         }
         if (table.Fields == null)
         {
             table.Fields = new Dictionary <string, AbstractField>();
         }
         var fieldName = (!string.IsNullOrEmpty(name)) ? name : field.Name;
         if (!table.Fields.ContainsKey(fieldName))
         {
             field.Table = table;
             table.Fields.Add(fieldName, field);
         }
     }
     return(this);
 }
Example #2
0
        protected override void Execute(Map map)
        {
            AbstractField position = map.GetPlayerById(_agentId).Position;
            AbstractPiece piece    = map.GetPlayerById(_agentId).Holding;

            PutPieceAt(piece, position, map);
        }
Example #3
0
        private void EnsureDocument()
        {
            if (document == null)
            {
                document = new Document();
                var fields = DocumentBuilder.GetFields(TypeName);
                foreach (var f in fields)
                {
                    AbstractField af = null;
                    switch (f.FieldType)
                    {
                    case FieldType.Int:
                    case FieldType.Float:
                    case FieldType.Long:
                    case FieldType.Double:
                        af = new LN.Documents.NumericField(f.FieldName, (LN.Documents.Field.Store)((int)f.StoreMode), (int)f.IndexMode > 0);
                        break;

                    case FieldType.String:
                    case FieldType.DateTime:
                    default:
                        af = new LN.Documents.Field(f.FieldName, string.Empty, (LN.Documents.Field.Store)((int)f.StoreMode), (LN.Documents.Field.Index)((int)f.IndexMode));
                        break;
                    }
                    af.Boost = f.Boost;
                    document.Add(af);
                }
            }
        }
        protected override void Execute(Map map)
        {
            AbstractField oldField = map.GetPlayerById(_agentId).Position;
            AbstractField newField = map[_newX, _newY];

            oldField.MoveOut(map.GetPlayerById(_agentId));
            newField.MoveHere(map.GetPlayerById(_agentId));
            map.GetPlayerById(_agentId).Position = newField;
        }
Example #5
0
        public void PutGoalTest(AbstractField field, List <AbstractPiece> pieces, List <PutEvent> expectedEvents)
        {
            // Arrange

            // Act & Assert
            for (int i = 0; i < pieces.Count; ++i)
            {
                PutEvent result = field.Put(pieces[i]).putEvent;
                Assert.Equal(expectedEvents[i], result);
            }
        }
Example #6
0
 private void PutPieceInGoalArea(AbstractPiece piece, AbstractField position, Map map)
 {
     if (piece.IsSham())
     {
         PutShamInGoalArea(piece, position);
     }
     else
     {
         PutNonShamInGoalArea(piece, position, map);
     }
 }
Example #7
0
 private void PutNonShamInGoalArea(AbstractPiece piece, AbstractField position, Map map)
 {
     position.Discover();
     if (position.IsGoalField)
     {
         PutNonShamOnGoal(piece, position, map);
     }
     else
     {
         PutNormalOnNonGoal(piece, position);
     }
 }
Example #8
0
 protected override void Execute(Map map)
 {
     _position            = map.GetPlayerById(_agentId).Position;
     _distanceFromCurrent = map.ClosestPieceForField(_position);
     _distanceN           = map.IsInsideMap(_position.X, _position.Y + 1) ? map.ClosestPieceForField(map[_position.X, _position.Y + 1]) : int.MaxValue;
     _distanceNE          = map.IsInsideMap(_position.X + 1, _position.Y + 1) ? map.ClosestPieceForField(map[_position.X + 1, _position.Y + 1]) : int.MaxValue;
     _distanceE           = map.IsInsideMap(_position.X + 1, _position.Y) ? map.ClosestPieceForField(map[_position.X + 1, _position.Y]) : int.MaxValue;
     _distanceSE          = map.IsInsideMap(_position.X + 1, _position.Y - 1) ? map.ClosestPieceForField(map[_position.X + 1, _position.Y - 1]) : int.MaxValue;
     _distanceS           = map.IsInsideMap(_position.X, _position.Y - 1) ? map.ClosestPieceForField(map[_position.X, _position.Y - 1]) : int.MaxValue;
     _distanceSW          = map.IsInsideMap(_position.X - 1, _position.Y - 1) ? map.ClosestPieceForField(map[_position.X - 1, _position.Y - 1]) : int.MaxValue;
     _distanceW           = map.IsInsideMap(_position.X - 1, _position.Y) ? map.ClosestPieceForField(map[_position.X - 1, _position.Y]) : int.MaxValue;
     _distanceNW          = map.IsInsideMap(_position.X - 1, _position.Y + 1) ? map.ClosestPieceForField(map[_position.X - 1, _position.Y + 1]) : int.MaxValue;
 }
Example #9
0
 public virtual void AddField(AbstractField field)
 {
     fields.Add(field);
     if (fieldDict.ContainsKey(field.name))
     {
         fieldDict[field.name] = field;
     }
     else
     {
         fieldDict.Add(field.name, field);
     }
     field.id = fields.Count - 1;
 }
Example #10
0
 private void PutPieceAt(AbstractPiece piece, AbstractField position, Map map)
 {
     map.GetPlayerById(_agentId).Holding = null;
     if (map.IsInGoalArea(position))
     {
         map.AddPiece();
         PutPieceInGoalArea(piece, position, map);
     }
     else
     {
         PutPieceOutsideGoalArea(piece, position);
     }
 }
Example #11
0
 public override string ConvertType(DbType type, AbstractField field)
 {
     switch (type)
     {
     case DbType.VarNumeric:
     case DbType.Decimal:
         if (field is DecimalField decimalField && decimalField.Precision != null && decimalField.Scale != null)
         {
             return(string.Format("DECIMAL({0},{1})", decimalField.Precision, decimalField.Scale));
         }
         else
         {
             return("DECIMAL");
         }
        public AbstractField[] CreateIndexableFields(Rectangle bbox)
        {
            var fields = new AbstractField[5];

            fields[0] = DoubleField(field_minX, bbox.GetMinX());
            fields[1] = DoubleField(field_maxX, bbox.GetMaxX());
            fields[2] = DoubleField(field_minY, bbox.GetMinY());
            fields[3] = DoubleField(field_maxY, bbox.GetMaxY());
            fields[4] = new Field(field_xdl, bbox.GetCrossesDateLine() ? "T" : "F", Field.Store.NO,
                                  Field.Index.NOT_ANALYZED_NO_NORMS)
            {
                OmitNorms = true, OmitTermFreqAndPositions = true
            };
            return(fields);
        }
Example #13
0
        public List <(AbstractField, int, Direction)> GetNeighbours(AbstractField field, AbstractField[][] board, int height, int width)
        {
            int[] center = field.GetPosition();
            List <(AbstractField, int, Direction)> neighbours = new List <(AbstractField, int, Direction)>();
            var neighbourCoordinates = DirectionExtensions.GetCoordinatesAroundCenter(center);

            for (int i = 0; i < neighbourCoordinates.Length; i++)
            {
                var(dir, y, x) = neighbourCoordinates[i];
                if (y >= 0 && y < height && x >= 0 && x < width)
                {
                    neighbours.Add((board[y][x], int.MaxValue, dir));
                }
            }
            return(neighbours);
        }
        private AbstractFieldViewModel GetViewModelFromField(AbstractField field)
        {
            if (field is TextField)
            {
                return(Mapper.Map <TextFieldViewModel>(field));
            }
            if (field is DropdownBackendField)
            {
                return(Mapper.Map <DropdownBackendFieldViewModel>(field));
            }
            if (field is DropdownEdenField)
            {
                return(Mapper.Map <DropdownEdenFieldViewModel>(field));
            }

            throw new Exception("not supported");
        }
Example #15
0
    private void OnGUI()
    {
        Event e = Event.current;

        mousePos = e.mousePosition;
        if (e.type == EventType.MouseDown)
        {
            BaseNode tempNode = ClickedOnANode();
            if (e.button == 1)
            {
                if (!tempNode)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Add Noise Node"), false, AddNode, typeof(NoiseNode));
                    menu.AddItem(new GUIContent("Add Vector2 Node"), false, AddNode, typeof(Vector2Node));
                    menu.ShowAsContext();
                    e.Use();
                }
                else
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Delete Node"), false, DeleteNode, tempNode);
                    menu.ShowAsContext();
                    e.Use();
                }
            }
            if (e.button == 0)
            {
                AbstractField tempField = tempNode.ClickedOnField();
                if (tempField != null)
                {
                }
            }
        }

        BeginWindows();
        for (int i = 0; i < nodes.Count; i++)
        {
            nodes[i].windowRect = GUILayout.Window(i, nodes[i].windowRect, showNode, nodes[i].windowName);
        }
        EndWindows();
    }
        public AbstractField[] CreateIndexableFields(Point point)
        {
            var f = new AbstractField[2];

            var f0 = new NumericField(fieldNameX, precisionStep, Field.Store.NO, true); // {OmitNorms = true, OmitTermFreqAndPositions = true};

            f0.SetOmitNorms(true);
            f0.SetOmitTermFreqAndPositions(true);
            f0.SetDoubleValue(point.GetX());
            f[0] = f0;

            var f1 = new NumericField(fieldNameY, precisionStep, Field.Store.NO, true); //{OmitNorms = true, OmitTermFreqAndPositions = true};

            f1.SetOmitNorms(true);
            f1.SetOmitTermFreqAndPositions(true);
            f1.SetDoubleValue(point.GetY());
            f[1] = f1;

            return(f);
        }
        protected override bool CheckRequest(Map map)
        {
            AbstractField position = map.GetPlayerById(_agentId).Position;

            _playerAlreadyHasPiece = map.GetPlayerById(_agentId).Holding != null;
            if (_playerAlreadyHasPiece)
            {
                return(false);
            }
            _fieldIsOnGoalArea = map.IsInsideBlueGoalArea(position) || map.IsInsideRedGoalArea(position);
            if (_fieldIsOnGoalArea)
            {
                return(false);
            }
            _noPieceOnField = !position.ContainsPieces();
            if (_noPieceOnField)
            {
                return(false);
            }
            return(true);
        }
Example #18
0
        protected void SetBoost(AbstractField field)
        {
            if (field == null)
            {
                return;
            }

            Func <float?> getBoost;

            if (!_fieldBoosts.TryGetValue(field.name(), out getBoost))
            {
                return;
            }

            var boost = getBoost();

            if (boost != null)
            {
                field.setBoost(boost.Value);
            }
        }
Example #19
0
        private AbstractField GetFieldFromProperty(PropertyInfo property, IContent content)
        {
            AbstractField field = null;

            if (!property.IsPrimitive())
            {
                return(null);
            }
            var propertyType = property.PropertyType;
            var indexFieldName = GetIndexFieldName(property); var value = property.GetValue(content, null);

            if (value != null)
            {
                if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
                {
                    DateTime d1 = Convert.ToDateTime(value);
                    field = new Field(indexFieldName, DateTools.DateToString(d1.ToUniversalTime(), DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
                }
                else if (propertyType == typeof(bool) || propertyType == typeof(bool?) || propertyType == typeof(Boolean) || propertyType == typeof(Boolean?))
                {
                    if (bool.TryParse(value + "", out var tmp))
                    {
                        field = new Field(indexFieldName, tmp.ToString().ToLower(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
                    }
                }
                else if (property.IsNumeric())
                {
                    if (long.TryParse(value + "", out var tmp))
                    {
                        field = new NumericField(indexFieldName, Field.Store.YES, true).SetLongValue(tmp);
                    }
                }
                else
                {
                    field = new Field(indexFieldName, value.ToString(), Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.NO);
                }
            }
            return(field);
        }
 public void Add(AbstractField field)
 {
     _doc.Add(field);
 }
Example #21
0
        public static FunctionField CreateFunctionAggregateField(System.Reflection.PropertyInfo property, Attributes.AggregateField field, AbstractField tablefield)
        {
            FunctionField functionField = null;

            if (field is Attributes.AvgField)
            {
                functionField = (tablefield.IsNotNull)
                    ? new DecimalFunction(property, "AVG", new[] { tablefield.Name })
                    : new NullableDecimalFunction(property, "AVG", new[] { tablefield.Name });
            }
            if (field is Attributes.CountField)
            {
                functionField = (tablefield.IsNotNull)
                    ? new IntegerFunction(property, "COUNT", new[] { tablefield.Name })
                    : new NullableIntegerFunction(property, "COUNT", new[] { tablefield.Name });
            }
            else if (field is Attributes.MaxField)
            {
                if (tablefield is IntegerField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new IntegerFunction(property, "MAX", new[] { tablefield.Name })
                    : new NullableIntegerFunction(property, "MAX", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new DecimalFunction(property, "MAX", new[] { tablefield.Name })
                    : new NullableDecimalFunction(property, "MAX", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new BooleanFunction(property, "MAX", new[] { tablefield.Name })
                    : new NullableBooleanFunction(property, "MAX", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new DateTimeFunction(property, "MAX", new[] { tablefield.Name })
                    : new NullableDateTimeFunction(property, "MAX", new[] { tablefield.Name });
                }
                else if (tablefield is GuidField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new GuidFunction(property, "MAX", new[] { tablefield.Name })
                    : new NullableGuidFunction(property, "MAX", new[] { tablefield.Name });
                }
                else if (tablefield is CharField charfield)
                {
                    functionField = new CharFunction(property, "MAX", new[] { tablefield.Name }, charfield.Lenght);
                }
                else
                {
                    functionField = new StringFunction(property, "MAX", new[] { tablefield.Name });
                }
            }
            else if (field is Attributes.MinField)
            {
                if (tablefield is IntegerField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new IntegerFunction(property, "MIN", new[] { tablefield.Name })
                    : new NullableIntegerFunction(property, "MIN", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new DecimalFunction(property, "MIN", new[] { tablefield.Name })
                    : new NullableDecimalFunction(property, "MIN", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new BooleanFunction(property, "MIN", new[] { tablefield.Name })
                    : new NullableBooleanFunction(property, "MIN", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new DateTimeFunction(property, "MIN", new[] { tablefield.Name })
                    : new NullableDateTimeFunction(property, "MIN", new[] { tablefield.Name });
                }
                else if (tablefield is GuidField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new GuidFunction(property, "MIN", new[] { tablefield.Name })
                    : new NullableGuidFunction(property, "MIN", new[] { tablefield.Name });
                }
                else if (tablefield is CharField charfield)
                {
                    functionField = new CharFunction(property, "MIN", new[] { tablefield.Name }, charfield.Lenght);
                }
                else
                {
                    functionField = new StringFunction(property, "MIN", new[] { tablefield.Name });
                }
            }
            else if (field is Attributes.SumField)
            {
                if (tablefield is IntegerField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new IntegerFunction(property, "SUM", new[] { tablefield.Name })
                    : new NullableIntegerFunction(property, "SUM", new[] { tablefield.Name });
                }
                else if (tablefield is DecimalField)
                {
                    functionField = (tablefield.IsNotNull)
                    ? new DecimalFunction(property, "SUM", new[] { tablefield.Name })
                    : new NullableDecimalFunction(property, "SUM", new[] { tablefield.Name });
                }
            }
            if (functionField != null)
            {
                functionField.IsAggregate = true;
            }
            return(functionField);
        }
Example #22
0
 public void Add(AbstractField field)
 {
     _fields.Add(field);
 }
Example #23
0
 public int ManhattanDistance(AbstractField f1, AbstractField f2)
 {
     return(Math.Abs(f1.GetPosition()[0] - f2.GetPosition()[0]) + Math.Abs(f1.GetPosition()[1] - f2.GetPosition()[1]));
 }
Example #24
0
        public void TestInitGame()
        {
            // Arrange
            var conf       = new MockGameConfiguration();
            var queue      = new BufferBlock <Message>();
            var lifetime   = Mock.Of <IApplicationLifetime>();
            var client     = new TcpSocketClient <Message, Message>(logger);
            var gameMaster = new GM(lifetime, conf, queue, client, logger);

            // Act
            gameMaster.Invoke("InitGame");

            // Assert
            Assert.True(gameMaster.WasGameInitialized);

            int redGoalFieldsCount  = 0;
            int blueGoalFieldsCount = 0;
            int taskFieldsCount     = 0;
            int piecesCount         = 0;
            var board = gameMaster.GetValue <GM, AbstractField[][]>("board");

            for (int i = 0; i < board.Length; ++i)
            {
                for (int j = 0; j < board[i].Length; ++j)
                {
                    AbstractField field = board[i][j];
                    if (field is GoalField)
                    {
                        if (i < conf.GoalAreaHeight)
                        {
                            ++redGoalFieldsCount;
                        }
                        else if (i >= gameMaster.SecondGoalAreaStart)
                        {
                            ++blueGoalFieldsCount;
                        }
                        else
                        {
                            Assert.True(false, "Goal field should be on correct position");
                        }

                        if (field.ContainsPieces())
                        {
                            Assert.True(false, "Goal field should not contain any pieces");
                        }
                    }
                    else if (field is TaskField taskField)
                    {
                        ++taskFieldsCount;
                        if (field.ContainsPieces())
                        {
                            piecesCount += GetPieceCount(taskField);
                        }
                    }
                }
            }

            Assert.True(conf.NumberOfGoals == redGoalFieldsCount,
                        $"Number of red goal fields should match configuration setting.\n" +
                        $"Have: {redGoalFieldsCount}\n" +
                        $"Expected: {conf.NumberOfGoals}");
            Assert.True(conf.NumberOfGoals == blueGoalFieldsCount,
                        $"Number of red goal fields should match configuration setting.\n" +
                        $"Have: {blueGoalFieldsCount}\n" +
                        $"Expected: {conf.NumberOfGoals}");

            int expectedTaskFieldsCount = (conf.Height - (2 * conf.GoalAreaHeight)) * conf.Width;

            Assert.True(expectedTaskFieldsCount == taskFieldsCount,
                        "Task fields should cover all fields except goal areas.\n" +
                        $"Have: {taskFieldsCount}\n" +
                        $"Expected: {expectedTaskFieldsCount}");

            Assert.True(conf.NumberOfPiecesOnBoard == piecesCount,
                        "GM should generate enough pieces.\n" +
                        $"Have: {piecesCount}\n" +
                        $"Expected: {conf.NumberOfPiecesOnBoard}");
        }
Example #25
0
 private void PutNormalOnNonGoal(AbstractPiece piece, AbstractField position)
 {
     _returnedEnum = PutResultEnum.NormalOnNonGoalField;
     position.Put(piece);
 }
Example #26
0
 private void PutNonShamOnGoal(AbstractPiece piece, AbstractField position, Map map)
 {
     map.ScorePoint(position, _agentId);
     _returnedEnum = PutResultEnum.NormalOnGoalField;
     position.Put(piece);
 }
Example #27
0
 private void PutShamInGoalArea(AbstractPiece piece, AbstractField position)
 => _returnedEnum = PutResultEnum.ShamOnGoalArea;
Example #28
0
 private void PutPieceOutsideGoalArea(AbstractPiece piece, AbstractField position)
 {
     _returnedEnum = PutResultEnum.TaskField;
     position.Put(piece);
 }
Example #29
0
 void IBooster.SetBoost(AbstractField field)
 {
 }
Example #30
0
 public (PutEvent putEvent, bool wasPieceRemoved) Put(AbstractField field)
 {
     return(field.Put(this));
 }