Пример #1
0
 public AcceptTradeEvent(Guid buyerId, ResourceClutch buyingResources, Guid sellerId, ResourceClutch sellingResources)
     : base(buyerId)
 {
     this.buyingResources  = buyingResources;
     this.sellerId         = sellerId;
     this.sellingResources = sellingResources;
 }
Пример #2
0
 public ResourceClutch(ResourceClutch r)
 {
     this.BrickCount  = r.BrickCount;
     this.GrainCount  = r.GrainCount;
     this.LumberCount = r.LumberCount;
     this.OreCount    = r.OreCount;
     this.WoolCount   = r.WoolCount;
 }
Пример #3
0
 private static ResourceClutch MultiplyByNaturalNumber(ResourceClutch operand1, int operand2)
 {
     return(new ResourceClutch(
                operand1.BrickCount * operand2,
                operand1.GrainCount * operand2,
                operand1.LumberCount * operand2,
                operand1.OreCount * operand2,
                operand1.WoolCount * operand2));
 }
Пример #4
0
        public void RemoveResources(ResourceClutch resourceClutch)
        {
            if (this.Resources.BrickCount - resourceClutch.BrickCount < 0 ||
                this.Resources.GrainCount - resourceClutch.GrainCount < 0 ||
                this.Resources.LumberCount - resourceClutch.LumberCount < 0 ||
                this.Resources.OreCount - resourceClutch.OreCount < 0 ||
                this.Resources.WoolCount - resourceClutch.WoolCount < 0)
            {
                throw new ArithmeticException("No resource count can be negative.");
            }

            this.Resources -= resourceClutch;
        }
Пример #5
0
        public ResourceClutch LoseResourcesOfType(ResourceTypes resourceType)
        {
            ResourceClutch resourceClutch = ResourceClutch.Zero;

            switch (resourceType)
            {
            case ResourceTypes.Brick: resourceClutch = new ResourceClutch(this.Resources.BrickCount, 0, 0, 0, 0); break;

            case ResourceTypes.Grain: resourceClutch = new ResourceClutch(0, this.Resources.GrainCount, 0, 0, 0); break;

            case ResourceTypes.Lumber: resourceClutch = new ResourceClutch(0, 0, this.Resources.LumberCount, 0, 0); break;

            case ResourceTypes.Ore: resourceClutch = new ResourceClutch(0, 0, 0, this.Resources.OreCount, 0); break;

            case ResourceTypes.Wool: resourceClutch = new ResourceClutch(0, 0, 0, 0, this.Resources.WoolCount); break;
            }

            if (resourceClutch != ResourceClutch.Zero)
            {
                this.Resources -= resourceClutch;
            }
            return(resourceClutch);
        }
Пример #6
0
 public ResourceTransaction(Guid receivingPlayerId, Guid givingPlayerId, ResourceClutch resources)
 {
     this.ReceivingPlayerId = receivingPlayerId;
     this.GivingPlayerId    = givingPlayerId;
     this.Resources         = resources;
 }
Пример #7
0
 public ResourceCollection(uint location, ResourceClutch resourceClutch)
 {
     this.Location  = location;
     this.Resources = resourceClutch;
 }
Пример #8
0
        public virtual void BuildInitialPlayerActions(PlayerDataModel[] otherPlayerData, bool rolledSeven)
        {
            this.decisionMaker.Reset();

            var resourceClutch = new ResourceClutch(this.Resources.BrickCount, this.Resources.GrainCount, this.Resources.LumberCount, this.Resources.OreCount, this.Resources.WoolCount);

            if (resourceClutch >= ResourceClutch.RoadSegment && this.RemainingRoadSegments > 0)
            {
                // Get the current road segment build candidates
                var roadPathCandidates = this.gameBoard.BoardQuery.GetRoadPathCandidates(this.settlementCandidates);

                if (roadPathCandidates != null)
                {
                    // Can build at least one road segment
                    // Get the total number of road segments that we could build regardless of resources
                    var roadSegmentCandidateCount = 0;
                    foreach (var rpc in roadPathCandidates)
                    {
                        roadSegmentCandidateCount += rpc.Value.Count;
                    }

                    // if building the next road segment wins the game then do this
                    if (this.VictoryPoints >= 8 && !this.HasLongestRoad)
                    {
                        var requiredRoadSegmentCount = 0;
                        foreach (var otherPlayer in otherPlayerData)
                        {
                            if (!otherPlayer.HasLongestRoad)
                            {
                                continue;
                            }

                            requiredRoadSegmentCount = this.gameBoard.BoardQuery.GetLongestRoadForPlayer(otherPlayer.Id).Count -
                                                       this.gameBoard.BoardQuery.GetLongestRoadForPlayer(this.Id).Count;

                            break;
                        }

                        // Number of road segments to build to have the longest road
                        requiredRoadSegmentCount++;

                        if (requiredRoadSegmentCount <= roadSegmentCandidateCount)
                        {
                            // The number of road segments that is required to have the longest road is smaller than
                            // the number of possible road segments that can be built.
                            var requiredResources = ResourceClutch.RoadSegment * requiredRoadSegmentCount;
                            if (requiredResources <= resourceClutch && requiredRoadSegmentCount <= this.RemainingRoadSegments)
                            {
                                // Got the required resources to build the required road segments
                                var roadPathCandidateIndex = 0;
                                var roadPathCandidate      = roadPathCandidates[roadPathCandidateIndex++];
                                var index = 0;
                                while (requiredRoadSegmentCount-- > 0)
                                {
                                    if (index == roadPathCandidate.Value.Count)
                                    {
                                        index             = 0;
                                        roadPathCandidate = roadPathCandidates[roadPathCandidateIndex++];
                                    }

                                    var destination = roadPathCandidate.Value[index++];

                                    var roadBuildSegmentAction = new PlaceRoadSegmentAction(Guid.Empty, roadPathCandidate.Key, destination);
                                    this.actions.Enqueue(roadBuildSegmentAction);
                                }
                            }
                        }
                    }

                    var workingRemainingRoadSegments = this.RemainingRoadSegments;

                    foreach (var kv in roadPathCandidates)
                    {
                        foreach (var destination in kv.Value)
                        {
                            // Can build road - boost it if road builder strategy or if building the next road segment
                            // will capture the 2VP
                            uint multiplier = 1;

                            Action action = () =>
                            {
                                var roadBuildSegmentAction = new PlaceRoadSegmentAction(Guid.Empty, kv.Key, destination);
                                this.actions.Enqueue(roadBuildSegmentAction);
                            };

                            this.decisionMaker.AddDecision(action, multiplier);
                        }
                    }
                }
            }

            if (resourceClutch >= ResourceClutch.Settlement && this.RemainingSettlements > 0)
            {
                // Got the resources to build settlement. Find locations that can be build on
                // Boost it if can build on target settlement - increase boost multiplier based on desirablity of target settlement
                // If building the settlement on any location will win the game then do it
            }

            if (resourceClutch >= ResourceClutch.City && this.RemainingCities > 0 && this.PlacedSettlements > this.PlacedCities)
            {
                // Got resources to build city and got settlements to promote.
                // If building the city will win the game then do it

                // Otherwise include city promotion as a possible decision
            }

            if (resourceClutch >= ResourceClutch.DevelopmentCard)
            {
                // Can buy development card
                // Boost it if playing development card buyer strategy
            }

            var decision = this.decisionMaker.DetermineDecision();

            if (decision != null)
            {
                decision.Invoke();
            }
        }
Пример #9
0
 public void AddResources(ResourceClutch resourceClutch)
 {
     this.Resources += resourceClutch;
 }