A few years ago, I wrote a Blackjack game. The game uses statistics from a book on expert play and coaches the player in the statistically best play based on the player's and dealer's hands. (The game and source is available from my website at www.softconcepts.com.) The game was good enough that a programmer from Harrah's in Biloxi asked to use the source, and my understanding is that it is a pillow favor provided at the casino. In this article, game statistics from a round of play were saved as an XML file and that file is used for the demos. (You can download the game and save your own statistics or use the XML provided in Listing One.)
<?xml version="1.0" encoding="utf-8"?> <Blackjack> <Player Name="Player 1"> <Statistics> <AverageAmountLost>-28.125</AverageAmountLost> <AverageAmountWon>30.681818181818183</AverageAmountWon> <Blackjacks>1</Blackjacks> <Losses>8</Losses>44 <NetAverageWinLoss>5.9210526315789478</NetAverageWinLoss> <NetWinLoss>112.5</NetWinLoss> <PercentageOfBlackJacks>0.041666666666666664</PercentageOfBlackJacks> <PercentageOfLosses>33.333333333333329</PercentageOfLosses> <PercentageOfPushes>16.666666666666664</PercentageOfPushes> <PercentageOfWins>45.833333333333329</PercentageOfWins> <Pushes>4</Pushes> <Surrenders>1</Surrenders> <TotalAmountLost>-225</TotalAmountLost> <TotalAmountWon>337.5</TotalAmountWon> <Wins>11</Wins> </Statistics> </Player> </Blackjack>
Examples of how to use the cards.dll are all over the web, including in some of my articles, such as Programming for Fun and Profit -- Using the Card.dll.
The basic flow of the subsections that follow is that you are shown some code that uses LINQ-to-XML to query nodes followed by an equivalent XPath query that accomplishes the same goal. (You don't need both; in practice, use one or the other.)