private static int PlayGames(IGamePlayer contestant, IGamePlayer opponent, int gameCount) { int wins = 0; foreach (var randomGameI in Enumerable.Range(0, gameCount).Where(g => !shouldClose)) { var gameMatch = new GameMatch( GameStateFactory.StandardStartGameState(), contestant, opponent); var outcome = gameMatch.CompleteMatch(); if (outcome == GameMatchOutcome.WhiteWin) { wins++; } } return(wins); }
public int EvaluateNet(IReadOnlyList <Net> competingNets, Net evaluatingNet, TrainingStatus trainingStatus) { var currentPlayer = NetPlayerLookup[evaluatingNet]; foreach (var opponentNet in competingNets) { var opponent = NetPlayerLookup[opponentNet]; var gameMatch = new GameMatch( GameStateFactory.StandardStartGameState(), currentPlayer.GamePlayer, opponent.GamePlayer ); var matchResult = gameMatch.CompleteMatch(); Interlocked.Increment(ref _gamesPlayed); currentPlayer.IncrementMatch(); opponent.IncrementMatch(); int uniqueGameStateCount = gameMatch.GameStateList.Distinct().Count(); currentPlayer.AddUniqueGameStates(uniqueGameStateCount); if (matchResult == GameMatchOutcome.WhiteWin) { currentPlayer.IncrementWin(); Interlocked.Increment(ref _whiteWins); } else if (matchResult == GameMatchOutcome.BlackWin) { opponent.IncrementWin(); Interlocked.Increment(ref _blackWins); } else if (matchResult == GameMatchOutcome.Draw) { currentPlayer.IncrementDraw(); opponent.IncrementDraw(); Interlocked.Increment(ref _gamesDrawn); } } int winScore = currentPlayer.Wins * WinWeight; int drawScore = currentPlayer.Draws * DrawWeight; var randomGamePlayer = new RandomGamePlayer(_random); int randomWins = 0; foreach (var i in Enumerable.Range(0, RandomGamesToPlay)) { GameMatch gameMatch; GameMatchOutcome winOutcome; if (i % 2 == 0) { gameMatch = new GameMatch( GameStateFactory.StandardStartGameState(), currentPlayer.GamePlayer, randomGamePlayer); winOutcome = GameMatchOutcome.WhiteWin; } else { gameMatch = new GameMatch( GameStateFactory.StandardStartGameState(), randomGamePlayer, currentPlayer.GamePlayer); winOutcome = GameMatchOutcome.BlackWin; } var outcome = gameMatch.CompleteMatch(); if (outcome == winOutcome) { randomWins++; } } int randomScore = randomWins * RandomWinWeight; int score = winScore + drawScore + randomScore; return(score); }