CSHARP-71 Move Human GetWager logic

This commit is contained in:
Andrew Cooper
2022-07-01 17:20:13 +10:00
parent a132e881fe
commit 1558bfbfe8
3 changed files with 33 additions and 28 deletions

View File

@@ -76,7 +76,7 @@ internal class Computer : Player
{
_io.WriteLine("I'll see you.");
Bet = Table.Human.Bet;
Table.UpdatePot();
Table.CollectBets();
}
else
{

View File

@@ -1,4 +1,5 @@
using Poker.Cards;
using Poker.Strategies;
namespace Poker.Players;
@@ -30,6 +31,32 @@ internal class Human : Player
_io.Write(Hand);
}
internal bool SetWager()
{
var strategy = _io.ReadHumanStrategy(Table.Computer.Bet == 0 && Bet == 0);
if (strategy is Strategies.Bet or Check)
{
if (Bet + strategy.Value < Table.Computer.Bet)
{
_io.WriteLine("If you can't see my bet, then fold.");
return false;
}
if (Balance - Bet - strategy.Value >= 0)
{
HasBet = true;
Bet += strategy.Value;
return true;
}
RaiseFunds();
}
else
{
Fold();
Table.CollectBets();
}
return false;
}
public void RaiseFunds()
{
_io.WriteLine();

View File

@@ -113,34 +113,12 @@ internal class Table
Human.HasBet = false;
while (true)
{
var humanStrategy = _io.ReadHumanStrategy(Computer.Bet == 0 && Human.Bet == 0);
if (humanStrategy is Bet or Check)
{
if (Human.Bet + humanStrategy.Value < Computer.Bet)
{
_io.WriteLine("If you can't see my bet, then fold.");
continue;
}
if (Human.Balance - Human.Bet - humanStrategy.Value >= 0)
{
Human.HasBet = true;
Human.Bet += humanStrategy.Value;
break;
}
Human.RaiseFunds();
if (Human.IsBroke) { return; }
continue;
}
else
{
Human.Fold();
UpdatePot();
return;
}
if (Human.SetWager()) { break; }
if (Human.IsBroke || Human.HasFolded) { return; }
}
if (Human.Bet == Computer.Bet)
{
UpdatePot();
CollectBets();
return;
}
if (Computer.Strategy is Fold)
@@ -158,7 +136,7 @@ internal class Table
{
_io.WriteLine("I'll see you.");
Computer.Bet = Human.Bet;
UpdatePot();
CollectBets();
return;
}
}
@@ -170,7 +148,7 @@ internal class Table
}
}
private void UpdatePot()
internal void CollectBets()
{
Human.Balance -= Human.Bet;
Computer.Balance -= Computer.Bet;