示例#1
0
 internal void AddCard(CardColor card)
 {
     lock (_parent._drawLock)
     {
         foreach (var cardInHand in Cards)
         {
             if (cardInHand == card)
             {
                 Cards.Remove(cardInHand);
                 _parent.HasMatch    = true;
                 _parent.MatchIndex  = _index;
                 _parent.MatchPlayer = this;
                 if (Cards.Count == 0)
                 {
                     _parent.HasWon    = true;
                     _parent.WonPlayer = _index;
                 }
                 return;
             }
         }
         var indexToInsert = AegisRandom.RandomNumber(0, Cards.Count);
         Cards.Insert(indexToInsert, card);
         _parent.HasMatch = false;
     }
 }
示例#2
0
        public OldMaidService(DiscordChannel ch, DiscordMember p1, DiscordMember p2, DiscordClient client, string tempName)
        {
            _tempPath = Path.Combine(AppContext.BaseDirectory, "Temp/Images/OldMaid", tempName);
            Directory.CreateDirectory(_tempPath);
            _ch = ch;

            _centerBold.Alignment     = StringAlignment.Center;
            _centerBold.LineAlignment = StringAlignment.Center;

            Players = new List <OldMaidPlayer>();
            if (AegisRandom.RandomBool())
            {
                Players.Add(new OldMaidPlayer(this, p1, 0));
                Players.Add(new OldMaidPlayer(this, p2, 1));
            }
            else
            {
                Players.Add(new OldMaidPlayer(this, p2, 0));
                Players.Add(new OldMaidPlayer(this, p1, 1));
            }
            MatchPlayer = Players[0];
            var cards = new List <CardColor>
            {
                CardColor.BLACK,
                CardColor.BLACK,
                CardColor.BLUE,
                CardColor.BLUE,
                CardColor.CYAN,
                CardColor.CYAN,
                CardColor.GREEN,
                CardColor.GREEN,
                CardColor.ORANGE,
                CardColor.ORANGE,
                CardColor.PINK,
                CardColor.PINK,
                CardColor.PURPLE,
                CardColor.PURPLE,
                CardColor.RED,
                CardColor.RED,
                CardColor.YELLOW,
                CardColor.YELLOW
            };
            var indexToRemove = AegisRandom.RandomNumber(0, cards.Count - 1);

            cards.RemoveAt(indexToRemove);
            for (var i = 0; i < cards.Count; ++i)
            {
                var playerToInsert = i % Players.Count;
                Players[playerToInsert].AddCard(cards[i]);
            }
            Turn    = Players.Count - 1;
            _client = client;
        }
示例#3
0
 public async Task Roast(CommandContext ctx, DiscordMember user = null)
 {
     using (var uow = _db.UnitOfWork())
     {
         try
         {
             var msgs   = uow.RoastMsgs.GetAllByGuildId(ctx.Guild.Id);
             var msg    = msgs.ElementAt(AegisRandom.RandomNumber(0, msgs.Count()));
             var victim = user ?? ctx.Member;
             await ctx.Channel.SendMessageAsync($"{victim.DisplayName}{msg.Msg}").ConfigureAwait(false);
         } catch (Exception e)
         {
             await ctx.Channel.SendMessageAsync($"{ctx.Member.DisplayName} {e.Message}").ConfigureAwait(false);
         }
     }
     ctx.Message.DeleteAfter(3);
 }
示例#4
0
        public ReversiService(DiscordChannel ch, DiscordMember p1, DiscordMember p2, DiscordClient client, string tempName)
        {
            _tempPath = Path.Combine(AppContext.BaseDirectory, "Temp/Images/Reversi", tempName);
            Directory.CreateDirectory(_tempPath);
            _ch = ch;

            if (AegisRandom.RandomBool())
            {
                _blackPlayer = p1;
                _whitePlayer = p2;
            }
            else
            {
                _blackPlayer = p2;
                _whitePlayer = p1;
            }
            _client = client;
            Board   = InitBoard();
        }
示例#5
0
        public TaflService(DiscordChannel ch, DiscordMember p1, DiscordMember p2, DiscordClient client, string tempName)
        {
            _fontFamily = new FontFamily("Arial");
            _font       = new Font(_fontFamily, 24, FontStyle.Bold, GraphicsUnit.Pixel);
            _solidBrush = new SolidBrush(Color.DarkGray);
            _tempPath   = Path.Combine(AppContext.BaseDirectory, "Temp/Images/Tafl", tempName);
            Directory.CreateDirectory(_tempPath);
            _ch = ch;

            if (AegisRandom.RandomBool())
            {
                _blackPlayer = p1;
                _whitePlayer = p2;
            }
            else
            {
                _blackPlayer = p2;
                _whitePlayer = p1;
            }
            _client = client;
        }
