JavaScript library for Diplomacy
This package provides functions to play Diplomacy games. It supports the default rule and map, and also can define custom variants of Diplomacy.
$ npm install js-diplomacy
The following code snippets describe the basic usage of this library.
diplomacy.standard
provides the objects for the standard map and rule.
import diplomacy from "js-diplomacy"
const variant = diplomacy.standard.variant
const rule = variant.rule // This defines the default rule of Diplomacy
let board = variant.initalBoard // This represents the state of 1901, Spring.
This library contains a helper class for the standard rule, which provides the simple and readable way to write orders.
const Helper = diplomacy.standardRule.StandardRuleHelper
const $ = diplomacy.variant.standardMap.location // This defines locations (e.g., StP_SC, Swe)
let $$ = new Helper(board) // Create a helper instance
const orders = [
$$.F($.Lon).move($.Nth), $$.F($.Edi).move($.Nrg), $$.A($.Lvp).move($.Yor), // This is a Yor OP.
$$.U($.Con).move($.Bul) // We have not to specify Fleet or Army if we use `U` function
]
const result = rule.resolve(orders) // Resolve the orders using the default rule
if (result.result) {
console.log(result.result.results) // Show results
board = result.result.board // Go to the next turn (1901 Autumn, Movement phase)
$$ = new Helper(board) // Update the helper instance
}
The example of the standard Diplomacy game (with visualizers) is available.
The documentation is here.
This software is released under the MIT License, see LICESE.md