Beispiel #1
0
        private void PopulateChildren()
        {
            List <MiniMaxNode> nodes = new List <MiniMaxNode>();

            if (CurrentState.IsMaxPlayerTurn)
            {
                Score = int.MinValue;
                foreach (IGameState move in CurrentState.Moves)
                {
                    MiniMaxNode newNode = new MiniMaxNode(move);
                    nodes.Add(newNode);
                    if (newNode.Score > Score)
                    {
                        BestChild = newNode;
                        Score     = BestChild.Score;
                    }
                }
            }
            else
            {
                Score = int.MaxValue;
                foreach (IGameState move in CurrentState.Moves)
                {
                    MiniMaxNode newNode = new MiniMaxNode(move);
                    nodes.Add(newNode);
                    if (newNode.Score < Score)
                    {
                        BestChild = newNode;
                        Score     = BestChild.Score;
                    }
                }
            }
            Children = nodes.OrderByDescending(a => a.Score).ToArray();
        }
Beispiel #2
0
 internal MiniMaxNode(IGameState state)
 {
     CurrentState = state;
     if (state.IsTerminal)
     {
         Score    = state.Value;
         Children = new MiniMaxNode[0];
         return;
     }
     PopulateChildren();
 }