/// <summary> /// Returns the amount of wins the challenger got (from 100) /// </summary> private static int CalculateChallengerWinsFrom100(NoLookaheadStrategy strategy) { int totalPlacements = 0; PieceCollection empty = new PieceCollection(); //Parallel.For(0, GameCount, (i) => for (var i = 0; i < GameCount; i++) { var pieces = RandomPiecesCache[i]; var board = new BoardState(); var pieceIndex = 0; while (strategy.TryPlacePiece(board, pieces[pieceIndex], in empty, 0, out var bitmap, out var x, out var y)) { board.Place(bitmap, x, y); pieceIndex++; } totalPlacements += pieceIndex; //Interlocked.Add(ref totalPlacements, pieceIndex); } return(totalPlacements); }
/// <summary> /// Returns the amount of wins the challenger got (from 100) /// </summary> private static int CalculateChallengerWinsFrom100(NoLookaheadStrategy strategy) { int totalPlacements = 0; PieceCollection empty = new PieceCollection(); Parallel.For(0, GameCount, new ParallelOptions { MaxDegreeOfParallelism = 8 }, (i) => { var pieces = RandomPiecesCache[i]; var board = new BoardState(); var pieceIndex = 0; while (strategy.TryPlacePiece(board, pieces[pieceIndex], in empty, 0, out var bitmap, out var x, out var y)) { board.Place(bitmap, x, y); pieceIndex++; } Interlocked.Add(ref totalPlacements, pieceIndex); });