Article
Robert Cemper · Dec 9, 2019 1m read

SUDOKU demo

For those experts that can't stop after AoC2019
I have posted some rather old code in traditional style to improve it.

It was written based on a previous trial in .XLS
It is far from being perfect. Rather a challenge for
improvement in all directions (code, interface, ...)
So anyone may feel invited to make it better.

USER>d ^SUDOKU
;; Welcome to this SUDOKU demo !
;; you may solve your SUDOKU easier or create your own
;; under each box entry you find a list
;; of allowed values for this box
;; fill in numbers 1..9 as you need
;; to clear a box enter any character or blank
;; to stop enter . or , for the solver enter ?
;; navigate between boxes by cursor keys <>^v
;;
go:

SUDOKU3.JPG

This is a coding example working on Caché 2018.1.3 and IRIS 2020.2 
It will not be kept in sync with new versions 
It is also NOT serviced by InterSystems Support !

download here

100
0 13 389 2

Replies

Hi Robert.

Funny - I came across your post and it caught my eye because, over the weekend just for kicks I decided to write a terminal version of the old Battleship game and the board looked very similar smiley  Then I decided to do it using .CSP, but unfortunately lost my Caché extension for Dreamweaver so it's on hold for the moment while I search through my archive disk...

@Evgeny Shvarov  you raise a very important point.  yes
To my experience to write a CHUI game is one of the best exercises to learn a programming language and its environment. 

As the result is so easy to verify and the graphics can really challenge you
as you have to care for everything yourself.
AoC was the reminder and trigger to dis into the old archive. yes

Right !
looking through the Tag Tree  I didn't find a Tag "GAME".

Definitely we are all too serious  ! laugh

A-ha! This is the call for a tag, right? )

Thank you Evgeny.  I did take a look at that one, and mine started out that way with a function that printed out the grid.

I am now doing the UI in a .CSP page by having Javascript generate a table of addressable cells, and calling out to Caché to place the 5 ships of different sizes within the boundaries of the grid and avoiding intersections.

^grid(player,x-pos,y-pos).=ship#

Back in the 70s, I had the idea of 2 independent players running the game where the 2 versions communicated with each other via a global, or more recently, over a serial (now I/P) port to pass shot coordinates, and hit/miss results back and forth. 

I guess I'm a bit of a procrastinator :)

I have added a new version SUDOKU3.mac

Changes in this update:   
- new layout for use on standard terminal 48x80
- the solver is now triggered by * instead of  ?
- solving strategy expanded for higher hit rates:
  resolve unique options by row, column, group

on resolver:

version1 just filled empty cells when there was a dedicated unique value for the cell available

version3 now looks for unique values within a row
- next for unique values within a row
- then for unique values within a group of 9 boxes

Hint:
some SUDOKU examples contain contradictions
or are ambiguous by cyclic definitions
it is left to the user to resolve it.

Thanks !
Looks nice. wink

I have added a version: SUDOKU4.mac

It fixes an endless loop if there is no possible solution.

Also, some administration commands have been added:

    ;; navigate between boxes by cursor keys <>^v
    ;; simple administration commands:
    ;; . to stop
    ;; , to stop
    ;; * start the solver
    ;; x eXport status to csv_file (0 = terminal)
    ;; i import status from csv_file (0 = terminal)
    ;; ^ write snapshot to global ^box
    ;; ! load snapshot from global ^box

 

SUDOKU5.mac has some minor improvements on automatic navigation across the grid.
Supported by Google Translate there is also a Spanish version of this article.
 

As a service to our Spanish Community, I have added a translated version to the archive.

SUDOKU5es.mac