|
5 | 5 | <link href="https://learnbyexample.github.io/atom.xml" rel="self" type="application/atom+xml"/> |
6 | 6 | <link href="https://learnbyexample.github.io"/> |
7 | 7 | <generator uri="https://www.getzola.org/">Zola</generator> |
8 | | - <updated>2025-07-10T00:00:00+00:00</updated> |
| 8 | + <updated>2025-08-20T00:00:00+00:00</updated> |
9 | 9 | <id>https://learnbyexample.github.io/atom.xml</id> |
| 10 | + <entry xml:lang="en"> |
| 11 | + <title>Connect Four game with a twist</title> |
| 12 | + <published>2025-08-20T00:00:00+00:00</published> |
| 13 | + <updated>2025-08-20T00:00:00+00:00</updated> |
| 14 | + <link rel="alternate" href="https://learnbyexample.github.io/connect-four-game-with-a-twist/" type="text/html"/> |
| 15 | + <id>https://learnbyexample.github.io/connect-four-game-with-a-twist/</id> |
| 16 | + <content type="html"><p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/ConnectSquare/connect_square.png" alt="Sample screenshot for Connect Square game" /></p> |
| 17 | +<span id="continue-reading"></span><br> |
| 18 | +<p>From <a href="https://en.wikipedia.org/wiki/Connect_Four">wikipedia: Connect Four</a>:</p> |
| 19 | +<blockquote> |
| 20 | +<p>Connect Four is a game in which the players choose a color and then take turns dropping colored tokens into a six-row, seven-column vertically suspended grid. The pieces fall straight down, occupying the lowest available space within the column. The objective of the game is to be the first to form a horizontal, vertical, or diagonal line of four of one's own tokens.</p> |
| 21 | +</blockquote> |
| 22 | +<p>As a twist, this TUI implementation also offers two more variations of the game:</p> |
| 23 | +<ul> |
| 24 | +<li>form a square, i.e. four cells forming 90 degree angles and equidistant from each other</li> |
| 25 | +<li>form a line or square</li> |
| 26 | +</ul> |
| 27 | +<br> |
| 28 | +<h2 id="installation">Installation<a class="zola-anchor" href="#installation" aria-label="Anchor link for: installation">π</a></h2> |
| 29 | +<p>This app is available on PyPI as <a href="https://pypi.org/project/connectsquare/">connectsquare</a>. Example installation instructions are shown below, adjust them based on your preferences and OS.</p> |
| 30 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># virtual environment |
| 31 | +</span><span style="color:#5597d6;">$</span><span> python3</span><span style="color:#5597d6;"> -m</span><span> venv textual_apps |
| 32 | +</span><span style="color:#5597d6;">$</span><span> cd textual_apps |
| 33 | +</span><span style="color:#5597d6;">$</span><span> source bin/activate |
| 34 | +</span><span style="color:#5597d6;">$</span><span> pip install connectsquare |
| 35 | +</span><span> |
| 36 | +</span><span style="color:#7f8989;"># launch the app |
| 37 | +</span><span style="color:#5597d6;">$</span><span> connectsquare |
| 38 | +</span></code></pre> |
| 39 | +<p>To run the app without having to enter the virtual environment again, add this alias to <code>.bashrc</code> (or equivalent):</p> |
| 40 | +<pre data-lang="bash" style="background-color:#f5f5f5;color:#1f1f1f;" class="language-bash "><code class="language-bash" data-lang="bash"><span style="color:#7f8989;"># you&#39;ll have to change the path |
| 41 | +</span><span style="color:#b39f04;">alias </span><span style="color:#c23f31;">connectsquare</span><span style="color:#72ab00;">=</span><span style="color:#d07711;">&#39;/path/to/textual_apps/bin/connectsquare&#39; |
| 42 | +</span></code></pre> |
| 43 | +<p>As an alternative to manually managing such virtual environments, you can use <a href="https://github.com/astral-sh/uv">uv</a> or <a href="https://github.com/pypa/pipx">pipx</a> instead.</p> |
| 44 | +<p>As yet another alternative, you can install <code>textual==0.85.2</code> (see <a href="https://textual.textualize.io/getting_started/">Textual documentation</a> for more details), clone <a href="https://github.com/learnbyexample/TUI-apps">this repository</a> and run the <code>connect_square.py</code> file.</p> |
| 45 | +<br> |
| 46 | +<h2 id="screenshots">Screenshots<a class="zola-anchor" href="#screenshots" aria-label="Anchor link for: screenshots">π</a></h2> |
| 47 | +<p>Adjust your terminal's dimension for the game widgets to appear properly, for example 80x30 (characters x lines). Sample screenshots are shown below:</p> |
| 48 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/ConnectSquare/connect_four.png" alt="Sample screenshot for Connect Four game" /></p> |
| 49 | +<p align="center"><img src="https://raw.githubusercontent.com/learnbyexample/TUI-apps/main/ConnectSquare/connect_both.png" alt="Sample screenshot for Connect Four or Square game" /></p> |
| 50 | +<br> |
| 51 | +<h2 id="guide">Guide<a class="zola-anchor" href="#guide" aria-label="Anchor link for: guide">π</a></h2> |
| 52 | +<ul> |
| 53 | +<li>Press the <strong>n</strong> key to start a new game. Existing game, if any, will be abandoned</li> |
| 54 | +<li>You can choose between <strong>Connect Four</strong>, <strong>Connect Square</strong> (default) and <strong>Both</strong> types of game</li> |
| 55 | +<li>You can choose between <strong>Easy</strong> (default), <strong>Medium</strong> and <strong>Hard</strong> difficulty modes: |
| 56 | +<ul> |
| 57 | +<li>In the <em>Easy</em> mode, the AI will make a random move</li> |
| 58 | +<li>In the <em>Medium</em> mode, the AI will make a random move based on certain weight calculations</li> |
| 59 | +<li>In the <em>Hard</em> mode, the AI will make the best move based on the weight calculations (the algorithm is based only on the current board state and thus it is not impossible for the user to win)</li> |
| 60 | +</ul> |
| 61 | +</li> |
| 62 | +<li>The first move is based on the <strong>User first</strong> (default) and <strong>AI first</strong> choices</li> |
| 63 | +<li>Only the bottom most empty cell of each column will be considered as a valid move</li> |
| 64 | +<li>Press the <strong>t</strong> key to toggle between light and dark themes</li> |
| 65 | +<li>Press the <strong>q</strong> key to quit the app</li> |
| 66 | +</ul> |
| 67 | +<p>User moves are denoted by the βοΈ character and AI moves are denoted by the βοΈ character.</p> |
| 68 | +<p>The text panel under the game board displays the current status of the game. If the game ends with one of the players forming a valid line or square, the cells forming the winning move will be highlighted.</p> |
| 69 | +</content> |
| 70 | + </entry> |
10 | 71 | <entry xml:lang="en"> |
11 | 72 | <title>Python regular expression cheatsheet and examples</title> |
12 | 73 | <published>2025-06-09T00:00:00+00:00</published> |
|
0 commit comments