mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-12 15:50:20 -08:00
CSHARP-71 Move Human GetWager logic
This commit is contained in:
@@ -76,7 +76,7 @@ internal class Computer : Player
|
||||
{
|
||||
_io.WriteLine("I'll see you.");
|
||||
Bet = Table.Human.Bet;
|
||||
Table.UpdatePot();
|
||||
Table.CollectBets();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user