<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Chad</title>
    <description>The latest articles on DEV Community by Chad (@xzzz3).</description>
    <link>https://dev.to/xzzz3</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1444253%2F9bd76731-fbe2-4155-8958-e3a7d78f1bb6.jpeg</url>
      <title>DEV Community: Chad</title>
      <link>https://dev.to/xzzz3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xzzz3"/>
    <language>en</language>
    <item>
      <title>Tetris Development #6 - Risk and Reward</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Tue, 07 May 2024 17:50:03 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-6-risk-and-reward-1ge0</link>
      <guid>https://dev.to/xzzz3/tetris-development-6-risk-and-reward-1ge0</guid>
      <description>&lt;p&gt;In this post, I will talk about the implementation for the varied reward functions in implementing the Tetris game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro to Tetris Scoring
&lt;/h2&gt;

&lt;p&gt;After digging into Tetris documentations, I found a lot of resources on how each move in Tetris is scored. It is &lt;em&gt;A LOT&lt;/em&gt; more in-depth than what I knew about Tetris. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5foooyzmls3wq94vc0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff5foooyzmls3wq94vc0t.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's like, &lt;em&gt;have I really been playing the same game as them?&lt;/em&gt; I only knew that clearing more = better scores...&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;Overall, I took the same scoring system from this &lt;a href="https://tetris.wiki/Scoring" rel="noopener noreferrer"&gt;Tetris Wikipedia&lt;/a&gt;, as I want my game to behave as similarly to a real Tetris game as possible, so that my Tetris bot can extrapolate to the real game well.&lt;/p&gt;

&lt;p&gt;I implemented the normal scores (single, double, triple and quad) as well as combo scores pretty easily -- All they required was some variables to keep track of rows cleared and combo so far. &lt;/p&gt;

&lt;p&gt;To adhere to SWE principles, I also made sure to encapsulate the score calculation in a separate RewardManager class, and my game logic will call the API from this class to update the score.&lt;/p&gt;

&lt;p&gt;Once that's done, it is time to move on to the boss of the section:&lt;/p&gt;

&lt;h2&gt;
  
  
  T-spins
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;T-SPINS!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I have to say that this is the first time I had read a documentation on the formal definition of a T-spin. In essence, it is when the player is controlling a T-block, and rotates into a slot where 3 out of 4 corners in the 3x3 surrounding area are filled.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpo6ub12m5nwr1bg3pm4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpo6ub12m5nwr1bg3pm4.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To check for this, I implemented an additional function when I land a T-block to check whether this action is eligible for a T-spin. Since I need to check the 4 corners, I hardcoded the corner values from the center, and counted how many corners were filled. I then adjusted the RewardManager to award T-spin score if a T-spin was done.&lt;/p&gt;

&lt;p&gt;However, there is another move called &lt;strong&gt;T-spin Minis&lt;/strong&gt;, and I didn't even know they existed! From what I read, they are kind of like an easier version of the T-spin, where you have to slot the T-block into a hard-to-reach, yet not incredibly hard-to-reach space. Sounds complicated, right? It did for me, at least, and I am not confident that I can successfully and reliably pull T-spin Minis off to test the functionality. Therefore, I decided to put T-spin Minis on hold for potential future addition, and only consider the regular and more difficult T-spin.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With that, the Tetris game clone is looking good! I am planning to pause the development here, and look into building the AI bot for this Tetris game. Stay tuned for the next post!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tetris Development #5 - The HOLD Piece</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Sun, 28 Apr 2024 18:18:51 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-5-the-hold-piece-4cmi</link>
      <guid>https://dev.to/xzzz3/tetris-development-5-the-hold-piece-4cmi</guid>
      <description>&lt;p&gt;In this post, I will talk about the implementation of the HOLD piece in our Tetris game.&lt;/p&gt;

&lt;p&gt;First, what is a &lt;strong&gt;HOLD piece&lt;/strong&gt;? In Tetris, there is a &lt;strong&gt;HOLD slot&lt;/strong&gt;, which is empty at the start of the game, and the player can press a button to put the currently controlled piece into the HOLD slot to be used later. The game then continues as if the hold piece vanished. When the player thinks it is time to use the HOLD piece, they can press the same button again to swap the HOLD piece with the currently controlled piece and continue the game.&lt;/p&gt;

