PlayerGames

Central hub of the PlayerGames gamification ecosystem for Moodle — full documentation.

English | Português

View on GitHub Download .zip

Moodle License Status Latest Release PlayerGames Ecosystem Core Component Author

Moodle Plugin CI Last Commit Open Issues

⚠️ This plugin is under active development. It is not yet published on the Moodle Plugin Directory. Some features described below are planned and not yet implemented.

PlayerGames (local_playergames) is the central hub of the PlayerGames gamification ecosystem for Moodle. It serves four main purposes:

  1. Ecosystem Dashboard — a visual overview of all Player plugins installed on the site, with status, dependencies, and quick-access links.
  2. Player Hub — a site-wide gamification platform for students and/or other Moodle users (teachers, managers, administrators), with XP, levels, seasons, missions, achievements, avatars and daily streak. The administrator configures which groups participate.
  3. Daily Mini-games — concept-reinforcement mini-games and a daily check-in powered by content cartridges (JSON, optionally AI-generated via the companion local_aihub plugin), working as a Duolingo-style learning loop.
  4. Companion Sidebar Block — block_playergames mirrors a player’s profile (avatar, level, XP, streak, today’s games, ranking) on the site front page and Dashboard.

👈 Use the sidebar to jump to any section on this page.


🖼️ Screenshots

Browse with the arrows, the dots, or the left/right keys. Click the image to zoom.

✨ Features

✅ Implemented

⏳ In Development / Planned

🤖 AI Provider Chain

Key storage and provider transport (Gemini, Groq, DeepSeek, OpenAI-compatible) live in a dedicated companion plugin, local_aihub. PlayerGames itself only builds the cartridge generation prompt (topic, language, concept count, level) and parses the AI’s JSON response back into concepts, so it stays free of key management while still supporting AI-assisted cartridge generation wherever the Hub is installed.

The language field comes filled in with the language of the person on the page and can be changed, and the content level goes from very easy to very hard. For concepts, the prompt asks only for single words, letters only, with a length that serves PlayerGuess and PlayerFill.

Resolution order

Priority Source Notes
1 local_aihub Tried first when installed. Resolves personal keys, then site-wide keys, across Gemini / Groq / DeepSeek / OpenAI-compatible providers.
2 Moodle core_ai Institutional fallback, used only if the Hub is not installed or returns no usable source. Uses whichever providers the admin configured in Site administration → AI → AI providers.

A real provider failure (e.g. an invalid key configured in the Hub) is preserved and surfaced to the user — it is never silently masked as “no AI source available”.

Installing local_aihub is optional. Without it, cartridge AI generation still works if the site has core_ai configured; PlayerGames only loses the BYOK personal-key option (each teacher bringing their own Gemini/Groq/DeepSeek/OpenAI key) that the Hub provides.

Integration API for other plugins

cartridge\ai_generator exposes a small, stable API that other plugins in the ecosystem can call directly:

use local_playergames\cartridge\ai_generator;

$gen = new ai_generator();
if ($gen->has_key()) {
    // Free-form prompt, routed through the same chain as cartridge generation.
    $text = $gen->generate_text('Optional system instruction', 'Your prompt here');
}

Every AI generation triggered from PlayerGames is tagged in the Hub’s own usage log with the component (local_playergames) and a short description of what was generated (e.g. the cartridge topic), so site administrators can see AI usage per consuming plugin from the Hub’s admin report.

📦 Cartridge Format

Content cartridges are JSON files that power the mini-games. A concept cartridge (terms and definitions, as below) feeds PlayerGuess and PlayerFill; a question cartridge (questions with their answers) feeds PlayerQuiz and PlayerBattle:

{
  "name": "Gamification Fundamentals",
  "version": "1.0",
  "language": "en",
  "concepts": [
    {
      "term": "gamification",
      "definition": "Use of game elements in non-game contexts"
    }
  ]
}

🧠 How PlayerQuiz Works

PlayerQuiz is the first daily mini-game. It draws multiple-choice questions from the active cartridges and shows them one at a time.

Questions from the Moodle Question Bank

The Import from question bank tab of the cartridge page copies the multiple-choice questions of a category into a new question cartridge, which the games then use like any other. The category is limited to what Moodle keeps for reuse: question banks created to share questions across courses (Moodle 5.x) or categories in the system context (Moodle 4.5). A course’s own bank is never offered, so questions that belong to one course are not exposed to the whole site. The list only shows categories the person importing may use, and the choice is checked again on import.

Only the latest ready version of each question is copied, as plain text, and a question needs one answer worth the full grade and at least four wrong ones. Questions with an image, sound or video are left out, and the result says how many. The cartridge is a copy: to refresh it after the bank changes, import the category again and deactivate the old cartridge.

