<commit_before>﻿using System;
using System.Linq;
using System.Windows.Forms;
using BluffinMuffin.Client.DataTypes;
using BluffinMuffin.Client.DataTypes.EventHandling;
using BluffinMuffin.Client.Windows.Forms.Properties;
using BluffinMuffin.Protocol.DataTypes;
using BluffinMuffin.Protocol.DataTypes.Enums;
using BluffinMuffin.Protocol.DataTypes.EventHandling;
using Com.Ericmas001.Games;
using Com.Ericmas001.Util;

namespace BluffinMuffin.Client.Windows.Forms.Game
{
    public partial class TableViewerForm : AbstractTableForm
    {
        private readonly PlayerHud[] m_Huds = new PlayerHud[10];
        private readonly Label[] m_Bets = new Label[10];
        private readonly Label[] m_PotTitles = new Label[10];
        private readonly Label[] m_PotValues = new Label[10];
        private readonly CardPictureBox[] m_Board = new CardPictureBox[5];

        protected TableViewerForm()
        {
            InitializeComponent();
            m_Huds[0] = playerHud1;
            m_Huds[1] = playerHud2;
            m_Huds[2] = playerHud3;
            m_Huds[3] = playerHud4;
            m_Huds[4] = playerHud5;
            m_Huds[5] = playerHud6;
            m_Huds[6] = playerHud7;
            m_Huds[7] = playerHud8;
            m_Huds[8] = playerHud9;
            m_Huds[9] = playerHud10;
            m_Bets[0] = label1;
            m_Bets[1] = label2;
            m_Bets[2] = label3;
            m_Bets[3] = label4;
            m_Bets[4] = label5;
            m_Bets[5] = label6;
            m_Bets[6] = label7;
            m_Bets[7] = label8;
            m_Bets[8] = label9;
            m_Bets[9] = label10;
            m_Board[0] = cardPictureBox1;
            m_Board[1] = cardPictureBox2;
            m_Board[2] = cardPictureBox3;
            m_Board[3] = cardPictureBox4;
            m_Board[4] = cardPictureBox5;
            m_PotTitles[0] = lblPot0Title;
            m_PotTitles[1] = lblPot1Title;
            m_PotTitles[2] = lblPot2Title;
            m_PotTitles[3] = lblPot3Title;
            m_PotTitles[4] = lblPot4Title;
            m_PotTitles[5] = lblPot5Title;
            m_PotTitles[6] = lblPot6Title;
            m_PotTitles[7] = lblPot7Title;
            m_PotTitles[8] = lblPot8Title;
            m_PotTitles[9] = lblPot9Title;
            m_PotValues[0] = lblPot0;
            m_PotValues[1] = lblPot1;
            m_PotValues[2] = lblPot2;
            m_PotValues[3] = lblPot3;
            m_PotValues[4] = lblPot4;
            m_PotValues[5] = lblPot5;
            m_PotValues[6] = lblPot6;
            m_PotValues[7] = lblPot7;
            m_PotValues[8] = lblPot8;
            m_PotValues[9] = lblPot9;
            logConsole.RelativeSizeChanged += OnConsoleRelativeSizeChanged;
        }

        void OnConsoleRelativeSizeChanged(object sender, IntEventArgs e)
        {
            Height += e.Value;
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            new HandStrengthForm().Show();
        }

        public override void SetGame(IPokerGame c)
        {
            base.SetGame(c);
            InitializePokerObserverForGui();
            InitializePokerObserverForConsole();
        }

        private void WriteLine(string line)
        {
            LogManager.Log(LogLevel.Message, "Game", line);
            logConsole.WriteLine(line);
        }

        private void InitializePokerObserverForGui()
        {
            m_Game.Observer.EverythingEnded += OnEverythingEnded;
            m_Game.Observer.GameBettingRoundEnded += OnGameBettingRoundEnded;
            m_Game.Observer.GameBettingRoundStarted += OnGameBettingRoundStarted;
            m_Game.Observer.GameEnded += OnGameEnded;
            m_Game.Observer.GameGenerallyUpdated += OnGameGenerallyUpdated;
            m_Game.Observer.PlayerActionNeeded += OnPlayerActionNeeded;
            m_Game.Observer.PlayerActionTaken += OnPlayerActionTaken;
            m_Game.Observer.PlayerHoleCardsChanged += OnPlayerHoleCardsChanged;
            m_Game.Observer.SeatUpdated += OnSeatUpdated;
            m_Game.Observer.PlayerWonPot += OnPlayerWonPot;
        }

        private void OnEverythingEnded(object sender, EventArgs e)
        {
            ForceKill();
        }

        private void InitializePokerObserverForConsole()
        {
            m_Game.Observer.EverythingEnded += OnEverythingEnded_Console;
            m_Game.Observer.GameBettingRoundStarted += OnGameBettingRoundStarted_Console;
            m_Game.Observer.GameBlindNeeded += OnGameBlindNeeded_Console;
            m_Game.Observer.GameEnded += OnGameEnded_Console;
            m_Game.Observer.GameGenerallyUpdated += OnGameGenerallyUpdated_Console;
            m_Game.Observer.PlayerActionTaken += OnPlayerActionTaken_Console;
            m_Game.Observer.PlayerHoleCardsChanged += OnPlayerHoleCardsChanged_Console;
            m_Game.Observer.PlayerJoined += OnPlayerJoined_Console;
            m_Game.Observer.SeatUpdated += OnSeatUpdated_Console;
            m_Game.Observer.PlayerWonPot += OnPlayerWonPot_Console;
        }

        void OnGameBettingRoundEnded(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new EventHandler<RoundEventArgs>(OnGameBettingRoundEnded), new[] { sender, e });
                return;
            }
            SuspendLayout();<commit_msg>Preventing crash from happening<commit_after>﻿using System;
using System.Linq;
using System.Windows.Forms;
using BluffinMuffin.Client.DataTypes;
using BluffinMuffin.Client.DataTypes.EventHandling;
using BluffinMuffin.Client.Windows.Forms.Properties;
using BluffinMuffin.Protocol.DataTypes;
using BluffinMuffin.Protocol.DataTypes.Enums;
using BluffinMuffin.Protocol.DataTypes.EventHandling;
using Com.Ericmas001.Games;
using Com.Ericmas001.Util;

namespace BluffinMuffin.Client.Windows.Forms.Game
{
    public partial class TableViewerForm : AbstractTableForm
    {
        private readonly PlayerHud[] m_Huds = new PlayerHud[10];
        private readonly Label[] m_Bets = new Label[10];
        private readonly Label[] m_PotTitles = new Label[10];
        private readonly Label[] m_PotValues = new Label[10];
        private readonly CardPictureBox[] m_Board = new CardPictureBox[5];

        protected TableViewerForm()
        {
            InitializeComponent();
            m_Huds[0] = playerHud1;
            m_Huds[1] = playerHud2;
            m_Huds[2] = playerHud3;
            m_Huds[3] = playerHud4;
            m_Huds[4] = playerHud5;
            m_Huds[5] = playerHud6;
            m_Huds[6] = playerHud7;
            m_Huds[7] = playerHud8;
            m_Huds[8] = playerHud9;
            m_Huds[9] = playerHud10;
            m_Bets[0] = label1;
            m_Bets[1] = label2;
            m_Bets[2] = label3;
            m_Bets[3] = label4;
            m_Bets[4] = label5;
            m_Bets[5] = label6;
            m_Bets[6] = label7;
            m_Bets[7] = label8;
            m_Bets[8] = label9;
            m_Bets[9] = label10;
            m_Board[0] = cardPictureBox1;
            m_Board[1] = cardPictureBox2;
            m_Board[2] = cardPictureBox3;
            m_Board[3] = cardPictureBox4;
            m_Board[4] = cardPictureBox5;
            m_PotTitles[0] = lblPot0Title;
            m_PotTitles[1] = lblPot1Title;
            m_PotTitles[2] = lblPot2Title;
            m_PotTitles[3] = lblPot3Title;
            m_PotTitles[4] = lblPot4Title;
            m_PotTitles[5] = lblPot5Title;
            m_PotTitles[6] = lblPot6Title;
            m_PotTitles[7] = lblPot7Title;
            m_PotTitles[8] = lblPot8Title;
            m_PotTitles[9] = lblPot9Title;
            m_PotValues[0] = lblPot0;
            m_PotValues[1] = lblPot1;
            m_PotValues[2] = lblPot2;
            m_PotValues[3] = lblPot3;
            m_PotValues[4] = lblPot4;
            m_PotValues[5] = lblPot5;
            m_PotValues[6] = lblPot6;
            m_PotValues[7] = lblPot7;
            m_PotValues[8] = lblPot8;
            m_PotValues[9] = lblPot9;
            logConsole.RelativeSizeChanged += OnConsoleRelativeSizeChanged;
        }