&lt;p&gt;This allows for strategic planning and setup, where players can HOLD a useful piece to be used later in the game.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Ok but how do we implement it?"&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Logic
&lt;/h2&gt;

&lt;p&gt;I started by adding a new variable for HOLD piece, and it is empty at the start of the game.&lt;/p&gt;

&lt;p&gt;When the HOLD button (spacebar) is pressed, the game logic will check if there exists a piece being held. If there isn't, the HOLD piece will clone the current active piece, and the active piece will be replaced by the next piece in line.&lt;/p&gt;

&lt;p&gt;If there is already a piece being held, then pressing the HOLD button will swap the held piece with the active piece.&lt;/p&gt;

&lt;h2&gt;
  
  
  Details
&lt;/h2&gt;

&lt;p&gt;There are two important details in the HOLD implementation. &lt;br&gt;
Firstly, when the active piece is replaced by the HOLD piece, the drop indicator will need to change as well. Without it, the drop indicator will still show where the original block (now in HOLD) will drop, instead of the newly swapped piece. Therefore, extra logic on the drop indicator piece was implemented to correct the behavior.&lt;/p&gt;

&lt;p&gt;Next, to ensure consistency, I made it so that when a piece is put into HOLD, its orientation (i.e. rotation) is reverted back to upright. This means that every time the player swap a piece out of HOLD, the piece will be in an upright position, instead of whatever position it was when the player pressed HOLD. Since there are 4 possible orientations, if the player has to remember which orientation the HOLD piece was in, it is a huge burden especially if the player is swapping between different HOLD pieces. Thus, by reverting to always being upright, it adds more consistency to the outcome when using the HOLD functionality.&lt;/p&gt;

&lt;h2&gt;
  
  
  UI updates
&lt;/h2&gt;

&lt;p&gt;But the HOLD piece won't work if the player can't see it!&lt;br&gt;
Thus, the HUD must now have space for the HOLD slot, and the player should be able to see what piece is being held right now. I updated the UI to free up some space on the top-right in order to show the HOLD slot.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43n74b9k53xfu2qq8g81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F43n74b9k53xfu2qq8g81.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is the end of the HOLD piece implementation. Personally, I feel that similar to the Next Piece Indicators, the HOLD piece adds another level of depth to the game and more rewards to carefully planned gameplay by strategic players. This also makes the training of an AI to play the game later more interesting.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tetris Development #4 - Stop, Drop (and Roll?)</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Sat, 27 Apr 2024 13:50:43 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-4-stop-drop-and-roll-4l1l</link>
      <guid>https://dev.to/xzzz3/tetris-development-4-stop-drop-and-roll-4l1l</guid>
      <description>&lt;p&gt;Continuing my development from the basic Tetris game, I added some new features that will make the game more player-friendly and fun: &lt;strong&gt;"Next Piece" indicators, Ability to drop the block instantly, and a Drop Indicator that tells you where the block will fall to&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Piece Indicators (NPIs)
&lt;/h2&gt;

&lt;p&gt;I built the basic version of the Tetris game with 1 Next Piece Indicator (NPI), meaning that the player can see what will be the next ONE Tetris block coming up. &lt;/p&gt;

&lt;p&gt;However, one block seems pretty limited in allowing the player to plan ahead -- c'mon, with only one NPI, when I see that the next block is an I-block (the straight linear Tetris), most of the time it's already too late to set up for a satisfying clear with that block. But if I can see &lt;em&gt;THREE&lt;/em&gt; steps in advance, and know that the I-block is coming in &lt;em&gt;THREE&lt;/em&gt; turns, as a player I can (or hope I can) definitely cook up some strategies!&lt;/p&gt;

&lt;p&gt;Moreover, considering that I am planning to build an AI for this game (remember this is a Game &amp;amp; AI development!), looking 3 steps into the future makes the AI development much more interesting.&lt;/p&gt;

&lt;p&gt;Therefore, I added more NPIs to the game, allowing players to see up to 3 upcoming pieces. Here's how it looks like in the game:&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuou8fuq2z1b6ne13fjt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuou8fuq2z1b6ne13fjt.png" alt="Image description" width="236" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Instant Drop
&lt;/h2&gt;

