Straight optimization proposal
Closed this issue · 11 comments
better list clear than new list - line 97
Will be fixed. Thanks! Create pull request next time.
this way not the highest possible straight is returned but the lowest instead - will fix it
Add unit tests (for regression)
!!! line 134 - var straightCards = cards.Select(x => (int)x.Type).ToList(); - returns duplicates
renaming proposal: CompareTwoHandsWithHighCard => CompareKickers/CompareSideCards
Comparing straights - comparing any card[1-3] is enough - no Ace possible there -
bigger wins - no matter which way sorted - think will be faster O(1)
Open new issues for every single bug.
When comparing straights there are objects of type CardType
so Ace
is expected.
Mean if compare e.g. 2nd cards only - no Ace
possible there - Ace
may be first or last only
What about this case:
new[]
{
CardType.Six, CardType.Five,
CardType.Four, CardType.Three,
CardType.Two
},
new[]
{
CardType.Five, CardType.Four,
CardType.Three, CardType.Two,
CardType.Ace
}
e.g.
2nd cards: five > four => first wins
3rd cards: four > three => first wins
4th cards.......
Ace
s can be in the beginning or the end of hand - not in the middle - don't check ends - any middle card will do the trick
Not wrong now, of course, but may be less complex
I've got the idea but the current solution is O(n)
and the one you suggest requires sorting which will be O(n * log(n)
.
thought they come sorted from hand evaluator, from tests come shuffled - anyway U know better 👍