private int ScoreAllPossibleBoards(IGameBoard board, Direction direction, int depthToSearch) { int cumulativeScore = 0; int boardsTested = 0; var possibleBoardsAfterMove = board.GetAllPossibleResults(direction); foreach (IGameBoard gb in possibleBoardsAfterMove) { cumulativeScore += ScoreSingleBoard(gb); boardsTested++; } if (boardsTested == 0) { return 0; } if (depthToSearch <= 1) { return (cumulativeScore / boardsTested); } int depthTotal = 0; int boardsExplored = 0; foreach (IGameBoard gb in possibleBoardsAfterMove) { foreach (Direction d in Enum.GetValues(typeof(Direction))) { depthTotal += ScoreAllPossibleBoards(gb, d, depthToSearch - 1); boardsExplored++; } } return depthTotal / boardsExplored; }