Gwent Classic

Gwent is a card game featured in The Witcher 3 that serves as both a respite from the title’s action and a distillation of the cynical fantasy that pervades The Witcher’s world and narrative. In response to the popularity of the minigame, CD Projekt Red, The Witcher’s developer, expanded Gwent into its own standalone title. Despite the greater depth of the new version, I found myself returning to The Witcher for the sole purpose of playing a few rounds of the original card game. Given the inconvenience of starting up the base game and the prospect of inevitably uninstalling it, I had the idea of writing my own version of Gwent, but this time for the browser.

Select a faction

The browser game opens onto a deck customization menu which allows the player to select from one of 5 factions. The player can then pick a leader card and build their deck from a collection of cards that are compatible with their faction. Unlike the original game, the client can download their current deck as a json file to be saved or shared, and then upload it during a new session. Another change is a button that can be used to toggle the game’s music which is sourced from a YouTube playlist.

Initial redraw menu

Visually, the game is intended to closely match the look of the original Gwent. I found the artwork for the cards and edited screenshots of gameplay to isolate the icons, then arranged the elements of the board using CSS. The cards themselves are constructed dynamically through JavaScript using data collected with the aid of my json-table tool. The browser version is also animated, featuring the activation of card abilities and the translation of cards as they move between containers.

Muster card animation

To minimize complexity, the script is structured with an object-oriented emphasis, such that players, cards and card containers are each governed by their own classes. A game class controls the flow of the game, delegating control to the current player which can then play cards, activate their leader, or pass the round before returning control back to the game object. Card containers such as a deck or hand are extended from a base container class which consolidates redundant code and allows each child class to be defined by only what makes their behavior unique.

End screen

The game also has an AI opponent that will intelligently play against you. It contemplates an action by calculating a weight for each of its options and then makes a weighted random selection. Although the AI will generally take the better course of action, the randomness allows the AI to make sub-optimal decisions which adds an organic and unpredictable nature to the AI’s behavior. It calculates these weights based on a card’s abilities, power and the current state of the board, often considering how both player’s scores would change if that card were played.

So, if like me you’d just like to scratch an occasional Gwent itch, or aren’t quite ready to dive into the standalone version of the game, you now have the option to play a few no-fuss rounds of Gwent Classic.