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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0f8b60c
Add basic player for UltimateTTT
dylwhich Jul 12, 2024
5cea3be
Sort out CPU player movement
dylwhich Aug 2, 2024
4b85b19
Add difficulty levels
dylwhich Aug 3, 2024
bd956a8
Create medium difficulty CPU: plays perfectly within subgames
dylwhich Aug 4, 2024
8d94d1e
That does a surprisingly good job
dylwhich Aug 4, 2024
c7aefc5
Merge branch 'main' into ttt-ai
dylwhich Aug 26, 2024
da39545
Merge remote-tracking branch 'origin/main' into ttt-ai
dylwhich Sep 22, 2024
1cfbdfe
Add stashed changes with AI improvement
dylwhich Sep 22, 2024
d68495d
Remove unused function
dylwhich Sep 22, 2024
d4cb76d
Clean up TTT CPU logging
dylwhich Sep 22, 2024
7ea08b4
A bit more clean up
dylwhich Sep 22, 2024
370d8ac
Formatting
dylwhich Sep 22, 2024
dacb200
Change tttHandleGameInput() movement method to handle edge case
dylwhich Sep 24, 2024
a9181b9
Try to bump the cursor away from the edge
dylwhich Sep 24, 2024
a6958db
Fix more warnings
dylwhich Sep 24, 2024
fd0e468
Add direct MIDI-opening support for OSX (#284)
dylwhich Sep 23, 2024
3593cf5
Add Initial Swadge Hero (#297)
AEFeinstein Sep 23, 2024
d0a5257
Fix warnings on firmware
dylwhich Sep 24, 2024
546d553
Add more markers
AEFeinstein Sep 25, 2024
ddd9a92
Randomize CPU marker to not be the player's
AEFeinstein Sep 25, 2024
63fe768
Randomize who goes first in single player
AEFeinstein Sep 25, 2024
a07fdb5
Fix marker unlocks
AEFeinstein Sep 25, 2024
9eb33c5
Remove FW breaking debug message
AEFeinstein Sep 25, 2024
564b4f1
Fix hardcoded CPU player
dylwhich Sep 25, 2024
7b7461b
Unlock TTT markers for single-player victories
dylwhich Oct 2, 2024
e403a92
Remove dead code
dylwhich Oct 2, 2024
a4d58e8
Remove undefs
dylwhich Oct 2, 2024
9d613fd
Merge remote-tracking branch 'origin/main' into ttt-ai
dylwhich Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/ultimateTTT/banana_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/banana_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/banana_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/banana_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/dance_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/dance_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/dance_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/dance_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hand_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hand_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hand_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hand_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hat_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hat_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hat_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hat_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hotdog_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hotdog_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hotdog_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/hotdog_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/lizard_bl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/lizard_bs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/lizard_rl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ultimateTTT/lizard_rs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/ultimateTTT/pixil_bl.png
Binary file added assets/ultimateTTT/pixil_bs.png
Binary file added assets/ultimateTTT/pixil_rl.png
Binary file added assets/ultimateTTT/pixil_rs.png
Binary file added assets/ultimateTTT/spock_bl.png
Binary file added assets/ultimateTTT/spock_bs.png
Binary file added assets/ultimateTTT/spock_rl.png
Binary file added assets/ultimateTTT/spock_rs.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added assets/ultimateTTT/swadgeman_bl.png
Binary file added assets/ultimateTTT/swadgeman_bs.png
Binary file added assets/ultimateTTT/swadgeman_rl.png
Binary file added assets/ultimateTTT/swadgeman_rs.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ idf_component_register(SRCS "asset_loaders/common/heatshrink_encoder.c"
"modes/games/swadgeHero/swadgeHero_game.c"
"modes/games/swadgeHero/swadgeHero_menu.c"
"modes/games/ultimateTTT/ultimateTTT.c"
"modes/games/ultimateTTT/ultimateTTTcpuPlayer.c"
"modes/games/ultimateTTT/ultimateTTTgame.c"
"modes/games/ultimateTTT/ultimateTTThowTo.c"
"modes/games/ultimateTTT/ultimateTTTmarkerSelect.c"
Expand Down
2 changes: 1 addition & 1 deletion main/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ menu "Swadge Configuration"
config HARDWARE_WAVEBIRD
bool "HARDWARE_WAVEBIRD"
help
Build for the Squarewavebird Swadge (2023)
Build for the Squarewavebird Swadge (2023)
config HARDWARE_GUNSHIP
bool "HARDWARE_GUNSHIP"
help
Expand Down
55 changes: 39 additions & 16 deletions main/modes/games/ultimateTTT/ultimateTTT.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ static const char tttName[] = "Ultimate TTT";
static const char tttMultiStr[] = "Wireless Connect";
static const char tttMultiShortStr[] = "Connect";
static const char tttSingleStr[] = "Single Player";
static const char tttDiffEasyStr[] = "Easy";
static const char tttDiffMediumStr[] = "Medium";
static const char tttDiffHardStr[] = "Hard";
static const char tttMarkerSelStr[] = "Marker Select";
static const char tttHowToStr[] = "How To Play";
static const char tttResultStr[] = "Result";
Expand All @@ -52,13 +55,12 @@ const char tttUnlockKey[] = "ttt_unlock";
* Marker names to load WSGs
*/
const char* markerNames[NUM_UNLOCKABLE_MARKERS] = {
"x",
"o",
"sq",
"tri",
"x", "o", "sq", "tri", "banana", "dance", "hand", "hat", "hotdog", "lizard", "pixil", "spock", "swadgeman",
};

const int16_t markersUnlockedAtWins[NUM_UNLOCKABLE_MARKERS] = {0, 0, 1, 3};
const int16_t markersUnlockedAtWins[NUM_UNLOCKABLE_MARKERS] = {
0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
};

swadgeMode_t tttMode = {
.modeName = tttName,
Expand Down Expand Up @@ -96,18 +98,16 @@ static void tttEnterMode(void)
for (int16_t pIdx = 0; pIdx < ARRAY_SIZE(markerNames); pIdx++)
{
char assetName[32];
snprintf(assetName, sizeof(assetName) - 1, "up**_%s.wsg", markerNames[pIdx]);

assetName[2] = 'b'; // blue
assetName[3] = 's'; // small
snprintf(assetName, sizeof(assetName) - 1, "%s_%c%c.wsg", markerNames[pIdx], 'b', 's');

loadWsg(assetName, &ttt->markerWsg[pIdx].blue.small, true);
assetName[3] = 'l'; // large
snprintf(assetName, sizeof(assetName) - 1, "%s_%c%c.wsg", markerNames[pIdx], 'b', 'l');
loadWsg(assetName, &ttt->markerWsg[pIdx].blue.large, true);

assetName[2] = 'r'; // red
assetName[3] = 's'; // small
snprintf(assetName, sizeof(assetName) - 1, "%s_%c%c.wsg", markerNames[pIdx], 'r', 's');
loadWsg(assetName, &ttt->markerWsg[pIdx].red.small, true);
assetName[3] = 'l'; // large
snprintf(assetName, sizeof(assetName) - 1, "%s_%c%c.wsg", markerNames[pIdx], 'r', 'l');
loadWsg(assetName, &ttt->markerWsg[pIdx].red.large, true);
}

Expand All @@ -121,7 +121,13 @@ static void tttEnterMode(void)
// Initialize the main menu
ttt->menu = initMenu(tttName, tttMenuCb);
addSingleItemToMenu(ttt->menu, tttMultiStr);
addSingleItemToMenu(ttt->menu, tttSingleStr);

ttt->menu = startSubMenu(ttt->menu, tttSingleStr);
addSingleItemToMenu(ttt->menu, tttDiffEasyStr);
addSingleItemToMenu(ttt->menu, tttDiffMediumStr);
addSingleItemToMenu(ttt->menu, tttDiffHardStr);
ttt->menu = endSubMenu(ttt->menu);

addSingleItemToMenu(ttt->menu, tttMarkerSelStr);
addSingleItemToMenu(ttt->menu, tttHowToStr);
addSingleItemToMenu(ttt->menu, tttRecordsStr);
Expand Down Expand Up @@ -329,15 +335,32 @@ static void tttMenuCb(const char* label, bool selected, uint32_t value)
{
if (tttMultiStr == label)
{
ttt->game.singlePlayer = false;
// Show connection UI
tttShowUi(TUI_CONNECTING);
// Start multiplayer
p2pStartConnection(&ttt->game.p2p);
}
else if (tttSingleStr == label)
else if (tttDiffEasyStr == label)
{
ttt->game.singlePlayer = true;
ttt->game.cpu.difficulty = TDIFF_EASY;
tttBeginGame(ttt);
tttShowUi(TUI_GAME);
}
else if (tttDiffMediumStr == label)
{
ttt->game.singlePlayer = true;
ttt->game.cpu.difficulty = TDIFF_MEDIUM;
tttBeginGame(ttt);
tttShowUi(TUI_GAME);
}
else if (tttDiffHardStr == label)
{
// TODO implement single player
printf("Implement Single Player\n");
ttt->game.singlePlayer = true;
ttt->game.cpu.difficulty = TDIFF_HARD;
tttBeginGame(ttt);
tttShowUi(TUI_GAME);
}
else if (tttMarkerSelStr == label)
{
Expand Down
29 changes: 28 additions & 1 deletion main/modes/games/ultimateTTT/ultimateTTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Defines
//==============================================================================

#define NUM_UNLOCKABLE_MARKERS 4
#define NUM_UNLOCKABLE_MARKERS 13

#define ARROW_BLINK_PERIOD 1000000

Expand Down Expand Up @@ -63,6 +63,20 @@ typedef enum __attribute((packed))
TTR_RECORDS,
} tttResult_t;

typedef enum __attribute__((packed))
{
TCPU_INACTIVE,
TCPU_THINKING,
TCPU_MOVING,
} tttCpuState_t;

typedef enum __attribute__((packed))
{
TDIFF_EASY,
TDIFF_MEDIUM,
TDIFF_HARD,
} tttCpuDifficulty_t;

//==============================================================================
// Structs
//==============================================================================
Expand All @@ -87,14 +101,27 @@ typedef struct

typedef struct
{
tttCpuState_t state;
tttCpuDifficulty_t difficulty;
vec_t destSubgame;
vec_t destCell;
int64_t delayTime;
} tttCpuData_t;

typedef struct
{
bool singlePlayer;
playOrder_t singlePlayerPlayOrder;
p2pInfo p2p;
tttGameState_t state;
tttSubgame_t subgames[3][3];
vec_t cursor;
vec_t selectedSubgame;
tttCursorMode_t cursorMode;
vec_t cursorLastDir;
int32_t p1MarkerIdx;
int32_t p2MarkerIdx;
tttCpuData_t cpu;
} tttGameData_t;

typedef struct
Expand Down
Loading
Loading