private void timer1_Tick(object sender, EventArgs e) { timer1.Enabled = false; //bool doStart = true; try { //if (cbDebug.Checked) //{ // //if (cbSaveTableBmp.Checked) // //{ // // var bmp = _table.GetAreaFromScreen(_settings.TableRect); // // var dir = Application.StartupPath + @"\pics\"; // // if (!Directory.Exists(dir)) // // Directory.CreateDirectory(dir); // // int i = 0; // // while (File.Exists(dir + i + ".bmp")) // // i++; // // var graphicImage = Graphics.FromImage(bmp); // // bmp.Save(dir + i + ".bmp"); // //} //} int algo; int.TryParse(cbAlgo.SelectedItem.ToString(), out algo); if (_table == null) { _table = new Table((rbSix.Checked ? 6 : 9), _settings); _table.ClickLog += TableOnClickLog; _table.ClickLogDebug += TableOnClickLogDebug; _table.AfterClickLog += TableOnAfterClickLog; InitPlayerRects(_settings); InitButtonRects(_settings); InitBetRects(_settings); } else { _table.ClearTable(); } _table.WindowPoint = _settings.WindowPoint; _table.RecognizeFromWin(_settings); if (_collectAfterInfo) { CollectAfterInfo(); _collectAfterInfo = false; _afterClickInfo = ""; } #region TablePause if (cbUsePause.Checked && _swPause.Elapsed >= TimeSpan.FromMinutes(_pauseMinutes)) { _table.ClickPause(); _isPaused = !_isPaused; if (_isPaused) _pauseMinutes = _swRandom.Next(1, 2); else _pauseMinutes = _swRandom.Next(90, 120); _swPause.Reset(); _swPause.Restart(); } bool tableIsPaused = _table.IsPaused; if ( !( tableIsPaused && _isPaused || (!tableIsPaused && !_isPaused) ) ) { _table.ClickPause(); } lblNextPause.Text = tableIsPaused + ", pause in " + (TimeSpan.FromMinutes(_pauseMinutes) - _swPause.Elapsed).ToString(@"hh\:mm\:ss"); #endregion //**************************************************** #if !DEBUG if (!_table.IsOpened) { if (TryActivate()) return; _table.Open(); _currentTableName = _table.TableName; _table.ClearTable(); _table.WindowPoint = _settings.WindowPoint; _table.RecognizeFromWin(_settings); _lastTableTotal = _table.Bank.TotalValue; SaveBmpLog("", "", ""); LogApp("table opened: " + _currentTableName + " at " + DateTime.Now.ToString("HH:mm:ss"), false); return; } if ((_table.MyBalance.Posa >= _settings.Limit || (_table.TotalPlayers < 6)) && _table.IsValid && _table.IsPreFlop) { _lastCloseReason = (_table.MyBalance.Posa >= _settings.Limit ? "win" : "no players") + " at " + DateTime.Now.ToString("HH:mm:ss"); _lastTableName = _table.TableName; SaveBmpLog("", "", ""); if (!_table.IsPaused) _table.ClickPause(); _table.Close(); LogApp("table closed: " + _lastCloseReason, true); return; } int stackCnt = 2; if (_table.IsValid && _table.IsPreFlop && _table.Bank.TotalValueValid && _lastTableTotal != 0 && _lastTableTotal - _table.Bank.TotalValue >= _settings.BuyIn * stackCnt ) { _lastTableTotal = _table.Bank.TotalValue; _lastCloseReason = stackCnt + " stacks down at " + DateTime.Now.ToString("HH:mm:ss"); _lastTableName = _table.TableName; SaveBmpLog("", "", ""); if (!_table.IsPaused) _table.ClickPause(); _table.Close(); LogApp("table closed: " + _lastCloseReason, true); return; } #endif //**************************************************** _table.MoveToRandomPlayer(); _table.BetInput = _settings.BetInputRect; _table.MinBet = _settings.MinBet; //TODO в безлимитном $1/$2 - малый/большой блайнды, в лимитном - ставки префлоп-флоп/терн-ривер //if(_table.IsPreFlop || _table.IsFlop) // _table.MinBet = _settings.MinBet; //else // _table.MinBet = _settings.MinBet * 2; //TODO SLOWWW //if(algo > 3) // _table.CountPlayers(_playersTemplate); if (cbSetUi.Checked) { pbAllCards.Image = _table.AllCardsBmp; pbMyCards.Image = _table.MyCardsBmp; pbButtonsFold.Image = _table.ButtonFoldBmp; pbButtonsCallCheck.Image = _table.ButtonCallCheckBmp; pbButtonsBetRaise.Image = _table.ButtonBetRaiseBmp; pbMyBalance.Image = _table.MyBalance.Image; pbBank.Image = _table.Bank.BankImg; pbCall.Image = _table.Bank.CallImg; pbRaise.Image = _table.Bank.RaiseImg; pbTotal.Image = _table.Bank.TotalImg; } rbAllCards.Text = ""; rbMyCards.Text = ""; foreach (var item in _table.AllCards.CardsStr) { rbAllCards.AppendText(item.Item1, item.Item2); } foreach (var item in _table.MyCards.CardsStr) { rbMyCards.AppendText(item.Item1, item.Item2); } tbButtons.Text = _table.Buttons.ToString(); lbBalance.Text = "last=" + _lastTableTotal + " ,current=" + _table.Bank.TotalValue + " ,bluff=" + _bluff; tbMyBalance.Text = _table.MyBalance.ToString(); tbBank.Text = _table.Bank.BankValue.ToString(); tbCall.Text = _table.Bank.CallValue.ToString(); tbRaise.Text = _table.Bank.RaiseValue.ToString(); tbTotal.Text = _table.Bank.TotalValue.ToString(); if (_table.MyCards.Count == 0) { _table.BetCounterPreFlop = 1; _table.BetCounterFlop = 1; _table.BetCounterTurn = 1; _table.BetCounterRiver = 1; _table.RaiseCounter = 0; } lblBetCounter.Text = CurrentCounter + " bet counter"; int rand = 100; if (_table.ButtonPlayer != _table.ButtonPlayerPrev) //начало раздачи { _bluff = _bluffRandom.Next(0, 100); _table.PlayerActionCounter = 0; _table.TotalRounds += 1; //_logDebug.Info("table begin"); //_logDebug.Info("ButtonPlayer=" + _table.ButtonPlayer + ", ButtonPlayerPrev=" + _table.ButtonPlayerPrev); _table.IsInitiative = false; var stat = ""; foreach (var player in _table.Players) { stat += player.Stat.GetStat() + ";"; player.ParsePrev(_settings.RemoveDollar); if (!player.IsActive && player.IsFold) { player.Stat.Clear(); } } _table.ButtonPlayerPrev = _table.ButtonPlayer; //_logDebug.Info(stat); rand = _algoRandom.Next(0, 100); //_logDebug.Info("ButtonPlayer=" + _table.ButtonPlayer + ", ButtonPlayerPrev=" + _table.ButtonPlayerPrev); } if (_table.IsBlind && _table.IsPreFlop && CurrentCounter == 1) { _table.IsFreePlay = true; } else { _table.IsFreePlay = false; } //if (_table.IsValidButtons) //{ // _table.ButtonPlayerPrev = _table.ButtonPlayer; //} var swr = _swRandom.Next(1, 2); lblTimerInterval.Text = _sw.Elapsed.ToString(@"hh\:mm\:ss\.fff"); if (_sw.Elapsed.Seconds < swr) { return; } _sw.Restart(); if (_table.IsValid && (_table.Bank.RaiseValueValid || _table.Bank.CallValueValid)) { //====================== if (_table.IsPreFlop && _table.PlayerActionCounter == 0 && _table.MyBalance.Posa != 0 && _table.MyBalance.PosaPrev / _table.MyBalance.Posa * 100 <= _settings.RebuyLevel //&& _table.MyBalance.Posa - (_table.MyBalance.PosaPrev + _table.Bank.BankValue) > _settings.MinBet //но не выйграли && _settings.BuyIn - _table.MyBalance.Posa <= _settings.MinBet //и стек около бай-ина && _settings.BuyIn >= _table.MyBalance.Posa //&& _table.MyBalance.IsValid ) { _lastRebuy = "" + _table.MyBalance.Posa + " at " + DateTime.Now.ToString("HH:mm:ss"); _rebuyCount++; LogApp("possible rebuy " + _lastRebuy, true); } _table.MyBalance.PosaPrev = _table.MyBalance.Posa; //====================== var diff = _settings.MinBet; foreach (var player in _table.Players) { player.IsAllIn = false; player.Parse(_settings.RemoveDollar); if (player.IsActive) { var newDiff = player.AnalyseBets(diff); if (player.Action == PlayerAction.Raise) { diff = newDiff; } //Ex.Info(player.Posa + ";" + player.PosaPrev); } if (!player.IsFold && !player.IsActive) { player.IsAllIn = true; } player.Stat.Collect(player); } //После анализа записываем в PosaPrev foreach (var player in _table.Players) { player.PosaPrevLog = player.PosaPrev; player.PosaPrev = player.Posa; //player.ParsePrev(_settings.RemoveDollar); } _table.SetRaiserPosition(); //if(algo == 1) // Algo1(true, rand); //if (algo == 2) //Algo2(true, rand); if (_bluff < _settings.ShortStackPercent) { Algo1(true, rand, _bluff); } else { Algo2(true, rand, _bluff); } //if (algo == 1 || algo == 2) //{ // Algo1(true); //} ////useless //if (algo == 2) //{ // if (!Algo1(false)) // Algo2(true); //} //if (algo == 3) //{ // if (!Algo1(false)) // if (!Algo2(false)) // Algo3(true); //} //if (algo == 4) //{ // if (!Algo1(false)) // if (!Algo2(false)) // if (!Algo3(false)) // Algo4(true); //} //if (algo == 5) //{ // if (!Algo1(false)) // if (!Algo2(false)) // if (!Algo3(false)) // if(!Algo4(false)) // Algo1(true); //} } if(cbSetUi.Checked) SetPlayerUis(); lblPlayersCount.Text = _table.TotalPlayers + " players, " + _table.FoldPlayers + " fold, " + _table.RaiserCount + " raised at " + _table.RaiserPosition + "," + "button=" + (_table.ButtonPlayer + 1); //lblPlayersCount.Text = _table.TotalPlayers + " players, " + _table.FoldPlayers + " fold, button=" + (_table.ButtonPlayer + 1); lblDealerButton.Text = (_table.DealerButtons.IndexOf(true) + 1).ToString() + " - " + _table.MyPosition; } catch (Exception ex) { Ex.Report(ex); } finally { //GC.Collect(); timer1.Enabled = true; //if (doStart) // timer1.Enabled = true; //else //{ // _log.Info("stopped by profit"); // StopTrade(); //} } }
private void btnTest_Click(object sender, EventArgs e) { var ptr = WndSearcher.SearchForWindow("", "WinRAR"); WndSearcher.SetForegroundWindow(ptr); return; //_table = new Table(0, _settings); _table.WindowPoint = _settings.WindowPoint; SaveBmpLog("test", "test2", "test3"); return; if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var image = Bitmap.FromFile(openFileDialog1.FileName) as Bitmap; var myEncoderParameters = new EncoderParameters(1); var myEncoderParameter = new EncoderParameter(Encoder.Quality, 70L); var fi = new FileInfo(openFileDialog1.FileName); myEncoderParameters.Param[0] = myEncoderParameter; var jgpEncoder = GetEncoder(ImageFormat.Jpeg); image.Save(fi.Directory.FullName + @"\1.jpeg", jgpEncoder, myEncoderParameters); } return; _table = new Table(6, AppSettingsManager.Load("six")); var pt = tbLog.PointToScreen(tbLog.Location); _table.ClickOnPoint(pt); _table.TypeNumber((decimal)0.98); return; var txt = "test t t"; var t = txt.Replace("\t", string.Empty); Trace.WriteLine(DateTime.Now.ToString("HH:mm:ss")); //lblNextPause.Text = _table.IsPaused.ToString(); return; //_logDebug.Info("test"); //return; //_table.BetInput = _settings.BetInputRect; //_table.AllCards = new CardCollection(); //_table.MyCards = new CardCollection(); //_table.ClickBet((decimal)0.05); //return; //_table.ClickButton2(); //return; //var str = "1"; //str = str.Substring(1); //var pl = new PlayerCollection(); //pl.Add(new Player {Action = PlayerAction.Check }); //pl.Add(new Player { Action = PlayerAction.Check }); //pl.Add(new Player { Action = PlayerAction.Check }); //pl.Add(new Player { Action = PlayerAction.Check }); //pl.Add(new Player { Action = PlayerAction.Call }); //pl.Add(new Player { Action = PlayerAction.Check, IsMe = true }); //_table.Players = pl; //Trace.WriteLine(_table.DdAllCalled + "," +_table.DdAllCheckOrFold // + "," + _table.DdOneRaisedAllFold // +"," + _table.DdOneRaisedOneCalled // ); //return; /* _table.MyCards = new CardCollection(); _table.MyCards.Clear(); _table.MyCards.Add(new Card {Rank = Rank.Queen, Suit = Suit.Diamonds}); _table.MyCards.Add(new Card { Rank = Rank.King, Suit = Suit.Spades }); Trace.WriteLine(_table.MyCards.HasCards("T.,KQs")); Trace.WriteLine(_table.MyCards.HasCards("T.o,KTo")); Trace.WriteLine(_table.MyCards.HasCards("T.s,KQo")); return; var r = CheckPair( new Card {Rank = Rank.Ten}, new Card {Rank = Rank.Four}, new Card {Rank = Rank.Four}, null, //new Card {Rank = Rank.King}, null, //new Card {Rank = Rank.Four}, new Card {Rank = Rank.Two}, new Card {Rank = Rank.Ten}, Rank.Four ); Trace.WriteLine(r); return; //Ex.Report(new Exception("test")); //*/ var ids = new Dictionary<Rank, int>() { {Rank.Two, 0}, {Rank.Three, 0}, {Rank.Four, 0}, {Rank.Five, 0}, {Rank.Six, 0}, {Rank.Seven, 1}, {Rank.Eight, 0}, {Rank.Nine, 0}, {Rank.Ten, 1}, {Rank.Jack, 1}, {Rank.Queen, 1}, {Rank.King, 1}, {Rank.Ace, 1}, }; var cards = new List<Card>(); foreach (KeyValuePair<Rank, int> pair in ids) { if (pair.Value == 1) { cards.Add(new Card(){Rank = pair.Key}); } } Trace.WriteLine("street = " + CheckStreetAlgo(cards.ToArray(), 5)); Trace.WriteLine("half-street = " + CheckHalfStreetAlgo(cards.ToArray(), 4)); lblStatus.Text =((int)(Rank.Ace & Rank.King)).ToString(); //if (_table != null) //{ // _table.ClickFold(); //} }
void RecognizeTable(Bitmap image) { if (_table == null) { _table = new Table((rbSix.Checked ? 6 : 9), _settings); _table.ClickLog += TableOnClickLog; _table.ClickLogDebug += TableOnClickLogDebug; _table.AfterClickLog +=TableOnAfterClickLog; InitPlayerRects(_settings); InitButtonRects(_settings); InitBetRects(_settings); } else { _table.ClearTable(); } var dir = Application.StartupPath + @"\Temp\"; if (!Directory.Exists(dir)) Directory.CreateDirectory(dir); _table.TempDir = dir; _table.MinBet = _settings.MinBet; _table.BetInput = _settings.BetInputRect; _table.WindowPoint = _settings.WindowPoint; _table.RecognizeFromWholeBmp(image, _settings); tbTxtResult.Text = _table.TxtResult; var diff = _settings.MinBet; foreach (var player in _table.Players) { player.IsAllIn = false; player.Parse(_settings.RemoveDollar); if (player.IsActive) { var newDiff = player.AnalyseBets(diff); if (player.Action == PlayerAction.Raise) { diff = newDiff; } //Ex.Info(player.Posa + ";" + player.PosaPrev); } if (!player.IsFold && !player.IsActive) { player.IsAllIn = true; } player.Stat.Collect(player); //if(player.IsActive) // player.AnalyseBets(_settings.MinBet); } ////TODO players //var crop = new Crop(_settings.Player1); //var playerBmp = crop.Apply(image); //_table.RecognisePlayer(playerBmp); //TODO SLOWWW //_table.CountPlayers(_playersTemplate); _table.SetRaiserPosition(); lblPlayersCount.Text = _table.TotalPlayers + " players, " + _table.FoldPlayers + " fold, " + _table.RaiserCount + " raised at " + _table.RaiserPosition + "," + "button=" + (_table.ButtonPlayer + 1); lblDealerButton.Text = (_table.DealerButtons.IndexOf(true) + 1).ToString() + " - " + _table.MyPosition; pbAllCards.Image = _table.AllCardsBmp; pbMyCards.Image = _table.MyCardsBmp; pbButtonsFold.Image = _table.ButtonFoldBmp; pbButtonsCallCheck.Image = _table.ButtonCallCheckBmp; pbButtonsBetRaise.Image = _table.ButtonBetRaiseBmp; rbAllCards.Text = ""; rbMyCards.Text = ""; foreach (var item in _table.AllCards.CardsStr) { rbAllCards.AppendText(item.Item1, item.Item2); } foreach (var item in _table.MyCards.CardsStr) { rbMyCards.AppendText(item.Item1, item.Item2); } tbButtons.Text = _table.Buttons.ToString(); pbMyBalance.Image = _table.MyBalance.Image; tbMyBalance.Text = _table.MyBalance.ToString(); pbBank.Image = _table.Bank.BankImg; tbBank.Text = _table.Bank.BankValue.ToString(); pbCall.Image = _table.Bank.CallImg; tbCall.Text = _table.Bank.CallValue.ToString(); pbRaise.Image = _table.Bank.RaiseImg; tbRaise.Text = _table.Bank.RaiseValue.ToString(); SetPlayerUi(tb1, pb1, 0); SetPlayerUi(tb2, pb2, 1); SetPlayerUi(tb3, pb3, 2); SetPlayerUi(tb4, pb4, 3); SetPlayerUi(tb5, pb5, 4); SetPlayerUi(tb6, pb6, 5); SetPlayerUi(tb7, pb7, 6); SetPlayerUi(tb8, pb8, 7); SetPlayerUi(tb9, pb9, 8); SetBetUi(tbBet1, pbBet1, 0); SetBetUi(tbBet2, pbBet2, 1); SetBetUi(tbBet3, pbBet3, 2); SetBetUi(tbBet4, pbBet4, 3); SetBetUi(tbBet5, pbBet5, 4); SetBetUi(tbBet6, pbBet6, 5); SetBetUi(tbBet7, pbBet7, 6); SetBetUi(tbBet8, pbBet8, 7); SetBetUi(tbBet9, pbBet9, 8); }
private void btnLoadSettings_Click(object sender, EventArgs e) { LoadSettings(); _table = new Table((rbSix.Checked ? 6 : 9), _settings); _table.ClickLog += TableOnClickLog; _table.ClickLogDebug += TableOnClickLogDebug; _table.AfterClickLog += TableOnAfterClickLog; InitPlayerRects(_settings); InitButtonRects(_settings); InitBetRects(_settings); }