-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
689bd42
commit b27b50a
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}!"); | ||
} | ||
} |