I am making a Cribbage game and I am having trouble figuring out the logic of how to recognize a card run. In Cribbage you can score points for card runs that are played out of order sequentially but are still connected as a group. eg. 4-5-6 is a run and 6-4-5 , 5-6-4 are also runs.
Each card has a variable for the face value, 1-13. I am placing each card in the order they are played into an array. So using the example above, when the third card being played is a 6, how do I check if the last two cards played are both a 4 or a 5. (there can be no other cards played in between any of the cards in the run)
I would need it to recognized longer runs too. eg 5-3-1-2-4 (when the 2 is played it becomes a 3 card run(3-1-2) and when the 4 is played it becomes a 5 card run)