Simplified Chess Engine

  • + 0 comments

    Finally my solution got accepted. But I fail to understand why the difficulty level is medium. Anyways, here is how you can efficiently solve this problem 1) Use bit boards to represent the chess board and in this case it is uint16_t 2) Maintain separate black & white bit-boards and game board at any point in time is (white | black) 3) Generate move vectors offline. A move vector is an array of 4X4 elements that represents the line of attack given a file and a rank. 4) Sliding pieces are the tricky ones that need occlusion mask along the line of attack. You can generate a lookup table consisting of masks based on every position w.r.t to every other position (16X16 table for Rook & Bishop) 5) Use huerestics to score the game board. At any point in time board's score is sum of weights of its pieces with queen having the highest rank and knight having the lowest rank. The game score is always whiteboard score minus the blackboard score. 6) You should have a very large score representing win score and a very small score representing a lose. 7) Run minimax to choose the best move for a given ply. 8) Last but not the least is to implement Alpha, Beta pruning. This is important else there are chances of your solution getting timed out.