This is what all chess engines do. You can send them the board position, (or, more accurately, the preceding game history, so they will be able to detect repetitions), and they reply with the best move. So why would you need the code? You can just run an engine of choice as a separate process; there is need tomeddle with the code, or even have access to it, and you can use any binary for the platform you are running on. There are more than a thousand of such engines.
Which engine you should choose also depends on your goals. Do you want something that crushes any opponent in about 20 moves, or do you want something they can beat? There are several highly commented source codes for engines, including some of my own. The latter simple are all in plain C,though; I don't know C++.