示例#1
0
        private void TrainNetwork(Move move)
        {
            // If there is just one option the training will always reward the NNet
            if (move.Children == null)
            {
                return;
            }
            if (move.Children.Count < 2)
            {
                return;
            }

            if (untrained.Count == 0)
            {
                UpdateGeneration();
            }

            JNNet nnet = untrained[random.Next(0, untrained.Count - 1)];

            untrained.Remove(nnet);
            trained.Add(nnet);

            Move   nnetMove = null, mostVisitedMove = null;
            double score = double.NegativeInfinity, childScore;
            int    mostVisitedTimes = int.MinValue;

            input = State.GetInput();
            foreach (Move child in move.Children)
            {
                childScore = nnet.Next(input)[0];
                if (childScore > score)
                {
                    nnetMove = child;
                    score    = childScore;
                }

                if (child.NumberOfVisits > mostVisitedTimes)
                {
                    mostVisitedMove  = child;
                    mostVisitedTimes = child.NumberOfVisits;
                }
            }

            // Give it a point if it chose the most explored route
            if (mostVisitedMove == nnetMove)
            {
                nnet.Score = 1;
            }
            else
            {
                nnet.Score = 0;
            }
        }
示例#2
0
        private Move Next()
        {
            bestNnet = BestNNet;

            double score = double.NegativeInfinity, currentScore;

            foreach (Move move in State.GetChildren())
            {
                State.DoMove(move);
                currentScore = bestNnet.Next(State.GetInput())[0];

                if (currentScore > score)
                {
                    score    = currentScore;
                    bestMove = move;
                }
                State.UndoMoves(1);
            }

            return(bestMove);
        }