public void AddBattleship(int startX, int startY, EnumOrientation orientation, int length)
        {
            if (Battlefield == null)
            {
                throw new InvalidOperationException("Create a board first.");
            }

            if (length == 0)
            {
                throw new ArgumentException("Battleship length must be greater than 0");
            }

            var battleshipPositions = GetPositions(startX, startY, orientation, length).ToArray();

            var isValid = ValidatePositions(battleshipPositions);

            if (!isValid)
            {
                throw new InvalidOperationException(
                          "Battleship cannot fit entirely on the board or has conflicts with existing ships.");
            }

            var battleship = new Battleship(battleshipPositions);

            foreach (var battleshipPosition in battleshipPositions)
            {
                Battlefield.Battleships[battleshipPosition.X, battleshipPosition.Y] = battleship;
            }
        }
Example #2
0
        public Battleship(int startX, int startY, EnumOrientation orientation, int length, int width = 1)
        {
            var startPosition = new Position(startX, startY);

            _orientation = orientation;
            _length      = length;
            _width       = width;
            Positions    = new HashSet <Position>();
        }
        public static Models.ImageSearchResult Search(string apikey,
                                                      string searchTerm               = "",
                                                      EnumLanguage language           = EnumLanguage.en,
                                                      string id                       = "",
                                                      EnumResponseGroup responseGroup = EnumResponseGroup.Image_Details,
                                                      EnumImageType imageType         = EnumImageType.All,
                                                      EnumOrientation orientation     = EnumOrientation.All,
                                                      EnumCategory category           = EnumCategory.All,
                                                      int minWidth                    = 0,
                                                      int minHeight                   = 0,
                                                      bool EditorsChoice              = false,
                                                      bool SafeSearch                 = false,
                                                      int Page    = 1,
                                                      int PerPage = 20
                                                      )
        {
            if (string.IsNullOrEmpty(apikey))
            {
                throw new System.ArgumentNullException("apiKey");
            }

            try
            {
                Models.ImageSearchOptions options = new Models.ImageSearchOptions()
                {
                    ApiKey        = apikey,
                    SearchTerm    = searchTerm,
                    Language      = language,
                    Id            = id,
                    ResponseGroup = responseGroup,
                    ImageType     = imageType,
                    Orientation   = orientation,
                    Category      = category,
                    MinWidth      = minWidth,
                    MinHeight     = minHeight,
                    EditorsChoice = EditorsChoice,
                    SafeSearch    = SafeSearch,
                    Page          = Page,
                    PerPage       = PerPage
                };
                return(SearchWithOptions(options));
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
 /// <summary>
 /// return an enumOrientation from a string
 /// </summary>
 /// <param name="strOri"></param>
 /// <returns></returns>
 public static EnumOrientation stringToOrientation(String strOri)
 {
     EnumOrientation orientation = new EnumOrientation();
     switch (strOri)
     {
         case "line":
             orientation = EnumOrientation.Line;
             break;
         case "diagonal":
             orientation = EnumOrientation.Diagonal;
             break;
         case "any":
             orientation = EnumOrientation.Any;
             break;
     }
     return orientation;
 }
        private IEnumerable <Position> GetPositions(int startX, int startY, EnumOrientation orientation, int length)
        {
            var positions = new Position[length];

            for (var i = 0; i < length; i++)
            {
                if (orientation == EnumOrientation.Horizontal)
                {
                    positions[i] = new Position(startX, startY + i);
                }
                else
                {
                    positions[i] = new Position(startX + i, startY);
                }
            }

            return(positions);
        }
Example #6
0
        public IActionResult AddBattleship(int startX, int startY, EnumOrientation orientation, int length)
        {
            try
            {
                _battlefieldService.AddBattleship(startX, startY, orientation, length);
            }
            catch (ArgumentException ae)
            {
                return(new BadRequestObjectResult(ae.Message));
            }
            catch (InvalidOperationException ie)
            {
                return(new BadRequestObjectResult(ie.Message));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw;
            }

            return(Ok());
        }
Example #7
0
 static JDFAutoPosition()
 {
     atrInfoTable[0] = new AtrInfoTable(AttributeName.ABSOLUTEBOX, 0x33333111, AttributeInfo.EnumAttributeType.rectangle, null, null);
     atrInfoTable[1] = new AtrInfoTable(AttributeName.MARGINBOTTOM, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[2] = new AtrInfoTable(AttributeName.MARGINTOP, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[3] = new AtrInfoTable(AttributeName.MARGINLEFT, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[4] = new AtrInfoTable(AttributeName.MARGINRIGHT, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[5] = new AtrInfoTable(AttributeName.ORIENTATION, 0x33333311, AttributeInfo.EnumAttributeType.enumeration, EnumOrientation.getEnum(0), null);
     atrInfoTable[6] = new AtrInfoTable(AttributeName.RELATIVEBOX, 0x33333311, AttributeInfo.EnumAttributeType.rectangle, null, null);
 }
Example #8
0
 //         ---------------------------------------------------------------------
 //        Methods for Attribute Orientation
 //        ---------------------------------------------------------------------
 ///
 ///          <summary> * (5) set attribute Orientation </summary>
 ///          * <param name="enumVar">: the enumVar to set the attribute to </param>
 ///
 public virtual void setOrientation(EnumOrientation enumVar)
 {
     setAttribute(AttributeName.ORIENTATION, enumVar == null ? null : enumVar.getName(), null);
 }
Example #9
0
 ///
 ///          <summary> * (9) get attribute Orientation </summary>
 ///          * <returns> the value of the attribute </returns>
 ///
 public virtual EnumOrientation getOrientation()
 {
     return(EnumOrientation.getEnum(getAttribute(AttributeName.ORIENTATION, null, null)));
 }
Example #10
0
        ///
        ///	 <summary> * fitsTransforms - checks whether <code>matrix</code> matches the
        ///	 * <code>Transforms</code> attribute specified for this Evaluation
        ///	 *  </summary>
        ///	 * <param name="matrix">
        ///	 *            matrix to test </param>
        ///	 * <returns> boolean - true, if <code>matrix</code> matches the Transforms or
        ///	 *         if Transforms is not specified </returns>
        ///
        private bool fitsTransforms(JDFMatrix matrix)
        {
            if (!hasAttribute(AttributeName.TRANSFORMS))
            {
                return(true);
            }

            double nT; // negative tolerance
            double pT; // positive tolerance

            if (hasAttribute(AttributeName.TOLERANCE))
            {
                nT = getTolerance().X;
                pT = getTolerance().Y;
            }
            else
            {
                nT = pT = JDFBaseDataTypes_Fields.EPSILON;
            }

            double a = matrix.A;
            double b = matrix.B;
            double c = matrix.C;
            double d = matrix.D;

            double det = (a * d - b * c);

            if (det == 0)
            {
                return(false);
            }

            a = a / Math.Sqrt(Math.Abs(det));
            b = b / Math.Sqrt(Math.Abs(det));
            c = c / Math.Sqrt(Math.Abs(det));
            d = d / Math.Sqrt(Math.Abs(det));

            List <ValuedEnum> vTransf = getTransforms();
            int siz = vTransf.Count;

            for (int i = 0; i < siz; i++)
            {
                EnumOrientation orientation = EnumOrientation.getEnum(vTransf[i].getName()); //.intValue());

                if (orientation.Equals(EnumOrientation.Flip0))                               // a=1 b=0 c=0 d=-1
                {
                    if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=-1
                else if (orientation.Equals(EnumOrientation.Flip90))
                // c=-1 d=0
                {
                    if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=-1 b=0
                else if (orientation.Equals(EnumOrientation.Flip180))
                // c=0 d=1
                {
                    if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=1
                else if (orientation.Equals(EnumOrientation.Flip270))
                // c=1 d=0
                {
                    if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=1 b=0
                else if (orientation.Equals(EnumOrientation.Rotate0))
                // c=0 d=1
                {
                    if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=1
                else if (orientation.Equals(EnumOrientation.Rotate90))
                // c=-1
                // d=0
                {
                    if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=-1
                else if (orientation.Equals(EnumOrientation.Rotate180))
                // b=0
                // c=0
                // d=-1
                {
                    if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0
                else if (orientation.Equals(EnumOrientation.Rotate270))
                // b=-1
                // c=1
                // d=0
                {
                    if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
Example #11
0
 static JDFAutoCollatingItem()
 {
     atrInfoTable[0]  = new AtrInfoTable(AttributeName.AMOUNT, 0x33333311, AttributeInfo.EnumAttributeType.integer, null, "1");
     atrInfoTable[1]  = new AtrInfoTable(AttributeName.BUNDLEDEPTH, 0x33333311, AttributeInfo.EnumAttributeType.integer, null, null);
     atrInfoTable[2]  = new AtrInfoTable(AttributeName.ORIENTATION, 0x33333311, AttributeInfo.EnumAttributeType.enumeration, EnumOrientation.getEnum(0), null);
     atrInfoTable[3]  = new AtrInfoTable(AttributeName.TRANSFORMATION, 0x33333311, AttributeInfo.EnumAttributeType.matrix, null, null);
     atrInfoTable[4]  = new AtrInfoTable(AttributeName.TRANSFORMATIONCONTEXT, 0x33333311, AttributeInfo.EnumAttributeType.enumeration, EnumTransformationContext.getEnum(0), "StackItem");
     elemInfoTable[0] = new ElemInfoTable(ElementName.COMPONENT, 0x66666611);
     elemInfoTable[1] = new ElemInfoTable(ElementName.MEDIA, 0x66666611);
 }
Example #12
0
 static JDFAutoBundleItem()
 {
     atrInfoTable[0]  = new AtrInfoTable(AttributeName.AMOUNT, 0x22222221, AttributeInfo.EnumAttributeType.integer, null, null);
     atrInfoTable[1]  = new AtrInfoTable(AttributeName.ITEMNAME, 0x33333311, AttributeInfo.EnumAttributeType.NMTOKEN, null, null);
     atrInfoTable[2]  = new AtrInfoTable(AttributeName.ORIENTATION, 0x33333331, AttributeInfo.EnumAttributeType.enumeration, EnumOrientation.getEnum(0), null);
     atrInfoTable[3]  = new AtrInfoTable(AttributeName.TRANSFORMATION, 0x33333331, AttributeInfo.EnumAttributeType.matrix, null, null);
     elemInfoTable[0] = new ElemInfoTable(ElementName.COMPONENT, 0x55555551);
 }
Example #13
0
 static JDFMatrixEvaluation()
 {
     atrInfoTable[0]  = new AtrInfoTable(AttributeName.ROTATEMOD, 0x33333333, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[1]  = new AtrInfoTable(AttributeName.SHIFT, 0x33333333, AttributeInfo.EnumAttributeType.NumberList, null, null);
     atrInfoTable[2]  = new AtrInfoTable(AttributeName.TOLERANCE, 0x33333333, AttributeInfo.EnumAttributeType.XYPair, null, "0 0");
     atrInfoTable[3]  = new AtrInfoTable(AttributeName.TRANSFORMS, 0x33333333, AttributeInfo.EnumAttributeType.enumerations, EnumOrientation.getEnum(0), null);
     elemInfoTable[0] = new ElemInfoTable(ElementName.BASICPREFLIGHTTEST, 0x33333333);
 }
Example #14
0
 static JDFAutoSignatureCell()
 {
     atrInfoTable[0] = new AtrInfoTable(AttributeName.BACKFACEPAGES, 0x33333311, AttributeInfo.EnumAttributeType.IntegerList, null, null);
     atrInfoTable[1] = new AtrInfoTable(AttributeName.BACKPAGES, 0x33333311, AttributeInfo.EnumAttributeType.IntegerList, null, null);
     atrInfoTable[2] = new AtrInfoTable(AttributeName.BOTTLEANGLE, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[3] = new AtrInfoTable(AttributeName.BOTTLEAXIS, 0x33333311, AttributeInfo.EnumAttributeType.enumeration, EnumBottleAxis.getEnum(0), null);
     atrInfoTable[4] = new AtrInfoTable(AttributeName.FRONTFACEPAGES, 0x33333311, AttributeInfo.EnumAttributeType.IntegerList, null, null);
     atrInfoTable[5] = new AtrInfoTable(AttributeName.FRONTPAGES, 0x33333311, AttributeInfo.EnumAttributeType.IntegerList, null, null);
     atrInfoTable[6] = new AtrInfoTable(AttributeName.ORIENTATION, 0x33333311, AttributeInfo.EnumAttributeType.enumeration, EnumOrientation.getEnum(0), "Up");
     atrInfoTable[7] = new AtrInfoTable(AttributeName.SECTIONINDEX, 0x33333311, AttributeInfo.EnumAttributeType.integer, null, "0");
     atrInfoTable[8] = new AtrInfoTable(AttributeName.STATIONNAME, 0x33333111, AttributeInfo.EnumAttributeType.string_, null, "0");
 }
Example #15
0
 static JDFMatrixState()
 {
     atrInfoTable[0]  = new AtrInfoTable(AttributeName.ALLOWEDROTATEMOD, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[1]  = new AtrInfoTable(AttributeName.ALLOWEDSHIFT, 0x33333311, AttributeInfo.EnumAttributeType.NumberList, null, null);
     atrInfoTable[2]  = new AtrInfoTable(AttributeName.ALLOWEDTRANSFORMS, 0x33333311, AttributeInfo.EnumAttributeType.enumerations, EnumOrientation.getEnum(0), null);
     atrInfoTable[3]  = new AtrInfoTable(AttributeName.CURRENTVALUE, 0x33333331, AttributeInfo.EnumAttributeType.matrix, null, null);
     atrInfoTable[4]  = new AtrInfoTable(AttributeName.DEFAULTVALUE, 0x33333331, AttributeInfo.EnumAttributeType.matrix, null, null);
     atrInfoTable[5]  = new AtrInfoTable(AttributeName.PRESENTROTATEMOD, 0x33333311, AttributeInfo.EnumAttributeType.double_, null, null);
     atrInfoTable[6]  = new AtrInfoTable(AttributeName.PRESENTSHIFT, 0x33333311, AttributeInfo.EnumAttributeType.NumberList, null, null);
     atrInfoTable[7]  = new AtrInfoTable(AttributeName.PRESENTTRANSFORMS, 0x44444431, AttributeInfo.EnumAttributeType.enumerations, EnumOrientation.getEnum(0), null);
     elemInfoTable[0] = new ElemInfoTable(ElementName.VALUE, 0x33333311);
 }
Example #16
0
        ///
        ///	 <summary> * fitsTransforms - checks whether <code>matrix</code> matches the
        ///	 * AllowedTransforms or PresentTransforms, specified for this State
        ///	 *  </summary>
        ///	 * <param name="matrix">
        ///	 *            matrix to test </param>
        ///	 * <param name="transforms">
        ///	 *            switches between AllowedTransforms and PresentTransforms. </param>
        ///	 * <returns> boolean - true, if <code>matrix</code> matches the Transforms or
        ///	 *         if AllowedTransforms is not specified </returns>
        ///
        private bool fitsTransforms(JDFMatrix matrix, EnumFitsValue transforms)
        {
            if (transforms == null || transforms.Equals(EnumFitsValue.Allowed))
            {
                if (!hasAttribute(AttributeName.ALLOWEDTRANSFORMS))
                {
                    return(true);
                }
            }
            else
            {
                if (!hasAttribute(AttributeName.ALLOWEDTRANSFORMS) && !hasAttribute(AttributeName.PRESENTTRANSFORMS))
                {
                    return(true);
                }
            }

            double nT = JDFBaseDataTypes_Fields.EPSILON; // negative tolerance
            double pT = JDFBaseDataTypes_Fields.EPSILON; // positive tolerance

            double a = matrix.A;
            double b = matrix.B;
            double c = matrix.C;
            double d = matrix.D;

            double det = (a * d - b * c);

            if (det == 0)
            {
                return(false);
            }

            a = a / Math.Sqrt(Math.Abs(det));
            b = b / Math.Sqrt(Math.Abs(det));
            c = c / Math.Sqrt(Math.Abs(det));
            d = d / Math.Sqrt(Math.Abs(det));

            List <ValuedEnum> vTransf;

            if (transforms == null || transforms.Equals(EnumFitsValue.Allowed))
            {
                vTransf = getAllowedTransforms();
            }
            else
            {
                vTransf = getPresentTransforms();
            }
            int siz = vTransf.Count;

            for (int i = 0; i < siz; i++)
            {
                EnumOrientation orientation = (EnumOrientation)vTransf[i];

                if (orientation.Equals(EnumOrientation.Flip0)) // a=1 b=0 c=0 d=-1
                {
                    if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=-1
                else if (orientation.Equals(EnumOrientation.Flip90))
                // c=-1 d=0
                {
                    if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=-1 b=0
                else if (orientation.Equals(EnumOrientation.Flip180))
                // c=0 d=1
                {
                    if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=1
                else if (orientation.Equals(EnumOrientation.Flip270))
                // c=1 d=0
                {
                    if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=1 b=0
                else if (orientation.Equals(EnumOrientation.Rotate0))
                // c=0 d=1
                {
                    if ((a - 1 < pT) && (a - 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d - 1 < pT) && (d - 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0 b=1
                else if (orientation.Equals(EnumOrientation.Rotate90))
                // c=-1
                // d=0
                {
                    if ((a < pT) && (a > -nT) && (b - 1 < pT) && (b - 1 > -nT) && (c + 1 < pT) && (c + 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=-1
                else if (orientation.Equals(EnumOrientation.Rotate180))
                // b=0
                // c=0
                // d=-1
                {
                    if ((a + 1 < pT) && (a + 1 > -nT) && (b < pT) && (b > -nT) && (c < pT) && (c > -nT) && (d + 1 < pT) && (d + 1 > -nT))
                    {
                        return(true);
                    }
                    continue;
                } // a=0
                else if (orientation.Equals(EnumOrientation.Rotate270))
                // b=-1
                // c=1
                // d=0
                {
                    if ((a < pT) && (a > -nT) && (b + 1 < pT) && (b + 1 > -nT) && (c - 1 < pT) && (c - 1 > -nT) && (d < pT) && (d > -nT))
                    {
                        return(true);
                    }
                    continue;
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
Example #17
0
 public virtual List <ValuedEnum> getPresentTransforms()
 {
     if (hasAttribute(AttributeName.PRESENTTRANSFORMS))
     {
         return(getEnumerationsAttribute(AttributeName.PRESENTTRANSFORMS, null, EnumOrientation.getEnum(0), false));
     }
     return(getAllowedTransforms());
 }
Example #18
0
 public virtual List <ValuedEnum> getAllowedTransforms()
 {
     return(getEnumerationsAttribute(AttributeName.ALLOWEDTRANSFORMS, null, EnumOrientation.getEnum(0), false));
 }