mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-25 04:15:45 -08:00
48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Poker.Strategies;
|
|
using static System.StringComparison;
|
|
|
|
namespace Poker;
|
|
|
|
internal static class IReadWriteExtensions
|
|
{
|
|
internal static bool ReadYesNo(this IReadWrite io, string prompt)
|
|
{
|
|
while (true)
|
|
{
|
|
var response = io.ReadString(prompt);
|
|
if (response.Equals("YES", InvariantCultureIgnoreCase)) { return true; }
|
|
if (response.Equals("NO", InvariantCultureIgnoreCase)) { return false; }
|
|
io.WriteLine("Answer Yes or No, please.");
|
|
}
|
|
}
|
|
|
|
internal static float ReadNumber(this IReadWrite io) => io.ReadNumber("");
|
|
|
|
internal static int ReadNumber(this IReadWrite io, string prompt, int max, string maxPrompt)
|
|
{
|
|
io.Write(prompt);
|
|
while (true)
|
|
{
|
|
var response = io.ReadNumber();
|
|
if (response <= max) { return (int)response; }
|
|
io.WriteLine(maxPrompt);
|
|
}
|
|
}
|
|
|
|
internal static Strategy ReadHumanStrategy(this IReadWrite io, bool noCurrentBets)
|
|
{
|
|
while(true)
|
|
{
|
|
io.WriteLine();
|
|
var bet = io.ReadNumber("What is your bet");
|
|
if (bet != (int)bet)
|
|
{
|
|
if (noCurrentBets && bet == .5) { return Strategy.Check; }
|
|
io.WriteLine("No small change, please.");
|
|
continue;
|
|
}
|
|
if (bet == 0) { return Strategy.Fold; }
|
|
return Strategy.Bet(bet);
|
|
}
|
|
}
|
|
} |