SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Filler



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Games
View previous topic :: View next topic  
Author Message
John Doe
Модератор
Модератор


Age: 46
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Tue Jun 24, 2008 4:17 pm    Post subject: Filler Reply with quote

Еще один логический тайм-киллер. Убивайте время на здоровье!
Code:
REPORT  ZFILLER NO STANDARD PAGE HEADING.

TYPES: BEGIN OF WA_MOVE,
         LEFT, RIGHT, UP, DOWN,
       END OF WA_MOVE,
       BEGIN OF WA_COLOR,
         X     TYPE I,
         Y     TYPE I,
         COLOR TYPE I,
         CLAW  TYPE C,
         CHECK TYPE C,
         DISCRX TYPE I,
         DISCRY TYPE I.
INCLUDE TYPE WA_MOVE.
TYPES: END OF WA_COLOR,
       TAB_COLOR TYPE TABLE OF WA_COLOR.
CONSTANTS: HUMAN VALUE 'H',
           ALIEN VALUE 'A'.

DATA: LT_COLORS TYPE TABLE OF WA_COLOR WITH KEY X Y,
      LS_COLOR TYPE WA_COLOR,
      LS_MOVE TYPE WA_MOVE.

DATA: XPOS TYPE I,
      NEXT_COLOR TYPE I.

DATA: HUMAN_COLOR TYPE I,
      ALIEN_COLOR TYPE I,
      TURN.

DATA: RND LIKE  DATATYPE-INTEGER2,
      COMPSUMM TYPE I, HUMSUMM TYPE I.

DATA: X TYPE I, Y TYPE I, L TYPE I.

DATA: ROW TYPE I, COL TYPE I, CONTROL_LINE TYPE I.
DATA: COMPPOINT TYPE TABLE OF WA_COLOR,
      CURRPOINT TYPE WA_COLOR,
      ALX TYPE I, ALY TYPE I,
      SUMM TYPE I, POINTSUMM TYPE I.

DATA: BEGIN OF DIM_COLOR OCCURS 0,
        COLOR TYPE I,
        SUMM  TYPE I,
        STEP  TYPE I,
      END OF DIM_COLOR,
      CURRCOLOR LIKE DIM_COLOR OCCURS 0 WITH HEADER LINE.

DATA: TMP_WA TYPE WA_COLOR,
      TMPX TYPE I, TMPY TYPE I,
      FIELDNAME TYPE STRING.
FIELD-SYMBOLS: <FS>.

PARAMETERS: MIN RADIOBUTTON GROUP SIZE,  "Text: 12*12 fields
            MED RADIOBUTTON GROUP SIZE,  "Text: 24*18 fields
            MAX RADIOBUTTON GROUP SIZE.  "Text: 48*24 fields

DEFINE WRITE_COLOR.
  DATA: FX TYPE I.
  FX = &1 * 2.
  CASE &2.
    WHEN 1. WRITE: AT FX '  ' COLOR 1.
    WHEN 2. WRITE: AT FX '  ' COLOR 2.
    WHEN 3. WRITE: AT FX '  ' COLOR 3.
    WHEN 4. WRITE: AT FX '  ' COLOR 4.
    WHEN 5. WRITE: AT FX '  ' COLOR 5.
    WHEN 6. WRITE: AT FX '  ' COLOR 6.
    WHEN 7. WRITE: AT FX '  ' COLOR 7.
  ENDCASE.
END-OF-DEFINITION.

DEFINE CHECK_COLOR.
  CASE &1.
    WHEN 4 OR 5.   NEXT_COLOR = 1.
    WHEN 12 OR 13. NEXT_COLOR = 2.
    WHEN 20 OR 21. NEXT_COLOR = 3.
    WHEN 28 OR 29. NEXT_COLOR = 4.
    WHEN 36 OR 37. NEXT_COLOR = 5.
    WHEN 44 OR 45. NEXT_COLOR = 6.
    WHEN 52 OR 53. NEXT_COLOR = 7.
  ENDCASE.
END-OF-DEFINITION.

DEFINE WRITE_FRAME.
  X = SY-COLNO. Y = SY-LINNO.
  WRITE: AT /X '|' , &1 COLOR &2 ,  '|' .
  L = SY-COLNO - X - 1.
  Y = Y - 1. SKIP TO LINE Y. POSITION X.
  ULINE AT X(L).
  Y = Y + 2. SKIP TO LINE Y. POSITION X.
  ULINE AT X(L).
  Y = Y - 1. X = SY-COLNO. SKIP TO LINE Y. POSITION X.
END-OF-DEFINITION.

DEFINE CHECK_POSITION.
  CASE &1.
    WHEN 'LEFT'.  TMPX = &2-X - 1.  TMPY = &2-Y.
    WHEN 'RIGHT'. TMPX = &2-X + 1.  TMPY = &2-Y.
    WHEN 'DOWN'.  TMPX = &2-X.  TMPY = &2-Y - 1.
    WHEN 'UP'.    TMPX = &2-X.  TMPY = &2-Y + 1.
  ENDCASE.
  CONCATENATE &3 '-' &1 INTO FIELDNAME.
  ASSIGN (FIELDNAME) TO <FS>.
  CHECK <FS> IS ASSIGNED.
  IF TMPX < 1 OR TMPX > COL OR TMPY < 1 OR TMPY > ROW.
    <FS> = 'X'.
  ELSE.
    READ TABLE &4 INTO TMP_WA WITH KEY X = TMPX Y = TMPY.
    IF SY-SUBRC = 0.
      IF TMP_WA-COLOR = &2-COLOR.
        <FS> = 'X'.
        TMP_WA-COLOR = &2-COLOR.
        TMP_WA-CLAW = &5.
      ENDIF.
      MODIFY &4 FROM TMP_WA
        TRANSPORTING LEFT RIGHT UP DOWN COLOR CLAW
        WHERE X = TMP_WA-X AND Y = TMP_WA-Y.
    ENDIF.
  ENDIF.
END-OF-DEFINITION.


INITIALIZATION.
  TURN = HUMAN.

START-OF-SELECTION.
  SET TITLEBAR 'NEW'. "Text: Filler by John Doe
  PERFORM GENERATE_LEVEL.
  PERFORM DRAW_LEVEL.
  PERFORM GET_COLOR.
  PERFORM CHECK_COMPLETE.

