Skip to content

Commit

Permalink
Merge pull request HearthSim#5 from Jin42/master
Browse files Browse the repository at this point in the history
 Added Simulate function (not 100% stable yet)
  • Loading branch information
ADockhorn authored May 16, 2018
2 parents c00eb1d + 12b5b38 commit f1cb934
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion core-extensions/SabberStoneCoreAi/src/POGame/POGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ namespace SabberStoneCoreAi.POGame
partial class POGame
{
private Game game;
private Game origGame;
private bool debug;

public POGame(Game game, bool debug)
{
this.origGame = game;
this.game = game.Clone();
game.Player1.Game = game;
game.Player2.Game = game;
Expand Down Expand Up @@ -112,9 +114,35 @@ public void Process(PlayerTask task)
game.Process(task);
}

/**
* Simulates the tasks against the current game and
* returns a Dictionary with the following POGame-Object
* for each task (or null if an exception happened
* during that game)
*/
public Dictionary<PlayerTask, POGame> Simulate(List<PlayerTask> tasksToSimulate)
{
Dictionary<PlayerTask, POGame> simulated = new Dictionary<PlayerTask, POGame>();
foreach (PlayerTask task in tasksToSimulate)
{
Game clone = this.origGame.Clone();
try
{
clone.Process(task);
simulated.Add(task, new POGame(clone, this.debug));
}
catch (Exception)
{
simulated.Add(task, null);
}
}
return simulated;

}

public POGame getCopy(bool debug)
{
return new POGame(game, debug);
return new POGame(origGame, debug);
}


Expand Down

0 comments on commit f1cb934

Please sign in to comment.