I took a look at it a bit ago, I didn’t have enough time to find the problem, but I did notice that you have two variables for each card. You could have more cards and less code to check the codes (and less code is often better) if you used an object as a list of cards, where each clone represents a card. I’d also recommend making the ai seem to every other object to be a second human player with full controls, so that the only ai specific code is in choosing what to do, not in responding to what the ai wants.
For example, when the ai plays a card, have it tell some other object which exists only to play cards to play the card for it. This object will remove it from the list of ai cards and add it to the current card pile. The player controls would tell the same object to do it, and the object would not be able to tell the difference between the ai and an actual player, and it doesn’t need to because to it, they are identical.
If you do this it will make your code more organized and easier to fix, as well as easier to customize the players (2 players? 2 ais? More than 2 players? If you do it right, that wouldn’t be too hard to make)
The main way this relates to the problem you are having is it takes a card from being something that is different but similar for every card in the game to being something that is basically the same but with different values for a few variables. It also reduces the check once ifs needed, which is definitely a plus.