Remove global V

This commit is contained in:
Andrew Cooper
2022-06-25 16:12:20 +10:00
parent 860dd40276
commit a777b3888b
2 changed files with 21 additions and 18 deletions

View File

@@ -10,8 +10,6 @@ internal class Game
private readonly IReadWrite _io; private readonly IReadWrite _io;
private readonly IRandom _random; private readonly IRandom _random;
private int V;
public Game(IReadWrite io, IRandom random) public Game(IReadWrite io, IRandom random)
{ {
_io = io; _io = io;
@@ -67,12 +65,12 @@ internal class Game
}; };
if (table.Computer.Strategy is Bet) if (table.Computer.Strategy is Bet)
{ {
V = table.Computer.Strategy.Value + Get0To9(); var bet = table.Computer.Strategy.Value + Get0To9();
if (table.Computer.Balance - table.Human.Bet - V < 0) if (table.Computer.Balance - table.Human.Bet - bet < 0)
{ {
if (table.Human.Bet == 0) if (table.Human.Bet == 0)
{ {
V = table.Computer.Balance; bet = table.Computer.Balance;
} }
else if (table.Computer.Balance - table.Human.Bet >= 0) else if (table.Computer.Balance - table.Human.Bet >= 0)
{ {
@@ -86,8 +84,8 @@ internal class Game
if (table.Computer.IsBroke) { return; } if (table.Computer.IsBroke) { return; }
} }
} }
_io.WriteLine($"I'll open with ${V}"); _io.WriteLine($"I'll open with ${bet}");
table.Computer.Bet = V; table.Computer.Bet = bet;
} }
else else
{ {
@@ -115,12 +113,12 @@ internal class Game
} }
else if (table.Computer.Strategy is Bet) else if (table.Computer.Strategy is Bet)
{ {
V = table.Computer.Strategy.Value + Get0To9(); var bet = table.Computer.Strategy.Value + Get0To9();
if (table.Computer.Balance - table.Human.Bet - V < 0) if (table.Computer.Balance - table.Human.Bet - bet < 0)
{ {
if (table.Human.Bet == 0) if (table.Human.Bet == 0)
{ {
V = table.Computer.Balance; bet = table.Computer.Balance;
} }
else if (table.Computer.Balance - table.Human.Bet >= 0) else if (table.Computer.Balance - table.Human.Bet >= 0)
{ {
@@ -134,8 +132,8 @@ internal class Game
if (table.Computer.IsBroke) { return; } if (table.Computer.IsBroke) { return; }
} }
} }
_io.WriteLine($"I'll bet ${V}"); _io.WriteLine($"I'll bet ${bet}");
table.Computer.Bet = V; table.Computer.Bet = bet;
GetWager(table.Computer.Strategy); GetWager(table.Computer.Strategy);
if (table.SomeoneIsBroke() || table.SomeoneHasFolded()) { return; } if (table.SomeoneIsBroke() || table.SomeoneHasFolded()) { return; }
} }
@@ -195,7 +193,6 @@ internal class Game
_io.WriteLine("I fold."); _io.WriteLine("I fold.");
return; return;
} }
V = 5;
} }
if (table.Human.Bet > 3 * computerStrategy.Value) if (table.Human.Bet > 3 * computerStrategy.Value)
{ {
@@ -208,12 +205,12 @@ internal class Game
} }
} }
V = table.Human.Bet - table.Computer.Bet + Get0To9(); var raise = table.Human.Bet - table.Computer.Bet + Get0To9();
if (table.Computer.Balance - table.Human.Bet - V < 0) if (table.Computer.Balance - table.Human.Bet - raise < 0)
{ {
if (table.Human.Bet == 0) if (table.Human.Bet == 0)
{ {
V = table.Computer.Balance; raise = table.Computer.Balance;
} }
else if (table.Computer.Balance - table.Human.Bet >= 0) else if (table.Computer.Balance - table.Human.Bet >= 0)
{ {
@@ -227,8 +224,8 @@ internal class Game
if (table.Computer.IsBroke) { return; } if (table.Computer.IsBroke) { return; }
} }
} }
_io.WriteLine($"I'll see you, and raise you{V}"); _io.WriteLine($"I'll see you, and raise you {raise}");
table.Computer.Bet = table.Human.Bet + V; table.Computer.Bet = table.Human.Bet + raise;
} }
} }
} }

View File

@@ -0,0 +1,6 @@
namespace Poker.Strategies;
internal class None : Strategy
{
public override int Value => -1;
}