* User-commands processing
AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'COMP_TURN'.
      PERFORM ANALIZE_COLOR TABLES LT_COLORS
                            CHANGING NEXT_COLOR.
      PERFORM SET_COLOR USING ALIEN NEXT_COLOR.
      ALIEN_COLOR = NEXT_COLOR.
      PERFORM DRAW_LEVEL.
      PERFORM CHECK_COMPLETE.
      TURN = HUMAN.

  ENDCASE.

AT LINE-SELECTION.
  CHECK TURN EQ HUMAN.
  CONTROL_LINE = ROW + 5.
  IF SY-LILLI EQ CONTROL_LINE.
    CLEAR NEXT_COLOR.
    XPOS = SY-CUCOL - 1.
    CHECK_COLOR XPOS.
    CHECK NEXT_COLOR IS NOT INITIAL.
    IF NEXT_COLOR = HUMAN_COLOR OR NEXT_COLOR = ALIEN_COLOR.
      MESSAGE 'Can not set this color. Re-select another color.' TYPE 'S'.
      EXIT.
    ENDIF.
    PERFORM SET_COLOR USING HUMAN NEXT_COLOR.
    HUMAN_COLOR = NEXT_COLOR.
    PERFORM DRAW_LEVEL.
    PERFORM CHECK_COMPLETE.

    TURN = ALIEN.
    CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
      PERFORMING TASK_END ON END OF TASK
      EXPORTING
        SECONDS               = 1 " Refresh time
        BUSY_WAITING          = SPACE
      EXCEPTIONS
        RESOURCE_FAILURE      = 1
        COMMUNICATION_FAILURE = 2
        SYSTEM_FAILURE        = 3
        OTHERS                = 4.

  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  TASK_END
*&---------------------------------------------------------------------*
FORM TASK_END USING TASK.
  SET USER-COMMAND 'COMP_TURN'.
ENDFORM.                    "TASK_END

*&---------------------------------------------------------------------*
*&      Form  CREATE_LEVEL
*&---------------------------------------------------------------------*
FORM GENERATE_LEVEL.
  DATA: PV1 TYPE I, PV2 TYPE P,
        VALUE TYPE P DECIMALS 2.
  IF MIN IS NOT INITIAL.
    ROW = 12. COL = 12.
  ELSEIF MED IS NOT INITIAL.
    ROW = 18. COL = 24.
  ELSEIF MAX IS NOT INITIAL.
    ROW = 24. COL = 48.
  ENDIF.
  DO ROW TIMES.
    LS_COLOR-Y = LS_COLOR-Y + 1.
    CLEAR LS_COLOR-X.
    DO COL TIMES.
      LS_COLOR-X = LS_COLOR-X + 1.
      CALL FUNCTION 'RANDOM_I2'
        EXPORTING
          RND_MIN   = 1
          RND_MAX   = 7
        IMPORTING
          RND_VALUE = RND.
      LS_COLOR-COLOR = RND.

      VALUE = LS_COLOR-X / 4.
      PV1 = TRUNC( VALUE ).
      PV2 = LS_COLOR-X MOD 4.
      IF PV2 IS NOT INITIAL.
        LS_COLOR-DISCRX = PV1 + 1.
      ELSE.
        LS_COLOR-DISCRX = PV1.
      ENDIF.

      VALUE = LS_COLOR-Y / 4.
      PV1 = TRUNC( VALUE ).
      PV2 = LS_COLOR-Y MOD 4.
      IF PV2 IS NOT INITIAL.
        LS_COLOR-DISCRY = PV1 + 1.
      ELSE.
        LS_COLOR-DISCRY = PV1.
      ENDIF.

      APPEND LS_COLOR TO LT_COLORS.
    ENDDO.
  ENDDO.

* Check colors are different.
  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = COL Y = 1.
  ALIEN_COLOR = LS_COLOR-COLOR.

  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = 1 Y = ROW.
  HUMAN_COLOR = LS_COLOR-COLOR.

  WHILE ALIEN_COLOR = HUMAN_COLOR.
    CALL FUNCTION 'RANDOM_I2'
      EXPORTING
        RND_MIN   = 1
        RND_MAX   = 7
      IMPORTING
        RND_VALUE = RND.
    HUMAN_COLOR = RND.
  ENDWHILE.

  LS_COLOR-COLOR = HUMAN_COLOR.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.

  DESCRIBE TABLE LT_COLORS LINES POINTSUMM.

ENDFORM.                    " CREATE_LEVEL

*&---------------------------------------------------------------------*
*&      Form  DRAW_LEVEL
*&---------------------------------------------------------------------*
FORM DRAW_LEVEL .
  DATA: NX TYPE I,
        YPOS TYPE I,
        CURR_Y TYPE I.

  SY-LSIND = 0.
* Create color level
  SORT LT_COLORS BY Y X.
  L = COL * 2 + 2.
  ULINE AT 1(L).
  LOOP AT LT_COLORS INTO LS_COLOR.
    IF LS_COLOR-Y <> CURR_Y .
      WRITE AT 1 '|'.
      CURR_Y = LS_COLOR-Y.
    ENDIF.
    YPOS = LS_COLOR-Y + 1.
    SKIP TO LINE YPOS.
    POSITION LS_COLOR-X.
    WRITE_COLOR LS_COLOR-X LS_COLOR-COLOR.
    NX = LS_COLOR-X * 2 + 2.
    WRITE AT NX '|'.
  ENDLOOP.
  POSITION 1. WRITE '|'. NEW-LINE.
  ULINE AT 1(L).

* Set color for selection
  WRITE: /, /.
  IF ALIEN_COLOR NE 1 AND HUMAN_COLOR NE 1.
    SY-COLNO = 2. WRITE_FRAME '  ' 1.
  ENDIF.
  IF ALIEN_COLOR NE 2 AND HUMAN_COLOR NE 2.
    SY-COLNO = 10. WRITE_FRAME '  ' 2.
  ENDIF.
  IF ALIEN_COLOR NE 3 AND HUMAN_COLOR NE 3.
    SY-COLNO = 18. WRITE_FRAME '  ' 3.
  ENDIF.
  IF ALIEN_COLOR NE 4 AND HUMAN_COLOR NE 4.
    SY-COLNO = 26. WRITE_FRAME '  ' 4.
  ENDIF.
  IF ALIEN_COLOR NE 5 AND HUMAN_COLOR NE 5.
    SY-COLNO = 34. WRITE_FRAME '  ' 5.
  ENDIF.
  IF ALIEN_COLOR NE 6 AND HUMAN_COLOR NE 6.
    SY-COLNO = 42. WRITE_FRAME '  ' 6.
  ENDIF.
  IF ALIEN_COLOR NE 7 AND HUMAN_COLOR NE 7.
    SY-COLNO = 50. WRITE_FRAME '  ' 7.
  ENDIF.

