示例#1
0
        private void MainBoardControl_OnAction(object sender, Point e)
        {
            FieldCoordinates action = FieldCoordinates.Get((uint)e.X, (uint)e.Y);

            MainNavigator1.Navigator.Play(action);
            MainNavigator1.Forward(this, action);
        }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var rounds = MainNavigator1.Navigator.RoundWithDetails((int)numberOfPlayoutsControl.Value);

            playoutListControl.Items.Clear();
            int playoutNumber = 1;
            var whiteTrigger  = FieldCoordinates.Get(0, 5);

            foreach (var round in rounds)
            {
                string trigger = " ";
                var    played  = round.Playout?.FirstOrDefault(m => whiteTrigger.Equals(m.Item1));

                if (played != null)
                {
                    if (played.Item2.CurrentPlayer.Opposite.Color.State == FieldState.White)
                    {
                        trigger = "*";
                    }
                }

                string result = round.GetLastGameState().GetWinner().Color.State == FieldState.Black ? "B" : "W";
                playoutListControl.Items.Add(new NamedObject <GoMctsRound>($"{playoutNumber:000} {result}{trigger}", round));
                playoutNumber++;
            }

            GoBoardControlFieldFeaturesHelper.RefreshBoard(goBoardControl1, MainNavigator1);
        }
示例#3
0
        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();
        }