예제 #1
0
        /// <summary>
        /// Конструктор репозитория с заполнением тестовым данными.
        /// </summary>
        public DeckInMemoryRepository()
        {
            Decks decks = new Decks();

            this.Save(decks.BaseDeck);
            this.Save(decks.PrivateDeck);
        }
        static void Main(string[] args)
        {
            Console.Write("This programm represents the blackjack game with opportunity to split");
            Console.Write(" cards, double wagers and surrender.\n");
            Console.WriteLine("You can choose one of 3 strategies to play:");
            Console.WriteLine("0 - basic strategy");
            Console.WriteLine("1 - cards counting strategy, based on basic strategy and cards count");
            Console.WriteLine("2 - simple strategy, based on basic strategy and players score at the moment");
            Console.WriteLine("The programm will print the approximate sum of your wagers when the game ends");
            Console.WriteLine("Please enter the correct number of strategy you want to play");
            int strategy = Convert.ToInt32(Console.ReadLine()); // in ascii table "0" has 48 number

            if (strategy < 0 || strategy > 2)
            {
                Console.WriteLine("You number isn't right.");
                return;
            }
            Bots  botsStrategy = (Bots)strategy;
            Decks playingDecks = new Decks();

            playingDecks.FillCards();
            double        win  = 0;
            BlackjackGame game = new BlackjackGame(playingDecks, 1600, botsStrategy); // 1600 is initial players money

            for (int i = 0; i < 40; i++)
            {
                win += game.Game();
            }
            Console.WriteLine("Approximate sum with 40 played rounds is {0}", win / 40.0);
            Console.WriteLine("Press enter button to exit");
            Console.ReadLine();
        }
예제 #3
0
        public ActionResult <List <Decks> > Post([FromBody] Decks deck)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var jwttoken  = new JwtSecurityToken(userToken);
            var userId    = Int32.Parse(jwttoken.Claims.Where(x => x.Type == ClaimTypes.NameIdentifier).FirstOrDefault()?.Value);

            var newDeck = new Decks()
            {
                Commander          = deck.Commander,
                SecondaryCommander = deck.SecondaryCommander == "" ? null : deck.SecondaryCommander,
                Name   = deck.Name,
                UserId = userId
            };

            this.__context.Add(newDeck);
            this.__context.SaveChanges();

            return(Ok(new Response <dynamic>()
            {
                Data = new
                {
                    DeckId = newDeck.Id
                },
                Success = true
            }));
        }
예제 #4
0
        public override int GetHashCode()
        {
            int num = 1;

            if (AccountData)
            {
                num ^= AccountData.GetHashCode();
            }
            if (Occupation)
            {
                num ^= Occupation.GetHashCode();
            }
            if (HeroData)
            {
                num ^= HeroData.GetHashCode();
            }
            if (Decks)
            {
                num ^= Decks.GetHashCode();
            }
            if (Companions)
            {
                num ^= Companions.GetHashCode();
            }
            if (Weapons)
            {
                num ^= Weapons.GetHashCode();
            }
            if (_unknownFields != null)
            {
                num ^= ((object)_unknownFields).GetHashCode();
            }
            return(num);
        }
예제 #5
0
 public CNetDeckVO[] GetDecks()
 {
     lock (Decks)
     {
         return(Decks.ToArray());
     }
 }
예제 #6
0
        /// <summary>
        /// Sort a sub-deck into its parent
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="child"></param>
        private void SortIntoSubdeck(DeckInformation parent, DeckInformation child)
        {
            int currentIndex = decks.IndexOf(child);
            int parentIndex  = decks.IndexOf(parent);

            //No need to do anything if it's already next to its parent
            if (currentIndex == parentIndex + 1)
            {
                return;
            }

            Decks.Remove(child);
            int childLevel = child.ChildLevel;

            parentIndex = decks.IndexOf(parent);

            for (int i = parentIndex + 1; i < decks.Count; i++)
            {
                int level = decks[i].ChildLevel;
                if (level > childLevel)
                {
                    continue;
                }

                if ((level < childLevel) || (Compare(child, decks[i]) < 0))
                {
                    Decks.Insert(i, child);
                    return;
                }
            }

            Decks.Add(child);
        }
