# Advanced usage

`{chess}` has some tools for advanced users. Most of them can be discovered through documentation. Here are a few highlights:

    library(chess)

    # Create a game with comments and NAGs
    anderssen_kieseritzky <- game() %>%
      move(
        "e4", "e5", "f4", "exf4", "Bc4", "Qh4", "Kf1", "b5", "Bxb5", "Nf6", "Nf3",
        "Qh6", "d3", "Nh5", "Nh4", "Qg5", "Nf5", "c6", "g4", "Nf6", "Rg1", "cxb5",
        "h4", "Qg6", "h5", "Qg5", "Qf3", "Ng8", "Bxf4", "Qf6", "Nc3", "Bc5", "Nd5",
        "Qxb2", "Bd6", "Bxg1? {It is from this move that Black's defeat stems.}",
        list("Qxa1 {Wilhelm Steinitz suggested in 1879...}", "Ke2", "Qb2", "Kd2", "Bxg1"),
        "e5", "Qxa1", "Ke2", "Na6", "Nxg7", "Kd8", "Qf6", "Nxf6", "Be7"
      )

    # NAG
    anderssen_kieseritzky %>%
      root() %>%
      forward(36) %>%
      nag()
    #> [1] "?"

    # Comment
    anderssen_kieseritzky %>%
      root() %>%
      forward(36) %>%
      note()
    #> [1] "It is from this move that Black's defeat stems."

    # Some useful functions
    fen(anderssen_kieseritzky)
    #> [1] "r1bk3r/p2pBpNp/n4n2/1p1NP2P/6P1/3P4/P1P1K3/q5b1 b - - 1 23"
    turn(anderssen_kieseritzky) # White = TRUE and Black = FALSE
    #> [1] FALSE
    move_number(anderssen_kieseritzky)
    #> [1] 23
    ply_number(anderssen_kieseritzky)
    #> [1] 45
    result(anderssen_kieseritzky)
    #> [1] "1-0"

    # Find all moves available
    moves(root(anderssen_kieseritzky))
    #>  [1] "Nh3" "Nf3" "Nc3" "Na3" "h3"  "g3"  "f3"  "e3"  "d3"  "c3"  "b3"  "a3"
    #> [13] "h4"  "g4"  "f4"  "e4"  "d4"  "c4"  "b4"  "a4"

    # Some verifiers
    is_checkmate(anderssen_kieseritzky)
    #> [1] TRUE
    is_check(anderssen_kieseritzky)
    #> [1] TRUE
    is_game_over(anderssen_kieseritzky)
    #> [1] TRUE