예제 #1
0
        public void Calculate(object start)
        {
            SimulationThreadStart starter = start as SimulationThreadStart;

            this.input  = starter.input;
            this.output = starter.output;

            Board BestBoard = null;

            while (input.Count > 0)
            {
                List <Board> childs = new List <Board>();
                foreach (Board b in input)
                {
                    foreach (Action a in b.CalculateAvailableActions())
                    {
                        Board bb = b.ExecuteAction(a);

                        bool found = false;
                        foreach (Board lol in childs)
                        {
                            if (bb.Equals(lol))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            childs.Add(bb);
                        }
                    }
                }

                foreach (Board b in childs)
                {
                    if (BestBoard == null)
                    {
                        BestBoard = b;
                    }
                    else if (b.GetValue() > BestBoard.GetValue())
                    {
                        BestBoard = b;
                    }
                    else if (b.GetValue() == BestBoard.GetValue())
                    {
                        if (b.FriendCardDraw > BestBoard.FriendCardDraw)
                        {
                            BestBoard = b;
                        }
                    }
                }
                input = childs;
            }

            if (BestBoard != null)
            {
                lock (sync)
                {
                    output.Add(BestBoard);
                }
            }
        }
예제 #2
0
        public void Calculate(object start)
        {
            SimulationThreadStart st = (SimulationThreadStart)start;

            root           = st.root;
            output         = st.output;
            doneEvent      = st.doneEvent;
            maxWidePerTree = st.maxWidePerTree;
            if (FoundLethal)
            {
                doneEvent.Set();
                return;
            }


            int wide    = 0;
            int skipped = 0;

            List <Board> boards = new List <Board>();

            boards.Add(root);
            root.Update();


            bool  tryToSkipEqualBoards = false;
            Board bestBoard            = null;

            wide    = 0;
            skipped = 0;
            List <Board> childs = new List <Board>();

            foreach (Board b in boards)
            {
                if (FoundLethal)
                {
                    doneEvent.Set();
                    return;
                }
                if (wide > maxWidePerTree)
                {
                    break;
                }
                List <Action> actions = b.CalculateAvailableActions();
                foreach (Action a in actions)
                {
                    if (FoundLethal)
                    {
                        doneEvent.Set();
                        return;
                    }
                    if (wide > maxWidePerTree)
                    {
                        break;
                    }

                    Board bb = b.ExecuteAction(a);

                    if (bb != null)
                    {
                        if (bb.GetValue() > 10000)
                        {
                            FoundLethal = true;
                            bestBoard   = bb;
                            if (bestBoard != null)
                            {
                                output.Add(bestBoard);
                            }
                            doneEvent.Set();
                            return;
                        }
                        if (tryToSkipEqualBoards)
                        {
                            bool found = false;
                            foreach (Board lol in output.ToArray())
                            {
                                if (bb.Equals(lol))
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (!found)
                            {
                                wide++;
                                childs.Add(bb);
                            }
                            else
                            {
                                skipped++;
                            }
                        }
                        else
                        {
                            wide++;
                            childs.Add(bb);
                        }
                    }
                }
            }

            foreach (Board b in childs)
            {
                if (b != null)
                {
                    output.Add(b);
                }
            }
            doneEvent.Set();
        }