How to locate bug that keeps occuring on and off?
Hi all, I am creating a playing card game called All Fours. I have almost finish the gameplay but has been having a bug that seems to be occurring on and off. Most of the time the game plays as it is supposed to but ever so often it does not do what it supposed to.
I check the cards played in a coroutine called CheckTrick. After both players play the CheckTrick coroutine checks to see which player wins the trick, assign the played cards to the winner and selects the winner of the trick to play first on the next turn. Most of the time it works as it should but once in a while the player that is supposed to win the trick doesnt get the leaf and the one that suppose to lose the trick gets the leaf and the turn to play.
I have tried debgugging in visual sutsio to find the bug but can't seem to recreate the situation to track it. I am wondering if its the cocorutine that is causing the problem.
Here is my CheckTrick Coroutine public IEnumerator CheckTrick(List cards, int player) { // pause for 3 seconds yield return new WaitForSeconds(3f);
// if ther are cards and the gameState is Checktrick
if (cards != null && gameState == GameState.CheckTrick)
{
// if player1 played the last card of the trick
if (player == 1)
{
// if Player1 jack gets hang when he plays last
if ((cards[0].GetCardSuit() == trump.GetCardSuit() && (int)cards[0].GetCardValue() >= 12) &&
(cards[1].GetCardSuit() == trump.GetCardSuit() && cards[1].GetCardValue() == CardValue.Jack))
{
Player2HangJack();
yield return StartCoroutine(HangJackPause()); // Call the HangJackPause Coroutine
gameState = GameState.SettingUp; // Change the gameState to setting up
yield return null; // Return
}
else if ((cards[0].GetCardSuit() == trump.GetCardSuit() && cards[0].GetCardValue() == CardValue.Jack) &&
(cards[1].GetCardSuit() == trump.GetCardSuit() && (int)cards[1].GetCardValue() >= 12))
{
Player1HangJack();
yield return StartCoroutine("HangJackPause");
gameState = GameState.SettingUp;
yield return null;
}
// if the two played cards have different suits and player1 card is not trump
if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() != trump.GetCardSuit())
{
Player2WinsTrick();
}
// if the two played cards are of different suit and player1 card is trump
else if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() == trump.GetCardSuit())
{
Player1WinsTrick();
}
// if the two played cards have the same suit and player1 card is greater
else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() > (int)cards[0].GetCardValue())
{
Player1WinsTrick();
}
// if the two played cards have the same suit and player1 card value is less
else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() < (int)cards[0].GetCardValue())
{
Player2WinsTrick();
}
StopCoroutine(myCheckTrick);
}
// if player2 played the last card in the trick
else if (player == 2)
{
// if Player2 jack gets hang when he plays last
if ((cards[0].GetCardSuit() == trump.GetCardSuit() && (int)cards[0].GetCardValue() >= 12) &&
(cards[1].GetCardSuit() == trump.GetCardSuit() && cards[1].GetCardValue() == CardValue.Jack))
{
Player1HangJack();
yield return StartCoroutine("HangJackPause");
gameState = GameState.SettingUp;
yield return null;
}
// if player 1 jack gets hang when he plays first
else if ((cards[0].GetCardSuit() == trump.GetCardSuit() && cards[0].GetCardValue() == CardValue.Jack) &&
(cards[1].GetCardSuit() == trump.GetCardSuit() && (int)cards[1].GetCardValue() >= 12))
{
Player2HangJack();
yield return StartCoroutine("HangJackPause");
gameState = GameState.SettingUp;
yield return null;
}
// if the two played cards have different suits and player2 card is not trump
if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() != trump.GetCardSuit())
{
Player1WinsTrick();
}
// if the two played cards are of different suit and player2 card is trump
else if (cards[1].GetCardSuit() != cards[0].GetCardSuit() && cards[1].GetCardSuit() == trump.GetCardSuit())
{
Player2WinsTrick();
}
// if the two played cards have the same suit and player2 card is greater
else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() > (int)cards[0].GetCardValue())
{
Player2WinsTrick();
}
// if the two played cards have the same suit and player2 card value is less
else if (cards[1].GetCardSuit() == cards[0].GetCardSuit() && (int)cards[1].GetCardValue() < (int)cards[0].GetCardValue())
{
Player1WinsTrick();
}
StopCoroutine(myCheckTrick);
}
//StopCoroutine(myCheckTrick);
yield return StartCoroutine(AfterCheckTrickPause()); //
playedCards.Clear(); // clear the played cards list
CheckHand(); // check the hand to see if the players have any cards left. (If they dont then set the scoring state)
}
}
Can someone look over my code and see if they can Identify what I might have done wrong here and give suggestions as to how I can do this better to avoid this bug.
@LeonardNS can you check it out for me?
Your answer
Follow this Question
Related Questions
Index was out of range. error 1 Answer
Unity's Editor UI Frozen/ Not updating, Video included 0 Answers
Weird texture behaving on flat object 0 Answers