コード例 #1
0
 public void updateCounter(Salmon salmon)
 {
     int pos = salmon.getBoundingBox().X + salmon.getBoundingBox().Width;
     int initialPos = salmon.getInitialPos();
     if (initialPos < (int)_frameWidth / 2 && pos > (int)_frameWidth / 2)
     {
         Console.WriteLine("+1");
     }
     else if(initialPos > (int)_frameWidth / 2 && pos < (int)_frameWidth / 2)
     {
         Console.WriteLine("-1");
     }
 }
コード例 #2
0
ファイル: MarineFactory.cs プロジェクト: ratache/AnimalMotel
        public static MarineAnimal CreateMarine(MarineSpecies Species)
        {
            MarineAnimal animalObj = null;//Marine animal type not know yet.

            //Lets determine users choice of animal.
            switch (Species)
            {
                case MarineSpecies.Crayfish:
                    animalObj = new Crayfish();
                    break;
                case MarineSpecies.Salmon:
                    animalObj = new Salmon();
                    break;

                default:
                    Debug.Assert(false, "Not implemented");
                    break;
            }

            //Set animal category
            animalObj.Category = CategoryType.Marine;

            return animalObj;//Return created instance of object marine animal
        }
コード例 #3
0
ファイル: EntityHelpers.cs プロジェクト: lvyitian/Alex
        public static Entity Create(this EntityType entityType, World world)
        {
            Entity entity = null;

            switch (entityType)
            {
            case EntityType.None:
                return(null);

            case EntityType.Chicken:
                entity = new Chicken(world);
                break;

            case EntityType.Cow:
                entity = new Cow(world);
                break;

            case EntityType.Pig:
                entity = new Pig(world);
                break;

            case EntityType.Sheep:
                entity = new Sheep(world);
                break;

            case EntityType.Wolf:
                entity = new Wolf(world);
                break;

            case EntityType.Villager:
                entity = new Villager(world);
                break;

            case EntityType.MushroomCow:
                entity = new Mooshroom(world);
                break;

            case EntityType.Squid:
                entity = new Squid(world);
                break;

            case EntityType.Rabbit:
                entity = new Rabbit(world);
                break;

            case EntityType.Bat:
                entity = new Bat(world);
                break;

            case EntityType.IronGolem:
                entity = new VillagerGolem(world);
                break;

            case EntityType.SnowGolem:
                entity = new Snowman(world);
                break;

            case EntityType.Ocelot:
                entity = new Ocelot(world);
                break;

            case EntityType.Zombie:
                entity = new Zombie(world);
                break;

            case EntityType.Creeper:
                entity = new Creeper(world);
                break;

            case EntityType.Skeleton:
                entity = new Skeleton(world);
                break;

            case EntityType.Spider:
                entity = new Spider(world);
                break;

            case EntityType.ZombiePigman:
                entity = new ZombiePigman(world);
                break;

            case EntityType.Slime:
                entity = new Slime(world);
                break;

            case EntityType.Endermite:
                entity = new Endermite(world);
                break;

            case EntityType.Enderman:
                entity = new Enderman(world);
                break;

            case EntityType.Silverfish:
                entity = new Silverfish(world);
                break;

            case EntityType.CaveSpider:
                entity = new CaveSpider(world);
                break;

            case EntityType.Ghast:
                entity = new Ghast(world);
                break;

            case EntityType.MagmaCube:
                entity = new MagmaCube(world);
                break;

            case EntityType.Blaze:
                entity = new Blaze(world);
                break;

            case EntityType.ZombieVillager:
                entity = new ZombieVillager(world);
                break;

            case EntityType.Witch:
                entity = new Witch(world);
                break;

            case EntityType.Stray:
                entity = new Stray(world);
                break;

            case EntityType.Husk:
                entity = new Husk(world);
                break;

            case EntityType.WitherSkeleton:
                entity = new WitherSkeleton(world);
                break;

            case EntityType.Guardian:
                entity = new Guardian(world);
                break;

            case EntityType.ElderGuardian:
                entity = new ElderGuardian(world);
                break;

            case EntityType.Horse:
                entity = new Horse(world);
                break;

            case EntityType.ZombieHorse:
                entity = new ZombieHorse(world);
                break;

            case EntityType.PolarBear:
                entity = new PolarBear(world);
                break;

            case EntityType.Shulker:
                entity = new Shulker(world);
                break;

            case EntityType.EnderDragon:
                entity = new EnderDragon(world);
                break;

            case EntityType.SkeletonHorse:
                entity = new SkeletonHorse(world);
                break;

            case EntityType.Wither:
                entity = new Wither(world);
                break;

            case EntityType.Evoker:
                entity = new EvocationIllager(world);
                break;

            case EntityType.Vindicator:
                entity = new VindicationIllager(world);
                break;

            case EntityType.Vex:
                entity = new Vex(world);
                break;

            case EntityType.FallingBlock:
                entity = new EntityFallingBlock(world);
                break;

            case EntityType.ArmorStand:
                entity = new EntityArmorStand(world, null);
                break;

            case EntityType.Arrow:
                entity = new ArrowEntity(world, null);
                break;

            case EntityType.Item:
                entity = new ItemEntity(world);
                break;

            case EntityType.Mooshroom:
                entity = new Mooshroom(world);
                break;

            case EntityType.Snowball:
                entity = new SnowballEntity(world, null);
                break;

            case EntityType.ThrownEgg:
                entity = new EggEntity(world, null);
                break;

            case EntityType.Salmon:
                entity = new Salmon(world);
                break;

            case EntityType.Donkey:
                entity = new Donkey(world);
                break;

            case EntityType.Llama:
                entity = new Llama(world);
                break;

            case EntityType.Mule:
                entity = new Mule(world);
                break;

            case EntityType.Fox:
                entity = new Fox(world);
                break;

            case EntityType.Parrot:
                entity = new Parrot(world);
                break;

            case EntityType.Phantom:
                entity = new Phantom(world);
                break;

            case EntityType.Bee:
                entity = new Bee(world);
                break;

            case EntityType.LlamaSpit:
                entity = new LlamaSpit(world);
                break;

            case EntityType.Cat:
                entity = new Cat(world);
                break;

            case EntityType.SmallFireball:
                entity = new SmallFireball(world);
                break;

            case EntityType.Fireball:
                entity = new Fireball(world);
                break;

            //case EntityType.Human:
            //entity = new PlayerMob("test", world, );
            //	break;
            default:
                return(null);
            }

            return(entity);
        }