The play loop

Because a play ends on the first correct answer, a player rarely answers the whole pool — most questions in a session are just a buffer that provides variety and room to be wrong before repeating.

Two independent limits (this trips people up)

Setting Axis Meaning
Games per day (xp_games_quiz) the day How many plays earn XP per day. Also sets the daily XP cap: XP per game × games per day.
Questions per session (quiz_session_size) inside one play How many questions are drawn into a single play (the “deck” of that round).

Example — with XP per game = 25, games per day = 3, questions per session = 20: a player can complete 3 plays today (cap 75 XP), and each play is built from a fresh draw of 20 questions. The two numbers answer different questions: how many rounds today vs how big each round’s deck is.

Fresh questions and repeats

Admin settings

Site administration → Plugins → Local plugins → PlayerGames → Rules → Game rules

Setting Default What it does
Time per question (seconds) 120 (2 min) Countdown per question. Reaching zero counts as a wrong answer and advances. 0 disables the timer.
Maximum attempts Unlimited Wrong answers (including timeouts) that close PlayerQuiz for the rest of the day without XP, picked from Unlimited or 1 to 10. With Unlimited the game continues until the player answers correctly, so a play always pays XP.
Questions per session 20 Size of each play’s draw, chosen from a capped list (5–50).

How the timer and the attempts interlock

Why the session size is capped

Every question of a session is rendered into the page HTML at once (the browser just reveals them one by one). A very large session would format and ship hundreds of questions the player will never see — wasted server work and a heavy page. The capped list (max 50) keeps plenty of variety without that cost. Truly large sessions would require a different architecture (loading questions on demand), which is not how the game works today.

🔡 How PlayerGuess Works

PlayerGuess is a daily word-guessing mini-game: guess a term from the active cartridge, letter by letter, within a limited number of attempts.

The play loop

One concept per day, shared assignment pipeline

Every night, a scheduled task assigns one random concept to PlayerGuess (and, independently, to PlayerQuiz) from the currently active cartridges — the same pipeline used across the daily mini-games. For PlayerGuess specifically, only concepts whose term:

are eligible. This filter is applied identically at assignment time and again when validating a guess, so a term that happens to fit the length window but contains, say, a hyphen is never assigned to a PlayerGuess day.

Admin settings

Site administration → Plugins → Local plugins → PlayerGames → Rules → Game rules

Setting Default What it does
Maximum attempts 6 Guesses allowed before the round ends in a loss and the term is revealed.
Minimum term length 4 Shortest term eligible for the daily assignment.
Maximum term length 8 Longest term eligible for the daily assignment.

Site administration → Plugins → Local plugins → PlayerGames → Rules → Game XP

Setting Default What it does
XP per PlayerGuess game 25 XP awarded on a winning round.

Guess has one concept a day, so it has one round a day and pays its XP once, on the win; there is no “games per day” setting for it.

Round state

The in-progress round (guesses made so far, whether it’s finished, whether it was won) is kept in the database, one row per user and day. It automatically resets if the stored round no longer matches today’s assigned concept (a new day, or a re-assigned concept). This means:

📝 How PlayerFill Works

PlayerFill is a daily crossword-style mini-game: solve every one of the day’s terms, where letters shared between terms are revealed automatically as other terms are solved.

The play loop

Word count per day, shared assignment pipeline

Every night, a scheduled task assigns a configurable number of concepts to PlayerFill (default 5, admin-configurable between 4 and 8) from the currently active cartridges — the same pipeline used across the daily mini-games, extended for PlayerFill’s need for several terms at once instead of one. Only concepts whose term:

are eligible, the same filter PlayerGuess applies to its own single daily term. If fewer eligible concepts exist than the configured word count, PlayerFill is simply left unassigned for that day rather than starting an undersized puzzle.

The word of the day of PlayerGuess is left out of PlayerFill, and the other way round, also when two cartridges hold the same word: solving one game would otherwise give the answer of the other away. It goes in only when the other words are not enough for the puzzle, so the day is never left without a game.

The page explains the rules above the puzzle (each clue is below its tiles, the same number hides the same letter, and how many attempts each word has) and shows under each word how many attempts it has left.

Admin settings

Site administration → Plugins → Local plugins → PlayerGames → Rules → Game rules

Setting Default What it does
PlayerFill words per day 5 How many terms make up each day’s puzzle. Clamped between 4 and 8.
PlayerFill maximum attempts per word 4 Guesses allowed on a single term before the whole day ends in a loss.
Minimum term length for PlayerFill 3 Shortest term eligible for the daily assignment.
Maximum term length for PlayerFill 12 Longest term eligible for the daily assignment.

Site administration → Plugins → Local plugins → PlayerGames → Rules → Game XP

