

                          your challenge for the
             ¿  ڿ                       ڿ      ¿ 
             ٳ      ĿĿ Ŀ    ٳ
                               
                         
                  HUGI  SIZE  CODING  COMPETITION  #10     
                     

                        the 'Taquin' puzzle game.


.
.

            Ŀ 
Ĵ The Welcome Mat Ŀ
                                                                    
                                                                            
                                                                          
           elcome to the Hugi Size Coding Competition #10.               
         As the y2k year 00 is approaching what better way             
              is there to celebrate this event than by entering             
              this size coding competition? Just like the famous            
              y2k (or 'millennium') bug you must attempt to reach           
              the magic number 00, but this time with the size              
              of your ENTRY.COM program.                                    
                                                                            
              The smaller your competition entry is, the better!!           
                                                                            
              Send your entries to [adok/hugi]:    hugi@netway.at           
                                                                            
              Compo-homepage:   http://home.pages.de/~hugi-compo/           
                                                                            
              Subscribe to the mailing-list:                                
                                hugi-compo-subscribe@egroups.com            
                                                                            
              The deadline for entry submission is January 31st,            
              2000, 11:59 pm GMT. Until this minute you must                
              have sent your entry to Adok!                                 
                                                                            
              For the general rules that apply to all Hugi Size             
              Coding Competitions, please read general.txt!                 
                                                                            
         Ŀ                                                           
Ĵ The Credits 
        

       Ŀ
           hese generous people have given their time...
          
                Adok & all at Hugi
                Chut
                claw
                FirEdge
                GreenGhost
                INT-E
                Jibz
                Lawrence E. Boothby
                Ruud  (big T-H-A-N-X for all your help !!)
                Sniper
                TAD  (big thanx!)
                Vinzent Hoefler
                everyone on the eGroups mailing-list

           Ŀ 
