NOTE: This code will fail in the case of an infinite game. We'll handle that problem a bit later.

Trial Runs

Now we can run the program to see if it works as intended. Let's do a sample run. Here's the last few lines of output from running the game once:

It looks as though in this game we ran into the situation where one of the players (Alice) ran out of cards during a WAR, and so immediately lost. That's good validation; it means that one of the decision points from the earlier posts works as intended.

But now... let's run it a thousand times. Oh, and let's also keep track of how many finite (e.g. finished) games there are, and the average number of turns each finite game takes. Here's the new Main() method:

This kind of average is what I've seen a lot in running this app many times over. It's also the reason why I chose 1000 turns to be the cut-off point for an infinite game (thought I admit there is a small possibility that there could be games which would still resolve after 1000 turns, and this program will cut those out).

But we still want to find one more stat: do Bob and Alice win an equal number of games?

Who Wins the Most?

What we want to see now is if Alice or Bob wins statistically more games than the other. If one consistently wins more, we can assume that we introduced some kind of bias into our system.

To do this, we're going to make a change to the Game object from earlier, adding a new property called Winner:

To be more certain, I ran the system another 20 times, and every time Alice won more games than Bob. Given a fairly-shuffled deck, I would expect Bob to be the bigger winner at least some of the time. Yet this is not happening.

This system is clearly biased. The question now becomes: why?

Summary

Our card-game WAR playing C# app is finished, and it works as intended... mostly. However, our system is biased somehow, in some way that's not easily seen. I intend to find out why.

Don't forget to check out the sample project on GitHub!. If you have any ideas as to why this system appears to be biased, I'd love to hear them. Sound off in the comments!