Setting Default What it does
XP per PlayerFill game 25 XP awarded on a winning day.

Fill has one puzzle a day, so it has one round a day and pays its XP once, on the win; there is no “games per day” setting for it.

Round state

The in-progress puzzle (which terms are solved, which slots are revealed, attempts used per term) is kept in the database, one row per user and day, and every guess is validated server-side against a term that is never exposed to the browser ahead of time. It automatically rebuilds if the stored puzzle no longer matches today’s assigned terms (a new day, or a re-assigned set).

Adapted from mod_playercross

PlayerFill’s letter-to-slot algorithm is ported from the standalone mod_playercross activity’s puzzle builder. mod_playercross itself evolved a richer mechanic on top of it — a separate cipher-locked “mystery phrase” solved through clue words, with a bonus for guessing it directly and per-attempt partial grading — none of which carries over here: PlayerGames pays a fixed amount of XP per win regardless of how it was reached, so partial-credit grading has no place in this hub, and a set of peer terms that reveal each other is already a complete, self-contained puzzle without needing a separate phrase layered on top.

⚔️ How PlayerBattle Works

PlayerBattle is the daily match-3 mini-game. The player fights an opponent on an 8×8 board: lining up pieces hurts the opponent, and the Orb brings a question — a right answer lands a critical hit. The questions come from the same cartridges as PlayerQuiz.

The board

Swap two neighbouring pieces to line up three or more of the same kind. The pieces that match are destroyed, new ones fall in, and any match they make counts too (a cascade). A swap that makes no match slides back and does not cost the turn. The player moves first, then the opponent, in turns.

Piece Effect
⭐ Star +0.1 to the damage multiplier of whoever matched it. The multiplier raises Sword hits and the critical hit, and is spent by the critical hit or lost on a wrong answer.
📖 Grimoire Fills a hex meter. When full, it casts a hex on the other side for three turns: it loses the damage unit of whoever cast it at the start of each of its turns, and the shield does not stop it.
❓ Orb Fills the mana bar (20 per piece, 100 is full). When it fills, the player faces a question.
⚔️ Sword Direct damage: one damage unit for a match of three, ×1.5 for four, ×2 for five.
🛡️ Shield Fills a shield meter. When full, it cancels the next hit taken (a Sword, a critical hit or a wrong answer). The hex goes through it.
🧪 Potion Heals a quarter of the damage unit per piece, up to the maximum HP.

Both sides start with 200 HP. A match of three Swords hits for 10 when the player makes it and for 8 when the opponent does. These numbers are fixed: they come from simulated battles, in which a player who answers every question right wins almost always, one who answers two in three about three times in four, and one who guesses blindly among five options about one time in five. A battle lasts roughly 18 to 29 turns and asks 5 to 9 questions.

The questions

XP and daily plays

PlayerBattle follows the same daily rule as the other games: how much XP a play gives and how many plays a day count come from the Game XP settings the season was created with.

A result is accepted once for each battle the page opened, so a result sent twice earns nothing.

The board is played in the browser and the server cannot replay it, so it checks what it can. The questions are judged on the server: the page never receives which option is right, and the counts of questions answered and right are the server’s own. A victory is recorded as such only if the battle lasted at least 15 seconds and answered at least 2 questions; otherwise it is recorded as a defeat. This stops a result sent without playing. It does not stop someone who plays through with a script that answers questions and waits.

Content and settings

PlayerBattle asks question cartridges, including the ones imported from a Moodle Question Bank (see How PlayerQuiz Works), as chosen for the season in the Season games card of the Administration tab.

Where Setting
Season games Whether PlayerBattle runs in the season and which cartridges its questions come from.
Rules → Game XP XP per PlayerBattle game and how many plays a day give XP.
Rules → Game rules Maximum attempts: how many lost battles close the game for the day, Unlimited by default.

Playing it

Privacy

The result of each day is stored with the player: whether it was a victory, the damage dealt, the questions answered right and in total, the XP, the duration and the time. It is exported and deleted with the rest of the player’s data, and removed with the season by the retention task.

🦊 Avatars

PlayerGames has its own emoji avatar collection, unlocked permanently by the highest level a player has ever reached — no shop, no file uploads, just a level-tier reward.

Catalog and tiers

The default catalog has 17 emoji avatars split across 4 tiers (5 in tier 1, 4 each in tiers 2–4): 🤖 👾 🦊 🐱 🐶 (tier 1), 🕵️ 🤺 🧚 🧜 (tier 2), 🧝 🧙 🦸 🥷 (tier 3), and 🧛 🦹 🐉 🦁 (tier 4).

Unlock rule

