CYBERTEC PostgreSQL Logo

The Slonik's Gambit

12.2024 / Category: / Tags: | |

In the world of databases, we’re often consumed by abstracts. Yet, every so often, an opportunity arises to connect the cerebral with the tangible, the technical with the human. This year at PGConf.eu in Athens, among talks about the latest PostgreSQL features, a different kind of challenge was brewing — not one of data migration intricacies or deployment flexibility, but one of kings, queens, and strategic battles fought on 64 squares. The idea was simple: host a chess tournament to bring database enthusiasts together in a new way.

The CfP committee and Cybertec’s Marketing and Sales team saw an opportunity not just to play but to build. And so, the journey of developing a chess tournament application using CYPEX began.

It all started over a conversation with people who are key figures in the PostgreSQL community. What if we built an application to manage the tournament? Something quick, efficient, and, in the spirit of the conference, powered by PostgreSQL. With the conference dates upcoming, we had limited time to develop a functional application. Traditional development methods were out of the question. This is where CYPEX came into play — a tool known for its rapid application development capabilities atop PostgreSQL databases.

Every application starts with understanding the requirements.

Core Features

  1. Player Management:
    • App administrator was responsible for creating and managing player profiles.
    • A unique identifier for each participant.
  2. Game Management:
    • Recording game results with opponent selection.
    • Enforcing the rule that each pair plays only once.
  3. Scoring System:
    • Calculating scores based on wins, draws, and losses.
    • Implementing resistance points to account for the strength of opponents.
  4. Leaderboard:
    • Real-time rankings are displayed throughout the tournament.
    • Highlight not just top performers but also participants in prime-numbered positions — a quirky twist.

Setting Up the Database Schema for the chess tournament

First, we established the core tables in our chess_tournament schema:

Our initial focus was on getting the core functionality up and running for the tournament, but we also designed the database schema with future enhancements in mind. Just as a chess player thinks several moves ahead, anticipating potential developments, we structured our schema to be scalable and adaptable. Beyond the essential tables I previously described, the schema includes several additional tables intended to support more advanced features:

Chess tournament_technical_1

To ensure fairness and competitiveness, we needed a method to calculate player scores and rankings, especially considering that not all participants would play the same number of games.
Derk helped me a lot with ideas on how to write advanced SQL to cover these needs.

For exampleto aggregate the scores for each player, we created the “Direct scores for players” view:

Here, CTE “scores” combines the results from games where the player played as both white and black. The final SELECT aggregates the total score and total games for each player, consolidating scores from both perspectives.

Introducing Resistance Points

While direct scores indicate how many points a player has earned, they don’t account for the strength of their opponents. The idea is that defeating strong players should be more rewarding than defeating weaker ones. Resistance points help differentiate players who may have the same direct score but faced opponents of varying skill levels.

We calculated resistance points using the following view:

Final Ranking

With both direct scores and resistance points calculated, we can determine the players' rankings. The “Current Ranking” view brings it all together:

After defining the tables and composing complex queries — it was time to let the application ferment — transforming our carefully selected components into a full-bodied user experience.

Low-Code, High Efficiency

Using CYPEX was an exercise in focusing on logic over syntax. To create a more flexible user interface, I started building a fully functional dashboard to manage the chess tournament.

Chess tournament_technical_4
Chess tournament_technical_5

One of CYPEX’s features is its real-time layout editor - a WYSIWYG (What You See Is What You Get) tool that feels so natural to use. It took me just a few moments to drag and drop the necessary tables and forms onto the page. The real magic happened once all the elements were connected to the right data sources.
CYPEX’s built-in JavaScript custom expressions acted like the synapses in a neural network, allowing for complete functional collaboration between elements. Much like the cascading effect of signals in the brain leading to complex behaviors — changing one input causes the entire system to respond. So, when a form is submitted, other components of the dashboard update accordingly, enabling dynamic data synchronization.

Chess tournament_technical_2
Chess tournament_technical_3

Finally, the application was ready. Seeing the players interact, compete, and enjoy the experience was a pleasant reward. The success of the tournament inspired us to consider future enhancements to the application, so more features are planned to be integrated. This tournament demonstrated how, with a bit of creativity and the right technology, we could bring people together again and again.

We’d love to have more people join the chess tournament next time. It’s a fun way to connect with others at the conference. We’ve set up a Telegram Channel for future tournaments at the PostgreSQL Conferences. Feel free to join us there to stay updated!

Leave a Reply

Your email address will not be published. Required fields are marked *

CYBERTEC Logo white
Get the newest PostgreSQL Info & Tools


    This site is protected by reCAPTCHA and the Google Privacy Policy & Terms of Service apply.

    ©
    2024
    CYBERTEC PostgreSQL International GmbH
    phone-handsetmagnifiercrosscross-circle
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram