Пример #1
0
        /// <summary>
        /// Processes active players cards to a Hand.
        /// </summary>
        private void ProcessPlayerHands()
        {
            // Public message of each player's hands.
            string message = "";

            // Process each player's cards to their highest value combination
            foreach (var player in ActivePlayers)
            {
                // Get player's best hand
                player.Hand       = new Hand(player.Cards.Concat(Table).ToArray());
                player.Hand.Owner = Users.Get(player.UserId);

                // Start message with current's player's name in capital letters
                message = player.Username.ToUpper();

                message += "| " + player.Hand.Text;

                // Report player's hand and all of his cards privately
                string privMessage = player.Hand.Text + " | -";

                foreach (var card in player.Hand.Cards)
                {
                    privMessage += " | " + card.Name;
                }

                Bot.Say(player.Username, privMessage);

                if (ActivePlayers.Length > 1)
                {
                    Bot.Action(message);
                }
            }
        }
Пример #2
0
 private void cmd_hv()
 {
     if (Message.CommandParts.Length > 1)
     {
         Bot.Action("| " + Message.CommandParts[1] + " " + Library.Hv);
     }
     else
     {
         Bot.Action("| " + Library.Hv);
     }
 }
Пример #3
0
        private void ReportCards()
        {
            string message = "";

            foreach (var card in River)
            {
                message += " | " + card.Name;
            }

            Bot.Action(message);
        }
Пример #4
0
        /// <summary>
        /// Parses the message into filters and creates the statistics table
        /// </summary>
        /// <param name="message">Message.Text</param>
        private void PrintStats(string message)
        {
            string filters = message.ToLower().Substring(
                message.IndexOf(Message.Command)
                );

            string orderBy = String.Empty;

            if (message.Contains("orderby "))
            {
                string order = message.Substring(
                    message.IndexOf("orderby ")
                    );

                orderBy = order.Substring(order.IndexOf(' ')).Trim(' ');
            }

            // Game ID filters
            List <int> GameIdFilters = new List <int>();

            // Season ID filters
            List <int> SeasonIdFilters = new List <int>();

            // User ID filters
            List <int> UserIdFilters = new List <int>();

            // Extra Columns that will be mapped
            List <string> ExtraColumns = new List <string>();

            // Get all Games listed in the database
            var Games = Params.ParamAttName("Game");

            // Check if specific Game Names were given as filters.
            foreach (var game in Games)
            {
                if (filters.Contains(game.ParamText.ToLower()))
                {
                    GameIdFilters.Add(game.ParamCode);
                }
            }

            // Check if specific User Names were given as filters.
            foreach (var user in Users.All.Where(x => x.Scores.Count > 0))
            {
                if (filters.Contains(user.Username.ToLower()))
                {
                    UserIdFilters.Add(user.UserId);
                }
            }

            string columnOptions = filters;

            if (orderBy != String.Empty)
            {
                columnOptions = filters.Substring(0, filters.IndexOf(orderBy));
            }

            // Check if any extra columns were set to be added.
            foreach (var columnName in StatisticsRow.GetExtraProperties() /*typeof(StatisticsRow).GetProperties().Select(x => x.Name)*/)
            {
                if (columnOptions.Contains(columnName.ToLower()))
                {
                    ExtraColumns.Add(columnName.ToLower());
                }
            }

            // Check if an integer Range was given
            if (filters.Contains("-"))
            {
                int delimiterIndex = filters.IndexOf('-');

                string beforeFull = filters.Substring(0, delimiterIndex);

                int delimiterPreceedingSpaceIndex = beforeFull.LastIndexOf(' ');

                // Get the text between the last space before the delimite, and the delimite
                string before = filters.SubstringIndex(delimiterPreceedingSpaceIndex, delimiterIndex - 1);

                int delimiterFollowingSpaceIndex = filters.Substring(delimiterIndex).IndexOf(' ');

                // Get the text between the delimite and the next space. If no space, then everything after the delimiter
                string after = filters.Substring(delimiterIndex + 1);
                if (delimiterFollowingSpaceIndex != -1)
                {
                    after = after.SubstringIndex(0, delimiterFollowingSpaceIndex);
                }

                int fromValue = 0;
                int toValue   = Seasons.Current.SeasonId;

                // Try parsing the texts to new values for the ranges
                int.TryParse(before, out fromValue);
                int.TryParse(after, out toValue);

                for (int i = fromValue; i <= toValue; i++)
                {
                    SeasonIdFilters.Add(i);
                }
            }
            else
            {
                // Check if specific Season ID's were given as filters
                foreach (var season in Seasons.All)
                {
                    if (filters.Contains(" " + season.SeasonId.ToString() + " ") || filters.Contains(" all"))
                    {
                        SeasonIdFilters.Add(season.SeasonId);
                    }
                }
            }

            // If no games defined, add all games to filters
            if (GameIdFilters.Count == 0)
            {
                GameIdFilters.AddRange(Games.Select(x => x.ParamCode));
            }

            // If no seasons defined, add current season to filters
            if (SeasonIdFilters.Count == 0)
            {
                SeasonIdFilters.Add(Seasons.Current.SeasonId);//AddRange(Seasons.All.Select(x => x.SeasonId));
            }

            var stats = new Statistics(SeasonIdFilters.ToArray(), GameIdFilters.ToArray(), UserIdFilters.ToArray(), ExtraColumns.ToArray(), orderBy);

            foreach (string stat in stats.StatRows)
            {
                Bot.Action(stat.Colorize(Options.ColorOptions.StatisticsTableColor));
            }
        }
