2.9.20 • Published 2 years ago

amaurycoudr-checkers v2.9.20

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Checkers Project

\ test coverage : | Statements | Branches | Functions | Lines | | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | 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

  1. implements a notion of options to let user choses specific rules
  2. implements the first play option
  3. implements the maximum catch rule
  4. implements the fact that promote only when ending their move on the final rank
  5. implements the win notion
  6. correct bug can eat after travel
  7. correct bug winner
  8. correct bug queen transformation
  9. correct queen movement
  10. implements the draw notion
  11. handle case player can't make any play
2.9.20

2 years ago

2.8.19

2 years ago

2.8.18

2 years ago

2.8.17

2 years ago

2.8.16

2 years ago

2.8.15

2 years ago

2.8.11

2 years ago

2.8.9

2 years ago

2.8.6

2 years ago

2.8.3

2 years ago

2.8.2

2 years ago

2.8.1

2 years ago

2.8.0

2 years ago

2.7.1

2 years ago

2.7.0

2 years ago

2.6.4

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.6.1

2 years ago

2.5.1

2 years ago

2.5.0

2 years ago

2.4.4

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago