<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Poker.Core;
using Poker.Core.Interfaces;

namespace Poker.Core.Concrete
{
    class PokerGame : IPokerGame
    {
        private IBetManager betManager;

        public IBetManager BetManager
        {
            get { return betManager; }
        }

        public int BigBlind
        {
            get
            {
                return betManager.BigBlind;
            }
            set
            {
                betManager.BigBlind = value;
            }
        }

        IPlayer bigBlindPlayer;
        public IPlayer BigBlindPlayer
        {
            get { return bigBlindPlayer; }
        }

        public int SmallBlind
        {
            get
            {
                return betManager.SmallBlind;
            }
            set
            {
                betManager.SmallBlind = value;
            }
        }

        IPlayer smallBlindPlayer;
        public IPlayer SmallBlindPlayer
        {
            get { return smallBlindPlayer; }
        }

        public int CurrentBet
        {
            get { return betManager.CurrentBet; }
        }

        private IPlayer currentPlayer;
        public IPlayer CurrentPlayer
        {
            get { return currentPlayer; }
        }

        private List<IPlayer> players;
        public IList<IPlayer> Players
        {
            get { return players; }
        }

        PokerGameStage stage;
        public PokerGameStage Stage
        {
            get { return stage; }
        }

        public event EventHandler<PokerGameEventArgs> NextBettingRound;
        protected void raiseNextBettingRound(PokerGameEventArgs e)
        {
            var handler = NextBettingRound;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<PokerPlayerEventArgs> NextPlayer;
        protected void raiseNextPlayer(PokerPlayerEventArgs e)
        {
            var handler = NextPlayer;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public PokerGame(IBetManager betManager)
        {
            this.betManager = betManager;
            this.players = new List<IPlayer>();
            this.stage = PokerGameStage.Inactive;
        }

        public void AddPlayer(IPlayer player)
        {
            player.Participation = PlayerParticipation.Inactive;
            players.Add(player);
        }

        public void RemovePlayer(IPlayer player)
        {
            throw new NotImplementedException();
        }

        public void Fold()
        {
            currentPlayer.Fold();
        }

        public void PlaceBet(int amount)
        {
            betManager.PlaceBet(currentPlayer, amount);
        }

        public void NewGame()
        {
            // Check if we can start a new game
            if (this.stage != PokerGameStage.Finished && this.stage != PokerGameStage.Inactive)
                throw new PokerStageException("Game needs to be either in 'Inactive' or 'Finished' stage to start new game");

            if (players.Count(x => x.Balance > 0) < 2)
                throw new PokerException("At least two players should have positive balance to start a game");

            // Mark players active
            foreach (var player in players)
            {
                if (player.Balance > 0)
                    player.Participation = PlayerParticipation.Active;
                else
                    player.Participation = PlayerParticipation.Inactive;
            }

            // Arrange blinds
            smallBlindPlayer = players.NextActiveOrFirst(smallBlindPlayer);
            bigBlindPlayer = players.NextActiveOrFirst(smallBlindPlayer);

            betManager.PlaceBet(smallBlindPlayer, SmallBlind);
            betManager.PlaceBet(bigBlindPlayer, BigBlind);

            // Call nextPlayer
            nextPlayer();
        }

        internal void nextPlayer()
        {
            throw new NotImplementedException();
        }

        public bool PlayersWin(IList<IPlayer> winners)
        {
            return betManager.CalculateWinners(winners);
        }

        public bool PlayerWins(IPlayer winner)
        {
            return PlayersWin(new List<IPlayer>(){ winner });
        }
    }
}<commit_msg>Implemented nextRound<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Poker.Core;
using Poker.Core.Interfaces;

namespace Poker.Core.Concrete
{
    class PokerGame : IPokerGame
    {
        private IBetManager betManager;
        private Queue<IPlayer> activePlayerQueue;

        public IBetManager BetManager
        {
            get { return betManager; }
        }

        public int BigBlind
        {
            get
            {
                return betManager.BigBlind;
            }
            set
            {
                betManager.BigBlind = value;
            }
        }

        IPlayer bigBlindPlayer;
        public IPlayer BigBlindPlayer
        {
            get { return bigBlindPlayer; }
        }