&lt;p&gt;I'm pretty impatient when it comes to Tetris, so if I'm sure that I want the block to drop directly down, I want a way to make it drop instantly instead of waiting for it to slowly make its way down.&lt;/p&gt;

&lt;p&gt;With that thought in mind, I implemented a function where if the player taps the DOWN arrow key twice in quick succession, the block falls immediately. I did this by tracking the time delta since the last time the DOWN key was pressed. Using the &lt;code&gt;process&lt;/code&gt; function, I can keep track of the time between two DOWN key taps, and if they are within 0.5 seconds, the block will be immediately dropped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Drop Indicator
&lt;/h2&gt;

&lt;p&gt;After implementing the instant drop, I tested the game, and found that sometimes when I drop the block instantly, it falls to the left or right of where I intended it to fall. &lt;em&gt;This is due to my bad visual perception. Not the game.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In any case, it turns out that identifying which slot at the bottom of the board the block is going to fall into, when the block is at the top of the screen, is a not an easy task. Therefore, to help the players, I implemented a Drop Indicator to show where the block will fall to.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3k7krk348cy8da8hli6y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3k7krk348cy8da8hli6y.png" alt="Image description" width="375" height="691"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To implement this, I added a new variable: the &lt;code&gt;indicator piece&lt;/code&gt;, which is different from the &lt;code&gt;active piece&lt;/code&gt; which is the actual piece the player is controlling. Whenever the &lt;code&gt;active piece&lt;/code&gt; moves, the &lt;code&gt;indicator piece&lt;/code&gt; will instantiate at the same location, fall to the bottom, and stay there.&lt;/p&gt;

&lt;p&gt;With the new Drop Indicator, it became a lot easier to see where my Tetris pieces were falling, and made the game less frustrating as I wouldn't accidentally drop a piece somewhere I didn't intend to.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software Engineering Principles
&lt;/h2&gt;

&lt;p&gt;During this part of the development, I realised again that I overlooked some Software Engineering principles in my development due to the lack of planning.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Don't Repeat Yourself (DRY)&lt;br&gt;
As I implemented the &lt;code&gt;indicator piece&lt;/code&gt; to show the Tetris drop location, I realized that it also uses the &lt;code&gt;drop block&lt;/code&gt; function used by the &lt;code&gt;active piece&lt;/code&gt; controlled by the player. The only different is that the &lt;code&gt;indicator piece&lt;/code&gt; uses it to see where it will drop to, while the &lt;code&gt;active piece&lt;/code&gt; uses it when the player actively double taps DOWN to get an instant drop. There are also a few other functions that are used by both pieces, indicating a possibility for a &lt;code&gt;Game Piece&lt;/code&gt; class as an abstraction. However, as I did not think of the &lt;code&gt;indicator piece&lt;/code&gt; idea until I implemented the instant drop, I had to add some code refactoring and repeat some code to achieve the functionality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;God Class&lt;br&gt;
With more functionalities coming along, the Game script is getting longer and longer, making it difficult to locate specific functions within the script. During this phase of the development, I found myself using Ctrl+F to locate functions at times, simply because of the sheer size of the script file. I did not think a game like Tetris would have so many functions, and would have to take note to separate the game into components in the future.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;Up next, I will continue to implement the expected features of the Tetris game!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tetris Development #3 - Simple Tetris Game in Godot</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Thu, 25 Apr 2024 14:36:06 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-3-simple-tetris-game-in-godot-1o2b</link>
      <guid>https://dev.to/xzzz3/tetris-development-3-simple-tetris-game-in-godot-1o2b</guid>
      <description>&lt;p&gt;Following the tutorial video in my previous post, I have implemented the basic components of the Tetris game. &lt;/p&gt;

&lt;h2&gt;
  
  
  Here are what the tutorial covered:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Game Layers&lt;/strong&gt;