ENDFORM.                    " DRAW_LEVEL


*&---------------------------------------------------------------------*
*&      Form  FILL_COLOR
*&---------------------------------------------------------------------*
FORM FILL_COLOR  USING    CLAW.
  DATA: FLAG.
  CLEAR FLAG.
  WHILE FLAG IS INITIAL.
    FLAG = 'X'.
    LOOP AT LT_COLORS INTO LS_COLOR
      WHERE CLAW = CLAW AND CHECK IS INITIAL.
      MOVE-CORRESPONDING LS_COLOR TO LS_MOVE.
      CLEAR FLAG.
      " Check position
      IF LS_MOVE NE 'XXXX'.
        CHECK_POSITION 'LEFT' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'RIGHT' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'DOWN' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'UP' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
      ENDIF.
      LS_COLOR-CHECK = 'X'.
      MODIFY LT_COLORS FROM LS_COLOR.
    ENDLOOP.
  ENDWHILE.
  LS_COLOR-CHECK = SPACE.
  MODIFY LT_COLORS FROM LS_COLOR TRANSPORTING CHECK
    WHERE CLAW = CLAW.
ENDFORM.                    " FILL_COLOR


*&---------------------------------------------------------------------*
*&      Form  GET_COLOR
*&---------------------------------------------------------------------*
FORM GET_COLOR .
* Get current colors.
  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = COL Y = 1.
  ALIEN_COLOR = LS_COLOR-COLOR.
  LS_COLOR-CLAW = ALIEN.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.
  PERFORM FILL_COLOR USING ALIEN.

  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = 1 Y = ROW.
  HUMAN_COLOR = LS_COLOR-COLOR.
  LS_COLOR-CLAW = HUMAN.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.
  PERFORM FILL_COLOR USING HUMAN.
ENDFORM.                    " GET_COLOR


*&---------------------------------------------------------------------*
*&      Form  SET_COLOR
*&---------------------------------------------------------------------*
FORM SET_COLOR USING CLAW COLOR.
  LOOP AT LT_COLORS INTO LS_COLOR WHERE CLAW = CLAW.
    LS_COLOR-COLOR = COLOR.
    MODIFY LT_COLORS FROM LS_COLOR.
  ENDLOOP.
  PERFORM FILL_COLOR USING CLAW.
ENDFORM.                    " SET_COLOR


*&---------------------------------------------------------------------*
*&      Form  ANALIZE_COLOR
*&---------------------------------------------------------------------*
FORM ANALIZE_COLOR  TABLES DIMDATA TYPE TAB_COLOR
                    CHANGING P_NEXT_COLOR.

  DATA: FLAG, XLINE TYPE I, ALIENSUMM TYPE I.
  DATA: COLORTAB TYPE TAB_COLOR.

  CLEAR FLAG.

  CLEAR P_NEXT_COLOR.
  LOOP AT DIMDATA INTO LS_COLOR
    WHERE CLAW EQ ALIEN.
    ALIENSUMM = ALIENSUMM + 1.
    APPEND LS_COLOR TO COLORTAB.
  ENDLOOP.

  SORT COLORTAB BY DISCRX DISCRY.
  DELETE ADJACENT DUPLICATES FROM COLORTAB COMPARING DISCRX DISCRY.

  LOOP AT COLORTAB INTO CURRPOINT.
    ALX = CURRPOINT-DISCRX.
    ALY = CURRPOINT-DISCRY.
    LOOP AT DIMDATA INTO LS_COLOR
      WHERE DISCRX EQ ALX AND DISCRY EQ ALY
      AND   CLAW EQ SPACE.
      CURRCOLOR-COLOR = LS_COLOR-COLOR.
      APPEND CURRCOLOR.
    ENDLOOP.
  ENDLOOP.
  SORT CURRCOLOR BY COLOR.

  LOOP AT CURRCOLOR.
    SUMM = SUMM + 1.
    AT END OF COLOR.
      DIM_COLOR-COLOR = CURRCOLOR-COLOR.
      DIM_COLOR-SUMM = SUMM.
      APPEND DIM_COLOR.
      CLEAR SUMM.
    ENDAT.
  ENDLOOP.

  LOOP AT DIM_COLOR.
    COMPPOINT[] = DIMDATA[].
    CLEAR FLAG.
    WHILE FLAG IS INITIAL.
      FLAG = 'X'.
      LOOP AT COMPPOINT INTO CURRPOINT
        WHERE CLAW = ALIEN
        AND ( UP IS INITIAL OR DOWN IS INITIAL
                OR LEFT IS INITIAL OR RIGHT IS INITIAL )
        AND CHECK IS INITIAL.
        CLEAR FLAG.
        CURRPOINT-COLOR = DIM_COLOR-COLOR.
        CHECK_POSITION 'LEFT' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'RIGHT' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'DOWN' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'UP' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CURRPOINT-CHECK = 'X'.
        MODIFY COMPPOINT FROM CURRPOINT.
      ENDLOOP.
    ENDWHILE.

    DELETE COMPPOINT WHERE CLAW NE ALIEN.
    DESCRIBE TABLE COMPPOINT LINES XLINE.
    DIM_COLOR-STEP = XLINE - ALIENSUMM.
    MODIFY DIM_COLOR.
  ENDLOOP.

  DELETE DIM_COLOR WHERE COLOR EQ ALIEN_COLOR.
  DELETE DIM_COLOR WHERE COLOR EQ HUMAN_COLOR.
  SORT DIM_COLOR BY STEP DESCENDING.
  READ TABLE DIM_COLOR INDEX 1.
  IF SY-SUBRC IS INITIAL.
    P_NEXT_COLOR = DIM_COLOR-COLOR.
  ENDIF.
ENDFORM.                    " ANALIZE_COLOR