        public int SmallBlind
        {
            get
            {
                return betManager.SmallBlind;
            }
            set
            {
                betManager.SmallBlind = value;
            }
        }

        IPlayer smallBlindPlayer;
        public IPlayer SmallBlindPlayer
        {
            get { return smallBlindPlayer; }
        }

        public int CurrentBet
        {
            get { return betManager.CurrentBet; }
        }

        private IPlayer currentPlayer;
        public IPlayer CurrentPlayer
        {
            get { return currentPlayer; }
        }

        private List<IPlayer> players;
        public IList<IPlayer> Players
        {
            get { return players; }
        }

        PokerGameStage stage;
        public PokerGameStage Stage
        {
            get { return stage; }
        }

        public event EventHandler<PokerGameEventArgs> NextBettingRound;
        protected void raiseNextBettingRound(PokerGameEventArgs e)
        {
            var handler = NextBettingRound;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public event EventHandler<PokerPlayerEventArgs> NextPlayer;
        protected void raiseNextPlayer(PokerPlayerEventArgs e)
        {
            var handler = NextPlayer;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public PokerGame(IBetManager betManager)
        {
            this.betManager = betManager;
            this.players = new List<IPlayer>();
            this.stage = PokerGameStage.Inactive;
            this.activePlayerQueue = new Queue<IPlayer>();
        }

        public void AddPlayer(IPlayer player)
        {
            player.Participation = PlayerParticipation.Inactive;
            players.Add(player);
        }

        public void RemovePlayer(IPlayer player)
        {
            throw new NotImplementedException();
        }

        public void Fold()
        {
            currentPlayer.Fold();
            nextPlayer();
        }

        public void PlaceBet(int amount)
        {
            betManager.PlaceBet(currentPlayer, amount);
            nextPlayer();
        }

        public void NewGame()
        {
            // Check if we can start a new game
            if (this.stage != PokerGameStage.Finished && this.stage != PokerGameStage.Inactive)
                throw new PokerStageException("Game needs to be either in 'Inactive' or 'Finished' stage to start new game");

            if (players.Count(x => x.Balance > 0) < 2)
                throw new PokerException("At least two players should have positive balance to start a game");

            // Mark players active
            foreach (var player in players)
            {
                if (player.Balance > 0)
                    player.Participation = PlayerParticipation.Active;
                else
                    player.Participation = PlayerParticipation.Inactive;
            }

            // Arrange blinds
            smallBlindPlayer = players.NextActiveOrFirst(smallBlindPlayer);
            bigBlindPlayer = players.NextActiveOrFirst(smallBlindPlayer);

            betManager.PlaceBet(smallBlindPlayer, SmallBlind);
            betManager.PlaceBet(bigBlindPlayer, BigBlind);

            // Call nextPlayer
            nextPlayer();
        }

        internal void nextPlayer()
        {
            // Check if any players are in the queue
            // If there are, select the first one
            if (activePlayerQueue.Count > 0)
            {
                this.currentPlayer = activePlayerQueue.Dequeue();
                return;
            }

            // If there are no more players left in the queue
            // Check if the betting round is over
            bool roundOver = betManager.BettingRoundOver();

            if (roundOver)
            {
                // If the round is over => next round
                this.nextRound();
            }
            else
            {
                // If the round is not over, we should determine which
                // players are active, and pick the first one
                determinePlayerQueue();
                this.currentPlayer = activePlayerQueue.Dequeue();
            }
        }

        internal void determinePlayerQueue()
        {
            throw new NotImplementedException();
        }

        internal void nextRound()
        {
            throw new NotImplementedException();
        }

        public bool PlayersWin(IList<IPlayer> winners)
        {
            return betManager.CalculateWinners(winners);
        }

        public bool PlayerWins(IPlayer winner)
        {
            return PlayersWin(new List<IPlayer>(){ winner });
        }
    }
}
{'fraction_non_alphanumeric': 0.06826788917679888, 'fraction_numerical': 0.0006976280645804266, 'mean_word_length': 1.412839624909834, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '905226', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2410, 'n_words': 607}