PHP Classes

How to Use a PHP Wordle Implementation From the CLI Using the Package Wordle CLI: Run the Wordle game on the command line console

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-02-12 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
wordle-cli 1.0Custom (specified...7Games, Console, PHP 7
Description 

Author

This package can run the Wordle game on the command line console.

It provides a PHP implementation of the Wordle game that can be started from the command line console.

The game is available in English, Spanish, and Portuguese.

Picture of Rodolfo Berrios Arce
Name: Rodolfo Berrios Arce <contact>
Classes: 5 packages by
Country: Chile Chile
Innovation award
Innovation award
Nominee: 3x

Example

#!/usr/bin/env php
<?php

/*
 * This file is part of Chevere.
 *
 * (c) Rodolfo Berrios <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

use
League\CLImate\CLImate;
use
Rodber\Wordle\Compare;
use
Rodber\Wordle\Word;
use function
Chevere\Filesystem\filePhpReturnForPath;

require_once
__DIR__ . '/vendor/autoload.php';

$climate = new CLImate();
$climate->clear();
$climate->addArt(__DIR__ . '/app/banner');
$climate->animation('intro')->speed(200)->enterFrom('top');

$options = [
   
'en' => 'English',
   
'es' => 'Español',
   
'pt' => 'Português',
];
$input = $climate->radio('Language selection:', $options);
$lang = $input->prompt();

$climate->addArt(__DIR__ . "/app/lang/{$lang}/banner");

$en = [
   
'options' => 'Game options',
   
'length' => 'Word length [3, 8] (default 5)',
   
'responses' => 'Responses [0, n] (default 6, no limit 0)',
   
'looking' => 'Looking for <invert> %length% </invert> char word',
   
'try' => 'Try',
   
'must' => 'Word must be %s char length',
   
'unknown' => 'Unknown word (not in wordlist)',
   
'welcome' => 'Welcome to Wordle CLI!',
   
'instructions' => 'You have to guess a word of a certain length.',
   
'exact_match' => 'Exact match',
   
'partial_match' => 'Partial (wrong position)',
   
'no_match' => 'No match',
   
'tries' => 'tries',
];

$es = [
   
'options' => 'Opciones del juego',
   
'length' => 'Largo de palabra [3, 8] (defecto 5)',
   
'responses' => 'Respuestas [0, n] (defecto 6, sin límite 0)',
   
'looking' => 'Buscando palabra de <invert> %length% </invert> caracteres',
   
'try' => 'Intento',
   
'must' => 'La palabra debe ser de %s caracteres',
   
'unknown' => 'Palabra desconocida (no está en el diccionario)',
   
'welcome' => 'Bienvenido a Wordle CLI!',
   
'instructions' => 'Tienes que adivinar una palabra de cierta longitud.',
   
'exact_match' => 'Coincidencia exacta',
   
'partial_match' => 'Parcial (posición incorrecta)',
   
'no_match' => 'Sin coincidencia',
   
'tries' => 'intentos',
];

$pt = [
   
'options' => 'Opções do jogo',
   
'length' => 'Comprimento da palavra [3, 8] (padrão 5)',
   
'responses' => 'Respostas [0, n] (padrão 6, sem limite 0)',
   
'looking' => 'Procurando palavra de <invert> %length% </invert> caracteres',
   
'try' => 'Tente',
   
'must' => 'A palavra deve ter %s caracteres',
   
'unknown' => 'Palavra desconhecida (não está no dicionário)',
   
'welcome' => 'Bem-vindo ao Wordle CLI!',
   
'instructions' => 'Você tem que adivinhar uma palavra de certo comprimento.',
   
'exact_match' => 'Correspondência exata',
   
'partial_match' => 'Parcial (posição errada)',
   
'no_match' => 'Sem correspondência',
   
'tries' => 'tentativas',
];

$LANG = $$lang;

$climate->br()->out('? ' . $LANG['welcome'])->br();
$climate->out($LANG['instructions'])->br();
$climate->out('? ' . $LANG['exact_match']);
$climate->out('? ' . $LANG['partial_match']);
$climate->out('? ' . $LANG['no_match'])->br();

$options = range(3, 8);
$climate->out('<green>' . $LANG['options'] . '</green>');
$input = $climate->input('<green>* ' . $LANG['length'] . ':</green>');
$input->defaultTo('5');
$input->accept($options);
$wordLength = intval($input->prompt());

$input = $climate->input('<green>* ' . $LANG['responses'] .' :</green>');
$input->defaultTo('6');
$ansTries = intval($input->prompt());
$attempts = $ansTries === 0
   
? '?'
   
: $ansTries;

$wordListFile = filePhpReturnForPath(__DIR__ . "/app/lang/{$lang}/words/{$wordLength}.php");
$wordList = $wordListFile->cast()->array();
$randomWord = mb_strtoupper($wordList[rand(0, count($wordList))]);
$word = new Word($randomWord);
$climate->br()->out(
   
strtr(
       
'? ' . $LANG['looking'] . ':',
        [
           
'%length%' => $wordLength,
        ]
    )
)->
br();
$emojiLines = [];
$answers = [];
$try = 0;
do {
   
$input = $climate->input(
       
strtr('? '. $LANG['try'] .' %try/%attempts:', [
           
'%try' => strval($try + 1),
           
'%attempts' => $attempts,
        ])
    );
   
$ansTries = $input->prompt();
    if (
strlen($ansTries) === 0) {
       
$noMatch = true;
       
$climate->error(
           
sprintf($LANG['must'], $word->length())
        );

        continue;
    }
   
$attemptUpper = mb_strtoupper($ansTries);
   
$attemptLower = mb_strtolower($ansTries);
   
$against = new Word($attemptUpper);
    if (
$against->length() !== $word->length()) {
       
$noMatch = true;
       
$climate->error(
           
sprintf($LANG['must'], $word->length())
        );

        continue;
    }
    if (!
in_array($attemptLower, $wordList, true)) {
       
$noMatch = true;
       
$climate->error($LANG['unknown']);

        continue;
    }
   
$answers[] = $attemptUpper;
   
$compare = new Compare($word, $against);
   
$noMatch = ! $compare->match();
   
$explain = [];
   
$emoji = '';
    foreach (
$against->split() as $pos => $letter) {
       
$match = $compare->computed()[$pos][$letter];
       
$color = '' . match ($match) {
           
Word::CHAR_MATCH_EXACT => 'green',
           
Word::CHAR_MATCH_PARTIAL => 'light_yellow',
           
Word::CHAR_MATCH_NONE => 'dark_gray',
        };
       
$explain[] = "<invert><{$color}> {$letter} </{$color}></invert>";
       
$emoji .= match ($match) {
           
Word::CHAR_MATCH_EXACT => '?',
           
Word::CHAR_MATCH_PARTIAL => '?',
           
Word::CHAR_MATCH_NONE => '?',
        };
    }
   
$emojiLines[] = $emoji;
   
$explain[] = ' <invert><green>(' . $compare->fraction() . ')</green></invert>';
   
$climate->out(implode('', $explain));
   
$try++;
} while (
$noMatch && ($attempts !== '?' && $try < $attempts));
$climate->animation($noMatch ? 'lose' : 'win')->enterFrom('bottom');
$LANGdgame = strtr('%icon% GAME OVER (%tries% ' . $LANG['tries'] . ') ? %word%', [
   
'%tries%' => $try,
   
'%icon%' => $noMatch ? '?' : '?',
   
'%word%' => $randomWord,
]);
$climate->flank($LANGdgame, '*', 3);
$climate->br()->out(implode("\n", $emojiLines));


Details

Rodber's Wordle-CLI

<a href="https://github.com/rodber/wordle-cli/releases/latest"><img alt="Get it on macOS" src=".github/badge/macos.png" height="50" hspace="2"><img alt="Get it on Linux" src=".github/badge/linux.png" height="50" hspace="2"><img alt="Get it on Windows" src=".github/badge/windows.png" height="50" hspace="2"></a>

https://user-images.githubusercontent.com/20590102/151889072-ff1ef963-e18c-4554-a5f6-edeed50343ec.mp4

This is a Wordle CLI remix game:

  • Pick language to answer (En, Pt, Es)
  • Choose word length (3, 8)
  • Determine number of allowed responses (default 6)

Run binary

  • Get the latest binary from the releases page
  • Run `wordle-cli` from your terminal

Windows users can run wsl ./wordle-cli from the Windows terminal.

Run using Docker

docker run -it --rm --init --name rodber-wordle-cli ghcr.io/rodber/wordle-cli ./wordle-cli

Build Docker image

docker build -t ghcr.io/rodber/wordle-cli:latest .

Run from source

composer install

./wordle-cli

License

Copyright Rodolfo Berrios A.

This project is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


  Files folder image Files (56)  
File Role Description
Files folder image.ecs (3 files)
Files folder image.github (1 file, 2 directories)
Files folder image.vscode (1 file)
Files folder imageapp (2 directories)
Files folder imagesrc (3 files)
Files folder imagetests (2 files)
Files folder imagewordlist (2 files)
Accessible without login Plain text file .dockerignore Data Auxiliary data
Accessible without login Plain text file box.json.dist Data Auxiliary data
Accessible without login Plain text file build-words Example Example script
Accessible without login Plain text file cat.sh Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file docker-bake.hcl Data Auxiliary data
Accessible without login Plain text file Dockerfile Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Makefile Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit-coverage.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file wordle-cli Example Example script

  Files folder image Files (56)  /  .ecs  
File Role Description
  Accessible without login Plain text file .header Data Auxiliary data
  Accessible without login Plain text file ecs-chevere.php Class Class source
  Accessible without login Plain text file ecs.php Example Example script

  Files folder image Files (56)  /  .github  
File Role Description
Files folder imagebadge (3 files)
Files folder imageworkflows (2 files)
  Accessible without login Image file social.png Icon Icon image

  Files folder image Files (56)  /  .github  /  badge  
File Role Description
  Accessible without login Image file linux.png Icon Icon image
  Accessible without login Image file macos.png Icon Icon image
  Accessible without login Image file windows.png Icon Icon image

  Files folder image Files (56)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file docker.yml Data Auxiliary data
  Accessible without login Plain text file release.yml Data Auxiliary data

  Files folder image Files (56)  /  .vscode  
File Role Description
  Accessible without login Plain text file settings.json Data Auxiliary data

  Files folder image Files (56)  /  app  
File Role Description
Files folder imagebanner (1 file)
Files folder imagelang (3 directories)

  Files folder image Files (56)  /  app  /  banner  
File Role Description
  Accessible without login Plain text file intro Data Auxiliary data

  Files folder image Files (56)  /  app  /  lang  
File Role Description
Files folder imageen (2 directories)
Files folder imagees (2 directories)
Files folder imagept (2 directories)

  Files folder image Files (56)  /  app  /  lang  /  en  
File Role Description
Files folder imagebanner (2 files)
Files folder imagewords (6 files)

  Files folder image Files (56)  /  app  /  lang  /  en  /  banner  
File Role Description
  Accessible without login Plain text file lose Data Auxiliary data
  Accessible without login Plain text file win Data Auxiliary data

  Files folder image Files (56)  /  app  /  lang  /  en  /  words  
File Role Description
  Accessible without login Plain text file 3.php Aux. Configuration script
  Accessible without login Plain text file 4.php Aux. Configuration script
  Accessible without login Plain text file 5.php Aux. Configuration script
  Accessible without login Plain text file 6.php Aux. Configuration script
  Accessible without login Plain text file 7.php Aux. Configuration script
  Accessible without login Plain text file 8.php Aux. Configuration script

  Files folder image Files (56)  /  app  /  lang  /  es  
File Role Description
Files folder imagebanner (2 files)
Files folder imagewords (6 files)

  Files folder image Files (56)  /  app  /  lang  /  es  /  banner  
File Role Description
  Accessible without login Plain text file lose Data Auxiliary data
  Accessible without login Plain text file win Data Auxiliary data

  Files folder image Files (56)  /  app  /  lang  /  es  /  words  
File Role Description
  Accessible without login Plain text file 3.php Aux. Configuration script
  Accessible without login Plain text file 4.php Aux. Configuration script
  Accessible without login Plain text file 5.php Aux. Configuration script
  Accessible without login Plain text file 6.php Aux. Configuration script
  Accessible without login Plain text file 7.php Aux. Configuration script
  Accessible without login Plain text file 8.php Aux. Configuration script

  Files folder image Files (56)  /  app  /  lang  /  pt  
File Role Description
Files folder imagebanner (2 files)
Files folder imagewords (6 files)

  Files folder image Files (56)  /  app  /  lang  /  pt  /  banner  
File Role Description
  Accessible without login Plain text file lose Data Auxiliary data
  Accessible without login Plain text file win Data Auxiliary data

  Files folder image Files (56)  /  app  /  lang  /  pt  /  words  
File Role Description
  Accessible without login Plain text file 3.php Aux. Configuration script
  Accessible without login Plain text file 4.php Aux. Configuration script
  Accessible without login Plain text file 5.php Aux. Configuration script
  Accessible without login Plain text file 6.php Aux. Configuration script
  Accessible without login Plain text file 7.php Aux. Configuration script
  Accessible without login Plain text file 8.php Aux. Configuration script

  Files folder image Files (56)  /  src  
File Role Description
  Accessible without login Plain text file Compare.php Class Class source
  Accessible without login Plain text file Word.php Class Class source
  Accessible without login Plain text file Wordlist.php Class Class source

  Files folder image Files (56)  /  tests  
File Role Description
  Accessible without login Plain text file CompareTest.php Class Class source
  Accessible without login Plain text file WordTest.php Class Class source

  Files folder image Files (56)  /  wordlist  
File Role Description
  Accessible without login Plain text file en Data Auxiliary data
  Accessible without login Plain text file pt Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0