<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>thinkMoult &#187; blackjack</title>
	<atom:link href="http://thinkmoult.com/tag/blackjack/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkmoult.com</link>
	<description>Seriously who ever reads this description.</description>
	<lastBuildDate>Sun, 22 Jan 2012 04:58:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A Little 21 Fun with C++.</title>
		<link>http://thinkmoult.com/2009/01/17/a-little-21-fun-with-c/</link>
		<comments>http://thinkmoult.com/2009/01/17/a-little-21-fun-with-c/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 17:08:30 +0000</pubDate>
		<dc:creator>Dion Moult</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blackjack]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://thinkmoult.com/?p=396</guid>
		<description><![CDATA[Given the recent love I&#8217;ve shown to a great deal of languages, including but not limited to making a text editor with Python (Ssss!), challenging your manliness with LaTeX (what real men use™), and most recently a tribute to a great deal of languages that all mesh together in the most wonderful way in &#8220;How [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Given the recent love I&#8217;ve shown to a great deal of languages, including but not limited to <a href="http://thinkmoult.com/2009/01/04/a-little-python-fun/">making a text editor with Python</a> (Ssss!), <a href="http://thinkmoult.com/2009/01/08/word-processing-real-men-use-latex/">challenging your manliness with LaTeX</a> (what <em>real men</em> use™), and most recently a tribute to a great deal of languages that all mesh together in the most wonderful way in &#8220;<a href="http://thinkmoult.com/2009/01/12/how-to-make-a-website-part-1-the-environment/">How to Make a Website part 1 &#8211; The Environment</a>&#8220;, I&#8217;ve decided it&#8217;s time to give C++ a chance to show itself on this blog.</p>
<p>When I decided to learn application programming (from web programming), I chose the languages Python and C++. Python for the ultimate rapid application development it can be used for, as well as the ease of syntax that should introduce the application programming concepts a lot quicker to me, and C++ for, well, it&#8217;s pure power. C++ can be described as the swiss-army-knife of a programming language &#8230; a decently low level language, strictly typed, nicely object orientated, efficient, and it&#8217;s actually compiled, unlike what I&#8217;m used to (oh my, what a spoiled generation I live in). Another reason being that C++ is the main language used in KDE development, of which I would like to contribute to someday.</p>
<p>Today, being a Friday, was the be-all and end-all of the week, where I enter my weekend early, and take a break from the ongoings in my life. Therefore, I decided to poke again into C++. Armed with nothing but with whatever little I remembered from the first peek at the language more than 2-3 months ago, the man pages, and general knowledge of language syntax (well, the syntax highlighter gave some clues), I decided to make myself a BlackJack game. Suffice to say that the process was pain-free, and within 15 minutes I was playing BlackJack!</p>
<p>It is, of course, a CLI app, but I don&#8217;t see why it shouldn&#8217;t be cross platform. However, since I don&#8217;t have a Windows computer I can compile it on, you Windows folks will have to do it yourselves. For the technophobes, I give you a screenshot (hahaha):</p>
<p style="text-align: center;"><a href="http://thinkmoult.com/wp-content/uploads/2009/01/2009-01-16-234418_1280x800_scrot.png"><img class="size-full wp-image-397 aligncenter" title="2009-01-16-234418_1280x800_scrot" src="http://thinkmoult.com/wp-content/uploads/2009/01/2009-01-16-234418_1280x800_scrot.png" border="0" alt="2009-01-16-234418_1280x800_scrot" width="333" height="86" /></a></p>
<p>&#8230;and for the more logic inclined, well &#8230; a combination of basic common sense and mathematics should be enough for you to get the gist of what the code is doing. (It&#8217;s even commented for the hard of thinking) Take a look:</p>
<p><code>#include &lt;iostream&gt;<br />
/*<br />
* Generate random number that represents a card (1-13)<br />
*/<br />
int generate_card()<br />
{<br />
return rand() % 13 + 1;<br />
}</code></p>
<p><code>/*<br />
* The AI will always have a card between 15-21. This will generate their card.<br />
*/<br />
int generate_ai_card()<br />
{<br />
return rand() % 7 + 15;<br />
}</p>
<p>/*<br />
* Let's play the game!<br />
*/<br />
int main()<br />
{<br />
// This creates a random seed for rand() based on the time.</p>
<p>srand(time(NULL));</p>
<p>bool play;<br />
int ai_card, my_card;<br />
char x;</p>
<p>std::cout &lt;&lt; "Welcome to a very simple BlackJack game to kill time.\n";</p>
<p>play = true;</p>
<p>// Get the AI's card.<br />
ai_card = generate_ai_card();</p>
<p>// Get your first card.<br />
my_card = generate_card();</p>
<p>std::cout &lt;&lt; "You have " &lt;&lt; my_card &lt;&lt; " - (h)it or (s)tay?: ";</p>
<p>// Ask for a hit or stay.<br />
do<br />
{<br />
std::cin &gt;&gt; x;</p>
<p>// If they have hit...<br />
if ( x == 'h' )<br />
{<br />
// Generate a card, and add it on.<br />
my_card = my_card + generate_card();</p>
<p>// Have they bust?<br />
if ( my_card &gt; 21 )<br />
{<br />
std::cout &lt;&lt; "You got bust (" &lt;&lt; my_card &lt;&lt; ").\n";<br />
play = false;<br />
}<br />
else<br />
{<br />
std::cout &lt;&lt; "You now have " &lt;&lt; my_card &lt;&lt; " - (h)it or (s)tay?: ";<br />
}<br />
}<br />
// If they stayed...<br />
else if ( x == 's' )<br />
{</p>
<p></code></p>
<p><code> // ... See who is bigger.<br />
if ( my_card &gt; ai_card )<br />
{<br />
// You WIN!<br />
std::cout &lt;&lt; "You won! (" &lt;&lt; my_card &lt;&lt; " vs " &lt;&lt; ai_card &lt;&lt; ")\n";<br />
play = false;<br />
}<br />
else<br />
{<br />
// You have FAILED.<br />
std::cout &lt;&lt; "You lost! (" &lt;&lt; my_card &lt;&lt; " vs " &lt;&lt; ai_card &lt;&lt; ")\n";<br />
play = false;<br />
}<br />
}<br />
else<br />
{<br />
std::cout &lt;&lt; "Please either type \"h\" to hit or \"s\" to stay: ";<br />
}<br />
}<br />
while ( play == true );<br />
// Some credits and stuff.<br />
std::cout &lt;&lt; "Thank you for playing Dion Moult's C++ BlackJack game.\n";<br />
return 0;<br />
}</code></p>
<p>Again, it amazes me how I can turn a quick 15 minutes of nothing into an entire blog post. Perhaps I should finish off one of my drafts and give you something interesting for once.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://thinkmoult.com/2009/01/17/a-little-21-fun-with-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

