Пример #1
0
        public override bool Equals(object obj)
        {
            GameTree that = obj as GameTree;

            if (!this.BoardState.Equals(that.BoardState))
            {
                return(false);
            }
            else if (that.CurrentDepth == that.MaximumDepth)
            {
                return(true);
            }
            else
            {
                if (this.Children.Count != that.Children.Count)
                {
                    return(false);
                }
                for (int i = 0; i < this.Children.Count; ++i)
                {
                    if (!this.Children.ElementAt(i).Equals(that.Children.ElementAt(i)))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
Пример #2
0
 public void ChooseNewRoot(GameTree newRoot)
 {
     Rate       = newRoot.Rate;
     BoardState = newRoot.BoardState;
     NextPlayer = newRoot.NextPlayer;
     Children   = newRoot.Children;
     _setChildrenCurrentDepth();
 }
        public Board GetBoardWithDecisonExecuted(Board state)
        {
            GameTree gameTree = new GameTree(state, Me, 2, 0);

            gameTree.Expand();
            Board statusQuo = gameTree.Children.ElementAt(0).BoardState; //it may not be true status quo, but only when I can't win
            Board boardOnWhichIOccupyMiddlePoint = null;

            foreach (GameTree child in gameTree.Children)
            {
                if (IfIWin(GameResultChecker.CheckGameResult(child.BoardState)))
                {
                    return(child.BoardState);
                }
                foreach (GameTree child2 in child.Children)
                {
                    if (IfILoose(GameResultChecker.CheckGameResult(child2.BoardState)))
                    {
                        goto GoFurther;
                    }
                }
                if (child.BoardState.PositionAt(1, 1).Status == Me)
                {
                    boardOnWhichIOccupyMiddlePoint = child.BoardState;
                }
                statusQuo = child.BoardState;
GoFurther:
                continue;
            }
            if (boardOnWhichIOccupyMiddlePoint == null)
            {
                return(statusQuo);
            }
            else
            {
                return(boardOnWhichIOccupyMiddlePoint);
            }
        }
Пример #4
0
        public void MiniMaks(GameTree tree)
        {
            int howMany = 0;

            if (!(tree.Children is null))
            {
                howMany = tree.Children.Count();
            }
            if (howMany > 0)
            {
                if (tree.CurrentDepth % 2 == 1 && RateBoard(tree.BoardState) == 50 && tree.CurrentDepth != 0)
                {
                    tree.Rate = 50;
                    tree.Children.Clear();
                }
                else if (tree.CurrentDepth % 2 == 0 && RateBoard(tree.BoardState) == -50 && tree.CurrentDepth != 0)
                {
                    tree.Rate = -50;
                    tree.Children.Clear();
                }

                else
                {
                    for (int c = 0; c < howMany; c++)
                    {
                        MiniMaks(tree.Children[c]);
                    }

                    if (tree.CurrentDepth % 2 == 0)
                    {
                        int newRate = -50;

                        for (int c = 0; c < tree.Children.Count(); c++)
                        {
                            if (tree.Children[c].Rate >= newRate)
                            {
                                newRate = tree.Children[c].Rate;
                            }
                            else
                            {
                                tree.Children.Remove(tree.Children[c]);
                                c--;
                            }
                        }
                        tree.Rate = newRate;
                    }
                    else if (tree.CurrentDepth % 2 == 1)
                    {
                        int newRate = 50;

                        for (int c = 0; c < tree.Children.Count(); c++)
                        {
                            if (tree.Children[c].Rate <= newRate)
                            {
                                newRate = tree.Children[c].Rate;
                            }
                            else
                            {
                                tree.Children.Remove(tree.Children[c]);
                                c--;
                            }
                        }

                        tree.Rate = newRate;
                    }
                }
            }
            else
            {
                tree.Rate = RateBoard(tree.BoardState);
            }
        }