示例#6
0
        private async Task AttemptMatchmake(DiscordChannel channel)
        {
            var inhouseQueue = InhouseQueues.FirstOrDefault(x => x.ChannelId == channel.Id);

            // if less than 10 players in queue, no game can be made
            if (inhouseQueue.PlayersInQueue.Sum(x => x.Players.Count()) < 10)
            {
                return;
            }

            // brute force check for matchmake with buckets
            var buckets = new List <MatchmakeBucket>();

            buckets.Add(new MatchmakeBucket());

            // we reserve SOLO fill players for last
            MatchmakeBucket filledBucket = null;
            var             fillPlayers  = new List <QueueGroup>();

            foreach (var queueGroup in inhouseQueue.PlayersInQueue)
            {
                var tempBuckets = new List <MatchmakeBucket>();

                // check for SOLO fill players
                if (queueGroup.Players.Count() == 1 && queueGroup.Players[0].QueuedRoles[PlayerRole.Fill])
                {
                    fillPlayers.Add(queueGroup);
                    var maxBucket = buckets.FirstOrDefault(x => x.PlayerCount + fillPlayers.Count() >= 10);
                    if (maxBucket != null)
                    {
                        filledBucket = maxBucket;
                        break;
                    }
                    continue;
                }

                // get each role combination from each queueGroup
                foreach (var bucket in buckets)
                {
                    // check to see if a copy of bucket without roleCombination is already in
                    var hasOldBucket     = false;
                    var roleCombinations = queueGroup.PossibleRoleCombinations();
                    while (roleCombinations.Count() > 0)
                    {
                        var scramble        = AegisRandom.RandomNumber(0, roleCombinations.Count());
                        var roleCombination = roleCombinations[scramble];
                        roleCombinations.RemoveAt(scramble);
                        var playerSides = AegisRandom.RandomBool() ? new List <PlayerSide>()
                        {
                            PlayerSide.Blue, PlayerSide.Red
                        } : new List <PlayerSide>()
                        {
                            PlayerSide.Red, PlayerSide.Blue
                        };
                        foreach (var i in playerSides)
                        {
                            var tempBucket       = new MatchmakeBucket(bucket);
                            var canPutIntoBucket = tempBucket.TryAddRoleCombination(roleCombination, i);
                            if (canPutIntoBucket)
                            {
                                tempBucket.QueueGroups.Add(queueGroup);
                                tempBuckets.Add(tempBucket);
                            }
                            else if (!hasOldBucket)
                            {
                                tempBuckets.Add(tempBucket);
                                hasOldBucket = true;
                            }

                            if (tempBucket.PlayerCount + fillPlayers.Count() >= 10)
                            {
                                filledBucket = tempBucket;
                                break;
                            }
                        }
                        if (filledBucket != null)
                        {
                            break;
                        }
                    }
                    if (filledBucket != null)
                    {
                        break;
                    }
                }
                buckets = tempBuckets;
                if (filledBucket != null)
                {
                    break;
                }
            }

            // if no bucket is filled, then no game is found
            if (filledBucket == null)
            {
                return;
            }

            // now we put all fill players in
            var missingBlueRoles = new List <PlayerRole>();
            var missingRedRoles  = new List <PlayerRole>();

            foreach (PlayerRole role in Enum.GetValues(typeof(PlayerRole)))
            {
                if (role == PlayerRole.Fill)
                {
                    continue;
                }
                missingBlueRoles.Add(role);
                missingRedRoles.Add(role);
            }
            foreach (var role in filledBucket.BluePlayers)
            {
                missingBlueRoles.Remove(role.Key);
            }
            foreach (var role in filledBucket.RedPlayers)
            {
                missingRedRoles.Remove(role.Key);
            }

            foreach (var fillPlayer in fillPlayers)
            {
                var scramble = AegisRandom.RandomNumber(0, missingBlueRoles.Count() + missingRedRoles.Count());
                if (scramble < missingBlueRoles.Count())
                {
                    var role = missingBlueRoles[scramble];
                    missingBlueRoles.RemoveAt(scramble);
                    filledBucket.BluePlayers.Add(role, fillPlayer.Players[0]);
                    filledBucket.QueueGroups.Add(fillPlayer);
                    filledBucket.PlayerCount += 1;
                }
                else
                {
                    var role = missingRedRoles[scramble - missingBlueRoles.Count()];
                    missingRedRoles.RemoveAt(scramble - missingBlueRoles.Count());
                    filledBucket.RedPlayers.Add(role, fillPlayer.Players[0]);
                    filledBucket.QueueGroups.Add(fillPlayer);
                    filledBucket.PlayerCount += 1;
                }
            }

            // insert players into game and randomize side
            var inhouseGame = new InhouseGame(channel.Id);

            foreach (var player in filledBucket.BluePlayers)
            {
                player.Value.PlayerSide = PlayerSide.Blue;
                player.Value.PlayerRole = player.Key;
                inhouseGame.InhousePlayers.Add(player.Value);
            }

            foreach (var player in filledBucket.RedPlayers)
            {
                player.Value.PlayerSide = PlayerSide.Red;
                player.Value.PlayerRole = player.Key;
                inhouseGame.InhousePlayers.Add(player.Value);
            }

            InhouseGames.Add(inhouseGame);
            inhouseGame.QueueGroups = filledBucket.QueueGroups;

            // remove everybody in the game from queue
            var inhousePlayers = inhouseGame.InhousePlayers.Select(x => x.Player.Id);

            inhouseQueue.PlayersInQueue.RemoveAll(x => filledBucket.QueueGroups.Any(y => y == x));

            await ReadyCheck(channel, inhouseGame).ConfigureAwait(false);
        }