예제 #7
0
    void CheckEmptyDeck(Decks option)
    {
        GameObject[] deck = { };
        if (option == Decks.PlayerOne)
        {
            deck = playerOneDeck;
        }
        else if (option == Decks.PlayerTwo)
        {
            deck = playerTwoDeck;
        }
        else if (option == Decks.Board)
        {
            deck = boardDeck;
        }

        int emptySlots = 0;

        for (int i = 0; i < deck.Length; i++)
        {
            int cardValue = deck[i].GetComponent <Card>().CardValue;
            if (cardValue < 0)
            {
                emptySlots++;
            }
        }
        if (emptySlots == deck.Length)
        {
            FillDeck(option);
        }
    }
예제 #8
0
        private void RemoveDeck(object obj)
        {
            var deck = obj as Deck;

            Decks.Remove(deck);
            DeckDatabase.DeleteDeck(deck);
        }
예제 #9
0
 public void RemoveDeck(ulong id)
 {
     lock (Decks)
     {
         Decks.RemoveAll(deck => deck.Index == id);
     }
 }
예제 #10
0
 private void RemoveChildrenFromDecks(SubDecks children)
 {
     for (int i = 0; i < children.Desks.Count; i++)
     {
         Decks.RemoveAt(children.StartIndex);
     }
 }
예제 #11
0
        public static void LoadDecks()
        {
            Console.Write("Loading decks... ");

            try
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(Json.JsonLocation);
                var           decks         = directoryInfo.GetFiles("*.json", SearchOption.AllDirectories);

                foreach (FileInfo deck in decks)
                {
                    string   deckName = Path.GetFileNameWithoutExtension(deck.Name);
                    CardDeck cardDeck = Json.Load <CardDeck>(deckName);
                    cardDeck.Name = deckName;

                    Decks.Add(cardDeck);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Empty deck!");
                return;
            }

            Decks.First().Include = true;

            Console.WriteLine("Done!");
        }
예제 #12
0
        public async Task MainAsync()
        {
            Decks.LoadDecks();

            client = new DiscordSocketClient();

            client.Log += Log;
            commands    = new CommandService();
            services    = new ServiceCollection()
                          .AddSingleton(client)
                          .AddSingleton <InteractiveService>()
                          .BuildServiceProvider();

            await InstallCommands();

            string token = string.Empty;

            using (StreamReader reader = new StreamReader("token"))
            {
                token = reader.ReadLine();
            }

            await client.LoginAsync(TokenType.Bot, token);

            await client.StartAsync();

            await Task.Delay(-1);
        }
예제 #13
0
        protected bool isNotSplitted = true;          // Is player hand not splited. We can split the hand only one time.

        public Player(byte dealersFirst, uint money, Decks playingDecks, uint wager = 0)
        {
            Money            = money;
            FirstWager       = wager;
            Money           -= FirstWager;
            PlayersDecisions = new Decisions[21];
            PlayingDecks     = new Decks();
            PlayingDecks     = playingDecks;
            for (int i = 0; i < 21; i++)
            {
                PlayersDecisions[i] = 0;
            }
            dealerCard = dealersFirst;
            FirstHand  = new byte[21];
            for (int i = 2; i < 21; i++)
            {
                FirstHand[i] = 0;
            }
            SecondHand = new byte[21];
            for (int i = 0; i < 21; i++)
            {
                SecondHand[i] = 0;
            }
            FirstHand[0] = PlayingDecks.GetCard();
            FirstHand[1] = PlayingDecks.GetCard();
            FirstSum     = 0;
            SecondSum    = 0;
        }