Unlocks are based on the highest level the player has ever reached, for life — not their current level, and not scoped to the current season. Every time a player earns enough XP to level up, PlayerGames records the new level only if it exceeds the best level stored for that player; closing a season, which resets season XP back to zero, never takes an already-unlocked avatar away.

Tier thresholds

The tiers are spread evenly across the level ladder, so every avatar stays reachable however many levels the ladder has: tier 1 opens at level 1 and each later tier a further quarter of the ladder up.

Tier 5 levels (default ladder) 20 levels
1 1 1
2 2 6
3 3 11
4 4 16

There is nothing to set: the tiers follow the ladder of Levels and titles, which shows where each one opens, and move with it when it changes.

Equip and display

A player can equip any avatar they’ve unlocked (or unequip back to their default Moodle profile picture) from a tier-grouped picker — locked avatars show grayed out alongside their required level. The equipped avatar replaces the default profile picture in the Player Hub’s profile card and in the PlayerGames block’s widget, and stays in sync between the two since both read and write through the same avatar manager.

📘 Course XP

Course XP is a separate, optional XP pool that mirrors a student’s per-course XP earned in block_playerhud into PlayerGames, purely for cross-course visibility — it is never summed with season XP and never affects levels, avatar unlocks or the season ranking. It measures how engaged a student is with the courses gamified with PlayerHUD, not what they learned.

Where it comes from

When block_playerhud is installed and a student earns or loses course XP, PlayerGames listens for that change and mirrors the delta into its own windowed course XP total. Nothing needs to be configured on the block_playerhud side beyond having it installed — the bridge is optional and stays dormant if block_playerhud isn’t present.

The window

Course XP is not a lifetime total: it only counts XP earned within a rolling window (default 12 months, configurable in months; 0 means unlimited/lifetime). Data is kept in monthly buckets, so the window ages correctly month by month, and a nightly scheduled task recomputes every user’s windowed total to correct any drift and drop buckets that have aged out.

Visibility

Course XP is shown only when both are true:

Unlike most other student-facing features, visibility is not tied to whether the viewer is flagged as staff — a teacher who is also a genuine PlayerHUD-earning student in another course still sees their own course XP.

Its own ranking

Course XP has its own separate, opt-in ranking — a single top-50 list (not split by staff/student like the season ranking), gated by its own admin toggle. Players with zero windowed XP are excluded entirely rather than occupying a rank, and each player has an independent opt-in toggle from the season ranking’s own visibility setting. Position lookup for players outside the top 50 follows the same tie-break rule as the season ranking (highest XP first, then earliest to reach it).

Where it’s shown

Both the Player Hub page and the PlayerGames block’s sidebar widget read from the same manager and follow the same visibility and ranking rules, so the two surfaces are always consistent with each other.

🏆 Ranking Behavior

The season ranking is opt-in, split by participant group, and shows a player their own position even outside the visible top 50.

Opt-in and the top-50 list

Players choose whether to appear in the ranking from their profile. The visible list is the top 50 by season XP, ordered by XP descending → the moment they reached that XP ascending → user id ascending — a fully deterministic tie-break, so two players with the same XP are ranked by who got there first.

Staff / student split

Rankings are split into two groups: students and staff. Staff are the site administrators and everyone who can edit at least one course, such as managers and editing teachers. Everyone else counts as a student, a non-editing teacher included. Whether a viewer sees one or both groups depends on their own role and the site’s participant setting:

Your own position, even outside the top 50

A player who opted into the ranking but isn’t in the visible top 50 still sees their own exact position — computed with a single indexed count query against the same ordering rule used for the visible list, not by scanning the whole ranking.

Who stays on the list

Opting out of the gamification (Preferences → Gamification) takes a player off both rankings at once, and turning it back on starts hidden: they choose again whether to show up. A player whose role lost the local/playergames:viewhub capability, or whom a change of the participant setting no longer allows, is also left out of the list, within a minute (the lists are cached for 60 seconds).

How the staff group is kept up to date

Working out who counts as staff takes several queries for every teacher of the site, so a scheduled task, Refresh the set of staff users (refresh_staff_ids), does it every 10 minutes and the hub only reads the result. This has two consequences for administrators:

Scope

This page describes the season ranking (tied to season XP and reset when a season closes). Course XP has its own separate, single (not staff/student-split) ranking with its own opt-in — see that section for details.

🎓 Educational Purpose

PlayerGames is designed to:

Suitable for:

🕹️ PlayerGames Ecosystem

PlayerGames is the hub of a broader gamification ecosystem. Together, these plugins transform Moodle into an immersive experience:

📦 Requirements

Component Version
Moodle 4.5 – 5.3
PHP 8.1+

🛠️ Installation & Configuration