*&---------------------------------------------------------------------*
*&      Form  CHECK_COMPLETE
*&---------------------------------------------------------------------*
FORM CHECK_COMPLETE .
  DATA: FULLHUMSUMM TYPE I,
        FULLCOMPSUM TYPE I.
  DATA: WIN.

  CLEAR: COMPSUMM, HUMSUMM.
  LOOP AT LT_COLORS INTO LS_COLOR.
    IF LS_COLOR-CLAW EQ HUMAN.
      HUMSUMM = HUMSUMM + 1.
    ELSEIF LS_COLOR-CLAW EQ ALIEN.
      COMPSUMM = COMPSUMM + 1.
    ENDIF.
  ENDLOOP.

  DATA: XTEXT TYPE STRING,
        PROC TYPE P DECIMALS 2,
        TPROC TYPE STRING.
  SKIP TO LINE 2.
  MOVE HUMSUMM TO XTEXT.
  PROC = HUMSUMM / POINTSUMM * 100. MOVE PROC TO TPROC.
  IF PROC > '50.00'.
    WIN = HUMAN.
  ENDIF.
  CONCATENATE TPROC '%' INTO TPROC.
  CONCATENATE 'Human:' XTEXT '/' TPROC
    INTO XTEXT SEPARATED BY SPACE.
  SY-COLNO = COL * 2 + 6.
  PERFORM WRITE_COLOR_BOX USING HUMAN_COLOR.
  SY-COLNO = COL * 2 + 14. WRITE_FRAME XTEXT 2.

  SKIP TO LINE 5.
  MOVE COMPSUMM TO XTEXT.
  PROC = COMPSUMM / POINTSUMM * 100. MOVE PROC TO TPROC.
  IF PROC > '50.00'.
    WIN = ALIEN.
  ENDIF.
  CONCATENATE TPROC '%' INTO TPROC.
  CONCATENATE 'Computer:' XTEXT '/' TPROC
    INTO XTEXT SEPARATED BY SPACE.
  SY-COLNO = COL * 2 + 6.
  PERFORM WRITE_COLOR_BOX USING ALIEN_COLOR.
  SY-COLNO = COL * 2 + 14. WRITE_FRAME XTEXT 2.

  IF WIN = HUMAN.
    MESSAGE 'Human win!' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ELSEIF WIN = ALIEN.
    MESSAGE 'Computer win!' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " CHECK_COMPLETE

*&---------------------------------------------------------------------*
*&      Form  WRITE_COLOR_BOX
*&---------------------------------------------------------------------*
FORM WRITE_COLOR_BOX  USING    COLOR.
  CASE COLOR.
    WHEN 1. WRITE_FRAME '  ' 1.
    WHEN 2. WRITE_FRAME '  ' 2.
    WHEN 3. WRITE_FRAME '  ' 3.
    WHEN 4. WRITE_FRAME '  ' 4.
    WHEN 5. WRITE_FRAME '  ' 5.
    WHEN 6. WRITE_FRAME '  ' 6.
    WHEN 7. WRITE_FRAME '  ' 7.
  ENDCASE.
ENDFORM.                    " WRITE_COLOR_BOX
Back to top
View user's profile Send private message Blog
Armann
Модератор
Модератор



Joined: 01 Jan 2008
Posts: 422
Location: Moscow

PostPosted: Wed Jun 25, 2008 1:03 pm    Post subject: Reply with quote

А можно сюда скриншот выкласть? Smile или на мыло...
а то я на 4 версию вроде портировал, но как оно выглядит странно. Хотя мож так и должно Wink
Back to top
View user's profile Send private message Blog
vga
Мастер
Мастер


Age: 70
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Wed Jun 25, 2008 1:23 pm    Post subject: Reply with quote

Так у Андрея в блоге и скриншоты и комментарии.
Back to top
View user's profile Send private message Blog Visit poster's website
Armann
Модератор
Модератор



Joined: 01 Jan 2008
Posts: 422
Location: Moscow

PostPosted: Wed Jun 25, 2008 1:34 pm    Post subject: Reply with quote

vga wrote:
Так у Андрея в блоге и скриншоты и комментарии.

а блин, точно...
у нас закрыт content.foto.mail.ru, там вместо рисунка гордая надпись 'Рисунок' Smile спасиб, дома гляну
Back to top
View user's profile Send private message Blog
vga
Мастер
Мастер


Age: 70
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Wed Jun 25, 2008 11:09 pm    Post subject: Reply with quote

Андрей, как понял, при захвате новых клеток, программа анализирует количество клеток одного цвета, граничащих с уже захваченным полем и выбирает тот цвет, клеток которого больше. При этом весовой коэффициент каждой клетки = 1. Предложение, ввести весовые коэффициетны для клеток, чтобы они возрастали по направлению к полям противника, например так, как на рисунке и захватывали не менее 50% своей территории. Таким образом при анализе следующего хода будет учитываться не только количество клеток одного цвета, но и их расположение.
В качестве весового коэф. например использовать TYPE f в интервале от 0 до 1. Для описания подобрать какую-нибудь математическую функцию... вроде на параболу похоже.

Вторым этапом коррекция весовых коэффициентов в зависимости от действий противника. Если противник продвигается более интенсивно в одном из направлений, пытаться перекрыть это направление, выставляяя более высокие весовые коэф. этому флангу, чтобы он не прорвался в вашу 50% зону.

На войне, как на войне Smile



filler.jpg
 Description:
 Filesize:  27.05 KB
 Viewed:  50538 Time(s)

filler.jpg


Back to top
View user's profile Send private message Blog Visit poster's website
John Doe
Модератор
Модератор


Age: 46
Joined: 05 Nov 2007
Posts: 725
Location: КраснАдар

PostPosted: Wed Aug 06, 2008 3:03 pm    Post subject: Reply with quote

Чуть улучшил алгоритм захвата. Вот новая версия:
Code:
TYPES: BEGIN OF WA_MOVE,
         LEFT, RIGHT, UP, DOWN,
       END OF WA_MOVE,
       BEGIN OF WA_COLOR,
         X     TYPE I,
         Y     TYPE I,
         COLOR TYPE I,
         CLAW  TYPE C,
         CHECK TYPE C,
         DISCRX TYPE I,
         DISCRY TYPE I,
         COST  TYPE P DECIMALS 1.
INCLUDE TYPE WA_MOVE.
TYPES: END OF WA_COLOR,
       TAB_COLOR TYPE TABLE OF WA_COLOR.