Пример #5
0
 /// <summary>
 /// Colorizes the text before passing it to the BotMessager.
 /// </summary>
 /// <param name="message">Message to colorize</param>
 private void Action(string message)
 {
     message = "| " + message;
     Bot.Action(message.Colorize(Options.ColorOptions.StatisticsTableColor));
 }
Пример #6
0
        private void GameEnd()
        {
            Timer.Stop();

            if (CurrentPhase > Phase.Join)
            {
                // Process bets to pot.
                foreach (var player in Players)
                {
                    Pot += player.Bet;
                    player.CurrentWin = 0 - player.Bet;
                }

                // Check if game has multiple players left.
                if (Players.Count > 1)
                {
                    // Public message of each player's hands.
                    string message = "";

                    // List of players' hands.
                    List <Hand> Hands = new List <Hand>();

                    // Current hand being processed.
                    Hand myHand;

                    // Process each player's cards to their highest value combination
                    foreach (var player in Players)
                    {
                        // Get player's best hand
                        myHand       = new Hand(player.Cards.Concat(River).ToArray());
                        myHand.Owner = Users.Get(player.PlayerName);


                        // Start message with current's player's name in capital letters
                        message = player.PlayerName.ToUpper();

                        message += "| " + myHand.Text;

                        // Report player's hand and all of his cards privately
                        string privMessage = myHand.Text + " | -";

                        foreach (var card in myHand.Cards)
                        {
                            privMessage += " | " + card.Name;
                        }

                        Bot.Say(player.PlayerName, privMessage);

                        Hands.Add(myHand);
                        Bot.Action(message);
                    }

                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("");

                    Console.WriteLine("HANDS: ");

                    foreach (var hand in Hands)
                    {
                        Console.WriteLine(hand.Owner.Username);
                        Console.WriteLine(hand.HandScores);
                        Console.WriteLine(hand.CardScores);
                        Console.WriteLine("");
                    }

                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("____________________________________________________");

                    //Bot.Action(message);

                    // Get the winners
                    Hand[] WinningHands = Hand.ResolveWinningHands(Hands.ToArray());

                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("");

                    Console.WriteLine("WINNERS: ");

                    foreach (var winner in WinningHands)
                    {
                        Console.WriteLine(winner.Owner.Username);
                        Console.WriteLine(winner.HandScores);
                        Console.WriteLine(winner.CardScores);
                        Console.WriteLine("");
                    }

                    Console.WriteLine("____________________________________________________");
                    Console.WriteLine("____________________________________________________");

                    message = "";

                    int WinValue = 0;

                    if (WinningHands.Length == 1)
                    {
                        Hand WinningHand = WinningHands[0];

                        WinValue = Pot;

                        GetPlayer(WinningHand.Owner).CurrentWin += WinValue;

                        Bot.Say("VOITTAJA: " + WinningHand.Owner.Username.ToUpper() + " | " + WinningHand.Text + " " + WinningHand.TextAdd);
                    }
                    else
                    {
                        message = "TASAPELI: ";

                        WinValue = Pot / WinningHands.Length;

                        foreach (var WinningHand in WinningHands)
                        {
                            GetPlayer(WinningHand.Owner).CurrentWin += WinValue;
                            message += WinningHand.Owner.Username.ToUpper() + ", ";
                        }

                        message = message.Substring(0, message.Length - 2);

                        message += " ||| " + WinningHands[0].Text;

                        Bot.Say(message);
                    }

                    Bot.Say("Voitti: " + GetPlayer(WinningHands[0].Owner).CurrentWin);
                }
                else if (Players.Count == 1)
                {
                    Players[0].CurrentWin += Pot;
                    Bot.Say("VOITTAJA: " + Players[0].PlayerName.ToUpper());
                    Bot.Say("Voitti: " + Players[0].CurrentWin);
                }

                // Käsitellään voittajat
                ProcessWins();
            }

            CurrentPhase = Phase.Over;
        }
Пример #7
0
        private void EndGame()
        {
            if (Players.Count < 1)
            {
                Bot.Say("Talo voittaa.");
                currentPhase = Phase.Over;
                return;
            }

            int cardCount = 0;

            int best = Players.Max(x => x.Score);

            int TotalScore = 0;

            int Aces = 0;

            while ((cardCount < 2) || (TotalScore < best && TotalScore <= 21 && cardCount >= 2))
            {
                var card = Decks.Draw();

                int score = CardScore(card);

                if (score == 11)
                {
                    Aces++;
                }

                TotalScore += score;

                if (TotalScore > 21 && Aces > 0)
                {
                    TotalScore -= 10;
                    Aces--;
                }

                PositionString message = "";

                message.Section("Talo: " + card.Name);
                message.SectionInsert(16, "Pisteet: " + TotalScore);

                Bot.Action(message);

                cardCount++;
            }

            if (TotalScore > best && TotalScore <= 21)
            {
                Bot.Say("Talo voittaa.");

                foreach (var player in Players)
                {
                    var newScore = new Score(player.UserId, Score.Blackjack).Started();
                    newScore.Gains(player.CurrentBet * -1);

                    player.User.UpdateScore(newScore);
                    Bot.Say(player.Username, "Hävisit: " + player.CurrentBet);
                }
            }
            else if (TotalScore == best)
            {
                Bot.Say("Tasapeli.");

                foreach (var player in Players)
                {
                    if (player.Score < best)
                    {
                        var newScore = new Score(player.UserId, Score.Blackjack).Started();
                        newScore.Gains(player.CurrentBet * -1);

                        player.User.UpdateScore(newScore);
                        Bot.Say(player.Username, "Hävisit: " + player.CurrentBet);
                    }
                    else
                    {
                        var newScore = new Score(player.UserId, Score.Blackjack).Started();

                        player.User.UpdateScore(newScore);
                    }
                }
            }
            else
            {
                if (TotalScore > 21)
                {
                    Bot.Say("Talolla yli!");
                }
                Bot.Say("Pelaajat voittaa.");

                foreach (var player in Players)
                {
                    var newScore = new Score(player.UserId, Score.Blackjack).Started();
                    newScore.Gains(player.CurrentBet);

                    player.User.UpdateScore(newScore);
                    Bot.Say(player.Username, "Voitit: " + player.CurrentBet);
                }
            }

            currentPhase = Phase.Over;
        }
Пример #8
0
        private void cmd_weather()
        {
            Weather weather = null;
            string  city    = Message.NextCommand();
            string  country = Message.NextCommand();
            string  time    = Message.NextCommand();

            bool getForecast = false;
            int  hour        = 0;

            if (int.TryParse(city, out hour))
            {
                city        = "";
                country     = "";
                getForecast = true;
            }
            else if (int.TryParse(country, out hour))
            {
                country     = "";
                getForecast = true;
            }
            else if (int.TryParse(time, out hour))
            {
                getForecast = true;
            }

            if (getForecast)
            {
                DateTime now  = DateTime.Now;
                DateTime date = new DateTime(now.Year, now.Month, now.Day);

                hour = hour > 24 ? 24 : hour;
                hour = hour < 0 ? 0 : hour;

                if (hour < now.Hour)
                {
                    date = date.AddDays(1);
                }

                date = date.AddHours(hour);

                weather = MasterAPI.WeatherOrForecast(city, country, date);
            }
            else
            {
                weather = MasterAPI.WeatherOrForecast(city, country, null);
            }

            if (weather != null)
            {
                string message =
                    weather.City.Name + " " + weather.Date.ToShortDateTimeString() +
                    " | Lämpötila: " + weather.Temperature + TXT.CENTIGRADE +
                    ", tuntuu kuin: " + weather.FeelsLike +
                    " | Pilvisyys: " + weather.Cloudiness + "%" +
                    " | Ilmankosteus: " + weather.Humidity + "%" +
                    " | Tuulennopeus: " + weather.WindSpeed + "m/s" +
                    weather.WeatherDescription;

                Bot.Action(message);
            }
        }
Пример #9
0
        private void End()
        {
            Timer.Stop();
            var river = new Card[]
            {
                Deck.Draw(),
                Deck.Draw(),
                Deck.Draw(),
                Deck.Draw(),
                Deck.Draw()
            };

            string cardReport = "";

            foreach (var card in river)
            {
                cardReport += " | " + card.Name;
            }

            Bot.Action(cardReport);

            var hands = new List <Hand>();

            foreach (var player in Players)
            {
                var hand = new Hand(river.Concat(player.Cards).ToArray());
                hand.Owner = player.User;

                hands.Add(hand);

                string message = player.Username.ToUpper();
                message = message.InsertAbsolute(13, "| " + player.Cards[0].Name + " ");
                message = message.InsertAbsolute(22, player.Cards[1].Name);
                message = message.InsertAbsolute(29, "| " + hand.Text);

                Bot.Say(message);
            }

            var winningHands = Hand.ResolveWinningHands(hands.ToArray());

            int pot = (CurrentBet * Players.Count);

            if (winningHands.Length == 1)
            {
                var player = Players.First(x => x.UserId == winningHands[0].Owner.UserId);

                player.Gains += pot;

                Bot.Say(winningHands[0].Owner.Username + " Voitti " + player.Gains);
            }
            else
            {
                string message = "TASAPELI: ";

                int potSplit = pot / winningHands.Length;

                foreach (var winningHand in winningHands)
                {
                    var player = Players.First(x => x.UserId == winningHands[0].Owner.UserId);

                    player.Gains += potSplit;

                    message += player.Username + " ";
                }

                Bot.Say(message);
                Bot.Say("Voittivat: " + (potSplit - CurrentBet));
            }

            // Update the scores
            foreach (var player in Players)
            {
                var newScore = new Score(player.UserId, Score.Holdem).Started();
                newScore.Gains(player.Gains);

                player.User.UpdateScore(newScore);
                Bot.Say(player.Username, "Voitit/Hävisit: " + player.Gains);
            }

            CurrentPhase = Phase.Over;
        }