예제 #14
0
 private void MakeEnemyDeck()
 {
     m_enemyDeck = new Decks();
     m_enemyDeck.AddDinosaurToDeck(new Dinosaur(95, dinoAnimations[3]));
     m_enemyDeck.AddDinosaurToDeck(new Dinosaur(120, dinoAnimations[4]));
     m_enemyDeck.AddDinosaurToDeck(new Dinosaur(108, dinoAnimations[5]));
 }
예제 #15
0
 private void MakePlayerDeck()
 {
     m_playerDeck = new Decks();
     m_playerDeck.AddDinosaurToDeck(new Dinosaur(123, dinoAnimations[0]));
     m_playerDeck.AddDinosaurToDeck(new Dinosaur(129, dinoAnimations[1]));
     m_playerDeck.AddDinosaurToDeck(new Dinosaur(168, dinoAnimations[2]));
 }
예제 #16
0
        public override async Task Update()
        {
            IsLoadingDecks = true;
            Note           = _repository.GetGameNote()?.ToString();
            var deck = _repository.GetOpponentDeck();

            Cards.Clear();
            deck.Cards.ForEach(c => Cards.Add(c));
            PlayerClass = deck.Class.ToString();

            Decks.Clear();
            await Task.Run(() =>
            {
                var alldecks = _repository
                               .GetAllDecksWithTag(Strings.ArchetypeTag)
                               .Select(d => new ArchetypeDeck(d))
                               .ToList();
                var results = ViewModelHelper.MatchArchetypes(deck, alldecks);
                results.ForEach(r => Decks.Add(r));
                results.ForEach(r => _log.Info($"{r.Deck.Name} [{r.Similarity}, {r.Containment}]"));

                var firstDeck = Decks.FirstOrDefault();
                if (firstDeck != null && firstDeck.Similarity > MatchResult.THRESHOLD)
                {
                    DeckSelected(firstDeck);
                }

                IsLoadingDecks = false;
                IsNoteFocused  = true;
            });
        }
예제 #17
0
        public void Setup()
        {
            this.context = HubContextImplementation.GetContext;

            this.cardRepository             = new CardRepository();
            this.deckRepository             = new DeckRepository();
            this.discussionResultRepository = new DiscussionResultRepository();
            this.roomRepository             = new RoomRepository();
            this.userRepository             = new UserRepository();

            this.userService             = new UserService(this.userRepository, this.context);
            this.cardService             = new CardService(this.cardRepository, this.context, this.userService);
            this.deckService             = new DeckService(this.deckRepository, this.cardRepository, this.context, this.userService);
            this.discussionResultService = new DiscussionResultService(this.discussionResultRepository, this.cardRepository, this.userRepository);
            this.roomService             = new RoomService(this.roomRepository, this.userRepository, this.deckRepository, this.context, this.userService, this.discussionResultService);

            this.userService.AddUserToConnectionMap("TestUser", "TestConnection");

            this.cards             = new Cards();
            this.decks             = new Decks();
            this.discussionResults = new DiscussionResults();
            this.rooms             = new Rooms();
            this.users             = new Users();

            InvokedSignalRMethod = string.Empty;
        }
예제 #18
0
        public void SetResetDeck()
        {
            Decks.Clear();
            for (int j = 0; j < NumOfDecks; j++)
            {
                //Generate cards for deck that are numbers
                for (int i = 2; i < 11; i++)
                {
                    for (int NumofSuits = 1; NumofSuits < 5; NumofSuits++)
                    {
                        Decks.Add(i.ToString());
                    }
                }

                //Generate Face cards
                string[] FaceCards = { "J", "Q", "K", "A" };
                for (int i = 0; i < (FaceCards.Length); i++)
                {
                    for (int NumofSuits = 1; NumofSuits < 5; NumofSuits++)
                    {
                        Decks.Add(FaceCards[i]);
                    }
                }
            }
        }
예제 #19
0
 public CNetDeckVO GetDeck(ulong id)
 {
     lock (Decks)
     {
         return(Decks.FirstOrDefault(x => x.Index == id));
     }
 }
