- Record a sports match on-chain with structs, an enum and a mapping.
- Implement round-based scoring and winner rules with if/else logic.
- Build a readable status message with
string.concat.
Synopsis
Managing a badminton tournament involves player registration, match scheduling, live scoring, results and standings. Score records are often disputed, so storing them on a blockchain gives a tamper-proof match history that anyone can check.
This project focuses on the core of such a system: a single match between two players. The deploying account is the Match Referee, who registers both players, starts the match and records each point. The contract applies the rules – a game is won at 21 points, the player who wins two games wins the match, and a third game decides a 1–1 tie – and publishes the match status and winner.
Features of a Complete Tournament System (Scope)
- Player registration and profiles
- Tournament set-up and match scheduling
- Live score tracking
- Results and standings
- Notifications
- Analytics and reporting
- Referee / officiating tools
- Security and access control
- Scoring-system integration
The smart contract in this project implements the referee tools, live scoring and result parts; the other features belong to the surrounding web application and database.
Contract Architecture
| Part | Details |
|---|---|
| BlockFiles.sol | Structs PlayerBlock { playerAddress, playerName, PlayerCountry } and MatchBlock (two player addresses and points for each player in rounds 1–3) |
| Tournament.sol | Contract BadmintonTournament; imports contracts/BlockFiles.sol |
| enum & mapping | enum players { PLAYER1, PLAYER2 }; mapping(uint => PlayerBlock) public playerList |
| state | matchReferee, MatchBlock public matchBlockObj, roundNumber, matchStatus, player-initialised flags |
| modifiers | checkMatchReferee, checkPlayersInit (both players registered), checkRoundStatus (round 1–3 in progress) |
| functions | InitFirstPlayer, InitSecondPlayer, InitMatch, stepPlayer1, stepPlayer2 (add a point), gotoNextRound, private checkForNextRound, checkWinner, checkFinalWinner, and checkMatchStatus() (view) |
How It Works
After the match ends, roundNumber is set to 9, so checkRoundStatus rejects any further points.
Key Requirements (Concepts Used)
- Structs imported from a separate file and an enum for player slots (Chapters 11, 13).
- Mapping of player slots to player records (Chapter 12).
- Decision making for rounds and winners (Chapter 7).
- Private functions and a view function (Chapter 15).
- Modifiers for referee-only actions and valid rounds (Chapter 22).
- String building with
string.concat(Chapter 9).
How to Run in Remix
- Create
contracts/BlockFiles.solandcontracts/Tournament.sol; compile and deploy BadmintonTournament from the first account (referee). - Call
InitFirstPlayerandInitSecondPlayerwith an address, name and country, thenInitMatch. - Call
stepPlayer1/stepPlayer2to add points; readmatchBlockObjandroundNumberas the game progresses. - Call
checkMatchStatus()to read the result.
Limitations and Extension Exercises
| Observation in the teaching version | Improvement to try |
|---|---|
| A game ends at exactly 21 points; official badminton also requires a 2-point lead (up to a 30-point cap). | Implement the deuce rule. |
| Only one match can be stored. | Use mapping(uint => MatchBlock) with match IDs to build a tournament. |
| Every point is a transaction, which costs gas. | Record scores off-chain and store only the final, signed result on-chain. |
| The referee is the only trusted scorer. | Require confirmation from both players or a second official. |
| No events are emitted. | Emit PointScored and MatchWon events for a live scoreboard (Chapter 20). |
Key Takeaways
- Structs, an enum and a mapping represent players and a match; modifiers restrict scoring to the referee.
- if/else logic in private functions implements the game rules and winner detection.
- On-chain scoring gives a tamper-proof history but costs gas for every update.
Video : Project 5 : Smart Contract for Badminton Tournament System
Resource Files
Question / Answer (15 questions)
string.concat("Match Over : ", pname, " (WINNER)"), which joins strings (Solidity 0.8.12+).MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.
- Solidity Team. (n.d.). Types (value types, reference types, mappings, operators, conversions). Solidity Documentation. https://docs.soliditylang.org/en/latest/types.html
- Solidity Team. (n.d.). Expressions and Control Structures (if/else, loops, checked arithmetic, error handling, try/catch). Solidity Documentation. https://docs.soliditylang.org/en/latest/control-structures.html
- Solidity Team. (n.d.). Contracts (creating contracts, visibility and getters, function modifiers, constant and immutable, functions, events, custom errors, inheritance, abstract contracts, interfaces, libraries). Solidity Documentation. https://docs.soliditylang.org/en/latest/contracts.html
- Remix Project. (n.d.). Remix IDE Documentation. https://remix-ide.readthedocs.io/en/latest/
- Modi, R. (2018). Solidity Programming Essentials: A beginner’s guide to build smart contracts for Ethereum and blockchain. Packt Publishing. ISBN 978-1-78883-138-3.