Beispiel #1
0
    private bool FindConstituentToMove(District fromDistrict, District toDistrict, Constituent.Party party, out MoveManager.Move move)
    {
        //candidates for moving are any district in the "from" district, with the requested party, that hasn't already been moved this turn
        var moveCandidates = fromDistrict.ConstituentsQuery.Where(c => c.party == party && !moveManager.OriginalDistricts.ContainsKey(c));

        //intersect the move candidates with the moves the rules actually allow us to make
        HashSet <Constituent> validMoves = moveManager.GetValidMovesForDistrict(toDistrict);

        validMoves.IntersectWith(moveCandidates);

        //if there are any moves available, choose one at random
        if (validMoves.Count > 0)
        {
            Constituent chosenMove = Utils.ChooseRandom(moveCandidates.ToArray());
            move = new MoveManager.Move(chosenMove, chosenMove.District, toDistrict);
            return(true);
        }
        else
        {
            //we didn't find anything, so just populate it with defaults
            move = new MoveManager.Move(null, null, null);
            return(false);
        }
    }