Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement Request: plot after specific move #8

Open
pssguy opened this issue Jul 24, 2016 · 6 comments
Open

Enhancement Request: plot after specific move #8

pssguy opened this issue Jul 24, 2016 · 6 comments
Milestone

Comments

@pssguy
Copy link

pssguy commented Jul 24, 2016

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

@jbkunst
Copy link
Owner

jbkunst commented Jul 28, 2016

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])

image

Now we can iterate for every fen and try to create the gif as requested in #9

@pssguy
Copy link
Author

pssguy commented Jul 28, 2016

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

@jbkunst
Copy link
Owner

jbkunst commented Aug 1, 2016

I'll fix the axis :B, but not sure how to add the opposites axis. Im not sure if ggplot have this options.

@pssguy
Copy link
Author

pssguy commented Aug 1, 2016

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')).  

@jbkunst
Copy link
Owner

jbkunst commented Aug 1, 2016

Nice, I'll check it.

@pssguy
Copy link
Author

pssguy commented Aug 1, 2016

Also think it should be

gamemove <- 2 *(move-1) + (player != "white")

@jbkunst jbkunst added this to the v0.2.0 milestone Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants