Skip to content

Commit

Permalink
add random play benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonifatius94 committed Nov 6, 2023
1 parent 689bd42 commit b27b50a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Schafkopf.Training/RandomPlayBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace Schafkopf.Training;

public class RandomPlayBenchmark
{
public void Benchmark(ISchafkopfAIAgent agentToEval, int epochs = 10_000)
{
var players = new Player[] {
new Player(0, agentToEval),
new Player(1, new RandomAgent()),
new Player(2, new RandomAgent()),
new Player(3, new RandomAgent())
};
var table = new Table(
players[0], players[1],
players[2], players[3]);
var deck = new CardsDeck();
var session = new GameSession(table, deck);

int wins = 0;
for (int i = 0; i < epochs; i++)
{
var log = session.ProcessGame();
var eval = new GameScoreEvaluation(log);
bool isCaller = log.Meta.CallerIds.Contains(0);
bool isWin = !eval.DidCallerWin ^ isCaller;
wins += isWin ? 1 : 0;
}

double winRate = (double)wins / epochs;
Console.WriteLine($"agent scored a win rate of {winRate}!");
}
}

0 comments on commit b27b50a

Please sign in to comment.