



                        Brief Technical Information




ARTIFICIAL INTELIGENCE
----------------------

   The artificial inteligence (AI) is implemented using the
   minimax algorith.

   Minimax is based in maximizing evaluation scores when
   the turn is for the computed and minimizing if is human turn,
   better explanation down.
   
   The algorithm generate alternating all possible human and computer
   moves from one start board. This process is made some turns in
   forward and the result is a tree with possible boards configurations.
   Is not computed all possible moves from current configuration
   to game end because this would take very long time.

   The tree deph increase by one level for each turn generation.
   For example: generate all human moves from a given
   board configuration. Then, for each new board, is generated all
   computer possible moves. If maximum deph is 3, only 3 turns are
   generated. When the tree deph is enough, the boards in leaf are
   evaluated. The evaluation is made by one "static evaluetion function",
   where big scores are for better configuration boards at the computer
   point of view.
   
   After evaluation, is selected in the parent tree nodes one of its
   child boards. The selection is made acording the boards scores.
   If the node is for a human turn is selected the board if less score
   between all childs, if is computer turn the selected board is the
   greater one. The selected board is returned by the node to its parent.
   
   At tree root the greater child is selected for the next computed move.
   
   The tree deph is predefined by the dificulty level:
      very easy level .. deph 2;
      easy level ....... deph 3;
      hard level ....... deph 5.
      
   The progress bar lines indicate what is the computer piece in test,
   the rows indicate what move direction.


3D ENGINE
---------

   Is used a flat polygon 3D engine. All visible objects are composed
   by polygons. In this game, the board.

   To do the visualization is necessary 2 copies of the game board.
   One with vertices decripted in universe reference system (SRU),
   is the same reference system used to describe object in data file.
   The other board has a temporary copy of the object model obtained
   by the geometrical transformation to the camera reference system
   (SRC). SRC has the observator position and orientation. 

   The transformation from SRU to SRC must be done for each frame.
   After the board is transformed it can be viewed.

   The 3D rendering kernel draw polygons composed by 4 vertices in
   anticlockwise order.

   Is possiblen define one between 8 colors to
   draw the polygons. Each color has 32 shaded tones - going from
   dark to light. The shading is done using the flat model
   (known as Lambert model, too).

   The basic view algorithm is deph-sort.
   Deph-sort is made before back surface culling.

   Deph-sort principle: order each polygon by it`s Z distance
   to the observator and then draw back to front polygon per polygon.


VARIABLE AND FUNCTION NOTATION
------------------------------

   Here is a variation for the hungarian variable naming to define short,
   prefixes onto each variable, function and type name to denote its properties:

     PREFIX     DATA TYPE OR USE CASE
       a        array (compound type: ach aw)
       b        boolean
       ch       character
       d        double
       dw       unsigned long (double word)
       f        floating point
       ll       linked list (compound type: llptw)
       p        pointer (compound type: pf, pu)
       n        integer (32 or 16 bits)
       u        unsigned integer (32 or 16 bits)
       sz       NULL-terminated string
       w        word (16 bits)
       y        byte
       v        void
       C        class
       o        object
       tag      name of a structure
       enum     name of a enumeration
       c        variable used to count: for(int ncNum=0; ncNum < 5; ncNum ++)
       m_       member variable of a class
       m        member function of a class
       Atr      function basicaly set value
       Ret      function basicaly get (return) value


MODULES OVERVIEW
----------------

   The program is composed by 3 main modules:

                        Interaction Module

                       (coordenate betweed
                        the other 2 modules
                        and the user)

                   /                           \
                  /                             \
                 /                               \

            Logic Module                      IO+View Module

     (implement the checkers game,       (has the 3D engine,
      has the IA and board control        data loading, user
      using the game rules)               input/output control)

   Each module can be composed by many classes.

   Basicaly to do some thing like a chess or checkers game is needed
   program the rules and actions of the game.
   This is in the Logic Module - implemented in CControl class.
   The Logic Module has one logic board, is one more simple than the
   geometric board. It is used to make more easy implement
   the control operations on the board. The implementarion is one
   8x8 bytes array.

   Logical board diagram:

                (0,0)

                  + - + - + - + -
                  - + - + - + - +
                  + - + - + - + -
                  - + - + - + - +
                  + - + - + - + -    + position where pieces can be
                  - + - + - + - +    - position where pieces can`t be
                  + - + - + - + -

                                (7,7)


   For the 3D visualization the IO+View module has one 3D engine.
   The 3D engine render images for objects composed by polygons,
   but only one object can be loaded at a time.
   Because this limitation, the 3D geometric model of the board and
   all its  pieces, compose one big object.
   To make possible move pieces individualy, the object
   is divided in subsets.
   Each subset is the minimal operational part of the
   object (is possible move or rotate a piece).
   Each of this subsets is called a partition.
   The IO+View Module has the .
   The model is loaded using the class CArquivo3D; data is stored
   in CSolido and CUniverso and viewed using CRender class.

   The Interaction Module update the 3D model acording the logic
   board, control play turns and handle user input.
   Is is implemented in CDamas class.


CLASSES STRUCTURE
-----------------

     Class         Declaration          Description
   hierarchy          File

   CArquivo         arquivo.h    basic text file and binary file access functions
     CArq2D         arq2d.h      PCX files access
     CArq3D         arq3d.h      3D data files access
   CControle        controle.h   logic of the game (IA, rules)
   CControleSolido  contrsol.h   CSolido manipulation (polygons ordenation)
     CControleUniverso  contruni.h  CUniverso manipulation: piece status
   CDamas           damas.h      main module: interaction between user and the rest
   CGrVd            grvd.h       low level video graphics functions
     CGr            gr.h         low level virtual screen graphics functions
   CRender          render.h     high level graphics functions (3D kernel)
   CImagem          imagem.h     bitmaps and palette storage
   CSolido          solido.h     3D model description: vertices, polygons, poly colors
     CUniverso      universo.h   group vertices forming units (called partitions)
   CSr              sr.h         reference system (for geometrical transformations)
   CTransf          transf.h     geometrical transformations: rotation, move, escale
   CTeclado         teclado.h    keyboard handler

   Observations:
      CDamas is an aplication dependent class.
      CControle is a game dependent class.
      CControleUniverso is a 3D model dependent class.

   See the coments in source (*.cc and *.h files) or ask me for details.


BASIC CLASSES RELATIONS
-----------------------

   This diagram is a very simplificated overview of the
   classes relations:
   "What classes are member classes? And for what classes?"

   Example: CUniverso has a member object from CArquivo3D.

                           ---------------
                          |               |
                          |   CArquivo3D  |
                          | (file access) |
                           ---------------
                             |            |
                             |            |
                             |CUniverso   |
                             |(file model)|
                             |            |
                            -------------- -----------
                           |              | CTransf   |
                           |              |-----------------------
                           |              | CSolido (frame model) |
             --------------|   CDamas     |-----------------------
            |              |              |
            | CControle    | (start here) |-----------
            |   (AI)       |              | CSR       |
             --------------|              |-----------------
                           |              |ControleUniverso |
                           /--------------\-----------------
                          /                \
                          |                 |
                          | CControleSolido |
                          | (model ordering)|
                           -----------------


SOURCE FILES DESCRIPTION
------------------------

   ARQ2D.CC         CArquivo2D implementation file
   ARQ2D.H          CArquivo2D declaration file
   ARQ3D.CC         CArquivo3D implementation file
   ARQ3D.H          CArquivo3D declaration file
   ARQUIVO.CC       CArquivo implementation file
   ARQUIVO.H        CArquivo declaration file
   CONTROLE.CC      CControle implementation file
   CONTROLE.H       CControle declaration file
   CONTRSOL.CC      CControleSolido implementation file
   CONTRSOL.H       CControleSolido declaration file
   CONTRUNI.CC      CControleUniverso implementation file
   CONTRUNI.H       CControleUniverso declaration file
   DAMAS.CC         CDamas implementation file
   DAMAS.H          CDamas declaration file
   DEFS.H           general macros
   GR.CC            CGr implementation file
   GR.H             CGr declaration file
   GRVD.CC          CGrVd implementation file
   GRVD.H           CGrVd declaration file
   IMAGEM.CC        CImagem implementation file
   IMAGEM.H         CImagem declaration file
   RENDER.CC        CRender implementation file
   RENDER.H         CRender declaration file
   SOLIDO.CC        CSolido implementation file
   SOLIDO.H         CSolido declaration file
   SR.CC            CSR implementation file
   SR.H             CSR declaration file
   TECLADO.CC       CTeclado implementation file
   TECLADO.H        CTeclado declaration file
   TRANSF.CC        CTransf implementation file
   TRANSF.H         CTransf declaration file
   UNIVERSO.CC      CUniverso implementation file
   UNIVERSO.H       CUniverso declaration file