CONSTANTS: HUMAN VALUE 'H',
           ALIEN VALUE 'A'.

DATA: LT_COLORS TYPE TABLE OF WA_COLOR WITH KEY X Y,
      LS_COLOR TYPE WA_COLOR,
      LS_MOVE TYPE WA_MOVE.

DATA: XPOS TYPE I,
      NEXT_COLOR TYPE I.

DATA: HUMAN_COLOR TYPE I,
      ALIEN_COLOR TYPE I,
      TURN.

DATA: RND LIKE  DATATYPE-INTEGER2,
      COMPSUMM TYPE I, HUMSUMM TYPE I.

DATA: X TYPE I, Y TYPE I, L TYPE I.

DATA: ROW TYPE I, COL TYPE I, CONTROL_LINE TYPE I.
DATA: COMPPOINT TYPE TABLE OF WA_COLOR,
      CURRPOINT TYPE WA_COLOR,
      ALX TYPE I, ALY TYPE I,
      SUMM TYPE I, POINTSUMM TYPE I.

DATA: BEGIN OF DIM_COLOR OCCURS 0,
        COLOR TYPE I,
        SUMM  TYPE I,
        STEP  TYPE I,
        COST  TYPE I,
      END OF DIM_COLOR,
      CURRCOLOR LIKE DIM_COLOR OCCURS 0 WITH HEADER LINE.

DATA: TMP_WA TYPE WA_COLOR,
      TMPX TYPE I, TMPY TYPE I,
      FIELDNAME TYPE STRING.
FIELD-SYMBOLS: <FS>.

DATA: X1 TYPE I, X2 TYPE I, X3 TYPE I,
      Y1 TYPE I, Y2 TYPE I, Y3 TYPE I.
DATA: IN.

PARAMETERS: MIN RADIOBUTTON GROUP SIZE,  "Text: 12*12 fields
            MED RADIOBUTTON GROUP SIZE,  "Text: 24*18 fields
            MAX RADIOBUTTON GROUP SIZE.  "Text: 48*24 fields

DEFINE WRITE_COLOR.
  DATA: FX TYPE I.
  FX = &1 * 2.
  CASE &2.
    WHEN 1. WRITE: AT FX '  ' COLOR 1.
    WHEN 2. WRITE: AT FX '  ' COLOR 2.
    WHEN 3. WRITE: AT FX '  ' COLOR 3.
    WHEN 4. WRITE: AT FX '  ' COLOR 4.
    WHEN 5. WRITE: AT FX '  ' COLOR 5.
    WHEN 6. WRITE: AT FX '  ' COLOR 6.
    WHEN 7. WRITE: AT FX '  ' COLOR 7.
  ENDCASE.
END-OF-DEFINITION.

DEFINE CHECK_COLOR.
  CASE &1.
    WHEN 4 OR 5.   NEXT_COLOR = 1.
    WHEN 12 OR 13. NEXT_COLOR = 2.
    WHEN 20 OR 21. NEXT_COLOR = 3.
    WHEN 28 OR 29. NEXT_COLOR = 4.
    WHEN 36 OR 37. NEXT_COLOR = 5.
    WHEN 44 OR 45. NEXT_COLOR = 6.
    WHEN 52 OR 53. NEXT_COLOR = 7.
  ENDCASE.
END-OF-DEFINITION.

DEFINE WRITE_FRAME.
  X = SY-COLNO. Y = SY-LINNO.
  WRITE: AT /X '|' , &1 COLOR &2 ,  '|' .
  L = SY-COLNO - X - 1.
  Y = Y - 1. SKIP TO LINE Y. POSITION X.
  ULINE AT X(L).
  Y = Y + 2. SKIP TO LINE Y. POSITION X.
  ULINE AT X(L).
  Y = Y - 1. X = SY-COLNO. SKIP TO LINE Y. POSITION X.
END-OF-DEFINITION.

DEFINE CHECK_POSITION.
  CASE &1.
    WHEN 'LEFT'.  TMPX = &2-X - 1.  TMPY = &2-Y.
    WHEN 'RIGHT'. TMPX = &2-X + 1.  TMPY = &2-Y.
    WHEN 'DOWN'.  TMPX = &2-X.  TMPY = &2-Y - 1.
    WHEN 'UP'.    TMPX = &2-X.  TMPY = &2-Y + 1.
  ENDCASE.
  CONCATENATE &3 '-' &1 INTO FIELDNAME.
  ASSIGN (FIELDNAME) TO <FS>.
  CHECK <FS> IS ASSIGNED.
  IF TMPX < 1 OR TMPX > COL OR TMPY < 1 OR TMPY > ROW.
    <FS> = 'X'.
  ELSE.
    READ TABLE &4 INTO TMP_WA WITH KEY X = TMPX Y = TMPY.
    IF SY-SUBRC = 0.
      IF TMP_WA-COLOR = &2-COLOR.
        <FS> = 'X'.
        TMP_WA-COLOR = &2-COLOR.
        TMP_WA-CLAW = &5.
      ENDIF.

      CLEAR IN.
      PERFORM GET_POINT_COST USING TMPX TMPY
                             CHANGING IN.
      IF IN IS NOT INITIAL.
        TMP_WA-COST = '1.5'.
      ELSE.
        TMP_WA-COST = 1.
      ENDIF.

      MODIFY &4 FROM TMP_WA
        TRANSPORTING LEFT RIGHT UP DOWN COLOR CLAW
        WHERE X = TMP_WA-X AND Y = TMP_WA-Y.
    ENDIF.
  ENDIF.
END-OF-DEFINITION.


INITIALIZATION.
  TURN = HUMAN.

START-OF-SELECTION.
  SET TITLEBAR 'NEW'. "Text: Filler by John Doe
  PERFORM GENERATE_LEVEL.
  PERFORM DRAW_LEVEL.
  PERFORM GET_COLOR.
  PERFORM CHECK_COMPLETE.

* User-commands processing
AT USER-COMMAND.
  CASE SY-UCOMM.
    WHEN 'COMP_TURN'.
      PERFORM ANALIZE_COLOR TABLES LT_COLORS
                            CHANGING NEXT_COLOR.
      PERFORM SET_COLOR USING ALIEN NEXT_COLOR.
      ALIEN_COLOR = NEXT_COLOR.
      PERFORM DRAW_LEVEL.
      PERFORM CHECK_COMPLETE.
      TURN = HUMAN.

  ENDCASE.

