Add a stronger CPU opponent based on Minimax search.#8
Add a stronger CPU opponent based on Minimax search.#8maksverver wants to merge 0 commit intoElTh0r0:mainfrom
Conversation
|
Awesome! Thank you so much for this! I have heard of Minimax but never had the time to look into it. Since you were the first who provided a new CPU: Was the provided interface to the game "enough" to develop an opponent or are you missing any data from the game or would you have preferred the data in a different format? |
|
Thanks, I hope you enjoy it! The AI essentially looks two full moves ahead, so it can avoid a lot of simple traps. I haven't been able to beat it yet myself. Overall I found the CPU interface easy to understand and I had little trouble integrating with it, though so far I ignored the trickier parts like irregularly shaped boards, or games with more than 2 players (which the UI doesn't seem to support either). The only information that seems to be really missing is the player scores. This is relevant because there can be cases where a player can allow the opponent take a tower, knowing that it will be able to take a tower in return the next turn. It would make sense to do this, for example, when you're playing best-of-three and you're already one point ahead, but it doesn't make sense when the opponent is just one point away from winning. Currently, there is no way to distinguish these situations. Ideally, the game should inform the AI of the current scores and the target score to win the match. Related to this: I noticed that the game does not allow you create a winning tower for the opponent, but I didn't see anything in the official game rules that would forbid this. While this is rarely useful in practice anyway, it might come up occasionally, for example if this is the only legal move that exists (in which case you're not allowed to pass), or when you can prove that giving away a point to your opponent allows you to score a point on the next turn. To be honest I'm not sure how common either scenario is. Another piece of missing data is that the game does not explicitly tell the AI what its opponent's last move was, which is relevant because it's illegal to undo it. I ended up using the Finally, I was a little confused about which information is available where. It seems like most of the “fixed” state of the game (like rectangular dimensions of the board) are available to |
|
Thanks for the feedback, I really appreciate!
Both is planned and the UI is prepared for it. If you are compiling StackAndConquer yourself, you can already experiment with it. You need to change this line for 3 (or more) players and game dialog will provide you the option accordingly (the rules dialog is prepared for this game mode as well and will show "Rules à trois" , if the below is increased). stackandconquer/stackandconquer.cpp Line 60 in 729cba9 For enabling the board selection, you would need to change this line. If you want to try another shape, I uploaded a test board here: https://gist.github.com/ElTh0r0/25d23d7cbd0b73da40165a0b9789d0f0; you just need to copy it into the boards sub folder (or you can put it in your user folder; if you are on Linux: ~/.local/share/stackandconquer/boards/) Line 172 in 729cba9
Good idea, I like it! I will add it to the interface!
Correct, for 2 players the rules don't forbid creating a winning tower for the opponent. Main reason I implemented it like that (as far as I can remember 😉), was that my first "dummy" CPU is just picking a random legal move and it was the quickest to not letting the dummy CPU select such a "suicide move".
Got it, yes this we can discuss and I am open to add this information to the interface. What do you think is more convenient: Receiving the last move or directly receiving the illegal "undo move"?
Good question 🙂 the interface was just "somehow" growing without really thinking about that! But yes, main "fixed" data is provided from the |
Very cool! I'll try to experiment with them a bit when I have some free time.
I don't think it matters too much, but my preference would be the last move played in the same format used by
Got it. In that case, it might make sense to also provide the board layout in the (It's not critical; I can work around it by doing the initialization in
Aha. I hadn't read up on the 3-player rules before. But are you sure that the direction can change? From the rules here:
The way I interpret this is that if it is player 2's turn (for example), and he has only moves that would let player 3 win, he must pass and play transfers back to player 1, but the word “once” here suggests that this doesn't permanently change the direction of play. So from player 1's perspective, the next player is always player 2. (This is not all that closely related to the topic at hand. Maybe we can discuss the three-player rules in another issue.) |
|
Something else I just noticed: the number of stones per player is not exposed in the CPU API currently, which is a problem because it is configurable in the board file format. I've created separate issues for the things we discussed, because it's getting a little difficult to keep track of them in this thread. I hope you don't mind. (If you do, you can always close them.) |
This player is significantly stronger than AdvancedCPU.