找炸弹的bug
<public List<Card> FindBoom(List<Card> cards, int weight)
{
List<Card> select = new List<Card>();
for (int i = 0; i < cards.Count - 3; i++)
{
if ((int)cards[i].CardWeight == (int)cards[i + 1].CardWeight &&
(int)cards[i].CardWeight == (int)cards[i + 2].CardWeight &&
(int)cards[i].CardWeight == (int)cards[i + 3].CardWeight)
{
int totalWeight = (int)cards[i].CardWeight + (int)cards[i + 1].CardWeight + (int)cards[i + 2].CardWeight + (int)cards[i + 3].CardWeight;
if (totalWeight > weight)
{
select.Add(cards[i]);
select.Add(cards[i + 1]);
select.Add(cards[i + 2]);
select.Add(cards[i + 3]);
break;
}
}
}
return select;
}>
加入电脑手牌中只有四张牌且是炸弹的话,那么count-4就会是0了,那么循环体就进不去了,就会找不到炸弹了,但是又的确有炸弹,所以要写成count - 3,其他的地方也有类似的错误,不知道对不对~^_^