AT LINE-SELECTION.
  CHECK TURN EQ HUMAN.
  CONTROL_LINE = ROW + 5.
  IF SY-LILLI EQ CONTROL_LINE.
    CLEAR NEXT_COLOR.
    XPOS = SY-CUCOL - 1.
    CHECK_COLOR XPOS.
    CHECK NEXT_COLOR IS NOT INITIAL.
    IF NEXT_COLOR = HUMAN_COLOR OR NEXT_COLOR = ALIEN_COLOR.
      MESSAGE 'Can not set this color. Re-select another color.' TYPE 'S'.
      EXIT.
    ENDIF.
    PERFORM SET_COLOR USING HUMAN NEXT_COLOR.
    HUMAN_COLOR = NEXT_COLOR.
    PERFORM DRAW_LEVEL.
    PERFORM CHECK_COMPLETE.

    TURN = ALIEN.
    CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
      PERFORMING TASK_END ON END OF TASK
      EXPORTING
        SECONDS               = 1 " Refresh time
        BUSY_WAITING          = SPACE
      EXCEPTIONS
        RESOURCE_FAILURE      = 1
        COMMUNICATION_FAILURE = 2
        SYSTEM_FAILURE        = 3
        OTHERS                = 4.

  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  TASK_END
*&---------------------------------------------------------------------*
FORM TASK_END USING TASK.
  SET USER-COMMAND 'COMP_TURN'.
ENDFORM.                    "TASK_END

*&---------------------------------------------------------------------*
*&      Form  CREATE_LEVEL
*&---------------------------------------------------------------------*
FORM GENERATE_LEVEL.
  DATA: PV1 TYPE I, PV2 TYPE P,
        VALUE TYPE P DECIMALS 2.
  IF MIN IS NOT INITIAL.
    ROW = 12. COL = 12.
  ELSEIF MED IS NOT INITIAL.
    ROW = 18. COL = 24.
  ELSEIF MAX IS NOT INITIAL.
    ROW = 24. COL = 48.
  ENDIF.
  DO ROW TIMES.
    LS_COLOR-Y = LS_COLOR-Y + 1.
    CLEAR LS_COLOR-X.
    DO COL TIMES.
      LS_COLOR-X = LS_COLOR-X + 1.
      CALL FUNCTION 'RANDOM_I2'
        EXPORTING
          RND_MIN   = 1
          RND_MAX   = 7
        IMPORTING
          RND_VALUE = RND.
      LS_COLOR-COLOR = RND.

      VALUE = LS_COLOR-X / 4.
      PV1 = TRUNC( VALUE ).
      PV2 = LS_COLOR-X MOD 4.
      IF PV2 IS NOT INITIAL.
        LS_COLOR-DISCRX = PV1 + 1.
      ELSE.
        LS_COLOR-DISCRX = PV1.
      ENDIF.

      VALUE = LS_COLOR-Y / 4.
      PV1 = TRUNC( VALUE ).
      PV2 = LS_COLOR-Y MOD 4.
      IF PV2 IS NOT INITIAL.
        LS_COLOR-DISCRY = PV1 + 1.
      ELSE.
        LS_COLOR-DISCRY = PV1.
      ENDIF.

      APPEND LS_COLOR TO LT_COLORS.
    ENDDO.
  ENDDO.

* Check colors are different.
  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = COL Y = 1.
  ALIEN_COLOR = LS_COLOR-COLOR.

  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = 1 Y = ROW.
  HUMAN_COLOR = LS_COLOR-COLOR.

  WHILE ALIEN_COLOR = HUMAN_COLOR.
    CALL FUNCTION 'RANDOM_I2'
      EXPORTING
        RND_MIN   = 1
        RND_MAX   = 7
      IMPORTING
        RND_VALUE = RND.
    HUMAN_COLOR = RND.
  ENDWHILE.

  LS_COLOR-COLOR = HUMAN_COLOR.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.

  DESCRIBE TABLE LT_COLORS LINES POINTSUMM.

ENDFORM.                    " CREATE_LEVEL

*&---------------------------------------------------------------------*
*&      Form  DRAW_LEVEL
*&---------------------------------------------------------------------*
FORM DRAW_LEVEL .
  DATA: NX TYPE I,
        YPOS TYPE I,
        CURR_Y TYPE I.

  SY-LSIND = 0.
* Create color level
  SORT LT_COLORS BY Y X.
  L = COL * 2 + 2.
  ULINE AT 1(L).
  LOOP AT LT_COLORS INTO LS_COLOR.
    IF LS_COLOR-Y <> CURR_Y .
      WRITE AT 1 '|'.
      CURR_Y = LS_COLOR-Y.
    ENDIF.
    YPOS = LS_COLOR-Y + 1.
    SKIP TO LINE YPOS.
    POSITION LS_COLOR-X.
    WRITE_COLOR LS_COLOR-X LS_COLOR-COLOR.
    NX = LS_COLOR-X * 2 + 2.
    WRITE AT NX '|'.
  ENDLOOP.
  POSITION 1. WRITE '|'. NEW-LINE.
  ULINE AT 1(L).

* Set color for selection
  WRITE: /, /.
  IF ALIEN_COLOR NE 1 AND HUMAN_COLOR NE 1.
    SY-COLNO = 2. WRITE_FRAME '  ' 1.
  ENDIF.
  IF ALIEN_COLOR NE 2 AND HUMAN_COLOR NE 2.
    SY-COLNO = 10. WRITE_FRAME '  ' 2.
  ENDIF.
  IF ALIEN_COLOR NE 3 AND HUMAN_COLOR NE 3.
    SY-COLNO = 18. WRITE_FRAME '  ' 3.
  ENDIF.
  IF ALIEN_COLOR NE 4 AND HUMAN_COLOR NE 4.
    SY-COLNO = 26. WRITE_FRAME '  ' 4.
  ENDIF.
  IF ALIEN_COLOR NE 5 AND HUMAN_COLOR NE 5.
    SY-COLNO = 34. WRITE_FRAME '  ' 5.
  ENDIF.
  IF ALIEN_COLOR NE 6 AND HUMAN_COLOR NE 6.
    SY-COLNO = 42. WRITE_FRAME '  ' 6.
  ENDIF.
  IF ALIEN_COLOR NE 7 AND HUMAN_COLOR NE 7.
    SY-COLNO = 50. WRITE_FRAME '  ' 7.
  ENDIF.

