Beispiel #1
0
        public void ContructorTest()
        {
            Legality model;

            try
            {
                // Test exception is thrown.
                model = new Legality(null);
                Assert.True(false);
            }
            catch (ArgumentNullException ex)
            {
                Assert.Equal("item", ex.ParamName);
            }
            catch
            {
                Assert.True(false);
            }

            var dto = new LegalityDto()
            {
                Format       = "format1",
                LegalityName = "fake name"
            };

            model = new Legality(dto);

            Assert.Equal(dto.Format, model.Format);
            Assert.Equal(dto.LegalityName, model.LegalityName);
        }
Beispiel #2
0
    public MoveResult Move(Position origin, Position destination)
    {
        var move = new Move(origin, destination, this.Board);

        move.Legality = Legality.CheckMove(move, this.Board, this.Turn);

        this.LastAttemptedMove = move;

        switch (move.Legality)
        {
        case Rule.None:
            this.LastMove = this.LastAttemptedMove;

            this.CompleteMove(move);

            var win = false;
            if (win)
            {
                move.MoveResult = MoveResult.Checkmate;
                return(MoveResult.Checkmate);
            }

            move.MoveResult = MoveResult.Legal;
            break;

        case Rule.InCheck:
            move.MoveResult = MoveResult.Check;
            break;

        default:
            move.MoveResult = MoveResult.Illegal;
            break;
        }

        return(move.MoveResult);
    }
        private UpsertResult <Legality> UpsertLegality(Card card, string format, bool legal, bool leader)
        {
            var result = new UpsertResult <Legality>();

            var legality = card.Legalities.SingleOrDefault(l => l.Format == format);

            if (legality == null)
            {
                legality = new Legality()
                {
                    Card   = card,
                    Format = format
                };

                result.ObjectsToAdd.Add(legality);
            }

            legality.Legal            = legal;
            legality.LegalAsCommander = leader;

            result.MainObject = legality;

            return(result);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start");

            var serializer = new JsonSerializer();
            Dictionary <string, Models.Set> data = new Dictionary <string, Models.Set>();

            using (var s = File.Open(_path, FileMode.Open))
                using (var sr = new StreamReader(s))
                    using (var reader = new JsonTextReader(sr))
                    {
                        while (reader.Read())
                        {
                            if (reader.TokenType == JsonToken.StartObject)
                            {
                                data = serializer.Deserialize <Dictionary <string, Models.Set> >(reader);
                            }
                        }
                    }

            foreach (var set in data.OrderBy(x => x.Value.ReleaseDate))
            {
                Console.WriteLine("Inserting set: " + set.Value.Name);

                using (var context = new Context())
                {
                    if (context.Sets.Any(s => s.Name == set.Value.Name))
                    {
                        Console.WriteLine("Skipping set: " + set.Value.Name);
                    }
                    else
                    {
                        var newSet = new Set
                        {
                            Block              = set.Value.Block,
                            Booster            = set.Value.Booster,
                            Border             = set.Value.Border,
                            Code               = set.Value.Code,
                            GathererCode       = set.Value.GathererCode,
                            MagicCardsInfoCode = set.Value.MagicCardsInfoCode,
                            Name               = set.Value.Name,
                            OldCode            = set.Value.OldCode,
                            OnlineOnly         = set.Value.OnlineOnly,
                            ReleaseDate        = set.Value.ReleaseDate,
                            Type               = set.Value.Type,
                            Cards              = new List <Card>()
                        };
                        foreach (var card in set.Value.Cards)
                        {
                            Console.WriteLine("\tInserting card: " + card.Name);

                            var newCard = new Card
                            {
                                Artist        = card.Artist,
                                Border        = card.Border,
                                CardId        = card.Id,
                                Cmc           = card.Cmc,
                                ColorIdentity = card.ColorIdentity,
                                Colors        = card.Colors,
                                Flavor        = card.Flavor,
                                Hand          = card.Hand,
                                ImageName     = card.ImageName,
                                Layout        = card.Layout,
                                Life          = card.Life,
                                Loyalty       = card.Loyalty,
                                ManaCost      = card.ManaCost,
                                MciNumber     = card.MciNumber,
                                MultiverseId  = card.MultiverseId,
                                Name          = card.Name,
                                Names         = card.Names,
                                Number        = card.Number,
                                OriginalText  = card.OriginalText,
                                OriginalType  = card.OriginalType,
                                Power         = card.Power,
                                Printings     = card.Printings,
                                Rarity        = card.Rarity,
                                ReleaseDate   = card.ReleaseDate,
                                Reserved      = card.Reserved,
                                Source        = card.Source,
                                Starter       = card.Starter,
                                SubTypes      = card.SubTypes,
                                SuperTypes    = card.SuperTypes,
                                Text          = card.Text,
                                TimeShifted   = card.TimeShifted,
                                Toughness     = card.Toughness,
                                Type          = card.Type,
                                Types         = card.Types,
                                Variations    = card.Variations,
                                WaterMark     = card.WaterMark,
                                ForeignNames  = new List <ForeignName>(),
                                Legalities    = new List <Legality>(),
                                Rulings       = new List <Ruling>()
                            };

                            if (card.ForeignNames != null)
                            {
                                foreach (var name in card.ForeignNames)
                                {
                                    var newName = new ForeignName
                                    {
                                        Language     = name.Language,
                                        MultiverseId = name.MultiverseId,
                                        Name         = name.Name
                                    };

                                    newCard.ForeignNames.Add(newName);
                                }
                            }

                            if (card.Legalities != null)
                            {
                                foreach (var legality in card.Legalities)
                                {
                                    var newLegal = new Legality
                                    {
                                        Format         = legality.Format,
                                        LegalityDetail = legality.LegalityDetail
                                    };

                                    newCard.Legalities.Add(newLegal);
                                }
                            }

                            if (card.Rulings != null)
                            {
                                foreach (var ruling in card.Rulings)
                                {
                                    var newRuling = new Ruling
                                    {
                                        Date = ruling.Date,
                                        Text = ruling.Text
                                    };

                                    newCard.Rulings.Add(newRuling);
                                }
                            }

                            newSet.Cards.Add(newCard);
                        }

                        context.Sets.Add(newSet);
                        context.SaveChanges();
                    }
                }
            }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
        private static bool GetLegality(int originRank, int originFile, int destinationRank, int destinationFile, Board board)
        {
            var move = GetMove(originRank, originFile, destinationRank, destinationFile, board);

            return(Legality.CheckMove(move, board, new Player(move.Piece.Color)) == Rule.None);
        }
Beispiel #6
0
        public static Set ConvertToModel(string json)
        {
            //deserialize json into import model
            var importSet = JsonConvert.DeserializeObject <ImportSet>(json);

            //use automapper to map into correct model
            var convertedModel = Mapper.Map <Set>(importSet);

            //TODO beautify
            //Manual mapping that I couldn't do in automapper
            #region manual mapping
            foreach (ImportCard card in importSet.Cards)
            {
                //verify that the card has a number
                if (card.MciNumber != null)
                {
                    //first to allow for duplicates in data
                    var newCard = convertedModel.Cards.First(x => x.Number == card.MciNumber);

                    if (card.Supertypes != null)
                    {
                        foreach (string supertype in card.Supertypes)
                        {
                            var super = new CardSuperType();
                            super.Name = supertype;
                            newCard.CardSuperType.Add(super);
                        }
                    }

                    if (card.Types != null)
                    {
                        foreach (string type in card.Types)
                        {
                            var newType = new CardType();
                            newType.Name = type;
                            newCard.CardType.Add(newType);
                        }
                    }

                    if (card.Subtypes != null)
                    {
                        foreach (string subtype in card.Subtypes)
                        {
                            var sub = new CardSubType();
                            sub.Name = subtype;
                            newCard.CardSubType.Add(sub);
                        }
                    }

                    if (card.ColorIdentity != null)
                    {
                        foreach (string coloridentity in card.ColorIdentity)
                        {
                            var identity = new ColorIdentity();
                            Enum.TryParse(coloridentity, out EColorIdentity ciEnum);
                            identity.Name = ciEnum;
                            newCard.ColorIdentity.Add(identity);
                        }
                    }

                    if (card.Colors != null)
                    {
                        foreach (string color in card.Colors)
                        {
                            var c = new Color();
                            Enum.TryParse(color, out EColor cEnum);
                            c.Name = cEnum;
                            newCard.Color.Add(c);
                        }
                    }

                    if (card.Rarity != null)
                    {
                        var r = new Rarity();
                        Enum.TryParse(card.Rarity, out ERarity rEnum);
                        r.Name         = rEnum;
                        newCard.Rarity = r;
                    }

                    if (card.Legalities != null)
                    {
                        var legal = new Legality();

                        foreach (ImportLegality legality in card.Legalities)
                        {
                            switch (legality.Format)
                            {
                            case "Vintage":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Vintage = true;
                                }
                                break;

                            case "Legacy":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Legacy = true;
                                }
                                break;

                            case "Commander":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Commander = true;
                                }
                                break;

                            case "Modern":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Modern = true;
                                }
                                break;

                            case "Standard":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Standard = true;
                                }
                                break;

                            case "Arena":
                                if (legality.Legality == "Legal")
                                {
                                    legal.Arena = true;
                                }
                                break;

                            default:
                                break;
                            }
                        }

                        if (newCard.Rarity.Name == 0)
                        {
                            legal.Pauper = true;
                        }

                        newCard.Legality = legal;
                    }

                    if (card.Power == null)
                    {
                        newCard.Power = " ";
                    }

                    if (card.Toughness == null)
                    {
                        newCard.Toughness = " ";
                    }
                }
            }
            #endregion

            return(convertedModel);
        }