Skip to main content
Fixed typo
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282

There are many places in the code where some operation is applied to a piece, but what exactly happens depends on whether it's a knight, bishop, queen, etc. For that reason, I'd suggest that a better approach may be to create a base Piece class and derive Knight, Bishop, etc. This would allow you to keep thingthings better organized and reduce a great deal of repetition from the code. The board could contain pointers to Piece and then invoking actions on each would automatically route to the correct routine, whether for evaluating value or determining legal moves.

There are many places in the code where some operation is applied to a piece, but what exactly happens depends on whether it's a knight, bishop, queen, etc. For that reason, I'd suggest that a better approach may be to create a base Piece class and derive Knight, Bishop, etc. This would allow you to keep thing better organized and reduce a great deal of repetition from the code. The board could contain pointers to Piece and then invoking actions on each would automatically route to the correct routine, whether for evaluating value or determining legal moves.

There are many places in the code where some operation is applied to a piece, but what exactly happens depends on whether it's a knight, bishop, queen, etc. For that reason, I'd suggest that a better approach may be to create a base Piece class and derive Knight, Bishop, etc. This would allow you to keep things better organized and reduce a great deal of repetition from the code. The board could contain pointers to Piece and then invoking actions on each would automatically route to the correct routine, whether for evaluating value or determining legal moves.

fixed URL and also added "Think of the user" section
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282

There is a fundamental problem in the way you're trying to draw the board. The problem is that you've already created a renderer, and then the code attempts to call SDL_GetWindowSurface(). Worse, the return value (which is nullptr on my machine) is never checked and it is later freed. You can either have a renderer or use SDL_GetWindowSurface() but not both. See https://wiki.libsdl.org/SDL_UpdateWindowSurfacehttps://wiki.libsdl.org/SDL_GetWindowSurface

Think of the user

I was surprised to find out that I could manually move either the white or the black pieces. Maybe that's intentional? Being able to reverse or alter a move that my opponent just made might come in handy, but it's unexpected. Also, I understand this is a work in progress, but I was disappointed that castling (which you did mention) and pawn promotion (which you didn't) aren't yet implemented. Still, it was kind of fun!

There is a fundamental problem in the way you're trying to draw the board. The problem is that you've already created a renderer, and then the code attempts to call SDL_GetWindowSurface(). Worse, the return value (which is nullptr on my machine) is never checked and it is later freed. You can either have a renderer or use SDL_GetWindowSurface() but not both. See https://wiki.libsdl.org/SDL_UpdateWindowSurface

There is a fundamental problem in the way you're trying to draw the board. The problem is that you've already created a renderer, and then the code attempts to call SDL_GetWindowSurface(). Worse, the return value (which is nullptr on my machine) is never checked and it is later freed. You can either have a renderer or use SDL_GetWindowSurface() but not both. See https://wiki.libsdl.org/SDL_GetWindowSurface

Think of the user

I was surprised to find out that I could manually move either the white or the black pieces. Maybe that's intentional? Being able to reverse or alter a move that my opponent just made might come in handy, but it's unexpected. Also, I understand this is a work in progress, but I was disappointed that castling (which you did mention) and pawn promotion (which you didn't) aren't yet implemented. Still, it was kind of fun!

Fixed formatting
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282

If you do that, ``Graphics::InitBoard()gets simpler, and you can completely removeGraphics::InitBoard()boardTexture` gets simpler, and you can completely remove boardTexture and all references to it too:

If you do that, ``Graphics::InitBoard()gets simpler, and you can completely removeboardTexture` and all references to it too:

If you do that, Graphics::InitBoard() gets simpler, and you can completely remove boardTexture and all references to it too:

added updated InitBoard code
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282
Loading
added 453 characters in body
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282
Loading
Source Link
Edward
  • 66.6k
  • 4
  • 118
  • 282
Loading