⚠️ This plugin is not yet published on the Moodle Plugin Directory. Install manually from this repository.

  1. Download the .zip file or clone this repository.
  2. Extract the folder into your Moodle local/ directory.
  3. Rename the folder to playergames (if necessary). Final path: your-moodle/local/playergames/
  4. Visit Site administration → Notifications to complete installation.
  5. Open the Administration tab of PlayerGames (or Site administration → Plugins → Local plugins → PlayerGames) and follow its cards in order: create a cartridge, create and activate the first season, and choose the games it runs. The XP, level, avatar and game rules have working defaults you can review under Rules — see Administration.
  6. Optional: install local_aihub if you want AI-assisted cartridge generation with personal/site API keys — see AI Provider Chain.

🧭 Administration

Everything an administrator sets up is gathered in the Administration tab of PlayerGames, as cards, in the order the work is usually done. Each card says what the function does and, where there is one, where things stand: which season is active, how many cartridges are on, and so on. A card is a link to the page of the function.

The tab shows up for whoever can open at least one card, and each card is shown only if the user can open where it leads.

The cards

Group Card What it is for Needs
Get started Cartridges The packs of questions and concepts the games draw from. Import a file, generate one with AI or write it by hand. Manage cartridges
  Seasons The period in which students earn XP and compete in the ranking. Create, edit, activate, close and delete seasons. Site administrator
  Season games Which games run in the season and which cartridges the questions or words of each one come from (PlayerQuiz and PlayerBattle use question cartridges; PlayerGuess and PlayerFill, concept cartridges). Site administrator
Rules Participation and seasons Who plays (students, staff or both), whether seasons renew by themselves and how long they last. Site administrator
  Game XP How much XP each game gives and how many times a day it can be played for XP. Site administrator
  Game rules Time per question, attempts and the other rules of each game. Site administrator
  Levels and titles How much XP each level takes and the title it gives. The avatars unlock along this ladder. Site administrator
  Streak and freeze How the daily streak works and how a freeze is earned. Site administrator
  Missions The goals that give extra XP or a freeze: their targets and rewards, and new ones of the same kinds. Site administrator
  Course XP The XP courses give through PlayerHUD, shown apart from the season XP. Site administrator
Data Reset data Deletes the seasons and everything the players earned, to start again from zero. The cartridges and the settings stay. Site administrator
Help and integrations AI keys Keys used to generate questions with AI. Shown only when the AI Hub plugin is installed. Site administrator
  Documentation This guide, in English and Portuguese. Anyone who sees the tab

The Engagement Meter and the Plugin ecosystem are not cards: they already have a tab of their own.

Who sees what

When there is no active season, the Player Hub tells the administrator so and offers a button to the seasons page.

Editing and deleting a season

On the seasons page each season has Edit and, unless it is the active one, Delete.

Seasons never share a day. Creating or editing a season whose dates cross another one is refused, with the name and dates of the other season, because the retention task and Delete remove the scores of a season by its dates. The form suggests a start date after the last season when that one still runs: after closing a season today, the next one can start tomorrow.

Resetting all the data

Deleting the seasons and the cartridges one by one leaves what belongs to no season: streaks, freezes, achievements, avatar progress, the activity history and the course XP mirrored from PlayerHUD. Reset data deletes all of it, for every user, to start again from zero, after a pilot for instance.

The page lists how many records each group holds, and nothing is deleted until the administrator types the confirmation word (RESET; ZERAR in Portuguese). It cannot be undone. The site log records who did it, when and how many records went (event PlayerGames data reset).

The same order in the Moodle administration

The plugin’s pages in Site administration → Plugins → Local plugins → PlayerGames follow the same groups: Get started (Cartridges, Seasons, Season games), Rules (Participation and seasons, Game XP, Game rules, Levels and titles, Streak and freeze, Missions, Course XP), Monitoring (Engagement Meter) and Data (Reset data). The Administration tab is a shortcut to them, not a replacement.

Missions

A mission asks for one of four things: games in one day, a streak of days, XP in the season or PlayerBattle victories. The site starts with six (streaks of 7, 14 and 30 days among them), and the administrator can change their target and rewards, give them a name, switch them off, or add more of the same kinds. A mission is done once per season, apart from the daily ones, which start again every day.

The streak missions follow the streak of the hub, which a freeze protects and which the Streak activity setting counts from games only, or from a game or the daily check-in. The streak goes on from one season to the next, but its missions count at most the days the season has had, so that a player who arrives with a long streak starts them from the first day, like everyone else.

Once somebody completes a mission in the active season, it cannot be switched off and its target and rewards stay as they are until the season ends, so that everyone plays by the same rules; only its name can change. A mission somebody has started can be switched off, but not deleted, because the seasons count the missions their players completed.

Most XP of a season

The seasons page shows, for each season, the most XP a player can earn in it: every game won on every day, every check-in up to its cap, and every mission the season can reach. The games and the check-in follow the rules the season froze when it was created; the missions are the ones on now. The XP of the courses is kept apart and is not part of it.

Season games opens the active season, or the next one if none is active. With no season at all it leads to the seasons page.

With every cartridge checked, a game also uses the ones created later. With none checked the game is switched off for the season: the switch follows the boxes, and turning it on again checks them all.

For PlayerGuess and PlayerFill, each cartridge shows how many of its words serve the game, and the page warns when the chosen cartridges are not enough. In the hub, the card of the game says why there is nothing to play: no active cartridge, no words that meet the requirements or no questions in the chosen cartridges, or words of the day not drawn yet. Deleting the only cartridge a game uses switches the game off, and the page says so.

First setup

  1. Create a cartridge (Cartridges): the games need something to ask.
  2. Create a season and activate it (Seasons).
  3. Choose the games the season runs and their cartridges (Season games).
  4. Review the rules (Rules): the defaults work, but the XP, the levels and who plays are yours to set.

📖 Usage

For Administrators

  1. Install the plugin and complete the Moodle upgrade step.
  2. Optionally install local_aihub if you want AI-assisted cartridge generation with personal/site keys (see AI Provider Chain) — otherwise cartridges can still be created manually or generated through Moodle’s own core_ai.
  3. Create a content cartridge in the Cartridges page (upload one or generate it): the games need something to ask.
  4. Create the first season in the Seasons page and activate it, setting name and dates.
  5. Choose the games the season runs, and where their questions come from, in Season games.
  6. Review the rules (XP, levels, who plays) under Rules: the defaults work, and you can tune them.
  7. Monitor gamification impact in the Engagement Meter page.

Steps 3 to 6 are cards in the Administration tab, in this order (the Engagement Meter has its own tab); see Administration.

For Teachers

  1. If local_aihub is installed, access its My AI Keys page to configure a personal API key (optional — site keys work if the admin configured them).
  2. Use the PlayerGames hub or any Player plugin — AI features will use the configured key chain automatically.

For Students

  1. Visit the Player Hub to see your XP, level, ranking position, streak, and daily missions.
  2. Play the daily mini-games to earn XP.
  3. Toggle “Show in ranking” in your profile to control ranking visibility.

🧪 Automated Tests

PlayerGames ships with a PHPUnit suite covering the gamification engine, the cartridge pipeline, scheduled tasks, privacy and events, and with Node tests for the rules of PlayerBattle. Every CI push runs the full matrix (Moodle 4.5 → 5.3, PostgreSQL & MariaDB).

PHPUnit — Unit & Integration Tests