예제 #20
0
        public CNetDeckVO CreateOrSave(CNetDeckVO deckToSave, List <CNetCardVO> playerCards)
        {
            CNetDeckVO deck;

            lock (Decks)
            {
                deck = Decks.FirstOrDefault(d => deckToSave.Index == d.Index);
            }

            if (deck == null)
            {
                deck = AddDeck(deckToSave);
            }
            else
            {
                deck.Cards         = deckToSave.Cards;
                deck.DeckName      = deckToSave.DeckName;
                deck.IdCardPool    = deckToSave.IdCardPool;
                deck.IdLimitedPool = deckToSave.IdLimitedPool;
            }

            deck.DeckLevel = deck.CalculateDeckLevel(Cards);
            deck.CoverCard = Cards.FirstOrDefault(c => c.Index == deckToSave.CoverCard.Index) ?? new CNetCardVO();
            deck.SetCardInfo(playerCards);
            return(deck);
        }
        public byte BjFlag; // if player has blackjack

        public Dealer(Decks Cards, byte bjFlag = 0)
        {
            PlayingDecks = new Decks();
            PlayingDecks = Cards;
            DealerCards  = new byte[21];
            this.BjFlag  = bjFlag;
        }
 private void RefreshAvailableDecks()
 {
     if (AvailableDecks.Count == 0)
     {
         for (var i = 1; i <= 9; i++)
         {
             var key   = i.ToString(CultureInfo.InvariantCulture);
             var model = new AvailableDecksModel
             {
                 Slot           = key,
                 AvailableDecks =
                     new BindableCollection <DeckModel>(Decks.Where(x => x.Key == key || String.IsNullOrEmpty(x.Key))),
                 SelectedDeck = Decks.FirstOrDefault(x => x.Key == key)
             };
             model.PropertyChanged += AvailableDecksModel_OnPropertyChanged;
             AvailableDecks.Add(model);
         }
         NotifyOfPropertyChange(() => AvailableDecks);
     }
     else
     {
         for (var i = 1; i <= 9; i++)
         {
             var key = i.ToString(CultureInfo.InvariantCulture);
             AvailableDecks[i - 1].AvailableDecks =
                 new BindableCollection <DeckModel>(Decks.Where(x => x.Key == key || String.IsNullOrEmpty(x.Key)));
             AvailableDecks[i - 1].PropertyChanged -= AvailableDecksModel_OnPropertyChanged;
             AvailableDecks[i - 1].SelectedDeck     = Decks.FirstOrDefault(x => x.Key == key);
             AvailableDecks[i - 1].PropertyChanged += AvailableDecksModel_OnPropertyChanged;
         }
         NotifyOfPropertyChange(() => AvailableDecks);
     }
 }
 public BlackjackGame(Decks playingDecks, uint initialMoney)
 {
     PlayingCards      = new Decks();
     PlayingCards      = playingDecks;
     this.InitialMoney = initialMoney;
     PlayingDealer     = new Dealer(playingDecks, 0);
     PlayingDealer.SetFirstCard();
 }
 public BlackjackGame(Decks playingDecks, uint initialMoney, Bots strategy)
 {
     PlayingCards      = new Decks();
     PlayingCards      = playingDecks;
     this.strategy     = strategy;
     this.initialMoney = initialMoney;
     PlayingDealer     = new Dealer(playingDecks, 0);
 }
