I am currently debugging and testing for my card game. The goal of this task is to see if all card number has to be in exact order and the number of cards picked must be at least 3. Not relatively in order but exact order without skipping, regardless what card number started. In case if all numbers picked in the wrong order, I stored it in a List object and using the Sort() method to automatically arranged in order numerically and check again if all the numbers stored are arrange in order exactly.
Let’s say here is what I am expecting the output result when computing the correct order:
Example 1
CARD INPUT CHOSEN: 1, 2, 3, 4
RESULT: true
REASON: All numbers are in exact order and at least 3 cards have met.
Example 2
CARD INPUT: 1, 2, 5, 6
RESULT: false
REASON: All numbers are in order. However, no. 3 and no. 4 is skipped.
Example 3
CARD INPUT: 4, 5
RESULT: false
REASON: All numbers are in exact order. However, player picked only two cards.
Example 4
CARD INPUT CHOSEN: 3, 4, 5
RESULT: true
REASON: Same as "Example 1".
These examples above are my expectations of the result. Now, for reality, when I tried, run, and tested the program and I got this error like this.
CARD INPUT: 3, 4, 5
RESULT: false
Say no. 3, no. 4, and no. 5 and arranged in that order are supposed to be valid. Technically, the reason I got this bug and I’m still figuring out yet for an alternate solution in order to check for exact order. Here is the code I’ve used in C# and see comments for details:
// See if the current card value deducted by next card value always 1 for every index.
for(int i = 0; i < temp.Length; i++) {
// The problem with this if-else condition is that the last array of the list
// and checking this index beyond the last resulted in an array index error.
// To remedy this index out of bounds error, the condition result jumped
// from "check _= true" to "check *= false".*_
_ if((temp[i+1] - temp*) == 1) {*_
_ check = true;_
* } else {*
_ check = false;_
* }*
}
// Finally, see if all cards are in correct order.
for(int i = 0; i < check.Length; i++) {
* if(i != check.Length) {*
_ if(check*) {*_
_ isStraight = check*;
print ("[ COMBO CHECK - Straight Flush ] → Combo valid. INDEX " +
i + " - " + isStraight);*_
* } else {*
* isStraight = false;*
* print ("[ COMBO CHECK - Straight Flush ] → Combo invalid. INDEX " +*
* i + " - " + isStraight);*
* }*
* }*
}