private Direction PickMoveDirection() { //check for a forced random value var forceRandom = rnd.NextDouble() <= RANDOMNESS; if (forceRandom) { var options = Board.State.PossibleDirections().ToArray(); var d = XT.GetRandom(options, rnd); RandomMoves++; return(d); } //get the database/policy value var canID = Board.State; var policy = PolicyData.GetPolicy(canID)?.Result; if (policy != null) { PolicyMoves++; return(GetRecommendation(policy.GetWeights())); } //It wasn't sufficient, so use the algorithm var recDir = GetRecommendation(GetMoveWeights()); MethodMoves++; return(recDir); }
public void Run() { while (!Board.Lost) { PrintBoardState(); var moveWeights = GetMoveWeights(); var highestWeight = moveWeights.Values.Max(); var highestDirs = moveWeights.Where(kvp => kvp.Value == highestWeight) .Select(kvp => kvp.Key); var recDir = highestDirs.Count() == 1 ? highestDirs.First() : XT.GetRandom(XT.EnumVals <Direction>().ToArray(), rnd); Board.Move(recDir); PrintMoveResults(moveWeights, recDir); } return; }