Test file Cases What is covered
cartridge/importer_test.php 14 Concept and quiz import; type inference; fields of an older file ignored; schema-error paths; fields of the wrong type; the whole import saved in one transaction
cartridge/exporter_test.php 5 Concept/quiz export structure and full import→export round-trip including root metadata
cartridge/quiz_generator_test.php 12 Quiz response parsing, save_standalone persistence; responses with fields of the wrong type
cartridge/ai_generator_test.php 7 Concept response parser: wrapped/bare/fenced JSON, invalid and missing-concepts errors; delegation to the AI Hub facade with a core_ai fallback; responses with fields of the wrong type
cartridge/payload_test.php 3 Cleaning of imported and AI-returned fields: a scalar becomes text and anything else counts as missing; a single value is wrapped as a list; numbers are clamped with a fallback
hub/xp_manager_test.php 17 Level thresholds, per-game cap enforcement, uncapped mission award, level-up event, season ranking position/tie-break
hub/avatar_manager_test.php 15 Default catalog seeding, tier thresholds, lifetime best-level tracking, unlock/equip rules, locked-equip rejection
hub/learning_xp_manager_test.php 22 Windowed monthly buckets, visibility gating (independent of staff status), ranking opt-in and position, recompute correctness
hub/daily_play_manager_test.php 6 Multiple plays split XP evenly; play beyond the daily quota rejected; last play trimmed to the exact cap; the extra payload (victory) reaches the event and completes the battle mission only when flagged; every pending game links to its page and a played one does not
hub/level_manager_test.php 8 Ladder seeding, XP/title lookups, save renumber + zero floor, restore defaults, linear generation and bounds
hub/checkin_manager_test.php 11 Check-in insert + XP award, idempotency, season cap, optional streak advance, participant eligibility
hub/served_questions_test.php 3 Per-day “already shown” set grouped by source, idempotent scoping, invalid items ignored
hub/streak_manager_test.php 12 Streak start/continue/reset, freeze consumption, overnight break processing
hub/season_manager_test.php 28 Season lifecycle, active/upcoming resolution, exclusive activation, snapshot, create_next; whether any season exists; editing (a closed season keeps its dates), deleting only a season’s own data, the active season refused; closing early ends the season today; overlapping dates found and named
hub/mission_manager_test.php 15 Mission sync, progress/completion with XP reward, daily resets; the streak missions counted from the start of the season; several missions of one kind; description from the target; switching off, deleting and the lock of a mission completed this season; the range of each kind
hub/season_xp_test.php 2 The days of a season, first and last included; the most XP of a season, game by game, with the check-in cap and the missions the season can reach
hub/achievement_manager_test.php 6 Achievement sync, granting (first game/level/all-games-day), idempotency
hub/title_manager_test.php 2 Level→title key clamping and translation
observer_test.php 5 game_completed drives streak/mission/achievement; records streak even without a season; mirrors block_playerhud XP changes into Course XP
hook_callbacks_test.php 5 Primary navigation link: the hub for a student, none after opting out, the dashboard for a teacher who opted out, none for a guest, and the staff lookup skipped (counted in queries) when gamification is on
games/quiz_loader_test.php 12 Completeness filter, session size, active-only, id filter, metadata, random draw, fresh-question exclusion and pool reuse
games/quiz_settings_test.php 6 Timer, max-attempts and session size configuration
games/day_loss_test.php 7 A lost day: the allowed defeats close it, Unlimited never does, it stays closed, it belongs to one user, game and day, and the word games read it from their own round
games/guess_manager_test.php 7 Daily concept resolution, term normalisation, Wordle-style letter feedback (including duplicate letters), guess validation
games/fill_manager_test.php 10 Word count/max-attempts config clamping, shared letter→slot assignment (including disjoint terms), tile reveal state, cross-reveal cascade, per-day term ordering and filtering, POST response payload reveal rules
games/battle_manager_test.php 12 PlayerBattle on the server: questions delivered ready for the browser with the text escaped once, no battle without questions, a defeat saved without XP and without spending the play, a victory with the season XP (also past the quota, with none), the best result of the day, a battle accepted once, counters kept in range, only the questions delivered counted as seen
games/word_pool_test.php 7 Which terms serve PlayerGuess and PlayerFill: the rule itself, length ranges, cartridges of the season, enough words for a day, count per cartridge
games/season_game_config_test.php 7 Source helpers; enabled-record lookup; per-season listing; default seeding and preservation
external/set_avatar_test.php 3 Equip/unequip via the AJAX endpoint, rejecting a locked avatar
external/set_ranking_visibility_test.php 2 Season ranking opt-in/opt-out toggle
external/set_learning_ranking_visibility_test.php 2 Course XP ranking opt-in/opt-out toggle
task/assign_daily_games_test.php 17 Per-game concept assignment, PlayerFill’s multi-concept assignment and pool-too-small skip, idempotency, no-cartridge and empty-cartridge cases, PlayerGuess eligibility filter, task name; PlayerGuess and PlayerFill never share a word while others are left
task/reset_daily_missions_test.php 1 Daily mission reset + streak break orchestration
task/close_expired_seasons_test.php 2 Closes expired season; auto-renew creates and activates next
task/purge_old_scores_test.php 3 Retention-window purge; keep-within-window no-op; battle results of seasons beyond the window are purged too
task/recompute_learning_xp_test.php 2 Nightly window recompute prunes aged-out buckets and corrects cache drift
privacy/provider_test.php 9 Metadata, contexts, userlist, export, and the three deletion paths; every declared table lists exactly its real columns
output/hub_test.php 2 Who is offered the seasons page while there is no season: the administrator, and no one else
output/season_games_test.php 2 The season games page: cartridges ticked as they were saved, all of them without a list and none with an empty one; warning about too few words
local/access_test.php 16 Staff detection (site admin, course-editing capability), bulk staff-id resolution, hub visibility rules; where each role lands
local/admin_cards_test.php 8 Administration tab: cards and groups by permission (administrator, manager, student), the tab in the navigation, the state of each card, a season name escaped once, and the documentation link opening in a new tab
local/game_page_test.php 2 The notice of the game pages when no season is active, and that it never says the game was already played
local/question_bank_reuse_test.php 3 Which question bank categories are kept for reuse (shared banks on Moodle 5.x, system context on 4.5), question counts, what a user may choose
cartridge/question_bank_importer_test.php 8 Copy into a new active question cartridge, left out questions with a medium (counted), unusable questions, latest ready version only, nothing to import, private categories and users who may not use them refused, text flattened keeping case and entities
cartridge/glossary_importer_test.php 4 Global glossaries listed with their approved entries, import into a concept cartridge, refusal of a course glossary and of an empty one
local/text_test.php 4 Plain-text names: text as typed, the level title, cartridge pages escaping names once, and edit forms filling inputs with the stored text
local/data_reset_test.php 4 Every table deleted or kept, the personal-data tables deleted, the seasons counted alone, and a reset that deletes the play, keeps the content, the settings and the users’ choices, and logs who did it
local/engagement_report_test.php 14 Empty metrics, course counting, player-course detection, scope split; the comparison kept for an hour per period and set of courses
ecosystem/plugin_registry_test.php 2 Catalog structure and unique components
ecosystem/plugin_status_test.php 1 Installed status keyed by component; hub reported installed
event/events_test.php 1 All nine events trigger, are captured and render a description
db_upgrade_test.php 6 Upgrade step that removes an index duplicating a key: two identical indexes become one, a column with no index gets the key’s index, a single index is left alone; concept games lose the glossary source and the category
uninstall_test.php 2 Uninstall removes only the plugin’s own prefixed user preferences, and does nothing when there are none
Total 320  
vendor/bin/phpunit --testsuite local_playergames