There are two layers of the game, one being the active layer, which contains only the Tetris block that the player is currently possessing, and the other is the board layer, which contains the Tetris board as well as all blocks that have been set in place. &lt;strong&gt;The general flow is to instantiate a random block in the active layer, let the player control it until the block can't fall any further, then send that block to the board layer and create a new block in the active layer.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ivpdue861e7fde7e3j9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2ivpdue861e7fde7e3j9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Player Input Movement&lt;/strong&gt;&lt;br&gt;
With player input, the currently possessed Tetris block can perform 4 actions: &lt;strong&gt;move left&lt;/strong&gt;, &lt;strong&gt;move right&lt;/strong&gt;, &lt;strong&gt;accelerate downwards&lt;/strong&gt;, as well as &lt;strong&gt;rotate&lt;/strong&gt;. There are also logic checks implemented for each of them, to prevent the block from going out of the game board or overlapping with existing blocks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Next Piece Preview&lt;/strong&gt;&lt;br&gt;
Like every Tetris game, there is a preview for the player to see what the upcoming piece is, so that they can strategise accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Score Calculation&lt;/strong&gt;&lt;br&gt;
A flat amount is added to the score each time a row is cleared.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1cnk8urukdywj43eppv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl1cnk8urukdywj43eppv.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And with that, I now have a functioning Tetris game, albeit simplistic and lacking some features.&lt;/strong&gt; The next step is to look back at the required features I set for the game in the first development post, and implement those additional features in the game.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are left?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Ability to Drop the Block Immediately&lt;/strong&gt;&lt;br&gt;
I want to implement an action, potentially a quick double-tap on the DOWN arrow key, that allows the player to drop the block immediately. This is needed for player satisfaction so players don't have to wait for the blocks to drop.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;More Varied Rewards and Tracking&lt;/strong&gt;&lt;br&gt;
In the tutorial, clearing a row always grants a flat amount of reward points. I want to implement it so that clearing consecutive rows, or clearing multiple rows at once, are rewarded more, since they require more planning on the player's side. This encourages more tactical playstyles. To do this, I will need some kind of variable to track the player's "combo" at the moment.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A stretch goal for this would be to implement a reward for &lt;strong&gt;T-Spin&lt;/strong&gt;, an advanced technique where the player can spin the T-block into hard-to-reach places. (Here is a &lt;a href="https://youtu.be/lt49XuMB0Ks?si=rm91iN2HjVsLgEmv&amp;amp;t=7" rel="noopener noreferrer"&gt;video&lt;/a&gt; where T-spin is used, at around the 10 seconds mark.) &lt;/p&gt;

&lt;p&gt;As you can see from the video, T-spin requires a very specific setup and thus careful planning, which is why I would want to include it in the game to reward highly-skilled players. There are two variations, the double T-spin (spin and clear 2 rows) and the triple T-spin (spin twice and clear 3 rows), and I will have to look more into how I can track these. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simulating Multiplayer by Adding Obstacle Rows&lt;/strong&gt;&lt;br&gt;
In a multiplayer Tetris game, if one player receives a lot of points in a short period of time, for example by clearing many rows, the other player will be punished by having a few "zombie" obstacle rows added to the bottom of their board. These rows have random openings in them, so the other player will have to clear those rows strategically. This is a good way to spice up the game and add some element of randomness, so I would want to simulate this effect by adding obstacle rows at random time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;More Next Block Indicators&lt;/strong&gt;&lt;br&gt;
The tutorial implements one Next Block indicator, which tells the player what is the next block. I want to increase the number to three, so that the player can plan ahead even further. This should be doable by extending the existing functionality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;HOLD Functionality&lt;/strong&gt;&lt;br&gt;
I want to implement a HOLD functionality to allow the player to hold one block in a HOLD slot. This block can then be used to replace the active block at anytime. This allows the player to strategize which block to use and which to hold. For example, the player may hold a I-block (the long linear block) and then proceed to prepare 4 almost full rows, then take out the I-block from the hold slot and get 4 rows cleared at once. This is also to make the game more fun and encourage strategic planning.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So these are some of the next features I intend to implement in the Tetris game.&lt;/strong&gt; During this post's development, I have also setup source control using Git, just for good practice. With that, it is time to push these updates to GitHub and work on the above features!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Tetris Development #2 - Intro to Godot and Basic Tetris Setup</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Wed, 24 Apr 2024 18:15:08 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-2-intro-to-godot-and-basic-tetris-setup-4m4h</link>
      <guid>https://dev.to/xzzz3/tetris-development-2-intro-to-godot-and-basic-tetris-setup-4m4h</guid>
      <description>&lt;p&gt;Time to start developing in &lt;strong&gt;Godot&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Having watched a few quick tutorial videos on how Godot worked, I began setting up my first scene.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11t405eabmbfs8gl6poz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F11t405eabmbfs8gl6poz.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the Tetris game is played in a grid, my scene began with a TileMap, which allows me to set a 10x20 tilemap (&lt;em&gt;essentially a grid&lt;/em&gt;) for the game. I followed a &lt;a href="https://www.youtube.com/watch?v=2T2Fkzwf6FM" rel="noopener noreferrer"&gt;beginner's guide to Tetris in Godot video&lt;/a&gt; to complete this step.&lt;/p&gt;

