1

In a nutshell, I'm trying to apply some machine learning techniques to a sample of images of chessboards, obtained with the rchess package from R, but I'm failing to get the images and, in fact, something at all, with a simple for loop. I will try to explain it as amene as possible, since it may require some background on chess and/or the rchess package.

The rchess packages is able to output a chessboard-like image (with the option of a ggplot chessboard) when a chessboard in FEN notation is provided. The FEN notation is a string of the kind "8/8/8/8/8/1R6/2k5/K7 w - c6 1 30" where the first 8 values separated with "/" refer to the rows of the board, the letters to the pieces, the numbers to the number of empty squares per row and the following characters are parameters of no rellevancy here. I've got a pretty large dataset of chess static positions (only endgames for ease) and I've made a function that, taking chess algebraic notation of a row of the dataset as the input, returns a string of the respective FEN. In the markdown of the rchess package, this FEN notation can be assigned to a variable fen (for instance) by doing

fen<-fenfunction(1) #This is my function 
chss <- Chess$new(fen)
plot(chss, type = "ggplot")

which will return the chessboard for the position in row 1 of the dataset. It can also be done by simply ggchessboard(fen), but the previous way is more illustrative. So far so good. The problem show up when trying to plot various rows of the dataset via a for loop, namely:

for(j in 1:nrow(dat)){

  fen<-fenfunction(j)    
  chss <- Chess$new(fen)    
  plot(chss, type = "ggplot")    

}

This is just one possible way to do it, but I have tried several and none of them gives any output or plot at all, not even a warning. It simply returns nothing. Since the function in itself works satisfactorily when performed in a for loop by its own, I think the problem reside in the fact that the chss variable that is created (and indeed any variable within the framework of the rchess package) is of the type "environment" (or class environment). It may be that this kind of operation is nonsensical with environments in R or something of the kind, and that just converting it to any other class would solve my issue.

I am not new to this language, but I am certainly not any expert nor advanced user and I have no clue if this makes any sense at all, I have no expirience with direct environment-type variables and I do not know why this for loop is not working. I hope that my question is understandable enough (Although i've had a hard time trying to phrase my issue in such a short sentence) and I would much appreciate any remarks on how to deal with all of this. It would be awesome that I just missed something trivial that one of you can easilly point out to me, for I have a feeling of it being the case.

darubik
  • 51
  • 5

0 Answers0