Kata courtesy of blndr
Original here: https://gitlab.com/blndr/risk/
This is a simplification of a Risk - Game of Thrones edition (only Westeros is modelled with its seven kingdoms - plus the Crownlands - and dominant houses).
War is about to start, and no one - not even this piece of sh*t of Littlefinger - could predict its outcome. You are the Many-face God, and can only be delighted for all the gifts your are about to receive. You will witness the raging battles, the endless plots and betrayals from above.
The domain model of the game is quite simple. It is modelled with 2 concepts :
-
House
: a powerful family of Westeros. There may be up to 8 of them : Stark, Tully, Martell, Lannister, Tyrell, Baratheon, Arryn, Targaryen. A givenHouse
owns an army of a certain number of battalions stationed on a givenKingdom
. -
Kingdom
: a region of Westeros that is controlled by oneHouse
and its army. A givenKingdom
is adjacent to some otherKingdoms
: they can attack them.
- The playing order of the
Houses
will be determined randomly before the game starts - A
House
occupying oneKingdom
can attack anotherHouse
occupying an adjacentKingdom
- The game is over after 10 turns : the winner
House
is the one controlling the mostKingdoms
- After every turn, every
House
recruits a new battalion on everyKingom
it owns
- the attacking
House
engages half of its attackingKingdom
army (rounded down if odd)- there is one chance out of two that a battalion of the attacking army will defect at the last moment
- the defending
House
uses half of its defendingKingdom
army (rounded up if odd)- there is one chance out of three that the defending army is helped by one sell-sword battalion
- the greater army wins
- a given
House
on a givenKingdom
cannot attack if it has 0 or 1 battalion - a given
House
on a givenKingdom
cannot attack the sameHouse
on anotherKingdom
The attacker wins
- its engaged battalions take possession of the newly conquered
Kingdom
- the newly conquered
Kingdom
receives a bonus of 1 battalion - the defending battalions are killed, the Many-face God feasts
The defender wins
- the attacking battalions are killed, the Many-face God feasts
- the defending army receives a bonus of 1 battalion
This is a many-face kata, there are steps to follow :
- write everything from scratch (with TDD)
- would you rather use FP or OO ?
- how will you model the game domain ?
- which test list will help you the most ?
- once the requirements are fulfilled, try and apply a better design to the code
- try to isolate the business code from the I/O code
- you should be able to either log or print each turn by only changing one line of code
- you should be able to use user
ìnputs
or random moves for each turn by only changing one line of code
- try to isolate the business code from the I/O code
- add a new feature : the Iron Islands - Greyjoy extension
- the Iron Islands are adjacent to every coastal
Kingdom
- the Iron Islands cannot be conquered, house Greyjoy will always occupy it
- if a
House
attacks them and win, Greyjoy's army drops to 0 battalions
- if a
- their habit of paying the iron price gives them a bonus of 2 battalions whenever they attack
- the Iron Islands are adjacent to every coastal
Here is the starting position of the game, right before Robert's Rebellion.
No worries. This works just as well with any map from the real world, as long as you define territories (Kingdoms
) and states (Houses
).
gradle build
gradle test