Open pssguy opened 8 years ago
How about this?
# function to get fens from a pgn game.
library("purrr")
get_fens <- function(pgn) {
chss <- Chess$new()
chss$load_pgn(pgn)
moves <- chss$history()
chss$reset()
fens <- map_chr(moves, function(x) chss$move(x)$fen())
fens
}
data("chesswc")
game <- head(chesswc,1)
pgn <- game$pgn
fens <- get_fens(pgn)
player <- "white"
move <- 11
gamemove <- 2 * move + (player != "white")
fens[gamemove]
[1] "r2qkb1r/p4ppp/b1n1pn2/8/PpNP4/1P6/5PPP/RNBQKB1R w KQkq - 1 12"
ggchessboard(fens[gamemove])
Now we can iterate for every fen and try to create the gif as requested in #9
Wonderful. Only quibble is could dispense with axis titles and label the x as a:h Also possibly replicate left axis on right and bottom axis at top
I'll fix the axis :B, but not sure how to add the opposites axis. Im not sure if ggplot have this options.
Just found this. looks promising re double axes
library(ggplot2)
library(cowplot)
p <- ggplot(mtcars, aes(mpg, disp)) + geom_line(colour = "blue")
ggdraw(switch_axis_position(p , axis = 'xy', keep = 'xy')).
Nice, I'll check it.
Also think it should be
gamemove <- 2 *(move-1) + (player != "white")
game <- head(chesswc,1)
Would it then be possible to have a function with parameters game,move, player so I could then plot board after e.g. whites 11th move