private void prepareOpponent()
        {
            Controller op          = game.CurrentOpponent;
            Card       placeHolder = PlaceHolder;

            op.DeckCards = DebugDecks.PartialObservationDeck;

            var hand = op.HandZone;
            var span = hand.GetSpan();

            for (int i = span.Length - 1; i >= 0; --i)
            {
                hand.Remove(span[i]);
                game.AuraUpdate();
                hand.Add(Entity.FromCard(in op, in placeHolder));
            }

            var deck = new DeckZone(op);

            for (int i = 0; i < op.DeckZone.Count; i++)
            {
                deck.Add(Entity.FromCard(in op, in placeHolder));
            }
            op.DeckZone = deck;
        }
 private void writeDeckZone(StringBuilder result, DeckZone zone, string prefix)
 {
     foreach (var id in zone.Order)
     {
         result.Append(prefix);
         result.AppendLine($"{zone.Count[id]} {_cardRepo.CardsById[id].NameEn}");
     }
 }
Example #3
0
 void Awake()
 {
     myDeckZone = GetComponent <DeckZone> ();
     if (myDeckZone == null)
     {
         Debug.LogError("we don't have a deckzone with a deck macro on " + name);
     }
 }
Example #4
0
 public void Draw(int number, DeckZone deck)
 {
     for (int i = 0; i < number; ++i)
     {
         Tile tile = deck.Draw();
         tile.Owner = this;
         this.handZone.AddTile(tile);
     }
 }
Example #5
0
        private void writeCards(StringBuilder result, DeckZone deckZone)
        {
            foreach (var cardId in deckZone.Order)
            {
                var count = deckZone.Count[cardId];
                var card  = _repository.CardsById[cardId];

                result.AppendLine($"{count} {ToMtgoName(card)}");
            }
        }
Example #6
0
        private void writeCards(StringBuilder result, DeckZone zone, string prefix)
        {
            foreach (var cardId in zone.Order)
            {
                var count = zone.Count[cardId];
                var card  = _repository.CardsById[cardId];

                result.AppendLine($"{prefix}{count} [{card.SetCode}:{0}] {card.NameNormalized}");
            }
        }
        public void CreateFullInformationGame(List <Card> deck_player1, DeckZone deckzone_player1, HandZone handzone_player1, List <Card> deck_player2, DeckZone deckzone_player2, HandZone handzone_player2)
        {
            game.Player1.DeckCards = deck_player1;
            game.Player1.DeckZone  = deckzone_player1;
            game.Player1.HandZone  = handzone_player1;

            game.Player2.DeckCards = deck_player2;
            game.Player2.DeckZone  = deckzone_player2;
            game.Player2.HandZone  = handzone_player2;
        }
Example #8
0
 private void writeCards(StringBuilder result, DeckZone deckZone)
 {
     foreach (var cardId in deckZone.Order)
     {
         var count = deckZone.Count[cardId];
         var card  = _cardRepo.CardsById[cardId];
         var set   = _forgeSetRepo.ToForgeSet(card.SetCode);
         result.AppendLine($"{count} {card.NameNormalized}|{set}");
     }
 }
Example #9
0
        private DeckZone GetDeckZone(SabberStoneCore.Model.Zones.DeckZone zone)
        {
            var result = new DeckZone();
            var span   = zone.GetSpan();

            for (int i = 0; i < span.Length; i++)
            {
                result.Entities.Add(GetPlayable(span[i], true));
            }
            return(result);
        }
Example #10
0
        private static InequalityFlags Equals(DeckZone a, DeckZone b)
        {
            if (a.Count == b.Count)
            {
                return(InequalityFlags.None);
            }
            return(InequalityFlags.Attributes);

            // TODO
            // Cost, ATK, HEALTH
        }
Example #11
0
 private static void add(Card card, int count, DeckZone collection)
 {
     if (collection.Count.ContainsKey(card.Id))
     {
         collection.Count[card.Id] += count;
     }
     else
     {
         collection.Count[card.Id] = count;
         collection.Order.Add(card.Id);
     }
 }
