SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.77k stars 1.06k forks source link

board.GetFenString(); is giving incorrect fen string with garbage values #359

Closed AdityaMeena001 closed 1 year ago

AdityaMeena001 commented 1 year ago

board.GetFenString();

this function gives a FEN string as output with some garbage values at the end.

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 this is the FEN string it gives as output for the starting position.

RobotLazerShark commented 1 year ago

I was also confused about the extra characters at first, but the wikipedia page on the FEN notation actually explains their purposes very well:

Explanation copied from https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation: A FEN record contains six fields, each separated by a space. The fields are as follows:

  1. Piece placement data: Each rank is described, starting with rank 8 and ending with rank 1, with a "/" between each one; within each rank, the contents of the squares are described in order from the a-file to the h-file. Each piece is identified by a single letter taken from the standard English names in algebraic notation (pawn = "P", knight = "N", bishop = "B", rook = "R", queen = "Q" and king = "K"). White pieces are designated using uppercase letters ("PNBRQK"), while black pieces use lowercase letters ("pnbrqk"). A set of one or more consecutive empty squares within a rank is denoted by a digit from "1" to "8", corresponding to the number of squares.
  2. Active color: "w" means that White is to move; "b" means that Black is to move.
  3. Castling availability: If neither side has the ability to castle, this field uses the character "-". Otherwise, this field contains one or more letters: "K" if White can castle kingside, "Q" if White can castle queenside, "k" if Black can castle kingside, and "q" if Black can castle queenside. A situation that temporarily prevents castling does not prevent the use of this notation.
  4. En passant target square: This is a square over which a pawn has just passed while moving two squares; it is given in algebraic notation. If there is no en passant target square, this field uses the character "-". This is recorded regardless of whether there is a pawn in position to capture en passant. An updated version of the spec has since made it so the target square is recorded only if a legal en passant capture is possible, but the old version of the standard is the one most commonly used.
  5. Halfmove clock: The number of halfmoves since the last capture or pawn advance, used for the fifty-move rule.
  6. Fullmove number: The number of the full moves. It starts at 1 and is incremented after Black's move.
AdityaMeena001 commented 1 year ago

Thank you for the explanation, the Active colour will also be very useful for the program,