        void OnConsoleRelativeSizeChanged(object sender, IntEventArgs e)
        {
            Height += e.Value;
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            new HandStrengthForm().Show();
        }

        public override void SetGame(IPokerGame c)
        {
            base.SetGame(c);
            InitializePokerObserverForGui();
            InitializePokerObserverForConsole();
        }

        private void WriteLine(string line)
        {
            LogManager.Log(LogLevel.Message, "Game", line);
            logConsole.WriteLine(line);
        }

        private void InitializePokerObserverForGui()
        {
            m_Game.Observer.EverythingEnded += OnEverythingEnded;
            m_Game.Observer.GameBettingRoundEnded += OnGameBettingRoundEnded;
            m_Game.Observer.GameBettingRoundStarted += OnGameBettingRoundStarted;
            m_Game.Observer.GameEnded += OnGameEnded;
            m_Game.Observer.GameGenerallyUpdated += OnGameGenerallyUpdated;
            m_Game.Observer.PlayerActionNeeded += OnPlayerActionNeeded;
            m_Game.Observer.PlayerActionTaken += OnPlayerActionTaken;
            m_Game.Observer.PlayerHoleCardsChanged += OnPlayerHoleCardsChanged;
            m_Game.Observer.SeatUpdated += OnSeatUpdated;
            m_Game.Observer.PlayerWonPot += OnPlayerWonPot;
        }

        private void OnEverythingEnded(object sender, EventArgs e)
        {
            ForceKill();
        }

        private void InitializePokerObserverForConsole()
        {
            m_Game.Observer.EverythingEnded += OnEverythingEnded_Console;
            m_Game.Observer.GameBettingRoundStarted += OnGameBettingRoundStarted_Console;
            m_Game.Observer.GameBlindNeeded += OnGameBlindNeeded_Console;
            m_Game.Observer.GameEnded += OnGameEnded_Console;
            m_Game.Observer.GameGenerallyUpdated += OnGameGenerallyUpdated_Console;
            m_Game.Observer.PlayerActionTaken += OnPlayerActionTaken_Console;
            m_Game.Observer.PlayerHoleCardsChanged += OnPlayerHoleCardsChanged_Console;
            m_Game.Observer.PlayerJoined += OnPlayerJoined_Console;
            m_Game.Observer.SeatUpdated += OnSeatUpdated_Console;
            m_Game.Observer.PlayerWonPot += OnPlayerWonPot_Console;
        }

        void OnGameBettingRoundEnded(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                // We're not in the UI thread, so we need to call BeginInvoke
                BeginInvoke(new EventHandler<EventArgs>(OnGameBettingRoundEnded), new[] { sender, e });
                return;
            }
            SuspendLayout();
{'fraction_non_alphanumeric': 0.08503994857195335, 'fraction_numerical': 0.01965286068509505, 'mean_word_length': 2.201058201058201, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6200908', 'n_tokens_mistral': 3581, 'n_tokens_neox': 3388, 'n_words': 530}