Example #12
0
        private void writeCards(StringBuilder result, DeckZone deckZone)
        {
            foreach (var cardId in deckZone.Order)
            {
                var card = Repo.CardsById[cardId].Faces.Main;
                if (card == null)
                {
                    continue;
                }

                var count = deckZone.Count[cardId];
                result.AppendLine($"{count} {ToMtgoName(card)}");
            }
        }
Example #13
0
        private DeckZone GetDeckZone(IProjectVersion version, MainVerticalZone mvz)
        {
            var p = SurfaceObject.CenterOfGravity;

            return(DeckZone.GetDefinedDeckZones(version)
                   .Select(z => {
                var s = version.GeometryManager.GetSurface(z.Surface);
                var pClosest = s.GetClosestPoint(p);
                return new { Zone = z, Point = pClosest };
            }).OrderBy(item => item.Point.GetDistance(p))
                   .Take(2)
                   .OrderByDescending(item => item.Point.Z)
                   .Select(item => item.Zone)
                   .FirstOrDefault());
        }
Example #14
0
    public void UpdateZone(Player player, DeckZone deckZone)
    {
        List <Tile> playerTiles = deckZone.Tiles.FindAll(t => t.Owner == player);

        foreach (TileGO go in this.deck)
        {
            go.gameObject.SetActive(false);
        }

        foreach (Tile tile in playerTiles)
        {
            this.deck[tile.DeckIdx].gameObject.SetActive(transform);
            this.deck[tile.DeckIdx].Tile = tile;
            this.deck[tile.DeckIdx].UpdateTile();
        }
    }
Example #15
0
        /// <summary>
        /// Initializes this agent's estimation of the opponent
        /// </summary>
        /// <param name="opponent"></param>
        /// <returns></returns>
        void SetupOpponent(Game game)
        {
            BlindGame     = game.Clone();
            Opponent      = BlindGame.CurrentOpponent;
            Opponent.Game = BlindGame;

            OpponentDeck     = DeckQuery.GetMostPopular(Opponent.HeroClass);
            OpponentDeckZone = new DeckZone(Opponent)
            {
                Controller = Opponent
            };

            Opponent.Deck     = OpponentDeck.Clone();
            Opponent.DeckZone = OpponentDeckZone;

            OpponentGraveyardZone = new GraveyardZone(Opponent);
            OpponentSecretZone    = new SecretZone(Opponent);

            OpponentSet = true;
        }
