Answers.Body: <p>To get you started, here's one way you could do this on your own in Python with the <a href="https://pypi.python.org/pypi/python-chess" rel="nofollow noreferrer">python-chess module</a>:</p>
  
  <ul>
  <li>In the example we're loading a simple pgn-file for illustration (which you generalize to reading pgns from a loaded database using the same module) and extracting its final position as a <a href="http://python-chess.readthedocs.io/en/latest/core.html#board" rel="nofollow noreferrer">bitboard</a>.  </li>
  <li>Then we check if it's a checkmate position, if true, you can extract the pieces on the board as a <a href="http://python-chess.readthedocs.io/en/latest/core.html#chess.SquareSet" rel="nofollow noreferrer">Square Set</a>.</li>
  <li>From that, you can then transform the data in any form, e.g. as lists or arrays of the piece symbols and corresponding squares (shown below), or however else it suits your follow-up purposes best.</li>
  </ul>
  
  <p>Here's the snippet for that:</p>
  
  <pre><code>import chess
  import chess.pgn
  import sys
  
  arguments = sys.argv
  pgnfilename = str(arguments[1])
  
  #Read pgn file:
  with open(pgnfilename) as f:
      game = chess.pgn.read_game(f)
  
  #Go to the end of the game and create a chess.Board() from it:
  game = game.end()
  board = game.board()
  
  if board.is_checkmate():
      print "checkmate found: "
      print board
  
      white_pieces = [(board.piece_at(sq),sq) for sq in chess.SquareSet(board.occupied_co[1])]
      black_pieces = [(board.piece_at(sq),sq) for sq in chess.SquareSet(board.occupied_co[0])]
  
      print "white pieces: "
      for el in white_pieces:
          print el[0].symbol(), " on ", chess.SQUARE_NAMES[el[1]]
  
      print "---------------------"
      print "black pieces: "
      for el in black_pieces:
          print el[0].symbol(), " on ", chess.SQUARE_NAMES[el[1]]
  </code></pre>
  
  <p>Which gives the following output for the downloaded PGN of <a href="http://www.chessgames.com/perl/chessgame?gid=1076122" rel="nofollow noreferrer">this game between Alexander Alekhine vs Oscar Tenner</a>:</p>
  
  <pre><code>r . . q . . . r
  p p p . . B p p
  . . . . . . . .
  . . B . k R . n
  . . . . P . . .
  . . . P . . . .
  P P P . . . P P
  R . . b . . K .
  white pieces:
  R  on  a1
  K  on  g1
  P  on  a2
  P  on  b2
  P  on  c2
  P  on  g2
  P  on  h2
  P  on  d3
  P  on  e4
  B  on  c5
  R  on  f5
  B  on  f7
  ---------------------
  black pieces:
  b  on  d1
  k  on  e5
  n  on  h5
  p  on  a7
  p  on  b7
  p  on  c7
  p  on  g7
  p  on  h7
  r  on  a8
  q  on  d8
  r  on  h8
  </code></pre>
  
  <p><strong>Additional details and ways of extension:</strong></p>
  
  <ul>
  <li>Conventionally, capital and small symbols are used for white and black pieces respectively. For a better display of the board, you can use the <a href="https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode" rel="nofollow noreferrer">Unicode symbols for chess pieces</a> and <a href="https://docs.python.org/2.7/howto/unicode.html" rel="nofollow noreferrer">encode them appropriately</a> (depending on your python installation or possibly OS) for printing. In our example above, you could have immediately retained the Unicode of each piece instead of its symbol, <code>board.piece_at(sq).unicode_symbol()</code> </li>
  <li>Given a PGN-formatted database (e.g., using <a href="http://theweekinchess.com/twic" rel="nofollow noreferrer">TWIC PGNS</a>), you can easily load it by reading it in python and extracting the starting/ending line indices of each game[*] in the database, and in a loop over all games, you pass each game as a PGN file to <code>chess.pgn.read_game</code> and the rest follows similarly as in the snippet above.</li>
  </ul>
  
  <p>Feel free to ask in comments if you have any questions about the snippet and other ways of extending it. </p>
  
  <p>[*]: All this depends on the database you're trying to work with, but once the formatting known, then you can e.g., parse games based on a keyword that occurs at the start of each game in the database, for instance in the TWIC ones, there's always a line with <code>Event ..</code> in the headers of the PGN, or even the empty lines between the games. However you go about it, once you know the starting and ending line indices of a game within the file, you can pass it to <code>chess.pgn.read_game</code> as a file-like object with <code>cStringIO.StringIO</code> in python. It's not the most efficient way necessarily, but it does the trick. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-19T21:40:36.227Z
Answers.Text: wow this is amazing, couldn't have asked for a better assist in the right direction from someone knowledgeable. Thanks!!
Answers.UserDisplayName: Monica Heddneck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-19T21:48:18.920Z
Answers.Text: My pleasure, sounds like a potentially cool project :) Let me know if you face any obstacles in trying to run the snippet or have any follow up questions.
Answers.UserDisplayName: Ellie
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-19T21:38:27.493Z
Answers.LastActivityDate: 2018-03-19T21:38:27.493Z
Answers.UserDisplayName: Ellie
Body: <p>I would like to do a simple project by looking at the pieces at play when checkmate occurs.  </p>
  
  <p>I have been scouring the internet for a dataset of standard chess games from which I can retrieve the final board representation, where a checkmate has been played to it's conclusion. </p>
  
  <p>At this point, any board representation would have to be fine, although I'm not trying to generate moves or anything, thus <a href="https://en.wikipedia.org/wiki/Board_representation_(chess)#Array_based" rel="nofollow noreferrer">array based</a> would be ideal.</p>
  
  <p>I'd need to have the graphical representation (i.e., like a screenshot a way to load up the games to view them), so I could organize by hand. Well, by sight, actually.</p>
  
  <p>If anyone has any ideas, I'd be grateful. </p>
  
  <p>Monica</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-19T20:23:12.790Z