Ĵ The Compo Task Ŀ
                                                                    
                                                                            
        Ŀ                                                               
            he name of the game is 'Taquin' (although some may know        
            this little puzzle game as 'slider' or another name).          
                                                                            
             The puzzle is based on a grid of 16 square 'slots'.            
             On this 4x4 grid of slots is placed the 15 movable             
             'tiles' and 1 empty space (the 'hole').                        
                                                                            
             The game normally has a scrambled picture which needs          
             to be unscrambled by sliding a tile into the space,            
             but for this compo some groovy old-style LED digits            
             have been choosen.                                             
                                                                            
             The following ASCII shows the 4x4 grid surrounded by           
             a 1 pixel wide border and the starting positions of            
             all 15 tiles (and the hole). It also shows the LED             
             style numbers on each tile.                                    
                                                                            
             (NOTE: Colors are incorrect & not to scale #=oP)               
                                                                            
                        
                         ĿĿĿ             
                             Ŀ      Ŀ    ĿĿ               
               <hole>         Ĵ                             
                                                        
                                      
             ĿĿĿĿ             
               Ŀ     Ŀ                                
                Ĵ             Ĵ                       
                                                      
                          
             ĿĿĿĿ             
               ĿĿ    ĿĿ    ĿĿ      Ŀ               
                Ĵ     Ŀ           Ŀ               
                                            
                          
             ĿĿĿĿ             
                 Ŀ    ĿĿ    ĿĿ    ĿĿ               
                      Ĵ     Ŀ      Ĵ               
                                            
                          
                        
                                                                            
                                                                          
             Which in plain ASCII is     13 10 07                         
                                      04 01 14 11                         
              (all numbers are        08 05 02 15                         
                in decimal)           12 09 06 03                         
                                                                          
                                                                            
             The player uses one of the [8] [2] [4] [6] keys to             
             slide a tile into the hole. The old tile position              
             within the grid now becomes the new hole.                      
                                                                            
             This process of sliding tiles around continues until           
             either the player presses the [QUIT] key OR the                
             puzzle is completely solved. In both situations an             
             exit message is printed on the screen together with            
             the number of moves taken.                                     
                                                                            
             The 'MovesCounter' records the number of VALID moves.          
             Any illegal move (like into/from the border) are NOT           
             counted.                                                       
                                                                            
          Ŀ                                                          
Ĵ The Solution 
         

       Ŀ
           he following diagram shows the puzzle's solution.
           Once this grid arrangement has been met the puzzle
            exits and the congratulations message is displayed
            together with the number of moves the player took.

           
                        ĿĿĿ 
                          Ŀ      ĿĿ    ĿĿ   
              <hole>                    Ĵ   
                                       
                         
            ĿĿĿĿ 
              Ŀ     ĿĿ    ĿĿ    ĿĿ   
               Ĵ     Ŀ     Ŀ          
                                 
             
            ĿĿĿĿ 
              ĿĿ    ĿĿ      Ŀ           
               Ĵ     Ĵ                  
                                   
             
            ĿĿĿĿ 
                Ŀ      Ŀ             Ŀ   
                       Ĵ      Ĵ      Ŀ   
                                       
             
           

                                                 
            Which in plain ASCII is     01 02 03 
                                     04 05 06 07 
             (all numbers are        08 09 10 11 
               in decimal)           12 13 14 15 
                                                 

     Ŀ 
Ĵ The Grid Ŀ
                                                                    
                                                                            
                                                                          
        Ĵ ere is the small print for the graphics. All the               
           co-ordinates are from the top-left corner (0,0)                
             and are designed for the standard 320x200x256cols              
             VGA screen mode 13 hex.                                        
                                                                            
             (claw:   co-ordinates = coordinates  #;o)                      
                                                                            
             The grid is divided up into 16 slots arranged in               
             a 4 by 4 manner (as shown below). The top-left                 
             (x,y) co-ordinates of each slot is shown next to               
             the  marker. The slots are placed 32 pixels apart.            
                                                                            
             The slots are basically screen positions where                 
             individual tiles are placed. The tiles are free                
             to move into different slots. This movement is                 
             controlled by the player according to the normal               
             Taquin puzzle game rules (shown elsewhere).                    
                                                                            
                                                                            
                width=30                                                    
              Ŀ                                                  
     (95,35)                                                              
                     
           ĿĿĿĿ            
 height      97,37     129,37    161,37    193,37               
 = 30 Ĵ                                                       
              slot 0    slot 1    slot 2    slot 3              
                       
             ĿĿĿĿ            
              97,69     129,69    161,69    193,69               
                                                                  
               slot 4    slot 5    slot 6    slot 7    border     
                          
             ĿĿĿĿ  130        
              97,101    129,101   161,101   193,101               
                                                       pixels     
               slot 8    slot 9    slot 10   slot 11              
                         
             ĿĿĿĿ            
              97,133    129,133   161,133   193,133              
                                                                 
               slot 12   slot 13   slot 14   slot 15             
                         
                     
             border = 130 pixels wide Ĵ            
                                                                            
                                                                            
             Here is perhaps a more useful table of co-ordinates:-          
                                                                            
                                                                            
                    Item     (left, top)    width x height                  
                                               
                    border    ( 95, 35)       130 x 130 pixels              
                                                                            
                                                                            
                    Item     (left, top)    A000:xxxx                       
                                                   
                    slot 0    ( 97, 37)          2EA1 hex                   
                    slot 1    (129, 37)          2EC1 hex                   
                    slot 2    (161, 37)          2EE1 hex                   
                    slot 3    (193, 37)          2F01 hex                   
                                                                            
                    slot 4    ( 97, 69)          56A1 hex                   
                    slot 5    (129, 69)          56C1 hex                   
                    slot 6    (161, 69)          56E1 hex                   
                    slot 7    (193, 69)          5701 hex                   
                                                                            
                    slot 8    ( 97, 101)         7EA1 hex                   
                    slot 9    (129, 101)         7EC1 hex                   
                    slot 10   (161, 101)         7EE1 hex                   
                    slot 11   (193, 101)         7F01 hex                   
                                                                            
                    slot 12   ( 97, 133)         A6A1 hex                   
                    slot 13   (129, 133)         A6C1 hex                   
                    slot 14   (161, 133)         A6E1 hex                   
                    slot 15   (193, 133)         A701 hex                   
                                                                            
             The spacing between each slot is 2 pixels wide.                
             And the starting co-ordinates of each slot are                 
             32-pixel apart on both the X-axis and Y-axis.                  
                                                                            
             Into the 16 grid 'slots' are placed the 15 tiles               
             together with the 'hole' (a blank tile space).                 
             Each tile (and the 'hole') can occupy only one                 
             particular slot at any one time.                               
                                                                            
                                                                            
                Item        width   height         color                    
                                                       
( the 'hole' )  tile  0       30      30              0                     
                                                                            
                tile  1       30      30              1                     
                tile  2       30      30              2                     
                tile  3       30      30              3                     
                tile  4       30      30              4                     
                tile  5       30      30              5                     
                tile  6       30      30              6                     
                tile  7       30      30              7                     
                tile  8       30      30              8                     
                tile  9       30      30              9                     
                tile 10       30      30             10                     
                tile 11       30      30             11                     
                tile 12       30      30             12                     
                tile 13       30      30             13                     
                tile 14       30      30             14                     
                tile 15       30      30             15                     
                                                                            
             Apart from the LED digits, no other pixels may                 
             drawn on the screen. All the background pixels                 
             MUST be cleared using color 0. The 'hole' tile                 
             MUST also be drawn using the background color 0.               
                                                                            
                                                                            
             Please look at the EXAMPLE.ASM source-code and                 
             pre-compiled program including with the test-suite             
             for more information.                                          
                                                                            
             I suggest playing around with the example puzzle               
             game to familiarize yourself with the puzzle, the              
             control system and the rules concerning VALID                  
             slide-moves.                                                   
                                                                            
                                                                            
            Ŀ                                                        
Ĵ The LED Digits 
           

       Ŀ
           he LED style digits are drawn using short vertical
           or horizontal line sections.

            On each tile are two LED digits:-

               - 10's column (this digit can be '0' or '1')
               -  1's column (this digit can be '0123456789')

            For example the number 16 is '1' in the 10's column
            and '6' in the 1's column.

            The following relative co-ordinates are measured
            from the top-left corner of each grid slot.


                         11111111112222222222
               012345678901234567890123456789

           0     <---- the tile
           1           1:1 scale
           2           1 char = 1 pixel
           3   
           4   
           5   <--------- drawn using the
           6           tile color (0 ... 15)
           7   777777777777
           8   6565 Ŀ
           9   6565  
          10   6565   6 pixels high
          11   6565  
          12   6565  
          13   6565 
          14   444444444444
          15   3232 Ŀ
          16   3232  
          17   3232  
          18   3232   7 pixels high
          19   3232  
          20   3232  
          21   3232 
          22   111111111111
          23   
          24   /\/\
          25    the 1's digit column
          26   
          27    the 10's digit column
          28   
          29   

            Each LED digit is identical in size and Y co-ordinate.
            The left (the 10's) digit begins at (+6,+7) and the
            right (the 1's) digit begins at (+16,+7).
            
            The LED digits are based on 7 short line sections.
            Every line section is drawn in background color 0.
            
            Here is a table which describes the 7 horizontal or
            vertical line sections for the left 10's digit.

            Section    (left,top)    width  height   direction   color
                            
               1       ( +7, +22)      6       -       horz        0
               2       (+13, +15)      -       7       vert        0
               3       ( +6, +15)      -       7       vert        0
               4       ( +7, +14)      6       -       horz        0
               5       (+13,  +8)      -       6       vert        0
               6       ( +6,  +8)      -       6       vert        0
               7       ( +7,  +7)      6       -       horz        0


            The right 1's digit is identical, except it begins
            10 pixels to the right.

            Section    (left,top)    width  height   direction   color
                            
               1       (+17, +22)      6       -       horz        0
               2       (+23, +15)      -       7       vert        0
               3       (+16, +15)      -       7       vert        0
               4       (+17, +14)      6       -       horz        0
               5       (+23,  +8)      -       6       vert        0
               6       (+16,  +8)      -       6       vert        0
               7       (+17,  +7)      6       -       horz        0

 NOTE:
 *****      Some vertical sections are 7 pixels !!


            Here is a table which describes each of the 10 possible
            LED digits "0123456789" using 7 bits. Each bit describes
            whether a particular line section should be drawn (bit=1)
            or should not be drawn (bit=0).

            The bit #0 position is simply padding, it is only there
            to waste space and fill up the spare bit position.

                     Bit/Line section Ŀ
             LED     
            Digit     7    6    5    4    3    2    1    0       Byte
                                =  
             '0'      1    1    1    0    1    1    1    0       EE hex
             '1'      0    0    1    0    0    1    0    0       24 hex
             '2'      1    0    1    1    1    0    1    0       BA hex
             '3'      1    0    1    1    0    1    1    0       B6 hex
             '4'      0    1    1    1    0    1    0    0       74 hex
             '5'      1    1    0    1    0    1    1    0       D6 hex
             '6'      1    1    0    1    1    1    1    0       DE hex
             '7'      1    1    1    0    0    1    0    0       E4 hex
             '8'      1    1    1    1    1    1    1    0       FE hex
             '9'      1    1    1    1    0    1    1    0       F6 hex

     Ŀ 
Ĵ The Keys Ŀ
                                                                    
                                                                            
        Ŀ                                                               
            he player can use four direction keys. These are the           
            [2] [4] [6] [8] number keys. When one of these keys            
             is pressed, the corresponding 'slide-move' is checked          
             to see if it is valid (you can NOT slide into/out of              
             the border area), if okay the correct tile is swapped          
             with the 'hole' and the MovesCounter is updated.               
                                                                            
             An illegal move (where the slide-move is stopped by            
             the border) is NOT counted as a move, so the counter              
             is not updated.                                                
                                                                            
             Here is some pseudo-code to help describe the keys:            
                                                                            
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   
                                                                            
        g(4,4)          ;; A 4x4 array of tile tokens ;;                    
                                                                            
        x,y             ;; coords on grid of the hole (0..3, 0..3) ;;       
                                                                            
        MovesCounter    ;; counts the number of valid moves so far.. ;;     
                                                                            
        IF key = [8] AND y < 3 THEN                                         
                                     SWAP g(x,y), g(x,y+1)                  
                                     y + 1                                  
                                     MovesCounter + 1                       
                                                                            
                                                                            
        IF key = [2] AND y > 0 THEN                                         
                                     SWAP g(x,y), g(x,y-1)                  
                                     y - 1                                  
                                     MovesCounter + 1                       
                                                                            
                                                                            
        IF key = [4] AND x > 0 THEN                                         
                                     SWAP g(x,y), g(x-1,y)                  
                                     x - 1                                  
                                     MovesCounter + 1                       
                                                                            
                                                                            
        IF key = [6] AND x < 3 THEN                                         
                                     SWAP g(x,y), g(x+1,y)                  
                                     x + 1                                  
                                     MovesCounter + 1                       
                                                                            
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   
                                                                            
             The [QUIT] key represents the SPACE character 32               
             (20 hex).                                                      
                                                                            
             Remember the [2] [4] [6] [8] keys appear both on the           
             keyboard under the F1...F12 function keys AND on the           
             side keypad. The scancode (AH) bytes are different!            
             But the ascii-code (AL) byte is the same for both.             
                                                                            
             Here are the 5 valid keys.                                     
                                                                            
                [2]     - '2'           50 decimal      32 hex              
                [4]     - '4'           52 decimal      34 hex              
                [6]     - '6'           54 decimal      36 hex              
                [8]     - '8'           56 decimal      38 hex              
                                                                            
                [QUIT]  - ' '           32 decimal      20 hex  (space)     
                                                                            
             Only the above 5 keys are allowed to affect the puzzle.        
             Every other key is illegal and MUST be ignored.                
                                                                            
          Ŀ                                                          
Ĵ The Messages 
         
       Ŀ
       Ĵ fter either the [QUIT] key OR the win condition is
          met, the screen display is switched back into
            text-mode 3 then a message is displayed on the screen
            together with the number of moves taken by the player.

            The win condition message is:-

                       'Winning field after <n> moves', 0Dh, 0Ah

            And the quit message is:-

                       'You have quit after <n> moves', 0Dh, 0Ah

            In both cases the <n> is the MovesCounter (the number
            of moves taken by the player).

            The <n> is written as a decimal number, WITHOUT the
            leading '0' characters. So the number 109 decimal is
            displayed as '109' and NOT as '00109'

            If the player quits the game without making any valid
            moves, then <n> must be displayed as '0'

            You can assume the <n> (the MovesCounter) is always
            in the range 0...65535 decimal (0000...FFFF hex).


           Ŀ 
Ĵ Critical Order Ŀ
                                                                    
                                                                            
                                                                          
         our entry MUST do the following in THIS order:                
                                                                           
                                                                            
        (1)  - switch to VGA mode 13 hex                                    
                                                                            
        (2)  - draw the puzzle                                              
             - read the keyboard using AH=00 INT 16 hex                     
             - write the key char to "KEYS" file                            
             - if [QUIT] key then                                           
                        ... goto (3)                                        
                                                                            
             - if [2,4,6 or 8] key AND move is valid then                   
                        ... update puzzle                                   
                        ... update MovesCounter                             
                                                                            
             - if the puzzle is not solved, then goto (2)                   
                                                                            
        (3)  - switch back to text-mode 3                                   
        (4)  - print either the win-message OR the quit-message             
               (including the <n> number of moves taken)                    
        (5)  - exit cleanly to DOS                                          
                                                                            
                                                                            
             Ŀ                                                       
Ĵ The "KEYS" file 
            

       Ŀ
           his file is a list of all the key-presses which
           the player made during the game. It allows a
            game to be recorded and examined at a later date.

            Currently EVERY key press is written to the "KEYS"
            file (see the previous <Critical-Order> (2) section).
            So it may contain every other character, not just
            the [2] [4] [6] [8] and [QUIT] keys...

            In order to read a key correctly, your entry MUST
            use the function AH=00, INT 16 hex.
            
            eg.
                       MOV     AH, 00h
                       INT     16h
            
            The low-byte of the returned value in the AX register
            (the ASCII char in the AL register) MUST be written
            out to the "KEYS" file and also used as the game's
            input. The test-suite(s) will automattically supply
            a variety of key-presses in to help verify that your
            entry works correctly.
            
            The "KEYS" file must have these, normal, attributes
            
               bit 0   = 0     (NOT a read-only file)
                   1   = 0     (NOT a hidden file)
                   2   = 0     (NOT a system file)
                   3   = 0     (NOT a volume label)
                   4   = 0     (NOT a sub-directory)
            
            One way to ensure the above attributes are correctly
            set is to use the following code-snippet to create
            and open the "KEYS" file.
            
            eg.
                       MOV     DX, OFFSET KeysFilename
                       SUB     CX, CX
                       MOV     AH, 3Ch
                       INT     21h
            
            Please see the EXAMPLE.ASM source code for more info.
            
              Ŀ                                                    
Ĵ The test-suite(s) Ŀ
                                                                    
        Ŀ                                                               
            he test-suites used during this compo are only there           
            to be a guide, a reference check.                              
                                                                            
             It is possible that an unforeseen loop-hole might be           
             discovered during the course of the compo. If this             
             happens a new, or updated test-suite will be released          
             as soon as possible through both the Hugi web-site             
             and the eGroups Hugi-compo mailing list.                       
                                                                            
             Please keep in mind that the test-suites are only              
             meant to be a guide, something to help you debug               
             and test that your entry does indeed comply with the           
             compo rules.                                                   
                                                                            
             After the compo deadline a period of public judgement          
             occurs in which you and others are free to comment             
             and discuss these unforeseen loop-holes.                       
                                                                            
                Ŀ                                                    
Ĵ That's All Folks.. 
                                                                   
                                                                           
       Ŀ                                                               
           hank you for reading this long, complicated text.
                                                            
            If you have any questions then please look at the
            supplied example program and source-code.            
                                                             
            If you still are unsure about a certain detail   
            then please post a question to the Hugi     
            compo mailing list (hugi-compo@egroups.com).
                                                            
                          Have fun, and good luck !!        
                                                            
                       Ŀ                             
Ĵ TAD ( tad.uk@dtn.ntl.com ) Ŀ
                                                                    
                                                                        TAD .

