Welcome back! Last week, we designed our heuristic algorithm for our A.I. players, and this week, we turn our attention to implementing it.
This is a very complicated algorithm with a large number of little pieces that can go wrong. Good code organization is always important, but it's especially important here. I recommend creating empty space in your existing code where you want your new code to go, and before you write any new C++, just start by writing comments describing how your code will execute at each step, according to your own thought processes and however it most makes sense to you.
I also strongly recommend judicious use of version control. I'm using Perforce, but you can use SVN, Git, or whatever system you prefer. Just make sure you have a way to commit your code after each small change you make. This way, if something goes wrong, you can test your code at every step of implementation and get more targeted information about where something went wrong. This practice has saved me from headaches many times, and I can't recommend it enough.
Once you've done all of this, you can get started writing your code. Since you've already designed the algorithm, commented it out, and set up version control, all you have to do is express those comments in C++, and commit and test after each step. It's simple.
Once you've got players visibly claiming routes they want, pat yourself on the back and be happy with what you've done. This is no small feat, and it'll be a very impressive piece of work to show off to people.
With the rest of this week, I recommend you start thinking about small tweaks you can make to improve your algorithm. For example, in my algorithm, I discovered that players would sometimes unexpectedly have lower scores than normal. This was because they would, at the last turn of the game, draw more destination tickets, even though there was no possible way to complete them with future turns. This should be disallowed. For that matter, drawing more train car cards on the last turn should also be disallowed: why would you draw cards if you know you'll never get a chance to use them? Except in very unusual circumstances, the only thing a player should be doing on their last turn is claiming a route to try and increase their score.
Another flaw is the following: you should not allow players to draw destination tickets if the game is too close to ending. We already established that this definitely shouldn't be done on the last turn, but drawing destination tickets slightly before that is still very risky. You might get stuck with a lengthy path to claim that you might not have time to get. I recommend, for the heuristic of a DrawDestinationTicketsTurn, that you return a minimum heuristic value if any player has fewer than 20 train pieces left.