Comments.Text: I'd just like to point out that most (>95%) of chess games, even at amateur level, aren't played out until checkmate.
Comments.UserDisplayName: Glorfindel
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-19T20:38:04.423Z
Comments.Text: I know, that is definitely an issue. Could be a major wrinkle in my plans :(
Comments.UserDisplayName: Monica Heddneck
Tags: <software><checkmate><programming><database>
Title: Data set of board representations at checkmate?
ThreadText: # Data set of board representations at checkmate?
  
  (Asked by: username_0 on 2018-03-19)
  
  I would like to do a simple project by looking at the pieces at play when checkmate occurs.
  
  I have been scouring the internet for a dataset of standard chess games from which I can retrieve the final board representation, where a checkmate has been played to it's conclusion.
  
  At this point, any board representation would have to be fine, although I'm not trying to generate moves or anything, thus [array based](https://en.wikipedia.org/wiki/Board_representation_(chess)#Array_based) would be ideal.
  
  I'd need to have the graphical representation (i.e., like a screenshot a way to load up the games to view them), so I could organize by hand. Well, by sight, actually.
  
  If anyone has any ideas, I'd be grateful.
  
  Monica
  
  **Tags:** software, checkmate, programming, database
  
  > **Comments:**
  > **username_1**: I'd just like to point out that most (>95%) of chess games, even at amateur level, aren't played out until checkmate.  
  > **username_0**: I know, that is definitely an issue. Could be a major wrinkle in my plans :(  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-03-19. Score: 1 | Accepted answer
  
  To get you started, here's one way you could do this on your own in Python with the python-chess module:
  
  In the example we're loading a simple pgn-file for illustration (which you generalize to reading pgns from a loaded database using the same module) and extracting its final position as a bitboard.  
  Then we check if it's a checkmate position, if true, you can extract the pieces on the board as a Square Set.
  From that, you can then transform the data in any form, e.g. as lists or arrays of the piece symbols and corresponding squares (shown below), or however else it suits your follow-up purposes best.
  
  Here's the snippet for that:
  import chess
  import chess.pgn
  import sys
  
  arguments = sys.argv
  pgnfilename = str(arguments[1])
  
  #Read pgn file:
  with open(pgnfilename) as f:
      game = chess.pgn.read_game(f)
  
  #Go to the end of the game and create a chess.Board() from it:
  game = game.end()
  board = game.board()
  
  if board.is_checkmate():
      print "checkmate found: "
      print board
  
      white_pieces = [(board.piece_at(sq),sq) for sq in chess.SquareSet(board.occupied_co[1])]
      black_pieces = [(board.piece_at(sq),sq) for sq in chess.SquareSet(board.occupied_co[0])]
  
      print "white pieces: "
      for el in white_pieces:
          print el[0].symbol(), " on ", chess.SQUARE_NAMES[el[1]]
  
      print "---------------------"
      print "black pieces: "
      for el in black_pieces:
          print el[0].symbol(), " on ", chess.SQUARE_NAMES[el[1]]
  
  Which gives the following output for the downloaded PGN of this game between Alexander Alekhine vs Oscar Tenner:
  r . . q . . . r
  p p p . . B p p
  . . . . . . . .
  . . B . k R . n
  . . . . P . . .
  . . . P . . . .
  P P P . . . P P
  R . . b . . K .
  white pieces:
  R  on  a1
  K  on  g1
  P  on  a2
  P  on  b2
  P  on  c2
  P  on  g2
  P  on  h2
  P  on  d3
  P  on  e4
  B  on  c5
  R  on  f5
  B  on  f7
  ---------------------
  black pieces:
  b  on  d1
  k  on  e5
  n  on  h5
  p  on  a7
  p  on  b7
  p  on  c7
  p  on  g7
  p  on  h7
  r  on  a8
  q  on  d8
  r  on  h8
  
  Additional details and ways of extension:
  
  Conventionally, capital and small symbols are used for white and black pieces respectively. For a better display of the board, you can use the Unicode symbols for chess pieces and encode them appropriately (depending on your python installation or possibly OS) for printing. In our example above, you could have immediately retained the Unicode of each piece instead of its symbol, board.piece_at(sq).unicode_symbol() 
  Given a PGN-formatted database (e.g., using TWIC PGNS), you can easily load it by reading it in python and extracting the starting/ending line indices of each game[*] in the database, and in a loop over all games, you pass each game as a PGN file to chess.pgn.read_game and the rest follows similarly as in the snippet above.
  
  Feel free to ask in comments if you have any questions about the snippet and other ways of extending it. 
  [*]: All this depends on the database you're trying to work with, but once the formatting known, then you can e.g., parse games based on a keyword that occurs at the start of each game in the database, for instance in the TWIC ones, there's always a line with Event .. in the headers of the PGN, or even the empty lines between the games. However you go about it, once you know the starting and ending line indices of a game within the file, you can pass it to chess.pgn.read_game as a file-like object with cStringIO.StringIO in python. It's not the most efficient way necessarily, but it does the trick.
  
  > **Comments:**
  > **username_0**: wow this is amazing, couldn't have asked for a better assist in the right direction from someone knowledgeable. Thanks!!  
  > **username_2**: My pleasure, sounds like a potentially cool project :) Let me know if you face any obstacles in trying to run the snippet or have any follow up questions.  
  
  ---
  
  