The Retzark Engine is a Node.js application that serves as the backend for the Retzark game. This engine is responsible for handling all game-related transactions, score calculations, matchmaking, and communications between the game and the Hive blockchain. It also manages the wagering system and the mana system for the game. The wagering system allows players to stake RET tokens on match outcomes, adding a strategic edge to gameplay. The mana system manages player mana for game actions and wagering. The Retzark Engine ensures fair play, accurate score calculations, secure transactions, and a seamless gaming experience for Retzark players.
- Blockchain Integration: Interacts with the Hive blockchain to manage transactions securely and transparently.
- Matchmaking: Matches players based on their rank and experience points to ensure fair competition.
- Game Logic: Handles core game logic, including card selection, attack value assignment, and round simulation.
- Wagering System: Allows players to stake RET tokens on match outcomes, adding a strategic edge to gameplay.
- Reward Distribution: Manages the distribution of rewards after matches based on the game outcome.
- Rank Management: Updates player ranks and experience points based on match outcomes.
- Mana System: Manages player mana for game actions and wagering.
- Logging and Monitoring: Logs all match-related events and monitors system health for reliability.
- Admin Dashboard: Provides an administrative dashboard for monitoring and management.
-
Prerequisites
- Node.js and npm: Ensure you have Node.js (version 14 or higher) and npm installed on your system.
- Hive Blockchain Node: Access to a reliable Hive blockchain node is required to read and post transactions.
- Database: MongoDB (version 4.4 or higher) is recommended for storing game state, player data, and transaction logs.
-
Installation
git clone https://github.com/retzark/retzark-engine.git cd retzark-engine npm install
-
Configuration Create a
.env
file in the root directory with the following configuration:HIVE_NODE=https://api.hive.blog DATABASE_URL=mongodb://localhost:27017/retzark PORT=3000 ENCRYPTION_KEY=your_encryption_key ADMIN_EMAIL=admin@retzark.com BOT_ACCOUNT=your_bot_account POSTING_KEY=your_bot_posting_key START_BLOCK=block_number_to_start_from
-
Running the Application
npm start
retzark-engine/
├── config/
│ └── config.js
├── controllers/
│ ├── adminController.js
│ ├── leaderboardController.js
│ ├── logController.js
│ ├── manaController.js
│ ├── matchController.js
│ ├── matchmakingController.js
│ ├── playerController.js
│ ├── rankController.js
│ └── wageringController.js
├── models/
│ ├── Admin.js
│ ├── BetTransaction.js
│ ├── Card.js
│ ├── Log.js
│ ├── Match.js
│ ├── Player.js
│ └── Wager.js
├── routes/
│ ├── adminRoutes.js
│ ├── indexRoutes.js
│ ├── leaderboardRoutes.js
│ ├── logRoutes.js
│ ├── manaRoutes.js
│ ├── matchRoutes.js
│ ├── playerRoutes.js
│ ├── rankRoutes.js
│ └── wageringRoutes.js
├── services/
│ ├── adminService.js
│ ├── blockchainService.js
│ ├── gameLogicHelpers.js
│ ├── gameLogicService.js
│ ├── hiveService.js
│ ├── leaderboardService.js
│ ├── logService.js
│ ├── manaService.js
│ ├── matchService.js
│ ├── matchmakingService.js
│ ├── playerService.js
│ ├── rankService.js
│ ├── rankUpdateService.js
│ └── wageringService.js
├── tests/
│ └── proceduralTest.js
├── utils/
│ ├── apiUtils.js
│ ├── cryptoUtils.js
│ ├── db.js
│ ├── logger.js
│ └── transactionHandler.js
├── seedCards.js
├── server.js
└── test/
└── test.js
- Admin: Stores admin user information.
- BetTransaction: Stores information about betting transactions.
- Card: Stores information about game cards.
- Log: Stores match event logs.
- Match: Stores match details.
- Player: Stores player profile information.
- Wager: Stores wager details for matches.
-
Blockchain Processing
startStreamingFrom(startBlock)
: Starts processing blocks from a specific start block.processBlock(block)
: Processes each block and its transactions.
-
Matchmaking
joinWaitingRoom(player)
: Adds a player to the waiting room with specified match type (ranked or wagered).createMatchmakingTransaction(players, matchType)
: Creates a matchmaking transaction for a pair of players with the specified match type.matchPlayersByRank()
: Matches players with similar rankings and same match type preference.
Match Types and Wagering:
- Ranked: Standard matches that affect player rankings and experience points. Players must wager MANA tokens to participate.
- Wagered: High-stakes matches where players wager RET tokens instead of MANA.
Every match requires a wager, with the token type determined by the match type:
- MANA Wagers: Used in ranked matches, players compete for MANA and ranking points
- RET Wagers: Used in wagered matches, players compete for higher RET token stakes
Blockchain Transaction Format for Joining Waiting Room:
{ "id": "RZ_JOIN_WAITING_ROOM", "matchType": "ranked|wagered", // Type of match the player wants to join "required_posting_auths": ["player_username"] }
Balance Requirements:
- For ranked matches: Sufficient MANA balance required
- For wagered matches: Sufficient RET balance required
-
Game Logic
simulateRound(cards, match)
: Simulates a round of the match.applyDamageAndUpdateHealth(attacker, target, targetPlayer, match, allCards, battleHistory)
: Applies damage to the target card and updates its health.checkWinConditions(matchId, roundNumber)
: Checks for win conditions after each round.
-
Wagering
Bet(username, matchId, wagerAmount, signature)
: Places a bet for a match.Call(matchId, username, signature, betId)
: Calls a bet.Raise(matchId, username, signature, betId, raiseAmount)
: Raises a bet.Fold(matchId, username, signature, betId)
: Folds a bet.
-
Player Management
getPlayerProfile(username)
: Retrieves a player's profile.updatePlayerProfile(username, updates)
: Updates a player's profile.
-
Reward Distribution
distributeRewards(matchId, outcome)
: Distributes rewards based on the match outcome.
-
Mana Management
getManaBalance(username)
: Retrieves a player's mana balance.updateManaWagered(matchId, player, manaAmount)
: Updates the mana wagered by a player.
-
Logging and Monitoring
logMatchEvents(matchId, event)
: Logs match-related events.monitorSystemHealth()
: Monitors the system health.
-
Admin Functions
provideAdminDashboard()
: Provides an administrative dashboard.generateReports(startDate, endDate)
: Generates reports for the specified date range.
GET /
: Checks if the API is running.
GET /player/:username
: Gets match status for a user.PUT /player/:username
: Updates player profile.
GET /match/:matchId
: Gets match details by match ID.POST /match/reveal/:matchId
: Handles card reveal requests from players.POST /match/resolve
: Resolves a match.
GET /rank/:username
: Gets a player's rank and XP.
GET /leaderboard
: Gets the leaderboard of top players.
GET /mana/:username
: Gets a player's mana balance.
POST /wager/check
: Checks if a player is in the waiting room or in a match.POST /wager/bet
: Places a wager.POST /wager/call
: Calls a wager.POST /wager/raise
: Raises a wager.POST /wager/fold
: Folds a wager.GET /wager/:matchId
: Gets match wager details.GET /wager/complianceReport
: Generates compliance report.
GET /admin/dashboard
: Provides admin dashboard.POST /admin/generate-report
: Generates a report.
POST /log/log-event
: Logs match events.GET /log/health
: Monitors system health.
-
Coding Standards
- Follow consistent coding style and naming conventions.
- Write clean, modular, and reusable code.
- Include comments and documentation.
-
Error Handling and Logging
- Implement robust error handling mechanisms.
- Use appropriate log levels and include relevant contextual information.
-
Testing and Quality Assurance
- Develop a comprehensive test suite.
- Implement unit tests and integration tests.
- Perform thorough testing before deploying updates.
This project is licensed under the MIT License. See the LICENSE file for details.
Note: The Retzark Engine is a work in progress. Contributions and suggestions are welcome to enhance the system and provide a better gaming experience for all players.