2ndQuadrant is now part of EDB

Bringing together some of the world's top PostgreSQL experts.

2ndQuadrant | PostgreSQL
Mission Critical Databases
  • Contact us
  • EN
    • FR
    • IT
    • ES
    • DE
    • PT
  • Support & Services
  • Products
  • Downloads
    • Installers
      • Postgres Installer
      • 2UDA – Unified Data Analytics
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
  • Postgres Learning Center
    • Webinars
      • Upcoming Webinars
      • Webinar Library
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Blog
    • Training
      • Course Catalogue
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
    • Books
      • PostgreSQL 11 Administration Cookbook
      • PostgreSQL 10 Administration Cookbook
      • PostgreSQL High Availability Cookbook – 2nd Edition
      • PostgreSQL 9 Administration Cookbook – 3rd Edition
      • PostgreSQL Server Programming Cookbook – 2nd Edition
      • PostgreSQL 9 Cookbook – Chinese Edition
    • Videos
    • Events
    • PostgreSQL
      • PostgreSQL – History
      • Who uses PostgreSQL?
      • PostgreSQL FAQ
      • PostgreSQL vs MySQL
      • The Business Case for PostgreSQL
      • Security Information
      • Documentation
  • About Us
    • About 2ndQuadrant
    • 2ndQuadrant’s Passion for PostgreSQL
    • News
    • Careers
    • Team Profile
  • Blog
  • Menu Menu
You are here: Home1 / Blog2 / Gianni's PlanetPostgreSQL3 / pgChess code published
Gianni Ciolli

pgChess code published

December 8, 2010/0 Comments/in Gianni's PlanetPostgreSQL /by Gianni Ciolli

I have been lucky enough to be invited at the marvellous PGDay.eu 2012 conference in Stuttgart, which ended just yesterday.

The topic of the first of my two talks has been a collection of PostgreSQL objects that play chess, either between themselves or against a human.


My intention was to present the software, tidy up the code a bit (out of respect for the fellow PostgreSQL user 🙂 and then release it as free software, for the usual reasons, if there was any interest during the talk.
That being the case, I have named the program pgChess and published the code on GitHub so that the interested reader can verify my claim that the code weights just around 20KB.
I split the core of the code in two files: the pgchess library, which in turn invokes the 2podg library, which stands for “2-player open deterministic games”: open meaning that each player knows 100% of the status of the  game, and deterministic because the whole game is determined uniquely by the choices that the players make.
Two (counter)examples: most card games are not open; Backgammon is not deterministic.
The strategy is quite simple, and is tailored on PostgreSQL features. As short as I can:

  • custom types are defined both for the game state, and for a single move
  • the chessboard is defined as an 8×8 array
  • a quite large function computes the valid moves available from a given game state
  • a recursive algorithm populates the tree of possible moves, up to the specified level (to David Fetter: I am really looking forward to writable CTEs for this part!)
  • a recursive SQL query selects the “best” move, according to the desired strategy which is encoded in the query itself
  • a multi-transactional psql script displays the chessboard, thanks to the Unicode chess characters: ♟,♜,♞,♝,♛ and ♚ for the Black; ♙,♖,♘,♗,♕ and ♔ for the White.
  • players can type their move like “b2Pb4”, or “g8Nh6” (the piece letter always uppercase regardless of the colour).

The reason for the talk is to show that PostgreSQL is an excellent framework to develop application prototypes quickly (which is not a big secret; but providing one more example reinforces the claim). And speed prototyping is one key summand that I recall from Simon Phipps in his remarkable keynote speech, whose slides I recommend when they will become available.
If you attended the conference, please consider giving feedback: who knows, you could win a free entrance for the 2011 conference!
Please note finally that my talk slides will be shortly published on the conference website, and that this article will be updated accordingly.

Tags: chess, European PostgreSQL conference, pgChess, PGDay.eu 2010, PostgreSQL 9.0
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

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

Search

Get in touch with us!

Recent Posts

  • Random Data December 3, 2020
  • Webinar: COMMIT Without Fear – The Beauty of CAMO [Follow Up] November 13, 2020
  • Full-text search since PostgreSQL 8.3 November 5, 2020
  • Random numbers November 3, 2020
  • Webinar: Best Practices for Bulk Data Loading in PostgreSQL [Follow Up] November 2, 2020

Featured External Blogs

Tomas Vondra's Blog

Our Bloggers

  • Simon Riggs
  • Alvaro Herrera
  • Andrew Dunstan
  • Craig Ringer
  • Francesco Canovai
  • Gabriele Bartolini
  • Giulio Calacoci
  • Ian Barwick
  • Marco Nenciarini
  • Mark Wong
  • Pavan Deolasee
  • Petr Jelinek
  • Shaun Thomas
  • Tomas Vondra
  • Umair Shahid

PostgreSQL Cloud

2QLovesPG 2UDA 9.6 backup Barman BDR Business Continuity community conference database DBA development devops disaster recovery greenplum Hot Standby JSON JSONB logical replication monitoring OmniDB open source Orange performance PG12 pgbarman pglogical PG Phriday postgres Postgres-BDR postgres-xl PostgreSQL PostgreSQL 9.6 PostgreSQL10 PostgreSQL11 PostgreSQL 11 PostgreSQL 11 New Features postgresql repmgr Recovery replication security sql wal webinar webinars

Support & Services

24/7 Production Support

Developer Support

Remote DBA for PostgreSQL

PostgreSQL Database Monitoring

PostgreSQL Health Check

PostgreSQL Performance Tuning

Database Security Audit

Upgrade PostgreSQL

PostgreSQL Migration Assessment

Migrate from Oracle to PostgreSQL

Products

HA Postgres Clusters

Postgres-BDR®

2ndQPostgres

pglogical

repmgr

Barman

Postgres Cloud Manager

SQL Firewall

Postgres-XL

OmniDB

Postgres Installer

2UDA

Postgres Learning Center

Introducing Postgres

Blog

Webinars

Books

Videos

Training

Case Studies

Events

About Us

About 2ndQuadrant

What does 2ndQuadrant Mean?

News

Careers 

Team Profile

© 2ndQuadrant Ltd. All rights reserved. | Privacy Policy
  • Twitter
  • LinkedIn
  • Facebook
  • Youtube
  • Mail
Australia: Last seats for our PostgreSQL courses in Melbourne 100% PostgreSQL again
Scroll to top
×