Node — PlayerBattle rules

The board and combat rules of PlayerBattle are plain modules (amd/src/battle/) that also load in Node, so they are tested without a browser. The CI runs them with node --test.

Test file Cases What is covered
js/battle/prng.test.js 5 The seeded generator: same seed, same sequence; different seeds differ; values in [0, 1); a fixed known sequence; seeds coerced to unsigned 32 bits
js/battle/board_rules.test.js 14 A new grid has only the types in play and no match; the number of types is the one asked for; matches found with their size; a piece in two matches is destroyed once; type 0 is a piece, not an empty cell; swaps; which type a swap would match; the opponent’s move; shuffling; gravity and refill
js/battle/combat_rules.test.js 23 Starting state and the pinned balance; combo bonus; Sword damage and the multiplier; Potion; the Shield and Grimoire meters; the Orb filling the mana bar; the critical hit and the cost of a wrong answer; hex ticks; victory and defeat; the rules never change the state they are given
Total 42  
node --test tests/js/battle/*.test.js

Coverage

Line/method coverage is measured locally with Xdebug (moodle-coverage, a bench tool — not part of CI) rather than published as a single plugin-wide percentage: this codebase deliberately does not unit-test Moodle’s own output renderers (classes/output/*) beyond the two that decide who sees what (the hub’s seasons button and the Administration tab), the cartridge management UI controller, or ai_generator’s real HTTP calls (only its response-parsing logic is tested, since mocking the network round-trip has low ROI) — none of that is a gap the PHPUnit suite is meant to close, so a raw plugin-wide number would just measure that policy rather than test quality. The classes it is meant to cover — game managers, hub services, scheduled tasks, events, external functions and the Privacy Provider — are what the case counts in the table above exercise, and games/fill_manager and task/assign_daily_games (the classes PlayerFill added or changed) are both at 100% line and method coverage.

Behat — Acceptance Tests

Feature file Scenarios What is covered
play_quiz.feature 2 The PlayerQuiz play flow end to end
php admin/tool/behat/cli/init.php
vendor/bin/behat --tags=@local_playergames --profile=chrome

🔎 Third-party Service Disclosure

PlayerGames includes optional AI-assisted cartridge generation. This is entirely optional — all content can be created manually.

Architecture

AI generation is routed through the companion local_aihub plugin when installed, which owns the key storage and the provider transport; if the Hub is not installed, PlayerGames falls back to Moodle’s own core_ai subsystem, whichever providers the site administrator configured there.

Supported Providers (via local_aihub)

These services operate under their own terms of service and privacy policies. Full disclosure of exact model IDs and data destinations is documented in local_aihub’s own Third-party Service Disclosure.

Data Transmission

When AI generation is used, the prompt built by PlayerGames (topic, language, level, and any optional reference text the teacher provides) is passed to whichever source resolved the request (the Hub or core_ai) for processing. PlayerGames:

No external communication occurs unless an AI feature is explicitly used.

Cost

None required by PlayerGames itself. If local_aihub is installed, any cost is whatever the underlying provider charges through that plugin’s own BYOK keys; without it, PlayerGames falls back to Moodle’s core_ai, which may be free if the site admin has configured a no-cost institutional provider.

Demo Credentials

Not applicable — no credentials are required to install or use PlayerGames; AI-assisted cartridge generation is entirely opt-in.

📄 License

This project is licensed under the GNU General Public License v3 (GPLv3).

Copyright: 2026 Jean Lúcio

Support

Found a bug or have a question? Open an issue on the issue tracker.

Maintainer

Maintained by Jean Lúcio.