I'm refactoring my world's-slowest-chess-engine, fussing around with beta 2.3, but my question also pertains to my work in 2.2. I define my chessboard as an 8 x 8 2D array. Since I want to refactor this array to meet the beta's new preference for arrays, I figured I might as well rethink how I define my pieces. Right now I define them as an array with two elements, using constants: for example, grid[1][1] = [PAWN, BLACK]. Will the game run faster if I represent the pieces as single numbers, either a macro or an enum? E.g., grid[1][1] = Black.Pawn or grid[1] = BLACK_PAWN? Will it run faster if I construct my own struct?
To complicate things a bit, a few chess pieces have special states that I currently don't handle very elegantly: e.g., can a king castle left or right or both or not at all; has a rook moved yet; can a pawn be promoted; is a pawn eligible to be captured en-passant. I could of course define macros for all these cases: KING_THAT_CAN_CASTLE_LEFT or KNIGHT_THAT_SAYS_NI or such. But that seems klunky. Setting flags can work too, but my AI passes thousands of possible moves back and forth (using Minmax), and I need to keep track of these special states without getting myself confused.
A related, newbish question: if I were to define the piece as part of an Enum, is there any way to test whether a piece is an enumerated type? In the case of my Black.Pawn enum, I don't think GMS supports (if grid[1][1] == Black); or at least, the compiler yells at me, and the manual is silent. I can't find an is_type(Enum) function either.
Finally, a question about posting etiquette. Should I have put these very short code snippets in code tags? I'm sorry for all the questions; I'm rather new to this.
Many thanks in advance.
To complicate things a bit, a few chess pieces have special states that I currently don't handle very elegantly: e.g., can a king castle left or right or both or not at all; has a rook moved yet; can a pawn be promoted; is a pawn eligible to be captured en-passant. I could of course define macros for all these cases: KING_THAT_CAN_CASTLE_LEFT or KNIGHT_THAT_SAYS_NI or such. But that seems klunky. Setting flags can work too, but my AI passes thousands of possible moves back and forth (using Minmax), and I need to keep track of these special states without getting myself confused.
A related, newbish question: if I were to define the piece as part of an Enum, is there any way to test whether a piece is an enumerated type? In the case of my Black.Pawn enum, I don't think GMS supports (if grid[1][1] == Black); or at least, the compiler yells at me, and the manual is silent. I can't find an is_type(Enum) function either.
Finally, a question about posting etiquette. Should I have put these very short code snippets in code tags? I'm sorry for all the questions; I'm rather new to this.
Many thanks in advance.