public override void ChooseCards(List <Card> choices,
                                     Func <Dictionary <Card, int>, bool> validateChoices,
                                     Func <List <Card>, Dictionary <Card, int>,
                                           List <Card> > filterChoices, Func <Dictionary <Card, int>, bool, bool> choicesComplete,
                                     bool stoppable,
                                     Game game,
                                     Player choosingPlayer,
                                     string description,
                                     out BoardChoices boardChoice)
    {
        ChoiceHandlerDelegator.Instance.TriggerChoice(this, choosingPlayer, new ChooseCardsInputHandler(description, choices, validateChoices, filterChoices, choicesComplete, stoppable));
        waitForInput.WaitOne();

        boardChoice = new BoardChoices();

        if (passedParams == null)
        {
            boardChoice.NotCancelled = false;
        }
        else
        {
            boardChoice.SelectedCards = (Dictionary <Card, int>)passedParams[0];
        }

        passedParams = null;
    }
    public override void ChooseBoardObjects(List <BoardObject> choices,
                                            Func <Dictionary <BoardObject, int>, bool> validateChoices,
                                            Func <List <BoardObject>, Dictionary <BoardObject, int>,
                                                  List <BoardObject> > filterChoices,
                                            Func <Dictionary <BoardObject, int>, bool> choicesComplete,
                                            Game game,
                                            Player choosingPlayer,
                                            string desc,
                                            out BoardChoices boardChoice)
    {
        ChoiceHandlerDelegator.Instance.TriggerChoice(this, choosingPlayer, new PickBoardObjectInputHandler(desc, choices, validateChoices, filterChoices, choicesComplete));
        waitForInput.WaitOne();

        boardChoice = new BoardChoices();

        if (passedParams == null)
        {
            boardChoice.NotCancelled = false;
        }
        else
        {
            boardChoice.SelectedObjs = (Dictionary <BoardObject, int>)passedParams[0];
        }

        passedParams = null;
    }
Beispiel #3
0
        public override void ChooseBoardObjects(List <BoardObject> choices, Func <Dictionary <BoardObject, int>, bool> validateChoices, Func <List <BoardObject>, Dictionary <BoardObject, int>, List <BoardObject> > filterChoices, Func <Dictionary <BoardObject, int>, bool> choicesComplete, Game game, Player choosingPlayer, string description, out BoardChoices boardChoice)
        {
            boardChoice = new BoardChoices();

            if (choices.Count == 0)
            {
                return;
            }

            Dictionary <BoardObject, int> selected         = new Dictionary <BoardObject, int>();
            List <BoardObject>            remainingChoices = new List <BoardObject>(choices);

            Random random = new Random();

            while (true)
            {
                if (remainingChoices.Count <= 0)
                {
                    break;
                }

                int idx = random.Next() % remainingChoices.Count;

                BoardObject obj = remainingChoices[idx];
                if (!selected.ContainsKey(obj))
                {
                    selected[obj] = 0;
                }
                selected[obj] += 1;

                bool valid = validateChoices(selected);

                if (!valid)
                {
                    selected[obj] -= 1;
                    if (selected[obj] < 0)
                    {
                        selected.Remove(obj);
                    }
                    continue;
                }

                bool complete = choicesComplete(selected);

                if (complete)
                {
                    break;
                }

                remainingChoices = filterChoices(remainingChoices, selected);
            }

            boardChoice.SelectedObjs = selected;
        }