Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ultimate TTT AI #298

Merged
merged 28 commits into from
Oct 2, 2024
Merged

Ultimate TTT AI #298

merged 28 commits into from
Oct 2, 2024

Conversation

dylwhich
Copy link
Collaborator

Description

Adds a single-player CPU opponent with 3 difficulties:

  • Easy -- Plays a random move
  • Medium -- Plays optimally within sub-games, but has no overall strategy
  • Hard -- Analyzes the board and tries to play the best overall move, taking into account the best sub-game move, and weighing that against what the opponent's best move would be in the sub-game they would get to move in. Or, if they would get to pick any sub-game, their best move overall.

Also changes tttHandleGameInput() to use a slightly different method, which should prevent any squares from becoming inaccessible and I think maybe it handles a bit more intuitively than the previous one? I recommend playing with it to see. But it pretty much tries to find a close free space before it wraps all the way around by bumping the cursor away from the edge of the board, and it also prioritizes the last intended direction for the secondary cursor direction.

Test Instructions

Play against the AIs, see how they feel. See if the cursor behaves reasonably in some funky situations.

Ticket Links

Closes #267

Readiness Checklist

  • I have run make format to format the changes
  • I have compiled the firmware and the changes have no warnings
  • I have compiled the emulator and the changes have no warnings
  • I have run make cppcheck and checked that cppcheck_result.txt has no warnings for the changes
  • I have added doxygen comments to any code used by more than one Swadge mode. This includes /*! \file comments with Design Philosophy, Usage, and Example sections for new headers.
  • I have run make docs and checked that doxy_warnings.txt has no warnings for the new code

@AEFeinstein
Copy link
Owner

@dylwhich I stapled three things onto this PR (hope you don't mind):

  1. More markers!
  2. Randomize play order for single player
  3. Randomize CPU marker to be an unlocked one which isn't the players

@dylwhich
Copy link
Collaborator Author

Nice, good idea! Hah, I think I might have hardcoded the Hard CPU to make the move that's most advantageous for Player 2, because it really feels like it's avoiding winning against me when it goes first

main/modes/games/ultimateTTT/ultimateTTTgame.c Outdated Show resolved Hide resolved
main/modes/games/ultimateTTT/ultimateTTTgame.c Outdated Show resolved Hide resolved
main/modes/games/ultimateTTT/ultimateTTTgame.c Outdated Show resolved Hide resolved
@AEFeinstein
Copy link
Owner

This all looks good to me (and feels good too). You can merge after addressing feedback (if you wanna)

@dylwhich dylwhich merged commit 2778516 into main Oct 2, 2024
6 checks passed
@AEFeinstein AEFeinstein deleted the ttt-ai branch October 2, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ultimate TTT: Empty squares are sometimes impossible to navigate to
2 participants