Skip to content

Commit

Permalink
fix training data collection (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonifatius94 committed Dec 3, 2023
1 parent f84ee37 commit 6fa71c5
Show file tree
Hide file tree
Showing 4 changed files with 251 additions and 196 deletions.
49 changes: 49 additions & 0 deletions Schafkopf.Training.Tests/EnvTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Schafkopf.Lib;

namespace Schafkopf.Training.Tests;

public class CardPickerEnvTests
{
[Fact]
public void Test_CanPlayGame()
{
var rules = new GameRules();
var cardCache = new Card[8];
var rng = new Random();

var env = new CardPickerEnv();
var state = env.Reset();
foreach (int i in Enumerable.Range(0, 32))
{
var possActions = rules.PossibleCards(state, cardCache);
var action = possActions[rng.Next(possActions.Length)];
(state, var __, var ___) = env.Step(action);
Assert.Equal(i+1, state.CardCount);
}

Assert.Equal(32, state.CardCount); // assert that no exception occurred
}

[Fact(Skip="raises error (needs to be fixed)")]
public void Test_CanPlayConsequtiveGames()
{
var rules = new GameRules();
var cardCache = new Card[8];
var rng = new Random();
var env = new CardPickerEnv();

foreach (int _ in Enumerable.Range(0, 1000))
{
var state = env.Reset();
foreach (int i in Enumerable.Range(0, 32))
{
var possActions = rules.PossibleCards(state, cardCache);
var action = possActions[rng.Next(possActions.Length)];
(state, var __, var ___) = env.Step(action);
Assert.Equal(i+1, state.CardCount);
}

Assert.Equal(32, state.CardCount); // assert that no exception occurred
}
}
}
Loading

0 comments on commit 6fa71c5

Please sign in to comment.