mirror of
https://github.com/Wessel/nhl-setgame.git
synced 2026-06-08 14:18:05 +02:00
fix(backend/game): Inverse set checking query
This commit is contained in:
@@ -83,12 +83,12 @@ public class Game {
|
|||||||
.Select(index => Card.ToCard(Hand[index]))
|
.Select(index => Card.ToCard(Hand[index]))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
bool matchingShapes = cards.Select(card => card.Shape).Distinct().Count() == 1;
|
if (!(
|
||||||
bool matchingColors = cards.Select(card => card.Color).Distinct().Count() == 1;
|
AllSameOrDifferent(cards[0].Shape, cards[1].Shape, cards[2].Shape) &&
|
||||||
bool matchingShades = cards.Select(card => card.Shade).Distinct().Count() == 1;
|
AllSameOrDifferent(cards[0].Color, cards[1].Color, cards[2].Color) &&
|
||||||
bool matchingCounts = cards.Select(card => card.Count).Distinct().Count() == 1;
|
AllSameOrDifferent(cards[0].Shade, cards[1].Shade, cards[2].Shade) &&
|
||||||
|
AllSameOrDifferent(cards[0].Count, cards[1].Count, cards[2].Count)
|
||||||
if (!matchingShapes && !matchingColors && !matchingShades && !matchingCounts) {
|
)) {
|
||||||
Fails += 1;
|
Fails += 1;
|
||||||
return new SetCheckResult { IsSet = false, NewState = this };
|
return new SetCheckResult { IsSet = false, NewState = this };
|
||||||
}
|
}
|
||||||
@@ -101,4 +101,12 @@ public class Game {
|
|||||||
|
|
||||||
return new SetCheckResult { IsSet = true, NewState = this };
|
return new SetCheckResult { IsSet = true, NewState = this };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool AllSameOrDifferent<T>(T a, T b, T c) where T : Enum {
|
||||||
|
int ai = Convert.ToInt32(a);
|
||||||
|
int bi = Convert.ToInt32(b);
|
||||||
|
int ci = Convert.ToInt32(c);
|
||||||
|
|
||||||
|
return (ai == bi && bi == ci) || (ai != bi && bi != ci && ai != ci);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user