//public GameTreeNavigationController(IGameTreeNavigator<TGameTree, TGameState, TGameAction, TNode> navigator, HScrollBar scrollBar) public GameTreeNavigationController(IObservableGameTreeNavigator <TNode, TState, TAction> navigator, HScrollBar scrollBar) { this.scrollBar = scrollBar; this.scrollBar.Minimum = 0; this.scrollBar.Maximum = 0; scrollBarPreviousValue = -1; this.scrollBar.Value = 0; this.scrollBar.ValueChanged += ScrollBar_ValueChanged; this.navigator1 = navigator; this.navigator1.Forwarded += OnForwarded; this.navigator1.Navigated += OnNavigated; }
public static void RefreshBoard(GoBoardControl boardControl, IObservableGameTreeNavigator <MCTreeSearchNode <GameState, FieldCoordinates>, GameState, FieldCoordinates> navigator) { GameState currentState = navigator.CurrentNode.State; var allowedActions = currentState.GetAllowedActions(); for (uint y = 0; y < boardControl.BoardSize; y++) { for (uint x = 0; x < boardControl.BoardSize; x++) { FieldCoordinates field = FieldCoordinates.Get(x, y); FieldState fieldState = currentState.InternalState.BoardFields[x, y]; boardControl.Fields[x, y].State = fieldState; boardControl.Fields[x, y].Labels.Clear(); // Illegal boardControl.Fields[x, y].Borders[0] = fieldState == FieldState.Empty ? allowedActions.Contains(field) == false : false; boardControl.Fields[x, y].Borders[1] = false; boardControl.Fields[x, y].Borders[2] = false; } } var currentNode = navigator.CurrentNode; //double[] mctsWeights = null;// mcts.Selector.GetWeights(mcts.CurrentNode); if (currentNode.Children != null) { foreach (var childNode in currentNode.Children) { if (childNode.Key != FieldCoordinates.Pass) { if (childNode.Value.Visits > 0) { boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Magenta, $"{childNode.Value.Visits}"); boardControl.Fields[childNode.Key.X, childNode.Key.Y].AddLabel(Brushes.Green, $"{childNode.Value.Value}"); } } } var mostFrequentlySimulated = currentNode.Children.Where(w => w.Key != FieldCoordinates.Pass && w.Value.Visits > 0).MaxItems(i => i.Value.Visits); foreach (var mostItem in mostFrequentlySimulated) { boardControl.Fields[mostItem.Key.X, mostItem.Key.Y].Borders[2] = true; } } //if (mctsWeights != null) //{ // mctsWeights = mctsWeights.Where(w => w.Item1.LastAction != null && w.Item1.LastAction != FieldCoordinates.Pass); // // foreach (var item in mctsWeights) // { // var move = item.Item1.LastAction; // // if (move != null && move != FieldCoordinates.Pass) // { // boardControl.Fields[move.X, move.Y].AddLabel(Brushes.Blue, $"{item.Item2:f2}"); // } // } // // var maxItem = mctsWeights.MaxItem(i => i.Item2); // var maxMove = maxItem.Item1.LastAction; // // boardControl.Fields[maxMove.X, maxMove.Y].Borders[1] = true; //} boardControl.Refresh(); }