예제 #1
0
    private BoardState Attack(BoardState board, Move move)
    {
        Territory from = move.From;
        Territory to   = move.To;

        // If attacking, must leave one troop behind
        int attackers = Min(move.From.TroopCount - 1, 3);
        int defenders = Min(move.To.TroopCount, 2);

        List <int> attack  = RollDice(attackers);
        List <int> defense = RollDice(defenders);

        int comparisons = Min(attack.Count, defense.Count);

        for (int i = 0; i < comparisons; i++)
        {
            // Defender wins ties
            if (attack[i] > defense[i])
            {
                to = to.ModifyTroops(-1);
            }
            else
            {
                from = from.ModifyTroops(-1);
            }
        }

        if (to.TroopCount == 0)
        {
            to = to.ChangeControl(from.Player, from.TroopCount - 1);
            from.ModifyTroops(-from.TroopCount + 1);
        }

        return(board.AttackUpdate(from, to));
    }