Exemplo n.º 1
0
        public GabStrategy()
            : base("ilmior")
        {
            _playedCards  = new Model.Deck();
            _winnedCards  = new Model.Deck();
            _loosedCards  = new Model.Deck();
            _missingCards = new Model.Deck(new[] { "Danari", "Coppe", "Bastoni", "Spade" }, new Range(1, 10));

            _league = new League();
        }
Exemplo n.º 2
0
 public static Model.Deck GetMockDeck()
 {
     Model.Deck retVal = new Model.Deck()
     {
         Cards = new List <Card>(),
         Name  = "Mock Deck"
     };
     for (int i = 0; i < 60; i++)
     {
         retVal.Cards.Add(GetMockCard());
     }
     return(retVal);
 }
Exemplo n.º 3
0
        //const string CONNECTIONSTRING = "Data Source=HPPROLIANT;Initial Catalog=MTG;User Id=Sql_Mtg;Password = Mag!c;";
        //const string CONNECTIONSTRING = @"Server=localhost\SQLEXPRESS;Database=MTG;Trusted_Connection=True;";

        public static Model.Deck GetDeck(int id)
        {
            FiveColorApi.Model.Deck retVal = new FiveColorApi.Model.Deck();

            //get cards from database
            SqlConnection sqlConnection1 = new SqlConnection(CONNECTIONSTRING);
            SqlCommand    cmd            = new SqlCommand();
            SqlDataReader reader;

            cmd.CommandText = "p_Get_Deck";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection  = sqlConnection1;

            sqlConnection1.Open();

            reader = cmd.ExecuteReader();

            //while (reader.Read())
            //    retVal.Cards.Add(Card.FromDataReader(reader));

            if (reader.Read())
            {
                DbDeck result;
                var    serializer = new XmlSerializer(typeof(DeckRepository));

                using (TextReader treader = new StringReader(reader[0].ToString()))
                {
                    result = (DbDeck)serializer.Deserialize(treader);
                }

                retVal = new Model.Deck()
                {
                    Name  = result.Name,
                    Cards = new List <Card>()
                };

                foreach (DeckCard card in result.Cards)
                {
                    Card newCard = new Card()
                    {
                        enabled        = true,
                        Id             = card.DeckCardId,
                        image          = card.ImageUrl,
                        Name           = card.Name,
                        tapped         = false,
                        ManaCost       = new List <string>(),
                        ManaProduction = new List <Mana>(),
                        Types          = new List <string>()
                    };
                    if (card.Types != null)
                    {
                        foreach (var type in card.Types)
                        {
                            newCard.Types.Add(type.Type);
                        }
                    }
                    if (card.ManaProduction != null)
                    {
                        foreach (var mana in card.ManaProduction)
                        {
                            newCard.ManaProduction.Add(new Mana()
                            {
                                ManaType = mana.Abbreviation, Quantity = mana.Quantity
                            });
                        }
                    }
                    if (card.ManaCost != null)
                    {
                        string cost = card.ManaCost.Mana.cost;
                        cost = cost.Replace("{", "").Replace("}", ",").Replace(" ", "");
                        newCard.ManaCost.Add(cost.Substring(0, cost.Length - 1));
                    }

                    retVal.Cards.Add(newCard);
                }
            }

            sqlConnection1.Close();

            return(retVal);
        }
Exemplo n.º 4
0
        public TrainingCardPage(Model.Deck deck, MainWindowViewModel mainWinVM)
        {
            InitializeComponent();

            DataContext = new ViewModel.TrainingCardViewModel(deck, mainWinVM);
        }
