Skip to content

Pass in a handler into a move object, as if it is Javascript. #5

@ikyman

Description

@ikyman

When a Pawn reaches the end of the board, it gets promoted. This is a special bespoke rule fit only for pawns and at the end of a board.
This means I will likely have to connect a function to the pawn object. After a move, check to see if the pawn is at the end of the board. If so, call a ChangePeice() function.

As a pawn is merely a sub-class of the abstract class "chess Piece", I feel no need to attach this extra handler exclusively to a pawn.
All Pieces will have the ability to add this sort of "Post-Move" handler. Specifically, I deem this to be worthy of investigation for its potential to solve the castling dilemma.

The issue with castling is two-fold: first, I have to move the opposing castle after moving the king two spaces. This can be done with the post-move handler.

Castling also requires quite stringent conditions. A King must be a virgin. It must be possible for a virgin rook to move beside the king. The kind itself must be not be in the danger zone, nor can the rook move in the danger zone, nor can the king be in the danger zone after castling.

  1. That's quite a lot of conditionals! & 2: The king is like any other piece, only more so. What I mean by point 2 is that it should not be necessary for this castling conditionality to cause the king to own exclusive functionality.

What that means in practice is something like this: A Bishop, much like a castling king, has it's own "Is this move possible" function that the movegenerator calls. Bishops have no conditionals attached to their moves, so their "Is This move possible" function is a mere (proposedMove, currentBoard) => {return true}.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions