We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Simplified Chess Engine
You are viewing a single comment's thread. Return to all 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.