ENDFORM.                    " DRAW_LEVEL


*&---------------------------------------------------------------------*
*&      Form  FILL_COLOR
*&---------------------------------------------------------------------*
FORM FILL_COLOR  USING    CLAW.
  DATA: FLAG.
  CLEAR FLAG.
  WHILE FLAG IS INITIAL.
    FLAG = 'X'.
    LOOP AT LT_COLORS INTO LS_COLOR
      WHERE CLAW = CLAW AND CHECK IS INITIAL.
      MOVE-CORRESPONDING LS_COLOR TO LS_MOVE.
      CLEAR FLAG.
      " Check position
      IF LS_MOVE NE 'XXXX'.
        CHECK_POSITION 'LEFT' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'RIGHT' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'DOWN' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
        CHECK_POSITION 'UP' LS_COLOR 'LS_COLOR' LT_COLORS CLAW.
      ENDIF.
      LS_COLOR-CHECK = 'X'.
      MODIFY LT_COLORS FROM LS_COLOR.
    ENDLOOP.
  ENDWHILE.
  LS_COLOR-CHECK = SPACE.
  MODIFY LT_COLORS FROM LS_COLOR TRANSPORTING CHECK
    WHERE CLAW = CLAW.
ENDFORM.                    " FILL_COLOR


*&---------------------------------------------------------------------*
*&      Form  GET_COLOR
*&---------------------------------------------------------------------*
FORM GET_COLOR .
* Get current colors.
  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = COL Y = 1.
  ALIEN_COLOR = LS_COLOR-COLOR.
  LS_COLOR-CLAW = ALIEN.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.
  PERFORM FILL_COLOR USING ALIEN.

  READ TABLE LT_COLORS INTO LS_COLOR WITH KEY X = 1 Y = ROW.
  HUMAN_COLOR = LS_COLOR-COLOR.
  LS_COLOR-CLAW = HUMAN.
  MODIFY TABLE LT_COLORS FROM LS_COLOR.
  PERFORM FILL_COLOR USING HUMAN.
ENDFORM.                    " GET_COLOR


*&---------------------------------------------------------------------*
*&      Form  SET_COLOR
*&---------------------------------------------------------------------*
FORM SET_COLOR USING CLAW COLOR.
  LOOP AT LT_COLORS INTO LS_COLOR WHERE CLAW = CLAW.
    LS_COLOR-COLOR = COLOR.
    MODIFY LT_COLORS FROM LS_COLOR.
  ENDLOOP.
  PERFORM FILL_COLOR USING CLAW.
ENDFORM.                    " SET_COLOR


*&---------------------------------------------------------------------*
*&      Form  ANALIZE_COLOR
*&---------------------------------------------------------------------*
FORM ANALIZE_COLOR  TABLES DIMDATA TYPE TAB_COLOR
                    CHANGING P_NEXT_COLOR.

  DATA: FLAG, XLINE TYPE I, ALIENSUMM TYPE I.
  DATA: COLORTAB TYPE TAB_COLOR.

  CLEAR FLAG.

  CLEAR P_NEXT_COLOR.
  LOOP AT DIMDATA INTO LS_COLOR
    WHERE CLAW EQ ALIEN.
    ALIENSUMM = ALIENSUMM + 1.
    APPEND LS_COLOR TO COLORTAB.
  ENDLOOP.

  SORT COLORTAB BY DISCRX DISCRY.
  DELETE ADJACENT DUPLICATES FROM COLORTAB COMPARING DISCRX DISCRY.

  LOOP AT COLORTAB INTO CURRPOINT.
    ALX = CURRPOINT-DISCRX.
    ALY = CURRPOINT-DISCRY.
    LOOP AT DIMDATA INTO LS_COLOR
      WHERE DISCRX EQ ALX AND DISCRY EQ ALY
      AND   CLAW NE ALIEN. "EQ SPACE.
      CURRCOLOR-COLOR = LS_COLOR-COLOR.
      APPEND CURRCOLOR.
    ENDLOOP.
  ENDLOOP.
  SORT CURRCOLOR BY COLOR.

  LOOP AT CURRCOLOR.
    SUMM = SUMM + 1.
    AT END OF COLOR.
      DIM_COLOR-COLOR = CURRCOLOR-COLOR.
      DIM_COLOR-SUMM = SUMM.
      APPEND DIM_COLOR.
      CLEAR SUMM.
    ENDAT.
  ENDLOOP.

  LOOP AT DIM_COLOR.
    COMPPOINT[] = DIMDATA[].
    CLEAR FLAG.
    WHILE FLAG IS INITIAL.
      FLAG = 'X'.
      LOOP AT COMPPOINT INTO CURRPOINT
        WHERE CLAW = ALIEN
        AND ( UP IS INITIAL OR DOWN IS INITIAL
                OR LEFT IS INITIAL OR RIGHT IS INITIAL )
        AND CHECK IS INITIAL.
        CLEAR FLAG.
        CURRPOINT-COLOR = DIM_COLOR-COLOR.
        CHECK_POSITION 'LEFT' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'RIGHT' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'DOWN' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CHECK_POSITION 'UP' CURRPOINT 'CURRPOINT' COMPPOINT ALIEN.
        CURRPOINT-CHECK = 'X'.
        MODIFY COMPPOINT FROM CURRPOINT TRANSPORTING CHECK.
      ENDLOOP.
    ENDWHILE.

    DELETE COMPPOINT WHERE CLAW NE ALIEN.
    DESCRIBE TABLE COMPPOINT LINES XLINE.
    DIM_COLOR-STEP = XLINE - ALIENSUMM.
    CLEAR DIM_COLOR-COST.
    LOOP AT COMPPOINT INTO CURRPOINT.
      DIM_COLOR-COST = DIM_COLOR-COST + CURRPOINT-COST.
    ENDLOOP.
    MODIFY DIM_COLOR.
  ENDLOOP.

  DELETE DIM_COLOR WHERE COLOR EQ ALIEN_COLOR.
  DELETE DIM_COLOR WHERE COLOR EQ HUMAN_COLOR.

  DATA: MOSTPOINT LIKE DIM_COLOR,
        MOSTCOST LIKE DIM_COLOR.

  SORT DIM_COLOR BY STEP DESCENDING.
  READ TABLE DIM_COLOR INTO MOSTPOINT INDEX 1.

  SORT DIM_COLOR BY COST DESCENDING.
  READ TABLE DIM_COLOR INTO MOSTCOST INDEX 1.

  IF MOSTPOINT-STEP > MOSTCOST-COST.
    P_NEXT_COLOR = MOSTPOINT-COLOR.
  ELSE.
    P_NEXT_COLOR = MOSTCOST-COLOR.
  ENDIF.
ENDFORM.                    " ANALIZE_COLOR


*&---------------------------------------------------------------------*
*&      Form  CHECK_COMPLETE
*&---------------------------------------------------------------------*
FORM CHECK_COMPLETE .
  DATA: FULLHUMSUMM TYPE I,
        FULLCOMPSUM TYPE I.
  DATA: WIN.

  CLEAR: COMPSUMM, HUMSUMM.
  LOOP AT LT_COLORS INTO LS_COLOR.
    IF LS_COLOR-CLAW EQ HUMAN.
      HUMSUMM = HUMSUMM + 1.
    ELSEIF LS_COLOR-CLAW EQ ALIEN.
      COMPSUMM = COMPSUMM + 1.
    ENDIF.
  ENDLOOP.

  DATA: XTEXT TYPE STRING,
        PROC TYPE P DECIMALS 2,
        TPROC TYPE STRING.
  SKIP TO LINE 2.
  MOVE HUMSUMM TO XTEXT.
  PROC = HUMSUMM / POINTSUMM * 100. MOVE PROC TO TPROC.
  IF PROC > '50.00'.
    WIN = HUMAN.
  ENDIF.
  CONCATENATE TPROC '%' INTO TPROC.
  CONCATENATE 'Human:' XTEXT '/' TPROC
    INTO XTEXT SEPARATED BY SPACE.
  SY-COLNO = COL * 2 + 6.
  PERFORM WRITE_COLOR_BOX USING HUMAN_COLOR.
  SY-COLNO = COL * 2 + 14. WRITE_FRAME XTEXT 2.

  SKIP TO LINE 5.
  MOVE COMPSUMM TO XTEXT.
  PROC = COMPSUMM / POINTSUMM * 100. MOVE PROC TO TPROC.
  IF PROC > '50.00'.
    WIN = ALIEN.
  ENDIF.
  CONCATENATE TPROC '%' INTO TPROC.
  CONCATENATE 'Computer:' XTEXT '/' TPROC
    INTO XTEXT SEPARATED BY SPACE.
  SY-COLNO = COL * 2 + 6.
  PERFORM WRITE_COLOR_BOX USING ALIEN_COLOR.
  SY-COLNO = COL * 2 + 14. WRITE_FRAME XTEXT 2.

  IF WIN = HUMAN.
    MESSAGE 'Human win!' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ELSEIF WIN = ALIEN.
    MESSAGE 'Computer win!' TYPE 'I'.
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " CHECK_COMPLETE

*&---------------------------------------------------------------------*
*&      Form  WRITE_COLOR_BOX
*&---------------------------------------------------------------------*
FORM WRITE_COLOR_BOX  USING    COLOR.
  CASE COLOR.
    WHEN 1. WRITE_FRAME '  ' 1.
    WHEN 2. WRITE_FRAME '  ' 2.
    WHEN 3. WRITE_FRAME '  ' 3.
    WHEN 4. WRITE_FRAME '  ' 4.
    WHEN 5. WRITE_FRAME '  ' 5.
    WHEN 6. WRITE_FRAME '  ' 6.
    WHEN 7. WRITE_FRAME '  ' 7.
  ENDCASE.
ENDFORM.                    " WRITE_COLOR_BOX

*&---------------------------------------------------------------------*
*&      Form  GET_POINT_COST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_POINT_COST USING POINT_X POINT_Y
                    CHANGING POINT_IN.

  DATA: A TYPE P DECIMALS 3,
        B TYPE P DECIMALS 3,
        C TYPE P DECIMALS 3,
        P TYPE P DECIMALS 3,
        S TYPE I,
        S1 TYPE P DECIMALS 3,
        S2 TYPE P DECIMALS 3,
        S3 TYPE P DECIMALS 3,
        SUMMS TYPE I.

  DATA: X TYPE I, Y TYPE I.

  DEFINE GET_VEKTOR.
    X = &1 - &3. X = X * X.
    Y = &2 - &4. Y = Y * Y.
    &5 = X + Y. &5 = SQRT( &5 ).
  END-OF-DEFINITION.

  DEFINE GET_SQUARE.
    CLEAR: A, B, C, P.
    GET_VEKTOR &1 &2 &3 &4 A.
    GET_VEKTOR &1 &2 &5 &6 B.
    GET_VEKTOR &5 &6 &3 &4 C.
    P = A + B + C. P = P / 2.
    &7 = P *  ( P - A ) * ( P - B ) * ( P - C ).
    &7 = SQRT( &7 ).
  END-OF-DEFINITION.

  X1 = COL. Y1 = 0.
  X2 = 0. Y2 = ROW / 2.
  X3 = COL / 2. Y3 = ROW.

  " Get big triangle triangle square
  GET_SQUARE X1 Y1 X2 Y2 X3 Y3 S.

  GET_SQUARE POINT_X POINT_Y X2 Y2 X3 Y3 S1.
  GET_SQUARE X1 Y1 POINT_X POINT_Y X3 Y3 S2.
  GET_SQUARE X1 Y1 X2 Y2 POINT_X POINT_Y S3.

  SUMMS = S1 + S2 + S3.

  IF S = SUMMS.
    POINT_IN = 'X'.
  ENDIF.

ENDFORM.                    "GET_POINT_COST
Back to top
View user's profile Send private message Blog
aus2007
Участник
Участник



Joined: 21 Mar 2009
Posts: 1

PostPosted: Sat Mar 21, 2009 1:39 am    Post subject: Reply with quote

Спасибо за код, оч пригодился! Smile
Автор +
Back to top
View user's profile Send private message
ШтернЕвгений
Участник
Участник



Joined: 03 Apr 2009
Posts: 2

PostPosted: Fri Apr 03, 2009 6:49 pm    Post subject: Reply with quote

Клевая игра, спасибо, Андрей!!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Games All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.