Example #16
0
        /// <summary>
        /// TODO: API
        /// </summary>
        /// <param name="oppGame"></param>
        /// <param name="opponent">the controller of the opponent</param>
        /// <param name="predicitionMap">the map with all predictions</param>
        /// <param name="newSimulations"></param>
        /// <returns></returns>
        private double simulateOpponentWithPrediction(double lowerTimeBound, double timePerLeaf, POGame.POGame oppGame, Controller opponent,
                                                      List <Prediction> predicitionMap, ref Dictionary <POGame.POGame, List <MCTSNode> > newSimulations)
        {
            double predictionScore = 0;

            if (predicitionMap?.Any() ?? false)
            {
                int denominator = predicitionMap.Count;
                var scorings    = predicitionMap.GroupBy(p => p.Deck.Scoring)
                                  .Select(c => new MCTSNode.ScoreExt(((double)c.Count() / denominator), c.Key))
                                  .OrderByDescending(s => s.Value).ToList();

                // the simulation time for one prediction
                double timePerPrediction = timePerLeaf / predicitionMap.Count;

                // use prediction for each game
                for (int i = 0; i < predicitionMap.Count; i++)
                {
                    Prediction prediction   = predicitionMap[i];
                    var        setasideZone = opponent.ControlledZones[Zone.SETASIDE] as SetasideZone;
                    setasideZone = new SetasideZone(opponent);

                    // create deck zone
                    List <Card> deckCards = prediction.Deck.Cards;
                    var         deckZone  = opponent.ControlledZones[Zone.DECK] as DeckZone;
                    deckZone = new DeckZone(opponent);
                    createZone(opponent, deckCards, deckZone, ref setasideZone);
                    deckZone.Shuffle();

                    // create hand zone
                    List <Card> handCards = prediction.Hand.Cards;
                    var         handZone  = opponent.ControlledZones[Zone.HAND] as HandZone;
                    handZone = new HandZone(opponent);
                    createZone(opponent, handCards, handZone, ref setasideZone);

                    var    oppLeafNodes = new List <MCTSNode>();
                    IScore oppStrategy  = prediction.Deck.Scoring;

                    // forward game
                    POGame.POGame forwardGame = oppGame.getCopy();

                    // upper time bound for simulation the opponent using the current prediction
                    double oppSimulationTime = lowerTimeBound + (i + 1) * timePerPrediction / 2;

                    // simulate opponent's moves
                    while (forwardGame != null &&
                           forwardGame.State == State.RUNNING &&
                           forwardGame.CurrentPlayer.Id == opponent.Id)
                    {
                        // simulate
                        var      oppRoot     = new MCTSNode(opponent.Id, scorings, forwardGame, null, null);
                        MCTSNode bestOppNode = simulate(oppSimulationTime, oppRoot, ref oppLeafNodes);
                        // get solution
                        List <PlayerTask> solutions = bestOppNode.GetSolution();
                        for (int j = 0; j < solutions.Count && (forwardGame != null); j++)
                        {
                            PlayerTask oppTask = solutions[j];
                            Dictionary <PlayerTask, POGame.POGame> dir = forwardGame.Simulate(new List <PlayerTask> {
                                oppTask
                            });
                            forwardGame = dir[oppTask];

                            if (forwardGame != null && forwardGame.CurrentPlayer.Choice != null)
                            {
                                break;
                            }
                        }
                    }

                    // upper time bound for simulation the player using the forwarded game
                    double simulationTime = oppSimulationTime + timePerPrediction / 2;
                    double score          = 0;
                    var    leafs          = new List <MCTSNode>();

                    // simulate player using forwarded opponent game
                    while (forwardGame != null &&
                           forwardGame.State == State.RUNNING &&
                           forwardGame.CurrentPlayer.Id == _playerId)
                    {
                        // simulate
                        var root = new MCTSNode(_playerId, new List <MCTSNode.ScoreExt> {
                            new MCTSNode.ScoreExt(1.0, _scoring)
                        }, forwardGame, null, null);
                        MCTSNode bestNode = simulate(simulationTime, root, ref leafs);
                        // get solution
                        List <PlayerTask> solutions = bestNode.GetSolution();
                        for (int j = 0; j < solutions.Count && (forwardGame != null); j++)
                        {
                            PlayerTask task = solutions[j];
                            Dictionary <PlayerTask, POGame.POGame> dir = forwardGame.Simulate(new List <PlayerTask> {
                                task
                            });
                            forwardGame = dir[task];

                            if (forwardGame != null && forwardGame.CurrentPlayer.Choice != null)
                            {
                                break;
                            }
                        }
                        // TODO: maybe penalty forwardGame == null
                        score = bestNode.TotalScore;
                    }
                    predictionScore += score;

                    if (forwardGame != null)
                    {
                        newSimulations.Add(forwardGame, leafs);
                    }
                }
            }
            return(predictionScore);
        }
Example #17
0
        private string GetArrangementName(MainVerticalZone mvz, DeckZone dz)
        {
            var str = GetGenericStructureType();

            return("STR*" + str + "_" + mvz.Index + "_" + dz.ID);
        }
Example #18
0
        private IHierarchicalArrangement GetLeafArrangement(IProjectVersion version, MainVerticalZone mvz, DeckZone dz)
        {
            var name    = GetArrangementName(mvz, dz);
            var deckArr = dz.GetArrangement(version, mvz);
            var leafArr = deckArr.SubArrangements.FirstOrDefault(arr => arr.Name == name);

            if (leafArr == null)
            {
                leafArr = deckArr.AddSubArrangement(name);
            }
            return(leafArr);
        }
Example #19
0
 public void SetDeck(DeckZone deckZone)
 {
     CountById = deckZone.Count.ToDictionary();
     Order     = deckZone.Order.ToList();
 }
Example #20
0
        private int getCardsLeftInDeck(Controller player)
        {
            DeckZone deckZone = player.DeckZone;

            return(deckZone.Count);
        }