I am not very familiar with this game, and I had never played it before this week, so I wasn’t very sure what the strategy would be. I decided to give it a try, and I developed a simple strategy that seems to work ok. I basically just dumped high cards, got melds where I could, dumped the most useless cards when high cards were similar, and knocked at the earliest opportunity. My strategy was very simple and algorithmic, so it should directly translate into an AI, with the additional bonus of card counting.
The choice of whether to draw or pick from the discard pile seems very simple, at least for now. I always drew unless taking the discard gave me a meld or added onto one I already had. It didn’t seem worth it to take it to get closer to a meld, because there was still a low chance of drawing the last card needed, and I could usually draw to try to get a meld immediately. Maybe it would be worth it to take in some cases, especially because if the other player dropped it, they probably don’t have a match or run with it. They still could, especially if they have a card that would go with it but is already in another meld. They would also be less likely to drop a match or run for that card in the future if they are watching out for it, so that makes it even harder. Maybe I’ll change it later, but for now I will only pick up cards for a meld, and will draw in all other cases.
The way I discarded cards was mostly discarding high cards, so that will be how I start the AI. If the highest value deadwood card I have is not beginning a run or a match, that will be the first card to ditch, because holding onto it will not likely have any payoff later. If I have some high cards that start a meld and a slightly lower card with no value, it could be better to drop the lower card, because it still reduces score without losing an opportunity. If I have no cards close to a high pair or run, then I will just drop the high cards anyway. Dropping a pair of kings isn’t risky, because the other player would have to have a pair already to use it in a match, and then they would take the first king and I would not drop the second. After that, neither player would be able to make a match with that card, and I would just have to find melds of the lower cards I kept. This is a part I could see changing, because I don’t really know if that is the best choice, especially if everyone else’s AIs always drop high cards too. I’ll have to adjust it later if it doesn’t work out.
The thing the computer can do that I couldn’t is a card tracker that keeps track of where every known card is. This helps determine if cards are safe to drop and have better chances of being drawn. If a match or run of a card is in the discard, there is a lower chance of the other player having it, and a lower chance of drawing it from the deck. Both of these mean it is a better card to drop. If the other player has a run or match of a card, it would be a worse idea to drop it, because they could pick it up. This would help inform the last step whenever possible, and help decide which melds to try to go for.
Optimal play can only get you so far in a two player game like this, and some of it will come down to playing the other player instead of the game. I’m thinking about making the AI keep track of how the other player plays, and looking out for patterns such as always dropping high cards to take advantage of. If that is how they play, it would be a good idea to hold onto higher pairs for a bit, waiting for the other player to drop them. It would still be a good idea to drop them later, because if they aren’t dropping them, they probably already made a meld or just didn’t start with any. Adding this whole process would likely improve performance when it is used, and shouldn’t decrease it at all, because it would only activate upon noticing the other player using the strategy, instead of just assuming the strategy from the start. I will try to put this in if I have the time and feel the need.
I am not incredibly confident in any of these strategies, and it will probably be a good idea to test the alternatives to these to see which is better. It should be easy enough to make the AI adjustable, either by making it data driven or just adjusting the code quickly.