&lt;p&gt;The tutorial video then proceeded to create Tetris blocks for the game. In the video, the developer used individual variables for the vertex positions for each of the 7 different blocks, and the code looks something like this: &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvydb5umbezxxfzlqxy8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwvydb5umbezxxfzlqxy8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this piece of code is repeated 7 times with minimal changes! ("How horrendous!" &lt;em&gt;is what my software engineering module professors would say, if they ever see this coding style&lt;/em&gt;) &lt;/p&gt;

&lt;p&gt;Therefore, as something of a Software Engineer myself, I decided to embrace the Object Oriented Programming Principles, and re-implement this code using inheritance and polymorphism. &lt;strong&gt;Thus began the long research into OOP in Godot...&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  OOP for Tetris in Godot
&lt;/h2&gt;

&lt;p&gt;First of all, there has to be a Base Tetris class. This class declares (only the names, without values) a few variables, including the current vertice positions of the Tetris block, the 4 possible orientations of this block, as well as the current rotation angle. Each child class (&lt;em&gt;e.g. Tetris_L for L-shaped Tetris blocks&lt;/em&gt;) will then define their own values for these variables when they are instantiated with &lt;code&gt;_ready()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The base class also has a function &lt;code&gt;rotate()&lt;/code&gt;, which rotates the Tetris block clockwise by updating its vertices and angle accordingly.&lt;/p&gt;

&lt;p&gt;With the classes set up, I implemented a function to draw Tetris blocks on the tilemap. It is surprisingly simple: Simply instantiate a Tetris child class, grab its coordinates variable, and set the corresponding coordinates on the TileMap to a random color!&lt;/p&gt;

&lt;p&gt;With the blocks ready, the next step is to make them start moving!&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons Learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Instantiating a class in Godot: I have encountered two types of files in Godot so far. One is the &lt;code&gt;.tscn&lt;/code&gt; files, which are for scenes, and another is the &lt;code&gt;.gd&lt;/code&gt; files, which are for GD scripts. The classes are in &lt;code&gt;.gd&lt;/code&gt; files, which must be instantiated with &lt;code&gt;.new()&lt;/code&gt;, instead of with &lt;code&gt;.load()&lt;/code&gt; and &lt;code&gt;instantiate()&lt;/code&gt; which is for scenes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;_ready()&lt;/code&gt; function: In the GDScript, there exists a &lt;code&gt;_ready()&lt;/code&gt; function. Initially, I treated it as an equivalent function to &lt;code&gt;__init__()&lt;/code&gt; in Python and Java, though after some debugging I found that there exist some subtle differences. In Python for instance, the &lt;code&gt;init()&lt;/code&gt; functions for classes are called immediately when the class objects are instantiated. On the other hand, for GDScript objects, &lt;code&gt;_ready()&lt;/code&gt; is only called when the object enters the scene tree, so you have to get the scene tree and &lt;code&gt;add_child()&lt;/code&gt; to it before your instantiated object is &lt;em&gt;fully instanced&lt;/em&gt;. I was stuck on this for a while wondering why my instanced objects did not have the updated variable values I defined in their &lt;code&gt;_ready()&lt;/code&gt; functions, but now we know!&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Tetris Development #1 - Setting Up</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Wed, 24 Apr 2024 16:59:13 +0000</pubDate>
      <link>https://dev.to/xzzz3/tetris-development-1-setting-up-548o</link>
      <guid>https://dev.to/xzzz3/tetris-development-1-setting-up-548o</guid>
      <description>&lt;p&gt;The first game that I would like to recreate is the game of &lt;strong&gt;&lt;em&gt;Tetris&lt;/em&gt;&lt;/strong&gt;. While it is a childhood game, it has also gained traction recently with the increase in popularity for the Puyopuyo-Tetris game in Japan.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqr92xddbbleta6w9hcn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqr92xddbbleta6w9hcn.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This setup post has two areas to tackle: &lt;strong&gt;&lt;em&gt;Game Specifications&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;Software&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Game Specification