コード例 #4
0
ファイル: UnitTest1.cs プロジェクト: JulieLy8619/CSharp-zoo
        public void TestSalmon2Inherited()
        {
            Salmon Jasper = new Salmon();

            Assert.True(Jasper.HasSpine);
        }
コード例 #5
0
 /// <summary>
 /// Put complex types that are polymorphic, omitting the discriminator
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='complexBody'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <Salmon> PutMissingDiscriminatorAsync(this IPolymorphism operations, Salmon complexBody, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PutMissingDiscriminatorWithHttpMessagesAsync(complexBody, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #6
0
 /// <summary>
 /// Put complex types that are polymorphic, omitting the discriminator
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='complexBody'>
 /// </param>
 public static Salmon PutMissingDiscriminator(this IPolymorphism operations, Salmon complexBody)
 {
     return(operations.PutMissingDiscriminatorAsync(complexBody).GetAwaiter().GetResult());
 }
コード例 #7
0
 /// <summary>
 /// Put complex types that are polymorphic, but not at the root of the
 /// hierarchy; also have additional properties
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='complexBody'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task PutComplicatedAsync(this IPolymorphism operations, Salmon complexBody, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.PutComplicatedWithHttpMessagesAsync(complexBody, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
コード例 #8
0
 /// <summary>
 /// Put complex types that are polymorphic, but not at the root of the
 /// hierarchy; also have additional properties
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='complexBody'>
 /// </param>
 public static void PutComplicated(this IPolymorphism operations, Salmon complexBody)
 {
     operations.PutComplicatedAsync(complexBody).GetAwaiter().GetResult();
 }
コード例 #9
0
ファイル: FishString.cs プロジェクト: danilluk1/MVPFishing
        public Fish GetFishByStr()
        {
            Fish fish  = null;
            var  regex = new Regex(@".*(?=:)");

            var fishName = regex.Match(LoadStr);
            var name     = fishName.Value;

            regex = new Regex(@"\d+");

            var matches = regex.Matches(LoadStr);
            var sizeCf  = Convert.ToSingle(matches[0].Value) / 100;
            var minDeep = Convert.ToInt32(matches[1].Value);
            var maxDeep = Convert.ToInt32(matches[2].Value);

            regex = new Regex(@"(?<=\[).*(?=\])");

            var match     = regex.Match(LoadStr);
            var luresList = match.Value;

            var lures = luresList.Split(',');

            HashSet <FishBait> baits = new HashSet <FishBait>();

            foreach (var s in lures)
            {
                baits.Add(FishBait.GetFishBaitByName(s));
            }
            switch (name)
            {
            case "Щука":
                fish = new Pike(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Арктич. Голец":
                fish = new ArcticChar(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Жерех":
                fish = new Asp(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Лещ":
                fish = new Bream(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Налим":
                fish = new Burbot(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Голавль":
                fish = new Chub(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Карась Зол":
                fish = new GoldCarp(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Карась Сер":
                fish = new SilverCarp(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Хариус":
                fish = new Grayling(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Окунь":
                fish = new Perch(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Горбуша":
                fish = new PinkSalmon(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Плотва":
                fish = new Roach(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Рыбец":
                fish = new Rybets(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Сёмга":
                fish = new Salmon(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Подлещик":
                fish = new Scavenger(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Змееголов":
                fish = new SnakeHead(minDeep, maxDeep, sizeCf, baits);
                break;

            case "Линь":
                fish = new Tench(minDeep, maxDeep, sizeCf, baits);
                break;
            }
            return(fish);
        }
コード例 #10
0
        /// <summary>
        /// Put complex types that are polymorphic, omitting the discriminator
        /// </summary>
        /// <param name='complexBody'>
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        /// <exception cref="ErrorException">
        /// Thrown when the operation returned an invalid status code
        /// </exception>
        /// <exception cref="SerializationException">
        /// Thrown when unable to deserialize the response
        /// </exception>
        /// <exception cref="ValidationException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        /// Thrown when a required parameter is null
        /// </exception>
        /// <return>
        /// A response object containing the response body and response headers.
        /// </return>
        public async Task <HttpOperationResponse <Salmon> > PutMissingDiscriminatorWithHttpMessagesAsync(Salmon complexBody, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (complexBody == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "complexBody");
            }
            if (complexBody != null)
            {
                complexBody.Validate();
            }
            // Tracing
            bool   _shouldTrace  = ServiceClientTracing.IsEnabled;
            string _invocationId = null;

            if (_shouldTrace)
            {
                _invocationId = ServiceClientTracing.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("complexBody", complexBody);
                tracingParameters.Add("cancellationToken", cancellationToken);
                ServiceClientTracing.Enter(_invocationId, this, "PutMissingDiscriminator", tracingParameters);
            }
            // Construct URL
            var _baseUrl = Client.BaseUri.AbsoluteUri;
            var _url     = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "complex/polymorphism/missingdiscriminator").ToString();
            // Create HTTP transport objects
            var _httpRequest = new HttpRequestMessage();
            HttpResponseMessage _httpResponse = null;

            _httpRequest.Method     = new HttpMethod("PUT");
            _httpRequest.RequestUri = new System.Uri(_url);
            // Set Headers


            if (customHeaders != null)
            {
                foreach (var _header in customHeaders)
                {
                    if (_httpRequest.Headers.Contains(_header.Key))
                    {
                        _httpRequest.Headers.Remove(_header.Key);
                    }
                    _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value);
                }
            }

            // Serialize Request
            string _requestContent = null;

            if (complexBody != null)
            {
                _requestContent      = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(complexBody, Client.SerializationSettings);
                _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8);
                _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8");
            }
            // Send Request
            if (_shouldTrace)
            {
                ServiceClientTracing.SendRequest(_invocationId, _httpRequest);
            }
            cancellationToken.ThrowIfCancellationRequested();
            _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

            if (_shouldTrace)
            {
                ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse);
            }
            HttpStatusCode _statusCode = _httpResponse.StatusCode;

            cancellationToken.ThrowIfCancellationRequested();
            string _responseContent = null;

            if ((int)_statusCode != 200)
            {
                var ex = new ErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusCode));
                try
                {
                    _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                    Error _errorBody = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Error>(_responseContent, Client.DeserializationSettings);
                    if (_errorBody != null)
                    {
                        ex.Body = _errorBody;
                    }
                }
                catch (JsonException)
                {
                    // Ignore the exception
                }
                ex.Request  = new HttpRequestMessageWrapper(_httpRequest, _requestContent);
                ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent);
                if (_shouldTrace)
                {
                    ServiceClientTracing.Error(_invocationId, ex);
                }
                _httpRequest.Dispose();
                if (_httpResponse != null)
                {
                    _httpResponse.Dispose();
                }
                throw ex;
            }
            // Create Result
            var _result = new HttpOperationResponse <Salmon>();

            _result.Request  = _httpRequest;
            _result.Response = _httpResponse;
            // Deserialize Response
            if ((int)_statusCode == 200)
            {
                _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                try
                {
                    _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Salmon>(_responseContent, Client.DeserializationSettings);
                }
                catch (JsonException ex)
                {
                    _httpRequest.Dispose();
                    if (_httpResponse != null)
                    {
                        _httpResponse.Dispose();
                    }
                    throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
                }
            }
            if (_shouldTrace)
            {
                ServiceClientTracing.Exit(_invocationId, _result);
            }
            return(_result);
        }
コード例 #11
0
        public override void Solve()
        {
            var n = ReadInt();

            salmonsArr = new Salmon[n + 1];
            var lengthArr = ReadArrString().Select(int.Parse).ToArray();
            var timeArr   = ReadArrString().Select(int.Parse).ToArray();

            for (int i = 1; i < salmonsArr.Length; i++)
            {
                salmonsArr[i] = new Salmon
                {
                    Id                   = i,
                    length               = lengthArr[i - 1],
                    time                 = timeArr[i - 1],
                    enclosingCost        = -1,
                    endtime              = lengthArr[i - 1] + timeArr[i - 1],
                    maxCostOverlappingId = -1
                };
            }
            //temp for sorting for max overlapping cost
            salmonsArr[0] = new Salmon
            {
                Id = -1
            };

            //Array.Sort(salmonsArr, delegate (Salmon x, Salmon y)
            //{
            //    if (x.time.CompareTo(y.time) == 0)
            //    {
            //        return (x.endtime).CompareTo(y.endtime);
            //    }
            //    return x.time.CompareTo(y.time);
            //});

            PopulateNeighbours();

            for (int i = 1; i < salmonsArr.Length; i++)
            {
                //MaxOverlappingCost(-1, i);
                ComputeMaxCostPerSalmon(-1, i);
            }

            //replace enclosingLi with optimal neighbourhood group
            for (int i = 1; i < salmonsArr.Length; i++)
            {
                salmonsArr[i].enclosingLi = ComputeOptimalNeighbourHood(-1, i, new HashSet <int>());
            }

            Array.Sort(salmonsArr, delegate(Salmon x, Salmon y) {
                if (x.Id == -1)
                {
                    return(-1);
                }
                if (y.Id == -1)
                {
                    return(1);
                }
                return(x.distinctLi.Count.CompareTo(y.distinctLi.Count));
            });

            for (int i = 1; i < salmonsArr.Length; i++)
            {
                int cost = 0, maxOverlappingId = 0;
                var enumerater  = salmonsArr[i].overlappingLi.GetEnumerator();
                var isCostAdded = false;
                while (enumerater.MoveNext())
                {
                    if (enumerater.Current != i)
                    {
                        if (cost < salmonsArr[enumerater.Current].maxCost)
                        {
                            cost = salmonsArr[enumerater.Current].maxCost + 1;
                            //cost -= (salmonsArr[enumerater.Current].overlappingLi.Contains(i) ? 1 : 0);
                            cost            -= IsPresent(i, enumerater.Current) ? 1 : 0;
                            maxOverlappingId = enumerater.Current;
                            if (IsPresent(i, enumerater.Current, false) && !isCostAdded)
                            {
                                cost       += 1;
                                isCostAdded = true;
                            }
                        }
                    }
                }
                salmonsArr[i].maxCostOverlappingId = maxOverlappingId;
                //salmonsArr[i].maxOverlappingCostIncludingThis = cost + 1;
                salmonsArr[i].maxOverlappingCostIncludingThis = cost == 0? 1 : cost; // need to change property name
                //ans = Math.Max(ans, cost + 1);
            }

            FindMaxPair();

            Console.Write(ans);
        }