コード例 #1
0
 public void ComputerMove()
 {
     Node next = _node.FindNextMove(_depth);
     
     if(next != null)
     {
         next._human = true;
         _node = next;
         _node._score = _node.Utility();
     }
     _moves++;
     
 }
コード例 #2
0
        public void Start()
        {
            _moves = 0;
            int[][] state = new int[6][];

            for (int i = 0; i < state.Length; i++)
            {
                state[i] = new int[7];
                for (int j = 0; j < state[i].Length; j++)
                {
                    state[i][j] = 0;
                }
            }

            _node = new Node(state, true);
        }
コード例 #3
0
        public int Minimax(out Node node, int alpha, int beta, int depth, bool needMax)
        {
            node = null;
            System.Diagnostics.Debug.Assert(_human == needMax);
            if (depth == 0 || _terminal)
            {
                RecursiveScore = _score;
                return _score;
            }

            foreach (Node child in getChildren())
            {
                Node chil = null;

                int score = child.Minimax(out chil, alpha, beta, depth-1, !needMax);

                if (!needMax)
                {
                    if (beta > score)
                    {
                        beta = score;
                        node = child;
                        if (alpha >= beta)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    if (alpha < score)
                    {
                        alpha = score;
                        node = child;
                        if (alpha >= beta)
                        {
                            break;
                        }
                    }
                }
            }

            RecursiveScore = needMax ? alpha : beta;
            return RecursiveScore;
        }