&lt;/h2&gt;

&lt;p&gt;Before diving into the implementation, the rules of the Tetris game must be clear. This is so that the implementation can be as efficient as possible, and does not obstruct future additions when implementing early features.&lt;/p&gt;

&lt;p&gt;While there may be many versions of Tetris games online, I will go with the ruleset of one that I am familiar with.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The Tetris game is played in a 20*10 (Height*Width) grid.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are 7 different Tetris blocks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudxechmvefqvg2ollk0r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudxechmvefqvg2ollk0r.png" alt="Image description" width="679" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;At one time, one Tetris block will fall slowly from the top of the screen, and the player can move it left, move right, or rotate it clockwise, as well as drop the block immediately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The player can see the next 3 Tetris blocks coming up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The player has a "Store" slot, which is empty at the start of the game. They can store the current block (block A) into the "Store" slot anytime they want to. If there is a block (block B) in the slot already, that block (B) will be popped out, and replace block A at block A's location on the grid. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the player fill any row with 10 Tetris blocks, the row disappears and rows above it will drop down. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clearing one-row awards points. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These actions award more points: Clearing more than one-row at once, Clearing rows in consecutive actions, Clearing 4 rows at once (a lot of points!), and possibly a T-spin (an advanced technique where the T block is spun as it falls so it goes into hard-to-reach spaces).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Most modern Tetris games are multiplayer, and when one player does well and receives a certain amount of points, the other player will be punished by having rows added to the bottom of their screen. Since multiplayer games are a whole new can of worms, I will simulate this effect by adding rows to the bottom of the screen at random intervals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the next Tetris cannot enter the screen, that is, the center of the screen reaches the full 20 rows height, the game is over.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As time progresses, the Tetris blocks will fall faster to increase the difficulty and give the players less time to react.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are the rules I can think of currently for the Tetris game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Software
&lt;/h2&gt;

&lt;p&gt;Moving on to the software used for development, I will need a simple lightweight 2D game development environment.&lt;/p&gt;

&lt;p&gt;While I am proficient in Unreal Engine from a previous game, I feel that it is more suited for 3D games. I also have some brief experience making games in Unity, which is equally popular, but I am not as proficient in Unity.&lt;/p&gt;

&lt;p&gt;Instead, I was recommended &lt;a href="https://godotengine.org/"&gt;Godot&lt;/a&gt; by a fellow developer. It is an easy-to-pickup and beginner-friendly open-source engine, which I will use to develop the Tetris game.&lt;/p&gt;

&lt;p&gt;In the next post, I will be starting my Tetris development in Godot, so stay tuned!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Beginner Dev Takes On AI and Games!</title>
      <dc:creator>Chad</dc:creator>
      <pubDate>Tue, 23 Apr 2024 13:20:41 +0000</pubDate>
      <link>https://dev.to/xzzz3/beginner-dev-takes-on-ai-and-games-38pe</link>
      <guid>https://dev.to/xzzz3/beginner-dev-takes-on-ai-and-games-38pe</guid>
      <description>&lt;p&gt;Hey! I'm Chad, a beginner developer on the way to learning more about AI and Games, and I'm starting this blog to document my progress and findings.&lt;/p&gt;

&lt;p&gt;Some of the game AIs that inspired me to dive deeper include the enemies in The Legend of Zelda: BOTW and the Last of Us, as well as characters in Skyrim and Sims. However, as a beginner dev, I'm going to start with something simpler: &lt;br&gt;
&lt;strong&gt;Recreate Classic Games, then Build AIs to play them.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With this in mind, the project will be split into a few sections:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Game Development&lt;/li&gt;
&lt;li&gt;Game Information Extraction&lt;/li&gt;
&lt;li&gt;AI Training&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And now, it's time to start developing!&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
