예제 #1
0
        public Boolean IsValidFieldLocations(int[] indices)
        {
            var closed = new List <Point>();

            for (var x = 0; x < WIDTH; x++)
            {
                for (var y = 0; y < HEIGHT; y++)
                {
                    var plot = Grid[y * WIDTH + x];
                    if (!(plot is Field) &&
                        !(plot is Empty && ((Empty)plot).HasStable))
                    {
                        closed.Add(new Point(x, y));
                    }
                }
            }

            var proposed = new List <Point>();

            foreach (var i in indices)
            {
                proposed.Add(IndexToCoords(i));
            }

            return(FarmyardPlacementValidator.AreValidPlots(WIDTH, HEIGHT, FieldLocations, closed, proposed));
        }
예제 #2
0
        public Boolean IsValidPastureLocations(List <int[]> pastures)
        {
            var closed = new List <Point>();

            for (var x = 0; x < WIDTH; x++)
            {
                for (var y = 0; y < HEIGHT; y++)
                {
                    var plot = Grid[y * WIDTH + x];
                    if (plot is Field || plot is Room)
                    {
                        closed.Add(new Point(x, y));
                    }
                }
            }

            var proposed = new List <Point>();

            foreach (var list in pastures)
            {
                foreach (var index in list)
                {
                    proposed.Add(IndexToCoords(index));
                }
            }

            return(FarmyardPlacementValidator.AreValidPlots(WIDTH, HEIGHT, null, closed, proposed));
        }
예제 #3
0
        /// <summary>
        /// Validates that both plow and sow data are valid, including checks for sowing
        /// proposed plow locations.
        /// </summary>
        /// <param name="fieldIndices"></param>
        /// <param name="sowIndices"></param>
        /// <returns></returns>
        public Boolean IsValidPlowAndSowLocations(int[] fieldIndices, SowData[] sowIndices)
        {
            var closed = new List <Point>();

            for (var x = 0; x < WIDTH; x++)
            {
                for (var y = 0; y < HEIGHT; y++)
                {
                    if (x < 0 || y < 0 || x >= WIDTH || y >= HEIGHT)
                    {
                        return(false);
                    }

                    var plot = Grid[y * WIDTH + x];
                    if (plot is Room ||
                        plot is Pasture ||
                        (plot is Empty && ((Empty)plot).HasStable))
                    {
                        closed.Add(new Point(x, y));
                    }
                }
            }

            var proposed = new List <Point>();

            foreach (var i in fieldIndices)
            {
                proposed.Add(IndexToCoords(i));
            }

            var fieldLocations = FieldLocations;

            if (!FarmyardPlacementValidator.AreValidPlots(WIDTH, HEIGHT, fieldLocations, closed, proposed))
            {
                return(false);
            }

            foreach (var sowData in sowIndices)
            {
                var i = sowData.Index;
                if (i < 0 || i > WIDTH * HEIGHT)
                {
                    return(false);
                }

                var x = i % WIDTH;
                var y = (int)(i / WIDTH);

                if (!fieldIndices.Contains(i) && !fieldLocations.Contains(new Point(x, y)))
                {
                    return(false);
                }

                if (fieldLocations.Contains(new Point(x, y)))
                {
                    if (((Field)Grid[y * WIDTH + x]).Sown.Count > 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }