<?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>tutorials | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Sat, 22 Mar 2025 12:11:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>tutorials | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>New tutorial posted &#8211; how to build controllermap in Linux</title>
		<link>https://learncgames.com/new-tutorial-posted-how-to-build-controllermap-in-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-tutorial-posted-how-to-build-controllermap-in-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 22 Mar 2025 12:11:07 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[controllermap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[SDL2]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3354</guid>

					<description><![CDATA[<p>Remember controllermap? The utility that creates a configuration string for a game pad etc. I found that it is no longer installed by default when you install libsdl2-dev on Linux.  I found the hard way, trying to use it on my new Raspbverry Piu 5. But the source code is available for it in the [&#8230;]</p>
The post <a href="https://learncgames.com/new-tutorial-posted-how-to-build-controllermap-in-linux/">New tutorial posted – how to build controllermap in Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-3352" src="https://learncgames.com/wp-content/uploads/2025/03/controllermap.png" alt="Controllermap utility" width="514" height="344" srcset="https://learncgames.com/wp-content/uploads/2025/03/controllermap.png 514w, https://learncgames.com/wp-content/uploads/2025/03/controllermap-300x201.png 300w" sizes="(max-width: 514px) 100vw, 514px" /></p>
<p>Remember controllermap? The utility that creates a configuration string for a game pad etc. I found that it is no longer installed by default when you install libsdl2-dev on Linux.  I found the hard way, trying to use it on my new Raspbverry Piu 5.</p>
<p>But the source code is available for it in the libsdl 2 releases.</p>
<p>So I wrote a quick tutorial that explains how to get the source code and build it using clang on VS Code on a Pi or any Linux box.  It&#8217;s <a title="Link to tutorial how to build controllermap on Linux" href="https://learncgames.com/tutorials/how-to-build-controllermap-on-linux-for-sdl2/" target="_blank" rel="noopener">linked here</a> or you can find it on the tutorials menu.</p>The post <a href="https://learncgames.com/new-tutorial-posted-how-to-build-controllermap-in-linux/">New tutorial posted – how to build controllermap in Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3354</post-id>	</item>
		<item>
		<title>How to encrypt text using Xor</title>
		<link>https://learncgames.com/how-to-encrypt-text-using-xor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-encrypt-text-using-xor</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 23 Mar 2021 00:00:52 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[xor]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2940</guid>

					<description><![CDATA[<p>This is not meant to offer protection, but if you want to say hide text by disguising it, then using Xor for reversible encryption will do the trick. It relies on the principle that if you Xor A and B to get C then you can Xor C and A to get B or Xor [&#8230;]</p>
The post <a href="https://learncgames.com/how-to-encrypt-text-using-xor/">How to encrypt text using Xor</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:85,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/geralt-9301\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=63530&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260128125116\/https:\/\/pixabay.com\/users\/geralt-9301\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:47:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:33&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-17 08:03:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 12:26:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-03 00:05:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-06 06:25:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 16:52:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 23:28:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-18 18:27:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-26 23:25:19&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-30 22:10:35&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-04 10:21:34&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-07 22:02:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 23:19:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-17 09:37:35&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-21 08:01:16&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 08:01:16&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:86,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=63530&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:47:47&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:33&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-17 08:03:38&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 12:26:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-03 00:05:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-06 06:25:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 16:52:48&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 23:28:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-18 18:27:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-25 00:58:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-29 11:23:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 22:01:40&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-06 03:59:21&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-13 23:19:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-17 09:37:40&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-21 08:01:16&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 08:01:16&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2935" aria-describedby="caption-attachment-2935" style="width: 300px" class="wp-caption alignleft"><img decoding="async" class="size-medium wp-image-2935" src="https://learncgames.com/wp-content/uploads/2021/03/binary-63530_640-300x300.jpg" alt="Binary" width="300" height="300" srcset="https://learncgames.com/wp-content/uploads/2021/03/binary-63530_640-300x300.jpg 300w, https://learncgames.com/wp-content/uploads/2021/03/binary-63530_640-150x150.jpg 150w, https://learncgames.com/wp-content/uploads/2021/03/binary-63530_640-250x250.jpg 250w, https://learncgames.com/wp-content/uploads/2021/03/binary-63530_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-2935" class="wp-caption-text">Image by <a href="https://pixabay.com/users/geralt-9301/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=63530">Gerd Altmann</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=63530">Pixabay</a></figcaption></figure>
<p>This is not meant to offer protection, but if you want to say hide text by disguising it, then using Xor for reversible encryption will do the trick. It relies on the principle that if you Xor A and B to get C then you can Xor C and A to get B or Xor C and B to get A.</p>
<p>I wrote a short program and tutorials to demonstrate taking a single bit of text then disguising it. To make it more challenging, I only used Xor values from the range 0-255 that had four or more bits with 1 in it, for example 15 which is 00001111 in binary.</p>
<p>You can find the tutorial <a title="Link to tutorial on How to do encryption using xor in C" href="https://learncgames.com/how-to-do-xor-encryption-in-c/" target="_blank" rel="nofollow noopener">How to do Xor encryption in C.</a> Please note this is only a very light weight encryption method so don&#8217;t use it for anything too important!</p>The post <a href="https://learncgames.com/how-to-encrypt-text-using-xor/">How to encrypt text using Xor</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2940</post-id>	</item>
		<item>
		<title>New Tutorial on getting started with SDL</title>
		<link>https://learncgames.com/new-tutorial-on-getting-started-with-sdl/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-tutorial-on-getting-started-with-sdl</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 07 Mar 2021 00:00:31 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[tutorials]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2838</guid>

					<description><![CDATA[<p>I had this tutorial pencilled in to do and it&#8217;s now done. It&#8217;s the old SDL rectangles program that was part of the eBook. I&#8217;ve modernised it a bit so the same file will now compile under either MSVC on Windows or VS Code/Clang on Linux without changes. I used the _WIN32 predefined macro so [&#8230;]</p>
The post <a href="https://learncgames.com/new-tutorial-on-getting-started-with-sdl/">New Tutorial on getting started with SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignleft size-medium wp-image-2836" src="https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-300x234.png" alt="SDL REctangles" width="300" height="234" srcset="https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-300x234.png 300w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-1024x798.png 1024w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles-768x599.png 768w, https://learncgames.com/wp-content/uploads/2021/03/SDL-Rectangles.png 1026w" sizes="(max-width: 300px) 100vw, 300px" />I had this tutorial pencilled in to do and it&#8217;s <a title="Link to Getting started with SDL tutorial" href="https://learncgames.com/getting-started-with-sdl-and-c/" target="_blank" rel="nofollow noopener">now done</a>. It&#8217;s the old SDL rectangles program that was part of the eBook. I&#8217;ve modernised it a bit so the same file will now compile under either MSVC on Windows or VS Code/Clang on Linux without changes.</p>
<p>I used the _WIN32 predefined macro so it compiles the call to Windows cod on Windows. Here&#8217;s an example:</p>
<pre><code class="language-c" data-line="">#ifdef _WIN32
		sprintf_s(buff, sizeof(buff), &quot;%10.6f&quot;, getElapsedTime(&amp;s));
#else
		snprintf(buff, sizeof(buff),&quot;%10.6f&quot;,diff(&amp;s));
#endif</code></pre>
<p>I do a similar thing with the path to SDL which is &#8220;SDL.h&#8221; on Windows but &#8220;SDL2/SDL.h&#8221; on Ubuntu. Writing code this way makes it  lot less of a hassle.</p>The post <a href="https://learncgames.com/new-tutorial-on-getting-started-with-sdl/">New Tutorial on getting started with SDL</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2838</post-id>	</item>
		<item>
		<title>Added a tutorial on memory use in C</title>
		<link>https://learncgames.com/added-a-tutorial-on-memory-use-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=added-a-tutorial-on-memory-use-in-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 27 Feb 2021 00:00:24 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[RAM]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2787</guid>

					<description><![CDATA[<p>You can read the tutorial here. It looks at the different ways memory is used in a C program. Do you know for instance what BSS is and when it is used compared to Data or where variables in a function declared static are held in memory? I also tried overwriting a text literal out [&#8230;]</p>
The post <a href="https://learncgames.com/added-a-tutorial-on-memory-use-in-c/">Added a tutorial on memory use in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-2776" src="https://learncgames.com/wp-content/uploads/2021/02/ram-98420_640-300x150.png" alt="RAM Board" width="300" height="150" srcset="https://learncgames.com/wp-content/uploads/2021/02/ram-98420_640-300x150.png 300w, https://learncgames.com/wp-content/uploads/2021/02/ram-98420_640.png 640w" sizes="auto, (max-width: 300px) 100vw, 300px" />You can read the tutorial <a title="Link to tutorial on memory use in C" href="https://learncgames.com/tutorials/an-indepth-look-at-memory-use-in-c/" target="_blank" rel="nofollow noopener">here</a>. It looks at the different ways memory is used in a C program. Do you know for instance what BSS is and when it is used compared to Data or where variables in a function declared <strong>static</strong> are held in memory?</p>
<p>I also tried overwriting a text literal out of curiosity to see what happens. Here&#8217;s the source:</p>
<pre><code class="language-c" data-line="">#include&lt;stdio.h&gt;
#include &lt;string.h&gt;

char* name=&quot;My name is David&quot;;
int main()
{    
    strcpy_s(name,10, &quot;New name&quot;);
    printf(&quot;Name = %s\n&quot;, name);
    return 0;
}</code>

</pre>
<p>&nbsp;<br />
As you&#8217;d expect it blew up&#8221;</p>The post <a href="https://learncgames.com/added-a-tutorial-on-memory-use-in-c/">Added a tutorial on memory use in C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2787</post-id>	</item>
		<item>
		<title>Slay Tutorial four published</title>
		<link>https://learncgames.com/slay-tutorial-four-published/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=slay-tutorial-four-published</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 24 Feb 2021 00:00:05 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[onslaught]]></category>
		<category><![CDATA[Slay]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2743</guid>

					<description><![CDATA[<p>Tutorial four of my reimagining of the game Slay continues. This was an interesting bit of code to write, particularly setting the player hexagons. Then I tried to do too much in one go, adding the forts at the same time. I split this into separate functions. It makes extensive use of recursion and that [&#8230;]</p>
The post <a href="https://learncgames.com/slay-tutorial-four-published/">Slay Tutorial four published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-2731" src="https://learncgames.com/wp-content/uploads/2021/02/debugmode-300x203.png" alt="Debug Mode" width="300" height="203" srcset="https://learncgames.com/wp-content/uploads/2021/02/debugmode-300x203.png 300w, https://learncgames.com/wp-content/uploads/2021/02/debugmode.png 401w" sizes="auto, (max-width: 300px) 100vw, 300px" /><a title="Link to slay Tutorial four" href="https://learncgames.com/tutorials/slay-tutorial-four-adding-forts-etc" target="_blank" rel="nofollow noopener">Tutorial four</a> of my reimagining of the game Slay continues.</p>
<p>This was an interesting bit of code to write, particularly setting the player hexagons. Then I tried to do too much in one go, adding the forts at the same time. I split this into separate functions.</p>
<p>It makes extensive use of recursion and that handy trick when you work with hexagons, the <strong>IsValidHex()</strong> function which tells you which six of the surrounding eight locations are valid. This is needed because the map is stored in a 2d array so in a 3&#215;3 block, the centre location is surrounded by eight locations.</p>
<p>When you use hexagons, it&#8217;s more like a brick wall with each alternate row moved over a bit.  Now every location is surrounded by six adjacent locations just like in a hexagon grid. It turns out that a very simple function can tell you which of the 8 surrounding locations are valid.</p>
<p>In the grid I&#8217;m using, which runs in rows horizontally either 1,3 or 5,7 cells are invalid depending on whether the row is odd or even.</p>
<p>Here is a normal block of 3 x 3 locations.</p>
<pre>7 0 1
6 x 2
5 4 3</pre>
<p>But if I slide it over by 2 characters you get this.</p>
<pre>  7 0 <strong>1</strong>     or     <strong>7</strong> 0 1
 6 x 2               6 x 2
  5 4 <strong>3 </strong>          <strong> 5</strong> 4 3</pre>
<p>So by ignoring the bold locations, you can simulate a hexagon grid.</p>
<p>I&#8217;ve also added Debug mode which toggles with the tab key and introduced a blockId to each hex so you can see which hexes are lumped together. In Debug mode, the BlockId is printed out over the hex as in the screenshot. I&#8217;ve used the <strong>SDL_ttf</strong> library to draw the text. It slows down the screen update by a factor of 40x but is just fast enough to do 60 frames per second.</p>
<p>It&#8217;s interesting that the Ubuntu code running under Hyper-V is actually a lot faster than the Windows code.  As with previous tutorials, the code includes conditional compilation so it will compile and run under Windows or Linux.</p>
<p>Note, this code is not quite perfect. It now has three bugs:</p>
<ol>
<li>The map generator occasionally produces a map with a 2nd smaller continent separated by one hex from the main continent.</li>
<li>Toggling Debug mode a lot makes it behave oddly. I thought I&#8217;d fixed that but I&#8217;m not so sure.</li>
<li>Some blocks of contiguous hexes (all the same colour) lack forts.</li>
</ol>The post <a href="https://learncgames.com/slay-tutorial-four-published/">Slay Tutorial four published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2743</post-id>	</item>
		<item>
		<title>Tutorial 14 on working with strings published</title>
		<link>https://learncgames.com/tutorial-14-on-working-with-strings-published/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=tutorial-14-on-working-with-strings-published</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 07 Feb 2021 00:00:05 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[text]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2630</guid>

					<description><![CDATA[<p>Reading the C reddit most days, I see from time to time question about strings. They&#8217;re not particularly complex but I feel you really have to get your head around pointers to grok strings. I&#8217;ve already done a C tutorial on Pointers and c-strings but I thought showing some examples of doing things with c-strings [&#8230;]</p>
The post <a href="https://learncgames.com/tutorial-14-on-working-with-strings-published/">Tutorial 14 on working with strings published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:196,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/markusspiske-670330\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1568556&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:197,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1568556&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:33:05&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:44&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-19 10:48:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-22 20:14:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-27 12:27:02&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-08 11:33:28&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-13 10:15:23&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 21:49:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 02:38:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-15 09:29:25&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-15 09:29:25&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:157,&quot;href&quot;:&quot;https:\/\/www.reddit.com\/r\/C_Programming&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2631" aria-describedby="caption-attachment-2631" style="width: 200px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-2631" src="https://learncgames.com/wp-content/uploads/2021/02/code-1568556_640-200x300.jpg" alt="Code listing on screen with keyboard" width="200" height="300" srcset="https://learncgames.com/wp-content/uploads/2021/02/code-1568556_640-200x300.jpg 200w, https://learncgames.com/wp-content/uploads/2021/02/code-1568556_640.jpg 426w" sizes="auto, (max-width: 200px) 100vw, 200px" /><figcaption id="caption-attachment-2631" class="wp-caption-text">Image by <a href="https://pixabay.com/users/markusspiske-670330/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1568556">Markus Spiske</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1568556">Pixabay</a></figcaption></figure>
<p>Reading the <a title="Link to C Subreddit" href="https://www.reddit.com/r/C_Programming/" target="_blank" rel="nofollow noopener">C reddit</a> most days, I see from time to time question about strings. They&#8217;re not particularly complex but I feel you really have to get your head around pointers to grok strings. I&#8217;ve already done a C tutorial on <a title="Link to tutorial on pointers and C-Strings" href="https://learncgames.com/tutorial-seven-about-pointers-and-strings/" target="_blank" rel="nofollow noopener">Pointers and c-strings</a> but I thought showing some examples of doing things with c-strings would not go amiss.</p>
<p>The pointers aspect of C strings probably muddies the water a bit. All you are doing is manipulating a contiguous block of characters in RAM that ends with a 0. The pointer just tells you where in RAM that block begins. So long as it finishes with a 0 (\0 in C), it will work ok.</p>
<p>That&#8217;s what <a title="Tutorial 14 – Working with strings in C" href="https://learncgames.com/tutorials/tutorial-14-working-with-strings-in-c/" target="_blank" rel="nofollow noopener">Tutorial 14- working with strings</a> is about.  Especially for beginners, doing things like converting ints to strings, or concatenating strings can be a bit fiddly. I&#8217;ve also provided both the Windows and Linux versions. i.e. compiling with Visual C on Windows and clang on Ubuntu.</p>
<p>For instance, you might have heard about the long to ascii function <strong>ltoa</strong>. Bad news. It doesn&#8217;t exist in Linux compilers.  There is a Windows version with the instantly memorable (not) name <strong>_ltoa_s</strong>, which is one of the safe C functions.  Incidentally if you are using SDL then there is a <strong>SDL_ltoa</strong> function provided for you although oddly it&#8217;s not documented.</p>The post <a href="https://learncgames.com/tutorial-14-on-working-with-strings-published/">Tutorial 14 on working with strings published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2630</post-id>	</item>
		<item>
		<title>C Tutorial thirteen published on allocating memory</title>
		<link>https://learncgames.com/c-tutorial-thirteen-published-on-allocating-memory/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-tutorial-thirteen-published-on-allocating-memory</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 02 Feb 2021 00:00:11 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[calloc]]></category>
		<category><![CDATA[malloc]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2590</guid>

					<description><![CDATA[<p>I&#8217;ve restricted this tutorial to using malloc as it&#8217;s the main way you allocate and use dynamic memory in the thirteenth tutorial. Pointers hold an address (of somewhere in RAM) and this can be an existing variable, a function or even data like a text string. But if you want to reserve a block of [&#8230;]</p>
The post <a href="https://learncgames.com/c-tutorial-thirteen-published-on-allocating-memory/">C Tutorial thirteen published on allocating memory</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:208,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/publicdomainpictures-14\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=20072&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260201001249\/https:\/\/pixabay.com\/users\/publicdomainpictures-14\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:45:21&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-24 20:13:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 14:18:58&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 05:31:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 12:22:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 23:28:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 21:49:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-30 15:12:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-03 14:00:52&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-15 09:29:34&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-15 09:29:34&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:209,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=20072&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:45:23&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-24 20:13:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 14:18:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-05 05:31:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 12:22:27&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-14 23:28:58&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 21:49:04&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-30 15:12:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-03 14:00:52&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-15 09:29:34&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-15 09:29:34&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2591" aria-describedby="caption-attachment-2591" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-2591" src="https://learncgames.com/wp-content/uploads/2021/02/chips-20072_640-300x200.jpg" alt="Memory chips" width="300" height="200" srcset="https://learncgames.com/wp-content/uploads/2021/02/chips-20072_640-300x200.jpg 300w, https://learncgames.com/wp-content/uploads/2021/02/chips-20072_640.jpg 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-2591" class="wp-caption-text">Image by <a href="https://pixabay.com/users/publicdomainpictures-14/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=20072">PublicDomainPictures</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=20072">Pixabay</a></figcaption></figure>
<p>I&#8217;ve restricted this tutorial to using <strong>malloc</strong> as it&#8217;s the main way you allocate and use dynamic memory in the <a title="Link to C tutorial thirteen on allocating memory" href="https://learncgames.com/tutorial-thirteen-allocating-memory-in-c/" target="_blank" rel="nofollow noopener">thirteenth tutorial</a>.</p>
<p>Pointers hold an address (<em>of somewhere in RAM</em>) and this can be an existing variable, a function or even data like a text string. But if you want to reserve a block of RAM and get a pointer to it, you have to call the stdlib function <strong>malloc()</strong>. (<em>Or <strong>calloc</strong>, but I will return to that in a future tutoria</em>l).</p>
<p>Of course once you&#8217;ve finished using a block of RAM, it&#8217;s only polite to return it to the operating system by calling <strong>free(). </strong>Don&#8217;t forget either that <strong>malloc</strong> always returns a void * pointer, so you should cast it to something appropriate.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/c-tutorial-thirteen-published-on-allocating-memory/">C Tutorial thirteen published on allocating memory</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2590</post-id>	</item>
		<item>
		<title>C Tutorial twelve on function pointers published</title>
		<link>https://learncgames.com/c-tutorial-twelve-on-function-pointers-published/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-tutorial-twelve-on-function-pointers-published</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 01 Feb 2021 00:00:22 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[pointers]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[function pointers]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2572</guid>

					<description><![CDATA[<p>While function pointers are important. I don&#8217;t think they&#8217;re quite as important as pointers. C would just not be C without pointers. There are so many things that you would not be able to do if the language lacked pointers. Things like most data structures (try doing a linked list without pointers!) . However function [&#8230;]</p>
The post <a href="https://learncgames.com/c-tutorial-twelve-on-function-pointers-published/">C Tutorial twelve on function pointers published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:210,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/pencilparker-7519217\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3045123&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:211,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3045123&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:45:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-11 15:44:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-15 01:01:06&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-26 08:56:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-02 21:00:03&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-10 20:37:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-17 05:36:49&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-24 21:49:05&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-01 14:32:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 19:10:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-11 04:38:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-15 09:29:38&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 22:53:09&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 22:53:09&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_2573" aria-describedby="caption-attachment-2573" style="width: 300px" class="wp-caption alignleft"><img loading="lazy" decoding="async" class="size-medium wp-image-2573" src="https://learncgames.com/wp-content/uploads/2021/01/desktop-3045123_640-300x271.jpg" alt="Lots of pointers" width="300" height="271" srcset="https://learncgames.com/wp-content/uploads/2021/01/desktop-3045123_640-300x271.jpg 300w, https://learncgames.com/wp-content/uploads/2021/01/desktop-3045123_640.jpg 640w" sizes="auto, (max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-2573" class="wp-caption-text">Image by <a href="https://pixabay.com/users/pencilparker-7519217/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3045123">pencil parker</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=3045123">Pixabay</a></figcaption></figure>
<p>While function pointers are important. I don&#8217;t think they&#8217;re quite as important as pointers. C would just not be C without pointers. There are so many things that you would not be able to do if the language lacked pointers. Things like most data structures (<em>try doing a linked list without pointers!</em>) .</p>
<p>However function pointers give additional flexibility. You can pass them as parameters in functions and store them in variables.</p>
<p>These are the earlier tutorials on pointers:</p>
<ul>
<li><a title="Link to tutorial six on pointers." href="https://learncgames.com/tutorial-six-about-pointers/" target="_blank" rel="nofollow noopener noreferrer">A look at pointers.</a> Intro to pointers</li>
<li><a title="Link to tutorial seven on c strings and pointers" href="https://learncgames.com/tutorial-seven-about-pointers-and-strings/" target="_blank" rel="nofollow noopener noreferrer">Pointers and c-strings.</a> A string in C is actually a pointer to a block of characters terminated by a 0.</li>
<li><a title="Link to tutorial eight on pointers and linked lists" href="https://learncgames.com/tutorial-eight-about-pointer-variables/" target="_blank" rel="nofollow noopener noreferrer">Pointers and linked lists.</a>  A way of storing data in a variable size structure.</li>
</ul>
<p>And this is the new one:</p>
<ul>
<li><a title="Link to tutorial twelve on function pointers" href="https://learncgames.com/tutorials/tutorial-twelve-a-look-at-function-pointers/" target="_blank" rel="nofollow noopener">A look at function pointers</a>. How to deine and use them,</li>
</ul>
<p>&nbsp;</p>The post <a href="https://learncgames.com/c-tutorial-twelve-on-function-pointers-published/">C Tutorial twelve on function pointers published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2572</post-id>	</item>
		<item>
		<title>Thinking about Slay tutorial 7- Game AI</title>
		<link>https://learncgames.com/thinking-about-slay-tutorial-7-game-ai/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thinking-about-slay-tutorial-7-game-ai</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 27 Jan 2021 00:00:54 +0000</pubDate>
				<category><![CDATA[design]]></category>
		<category><![CDATA[Game]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[onslaught]]></category>
		<category><![CDATA[Slay]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2533</guid>

					<description><![CDATA[<p>Having just published Slay Tutorial three, making the Onslaught game play well as a computer opponent(well up to 8 of them)  has been weighing on my mind. I have played the original Slay perhaps a couple of thousand times, so I&#8217;m reasonably familiar with strategy. There&#8217;s almost 500 games on the Slay game chooser screen [&#8230;]</p>
The post <a href="https://learncgames.com/thinking-about-slay-tutorial-7-game-ai/">Thinking about Slay tutorial 7- Game AI</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:227,&quot;href&quot;:&quot;https:\/\/en.wikipedia.org\/wiki\/Matchbox_Educable_Noughts_and_Crosses_Engine&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260102102746\/https:\/\/en.wikipedia.org\/wiki\/Matchbox_Educable_Noughts_And_Crosses_Engine&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:55:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-10 22:04:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-14 18:41:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 11:10:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 22:39:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 12:27:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-06 16:46:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-12 01:37:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-15 08:05:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 21:49:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 22:10:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-04 23:56:07&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-12 04:50:36&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-15 09:29:41&quot;,&quot;http_code&quot;:429}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-15 09:29:41&quot;,&quot;http_code&quot;:429},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-2534" src="https://learncgames.com/wp-content/uploads/2021/01/slay-games-300x236.png" alt="Slay games" width="300" height="236" srcset="https://learncgames.com/wp-content/uploads/2021/01/slay-games-300x236.png 300w, https://learncgames.com/wp-content/uploads/2021/01/slay-games-768x605.png 768w, https://learncgames.com/wp-content/uploads/2021/01/slay-games.png 802w" sizes="auto, (max-width: 300px) 100vw, 300px" />Having just published <a title="Link to Slay Tutorial Three" href="https://learncgames.com/tutorials/slay-tutorial-three-the-map-generator/" target="_blank" rel="nofollow noopener">Slay Tutorial three</a>, making the Onslaught game play well as a computer opponent(<em>well up to 8 of them</em>)  has been weighing on my mind. I have played the original Slay perhaps a couple of thousand times, so I&#8217;m reasonably familiar with strategy.</p>
<p>There&#8217;s almost 500 games on the Slay game chooser screen shown with four different sizes of islands; the four boxes. Usually by the time I&#8217;ve played through all games here (<em>probably taking 18 months to two years</em>) , I can start again and have forgotten what it was like. Plus I think it randomises the starting positions so you get a lot of replay value.</p>
<p>In the first <a title="Link to Slay Tutorial one" href="https://learncgames.com/tutorials/slay-tutorial-one-how-to-implement-slay-for-linux/" target="_blank" rel="nofollow noopener">Slay Tutorial</a> I published a map of the tutorials and so far am sticking to it. Tutorial seven is the one for the game AI and its on my mind. I play all the Slay games at the same top intelligence level and even it sometimes makes stupid mistakes like leaving an area vulnerable to splitting and losing all units due to starvation.</p>
<p>The main aim of any player is to expand their territory at the expense of other players. Joining territories can be one tactic as its lets you support the bigger units. The 2 point unit is a Peasant then there&#8217;s Spearmen (6 points) , Knights (18 point) and Baron (54 points).  Getting a Knight early on gives you a big advantage as it can defeat castles and too often I&#8217;ve seen a territory with one or two spearmen get trapped by castles and destroyed in a few turns.</p>
<p>Likewise putting a castle down early on can secure a territory for a while. Or if you have a larger area, a couple of castles can shield your flanks so you can focus yoyr troops against one enemy and not worry about other players moving in.</p>
<h3>Self Playing</h3>
<p>In Slay once you are eliminated the games plays through until one player beats everyone else. But self-playing can also be a useful way to have computer players learn. One possibility is to try and implement a &#8220;matchbox&#8221; AI. This was done with Tic-Tac-Toe (noughts and crosses for us Brits) with <a title="Link to Menace on Wikipedia" href="https://en.wikipedia.org/wiki/Matchbox_Educable_Noughts_and_Crosses_Engine" target="_blank" rel="nofollow noopener">Menace</a>, Now it may be that Onslaught is too complex to implement that but there&#8217;s a lot of RAM available, so if I can limit the number of setups that it recognises then maybe?</p>
<p>Anyway there&#8217;s a fair bit of time and Tutorials 4-6 to do before I get to Tutorial seven.</p>
<h3>PS</h3>
<p>If you move the mouse over the About Me, you&#8217;ll see a<a title="Link to page with links to past blog posts." href="https://learncgames.com/more-about-me/links-to-all-blog-posts/" target="_blank" rel="nofollow noopener"> link to a page</a> that has short cut links to all blog posts along with the title of each.  It&#8217;s a quicker way of navigating.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/thinking-about-slay-tutorial-7-game-ai/">Thinking about Slay tutorial 7- Game AI</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2533</post-id>	</item>
		<item>
		<title>Slay tutorial three published</title>
		<link>https://learncgames.com/slay-tutorial-three-published/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=slay-tutorial-three-published</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 25 Jan 2021 00:00:03 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[onslaught]]></category>
		<category><![CDATA[Slay]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2512</guid>

					<description><![CDATA[<p>This is a typical map produced by the generator. One large continent with coloured hexagons from 8 players arranged in clumps and individual hexes. It&#8217;s not quite perfect- in the top right corner there is a single blue hex but its not bad. I&#8217;ve just published Slay tutorial three with the source code in the [&#8230;]</p>
The post <a href="https://learncgames.com/slay-tutorial-three-published/">Slay tutorial three published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:119,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnCCode&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250213114359\/https:\/\/github.com\/David-H-Bolton\/LearnCCode&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:59:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-10 22:04:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:42:55&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 03:42:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 00:07:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:04:46&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 22:28:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 01:11:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 06:32:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-14 23:28:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 21:49:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 21:29:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 12:52:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 03:59:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 22:58:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-15 00:56:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 04:43:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 12:23:33&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 12:23:33&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-medium wp-image-2507" src="https://learncgames.com/wp-content/uploads/2021/01/onslaughtmap-300x169.png" alt="Onslaught map" width="300" height="169" srcset="https://learncgames.com/wp-content/uploads/2021/01/onslaughtmap-300x169.png 300w, https://learncgames.com/wp-content/uploads/2021/01/onslaughtmap-1024x576.png 1024w, https://learncgames.com/wp-content/uploads/2021/01/onslaughtmap-768x432.png 768w, https://learncgames.com/wp-content/uploads/2021/01/onslaughtmap.png 1304w" sizes="auto, (max-width: 300px) 100vw, 300px" />This is a typical map produced by the generator. One large continent with coloured hexagons from 8 players arranged in clumps and individual hexes. It&#8217;s not quite perfect- in the top right corner there is a single blue hex but its not bad.</p>
<p>I&#8217;ve just published <a title="Link to Slay Tutorial three" href="https://learncgames.com/tutorials/slay-tutorial-three-the-map-generator/" target="_blank" rel="nofollow noopener">Slay tutorial three</a> with the source code in the file onslaught2.zip on <a title="Link to LearnCCode on GitHub" href="https://github.com/David-H-Bolton/LearnCCode" target="_blank" rel="nofollow noopener">GitHub</a>. I&#8217;m quite pleased with the map generator which is based on the one I devised for Empire and which I covered in <a title="Link to blog entry on the Empire map generator" href="https://learncgames.com/about-that-empire-map-generator/" target="_blank" rel="nofollow noopener">an earlier blog post</a>.  It does a lot and quick enough that when you press the N key it can generate a new map in a fraction of a second.  C + SDL2 is very fast even when drawing nearly a thousand hexagons every frame. It&#8217;s mostly in just one file (<em>for now</em>) with timing code and a data file for generating maps in separate files. The main file is just over 600 lines long.</p>
<p>As it needed a fair bit of debugging, I made it cross-compile in Windows or Linux (<em>and probably Mac OS but that&#8217;s not tested</em>). You can load the solution file in Windows with Visual Studio or put the files into a Folder with Visual Studio Code on Linux. Included in the zip file is the <strong>assets</strong> folder which has all the individual hex graphics and a <strong>.vscode</strong> folder with JSO files for doing the build with clang on Linux.  I&#8217;ve compiled it and run on both Windows and Linux. The SDL2 Window is 1300 x 768 pixels wide.</p>The post <a href="https://learncgames.com/slay-tutorial-three-published/">Slay tutorial three published</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2512</post-id>	</item>
	</channel>
</rss>
