Databases 9 min read

SQL Tic‑Tac‑Toe Challenge: Generate All End‑Game Boards and Find Winning Strategies

The ITPUB SQL Database Programming Contest invites participants to solve two Oracle‑SQL puzzles—generating every possible tic‑tac‑toe end‑game board with moves and determining forced win strategies—following detailed rules, evaluation criteria, and prize information.

ITPUB
ITPUB
ITPUB
SQL Tic‑Tac‑Toe Challenge: Generate All End‑Game Boards and Find Winning Strategies

Competition Overview

The ITPUB community is hosting the 3rd "SQL Database Programming Contest" organized by 盛拓传媒. Participants submit SQL solutions to solve the defined puzzles within the announced time window, after which judges evaluate the submissions.

Process and Evaluation

Submission Phase : Contestants upload their solution files according to the published problem statements.

Review Phase : Judges review all submissions within ten days and provide feedback.

Result Publication : Scores and selected solutions are announced publicly.

Scoring Criteria

Readability and simplicity of a single‑SQL statement (20 points).

Problem‑solving approach (20 points).

Correctness and completeness of the solution (40 points).

Performance considerations (20 points).

Prizes

First to fourth place receive JD.com gift cards (500 CNY to 100 CNY) and a ticket to the 2016 China Database Technology Conference, plus the title “ITPUB SQL Database Programming Master” and a badge. All participants get a commemorative hoodie and a participation badge.

Puzzle Description

Problem 1 – Generate All End‑Game Boards (100 pts)

Write a single SQL statement that, when placed after INSERT INTO TICTACTOE, inserts every possible terminal tic‑tac‑toe game record. The required table definition is:

CREATE TABLE TICTACTOE (MOVES VARCHAR2(9) PRIMARY KEY, BOARD VARCHAR2(9), WINNER VARCHAR2(1));

Each record must contain: MOVES: a string of up to nine digits (1‑9) indicating the move order. BOARD: a nine‑character representation of the final board using X, O, and - for empty cells. WINNER: X, O, or D (draw).

All terminal positions, even those arising from sub‑optimal play, must be included. Different move sequences that lead to the same board are considered distinct and both must appear. Boards that are rotations or reflections of each other are still treated as separate if their MOVES differ.

Problem 2 – Forced Win Strategy (100 pts)

Given a valid board state stored in a variable V_BOARD (e.g., V_BOARD='X-0------'), write a single SQL query that returns: Xn or On where the letter indicates the player who can force a win and n is the maximum number of additional moves that player needs to guarantee victory. X0 or O0 if the board already shows a winner. D if no forced win exists (e.g., an empty board).

The query must be executable in SQL*Plus after declaring the variable:

VAR V_BOARD VARCHAR2(9);
EXEC :V_BOARD := 'X-O------';

The result string must not contain any single quotes.

Additional Challenge

Implement the solution for Problem 2 so that it works for any m×n board with a winning line length k (where m,n,k ≥ 3). This earns an extra 10 points.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

algorithmdatabaseOracleprogramming-contesttic-tac-toe
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.