amaurycoudr-checkers
v2.9.20
Published
checkers game
Downloads
12
Readme
Checkers Project
test coverage :
| Statements | Branches | Functions | Lines |
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
| | | | |
the purpose of this package is to offer a simple api to be able to play to the checkers
:warning: For the moment the work is still in progress
CheckersParty
To start a party you only need to create a new instance of CheckersParty
const party = new CheckersParty(options);
To specify the rules of your party you can pass an object options
.
party options
firstPlayer : "white" | "black"
- The first player to play.
default = "white"
boardSize : 10 | 8
- The Board size.
default = 10
shouldCatchPiecesMaximum : boolean
- decides if player must capture the maximum possible number of pieces
default = true
shouldPromoteWhenMoveEnding: boolean
- decides if pieces promote only when ending their move on the final rank
default = true
party.getState()
To access the state of the party you can use the method getState()
this returns an object of this format :
{
"board": {
"A1": { "type": "Pawn", "player": "white" },
"C1": { "type": "Pawn", "player": "white" },
"E1": { "type": "Pawn", "player": "white" },
"G1": { "type": "Pawn", "player": "white" },
"I1": { "type": "Pawn", "player": "white" }
} /* here only the first line is shown */,
"playerTurn:": "white",
"plays": [
{ "from": "B4", "to": "A5" },
{ "from": "B4", "to": "C5" },
{ "from": "D4", "to": "C5" },
{ "from": "D4", "to": "E5" },
{ "from": "F4", "to": "E5" },
{ "from": "F4", "to": "G5" },
{ "from": "H4", "to": "G5" },
{ "from": "H4", "to": "I5" },
{ "from": "J4", "to": "I5" }
]
}
:information_source: This is the result of
party.getState()
at the first turn
party.play(move: Movement)
Take in argument the move you want to play like { "from": "B4", "to": "A5" }
.
Return the state of the party (the new result for party.getState()
).
getCoordinate()
An helper is provide to handle the conversion from (x,y) to te format "A1", "C3"...
const coordinate = getCoordinate(3, 2);
// coordinate === D3
Road map to functional version
- ~~implements a notion of options to let user choses specific rules~~
- ~~implements the first play option~~
- ~~implements the maximum catch rule~~
- ~~implements the fact that promote only when ending their move on the final rank~~
- ~~implements the win notion~~
- ~~correct bug can eat after travel~~
- ~~correct bug winner~~
- ~~correct bug queen transformation~~
- ~~correct queen movement~~
- ~~implements the draw notion~~
- ~~handle case player can't make any play~~