Exemplo n.º 5
0
        protected override Card OnChoose(IPlayer myself, GameState state)
        {
            var briscola = state.Briscola;

            SetLeagueComponents(state.Dish.Count, state.Players);

            var probabilityPoints  = new List <MoveValue>();
            var strategyCalculator = new BriscolaCalculator(state, _league);

            var currentDish = new Model.Deck(state.Dish);

            if (state.Dish.Count == 0)
            {
                // Penalizzare la briscola
                // Meglio non mettere carichi
                // Favorire le carte forti
                Debug.WriteLine("CARTE DI PRIMA MANO ");

                var cardsInfo = new List <CardInfo>();
                foreach (var handCard in new Model.Deck(myself.HandCards))
                {
                    var baseWeight = strategyCalculator.GetCardWeight(handCard, _missingCards);
                    var weight     = baseWeight;

                    if (handCard.IsCaricoOBriscola(briscola))
                    {
                        weight *= (decimal) - 1;
                    }

                    cardsInfo.Add(new CardInfo()
                    {
                        Card = handCard, Weight = weight
                    });
                    Debug.WriteLine($"Weight del {handCard.Value} di {handCard.Seed} : {baseWeight:000.000} -> {weight:000.000}");
                }

                // Seleziona la carta che massimizza il peso
                var selectedCard = cardsInfo.Where(x => x.Weight == cardsInfo.Max(y => y.Weight))
                                   .Select(x => x.Card)
                                   .First();

                if (myself.HandCards.Count(x => x.IsCaricoOBriscola(briscola)) == myself.HandCards.Count())
                {
                    Debug.WriteLine("Non posso far altro che giocare carico o briscola");
                }

                if (myself.HandCards.Count(x => x.IsCaricoOBriscola(briscola)) < myself.HandCards.Count() &&
                    (selectedCard.IsCaricoOBriscola(briscola)))
                {
                    Debug.WriteLine("******* Ho buttato carico o briscola ad cazzum");
                }

                return(selectedCard);
            }

            if (state.Dish.Count == 1)
            {
                // Vai su se possibile ma non di carico
                // Non buttare carico
                // Non butto butta la briscola se ci sono pochi punti oppure un'altra briscola
                var firstDishCard = state.Dish.First();

                Debug.WriteLine("CARTE DI SECONDA MANO ");

                var cardsInfo = new List <CardInfo>();
                foreach (var handCard in new Model.Deck(myself.HandCards))
                {
                    var baseWeight = strategyCalculator.GetCardWeight(handCard, _missingCards);
                    var weight     = baseWeight;

                    if (handCard.IsBriscola(briscola))
                    {
                        if (!firstDishCard.IsCarico() || firstDishCard.IsBriscola(briscola))
                        {
                            weight = Math.Abs(weight) * (decimal) - 1;
                        }
                    }

                    if (handCard.IsCaricoNonBriscola(briscola) &&
                        (!strategyCalculator.IsBestCardInDish(currentDish, handCard) ||
                         strategyCalculator.GetCardWinningProbabilty(handCard, _missingCards) < 1))
                    {
                        weight = Math.Abs(weight) * (decimal) - 1;
                    }

                    cardsInfo.Add(new CardInfo()
                    {
                        Card = handCard, Weight = weight
                    });
                    Debug.WriteLine($"Weight del {handCard.Value} di {handCard.Seed} : {baseWeight:000.000} -> {weight:000.000}");
                }

                // Seleziona la carta che massimizza il peso
                var selectedCard = cardsInfo.Where(x => x.Weight == cardsInfo.Max(y => y.Weight))
                                   .Select(x => x.Card)
                                   .First();

                if (!selectedCard.IsBriscola(briscola) && selectedCard.IsCarico() && strategyCalculator.GetCardWinningProbabilty(selectedCard, _missingCards) == 1 &&
                    strategyCalculator.IsBestCardInDish(currentDish, selectedCard))
                {
                    Debug.WriteLine("Butto carico perchè vince");
                }

                if (selectedCard.IsBriscola(briscola) && firstDishCard.GetScore() >= 10 && !firstDishCard.IsBriscola(briscola))
                {
                    Debug.WriteLine("Butto briscola perchè c'è un carico");
                }

                if (myself.HandCards.Count(x => (x.IsBriscola(briscola) && x.GetScore() < 10) || x.IsCarico()) == myself.HandCards.Count())
                {
                    Debug.WriteLine("Non posso far altro che giocare carico o briscola");
                }

                return(selectedCard);
            }

            if (state.Dish.Count() == 2)
            {
                Debug.WriteLine("CARTE DI TERZA MANO ");

                var iWin = _league.Contains(strategyCalculator.Winner(new Model.Deck(state.Dish)));

                var cardsInfo = new List <CardInfo>();
                foreach (var handCard in new Model.Deck(myself.HandCards))
                {
                    var baseWeight = strategyCalculator.GetCardWeight(handCard, _missingCards);
                    var weight     = baseWeight;

                    var tempDish = new Model.Deck(state.Dish);
                    var points   = tempDish.GetPoints();
                    tempDish.Add(handCard);

                    //prendere di carico
                    var baseProbability = strategyCalculator.GetCardWinningProbabilty(handCard, _missingCards);
                    if (handCard.IsCaricoNonBriscola(state.Briscola) && baseProbability < 1)
                    {
                        weight = Math.Abs(weight) * (decimal) - 1;
                    }

                    //prendere di carico di briscola
                    if (handCard.IsCaricoDiBriscola(state.Briscola) && (points < 10 || !strategyCalculator.IsBestCardInDish(tempDish, handCard)))
                    {
                        weight = Math.Abs(weight) * (decimal) - 1;
                    }

                    // prende di briscola
                    if (handCard.IsBriscola(state.Briscola) && !handCard.IsCarico() && (points < 10 || !strategyCalculator.IsBestCardInDish(tempDish, handCard)))
                    {
                        weight = Math.Abs(weight) * (decimal) - 1;
                    }

                    cardsInfo.Add(new CardInfo()
                    {
                        Card = handCard, Weight = weight
                    });
                    Debug.WriteLine($"Weight del {handCard.Value} di {handCard.Seed} : {baseWeight:000.000} -> {weight:000.000}");
                }

                var selectedCard = cardsInfo.Where(x => x.Weight == cardsInfo.Max(y => y.Weight))
                                   .Select(x => x.Card)
                                   .First();

                return(selectedCard);
            }

            if (state.Dish.Count() == 3)
            {
                Debug.WriteLine("CARTE DI QUARTA MANO");

                var iWin = _league.Contains(strategyCalculator.Winner(new Model.Deck(state.Dish)));

                var cardsInfo = new List <CardInfo>();
                foreach (var handCard in new Model.Deck(myself.HandCards))
                {
                    var baseWeight = strategyCalculator.GetCardWeight(handCard, _missingCards);
                    var weight     = baseWeight;

                    // Non buttare briscola
                    if (iWin && handCard.IsCaricoNonBriscola(state.Briscola))
                    {
                        weight = Math.Abs(weight) * (decimal) - 1;
                    }

                    if (!iWin)
                    {
                        var tempDish = new Model.Deck(state.Dish);
                        var points   = tempDish.GetPoints();

                        tempDish.Add(handCard);

                        //prendere di carico
                        if (handCard.IsCaricoNonBriscola(state.Briscola) && !strategyCalculator.IsBestCardInDish(tempDish, handCard))
                        {
                            weight = Math.Abs(weight) * (decimal) - 1;
                        }

                        //prendere di carico di briscola
                        if (handCard.IsCaricoDiBriscola(state.Briscola) && (points < 10 || !strategyCalculator.IsBestCardInDish(tempDish, handCard)))
                        {
                            weight = Math.Abs(weight) * (decimal) - 1;
                        }

                        // prende di briscola
                        if (handCard.IsBriscola(state.Briscola) && !handCard.IsCarico() && (points < 10 || !strategyCalculator.IsBestCardInDish(tempDish, handCard)))
                        {
                            weight = Math.Abs(weight) * (decimal) - 1;
                        }

                        // prende senza briscola
                        if (!handCard.IsBriscola(state.Briscola) && (points < 6 || !strategyCalculator.IsBestCardInDish(tempDish, handCard)))
                        {
                            weight = Math.Abs(weight) * (decimal) - 1;
                        }
                    }

                    cardsInfo.Add(new CardInfo()
                    {
                        Card = handCard, Weight = weight
                    });
                    Debug.WriteLine($"Weight del {handCard.Value} di {handCard.Seed} : {baseWeight:000.000} -> {weight:000.000}");
                }

                // Seleziona la carta che massimizza il peso
                var selectedCard = cardsInfo.Where(x => x.Weight == cardsInfo.Max(y => y.Weight))
                                   .Select(x => x.Card)
                                   .First();

                return(selectedCard);
            }

            // random
            return(myself.HandCards.OrderBy(x => new Guid()).First());
        }