예제 #25
0
 private void UpdateDecks(List <DeckInformation> listDeck)
 {
     Decks.Clear();
     foreach (var deck in listDeck)
     {
         Decks.Add(deck);
     }
 }
        public void GameTest()
        {
            Decks playingDecks = new Decks();

            playingDecks.FillCards();
            byte[] gameCards = new byte[416];
            gameCards = playingDecks.Cards;
            byte          bjFlag;
            int           testResult;
            LibraryLoader libraryLoader = new LibraryLoader("../../../../BotsLibrary/BotsLibrary.dll");
            Assembly      asm           = libraryLoader.LoadLibrary();
            PluginHelper  pluginHelper  = new PluginHelper(asm);

            // Dealer has blackjack and player in both hands has blackjack too
            gameCards[0] = 10; gameCards[1] = 1; gameCards[2] = 1; gameCards[3] = 10;
            gameCards[4] = 10; gameCards[5] = 1; bjFlag = 3; testResult = 32;
            SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag);

            gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 10; gameCards[3] = 1;
            bjFlag       = 0; testResult = -16; // Dealer has blackjack, player's score is 20.
            SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag);

            gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 10; gameCards[3] = 7;
            bjFlag       = 0; testResult = 32; // Dealer has 17, player's score is 20.
            SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag);

            gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 5; gameCards[3] = 7;
            bjFlag       = 0; testResult = 8; // Player surrendered
            SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag);

            gameCards[0] = 9; gameCards[1] = 8; gameCards[2] = 8; gameCards[3] = 9; gameCards[4] = 10;
            gameCards[5] = 6; gameCards[6] = 10; bjFlag = 0; testResult = 64; // Player won with both hands
            SomeGameTest(pluginHelper, playingDecks, gameCards, testResult, bjFlag);
            // Now we test two games successively
            playingDecks.FillCards();
            gameCards    = playingDecks.Cards;
            gameCards[0] = 10; gameCards[1] = 10; gameCards[2] = 5; gameCards[3] = 7;
            bjFlag       = 0; testResult = 8; // Player surrendered
            uint          initialMoney = 1600;
            BlackjackGame testGame     = new BlackjackGame(playingDecks, initialMoney);

            object[] parameters = new object[] { testGame.PlayingDealer.DealerCards[0], (uint)testGame.InitialMoney, testGame.PlayingCards, (uint)16 };
            pluginHelper.CreatePlayer(parameters, 1);
            testGame.Player = pluginHelper.players[1];
            Assert.AreEqual(testGame.Game(), testResult);
            for (int i = 0; i < 416; i++)
            {
                Assert.AreEqual(testGame.PlayingCards.Cards[i], gameCards[i]);
            }
            // Second game
            gameCards[0] = 9; gameCards[1] = 8; gameCards[2] = 8; gameCards[3] = 9; gameCards[4] = 10;
            gameCards[5] = 6; gameCards[6] = 10; bjFlag = 0; testResult = 64; // Player won with both hands
            Assert.AreEqual(testGame.Game(), testResult);
            for (int i = 0; i < 416; i++)
            {
                Assert.AreEqual(testGame.PlayingCards.Cards[i], gameCards[i]);
            }
        }
예제 #27
0
        private void AddNewDeckAndCardCount(DeckDueNode deck)
        {
            Decks.Add(new DeckInformation(deck.NewCount, deck.LearnCount + deck.ReviewCount, deck.DeckId));

            if (!Collection.Deck.HasParent(deck.DeckId))
            {
                AddCardsCountToTotal(deck.NewCount, deck.LearnCount + deck.ReviewCount);
            }
        }
예제 #28
0
    public GameState(IEnumerable <Deck> decks, bool isAwaitingSubGameWinner)
    {
        var deckCopies = decks.Select(DeckHelper.GetDeckCopy).ToList();

        Decks = deckCopies;
        IsAwaitingSubGameWinner = isAwaitingSubGameWinner;
        StateString             = $"{IsAwaitingSubGameWinner}->{string.Join(";", Decks.Select(deck => deck.ToString()))}";
        StateStringHashCode     = StateString.GetHashCode();
    }
예제 #29
0
 public CNetDeckVO AddDeck(CNetDeckVO deck)
 {
     deck.Index = CNetDeckVO.NewIndex();
     lock (Decks)
     {
         Decks.Add(deck);
     }
     return(deck);
 }
예제 #30
0
 public PlayerData GetPlayerData()
 {
     return(new PlayerData()
     {
         Cards = Cards.ToArray(),
         Decks = Decks.ToArray(),
         Version = 1
     });
 }
예제 #31
0
파일: Card.cs 프로젝트: narlon/TOMClassic
 public abstract void SetData(Decks.DeckCard dc);