feat(tma): Full mock game engine with AI opponent, economy, and audit fixes#16
Open
feat(tma): Full mock game engine with AI opponent, economy, and audit fixes#16
Conversation
…onomy Replaces dead socket.ts with a comprehensive mock game engine that simulates the entire PvP match flow with an AI opponent. Uses real game logic from @elmental/shared for authentic gameplay. ## Mock Game Engine (mockGame.ts) - AI opponent with 3 personalities: aggressive, conservative, adaptive - Matchmaking simulation: 5-15 second search, random opponent names/ratings - Full commit → reveal → resolve round flow with delays - Energy calculation using real shared game-logic (all 3 modes) - Overclock system: 30% random move replacement - Round timer: 15s auto-submit on expire - Round cap: MAX_ROUNDS (9) prevents infinite draw loops - Match end detection + 1.5s delay for result overlay visibility ## Economy (fully mocked) - Stake deducted on match-found (100 ELM + 10 boost if enabled) - Winner payout: pool (200) - rake (5%) = 190 ELM - Loser: stake forfeited, boost burned (deflationary) - Draw (max rounds): both get refund - Transaction ledger: every economic event logged with type/amount/description - Balance protection: PLAY button disabled when insufficient ELM - Forfeit: stake lost + boost burned ## Bug Fixes from Audit - Chaos mode: now passes random chaosRoll (0-20) to calculateEnergy (was always defaulting to 10) - EnergyBar maxEnergy: dynamic based on boost (120 not hardcoded 100) - Overclock badge: shows on MoveCard when energy >= 0 but < cost (was dead UI — badge only showed on already-disabled cards) - MoveCard: allows overclock plays (energy >= 0 but < cost) instead of fully disabling - Round cap: MAX_ROUNDS (9) enforced, prevents infinite draw matches - Winning round overlay: 1.5s delay before ResultScreen (was 100ms) - Transaction amounts: boost_burn and loss now log correct negative amounts - ProfileScreen: replaced dead "Recent Rounds" with live Transaction History - HomeScreen: PLAY button shows stake cost, disabled when balance too low - Removed dead socket.ts (zero imports in app) ## Store Updates - Added: transactions[], matchStake, matchBoostStake, addTransaction() - MatchResult: added stake, rake, boostStake, boostBurned, boostReturned, totalPool, winnerPayout for economy breakdown display - EconomyTransaction type for transaction ledger Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Complete standalone mock game engine that simulates the full PvP user flow with an AI opponent. Replaces the dead
socket.tswithmockGame.ts— the entire game is now playable in the browser without any backend, database, or blockchain connection.This PR enables anyone to experience the full Elmental gameplay loop by simply running
pnpm dev.What's New
mockGame.ts) — AI opponent with 3 personalities (aggressive/conservative/adaptive), full commit→reveal→resolve flow, matchmaking simulation (5-15s search)Bug Fixes from Code Audit
chaosRoll(0-20) tocalculateEnergy()MAX_ROUNDS(9) enforced, match ends by score comparisonmaxEnergybased on boost statusboost_burntransaction loggedamount: 0socket.ts(zero imports)Files Changed
apps/tma/src/services/mockGame.tsapps/tma/src/services/socket.tsapps/tma/src/stores/gameStore.tstransactions[],matchStake,matchBoostStake,EconomyTransactiontype, expandedMatchResultapps/tma/src/screens/HomeScreen.tsxapps/tma/src/screens/MatchScreen.tsxmaxEnergy, boost-aware energy barapps/tma/src/screens/MatchmakingScreen.tsxapps/tma/src/screens/ResultScreen.tsxapps/tma/src/screens/ProfileScreen.tsxapps/tma/src/components/MoveCard.tsxGame Mechanics Verified
How to Test
Screenshots
Open the app and play a match — all 6 screens are fully interactive.
Test Plan
npx vitest run→ 78/78 shared logic tests passnpx vite build→ builds successfully🤖 Generated with Claude Code