//DateTime -> UnixTimestamp -> DateTime 변환

//DateTime -> UnixTimestamp -> DateTime 변환

 

#include<stdio.h>

#include<time.h>

 

int GetUnixTimeT(int year, int month, int day, int hour, int minute, int second)

{

  struct tm t = {0};

 

  t.tm_year = year - 1900;

  t.tm_mon = month - 1;

  t.tm_mday = day;

  t.tm_hour = hour;

  t.tm_min = minute;

  t.tm_sec = second;

 

  return(mktime(&t));

}

int main(int argc, char *argv[])

{

  time_t t = time(NULL);

  struct tm tm = *localtime(&t);

 

  int ____year = tm.tm_year + 1900;

  int ____month = tm.tm_mon = month + 1;

  int ____day = tm.tm_mday;

  int ____hour = tm.tm_hour;

  int ____minute = tm.tm_min;

  int ____second = tm.tm_sec;

 

  printf("DateTime(1):[%d-%d-%d %d:%d:%d]\n", ____year,

    ____month, ____day, ____hour, ____minute, ____second);

 

  time_t baseTime = GetUnixTimeT(____year,

            ____month, ____day, ____hour, ____minute, ____second);

 

  printf("UnixTimestamp:[%ld]\n", baseTime);

 

  struct tm *tmmm = (struct tm *)localtime(&baseTime);

 

  ____year = tmmm->tm_year + 1900;

  ____month = tmmm->tm_mon = month + 1;

  ____day = tmmm->tm_mday;

  ____hour = tmmm->tm_hour;

  ____minute = tmmm->tm_min;

  ____second = tmmm->tm_sec;

 

  printf("DateTime(2):[%d-%d-%d %d:%d:%d]\n", ____year,

    ____month, ____day, ____hour, ____minute, ____second);

 

  return(0);

}

 

 

 

 

  

 

#Compile

gcc -I/usr/local/jdk1.7.0_79/include -I/usr/local/jdk1.7.0_79/include/linux -I/usr2/sinfo/src/include -I/usr/local/mysql/include -I./../jni_include  -fPIC -g -c -Wall SiseLibJong.c

 

gcc -I/usr/local/jdk1.7.0_79/include -I/usr/local/jdk1.7.0_79/include/linux -I/usr2/sinfo/src/include -I/usr/local/mysql/include -I./../jni_include  -fPIC -g -c -Wall ShmOpJong.c

 

 

#Link(so)

#gcc -shared -fPIC -o libShmJong.so SiseLibJong.so ShmOpJong.so

../util/Common.o /usr2/sinfo/src/util/MEMORY.o /usr2/sinfo/src/util/IPC.o /usr2/sinfo/src/util/STRLIB.o /usr2/sinfo/src/util/FUNC.o -lm -lpthread -lnsl

 

#Link(exe)

#gcc -o exeShmJong SiseLibJong.so ShmOpJong.so

../util/Common.o /usr2/sinfo/src/util/MEMORY.o /usr2/sinfo/src/util/IPC.o /usr2/sinfo/src/util/STRLIB.o /usr2/sinfo/src/util/FUNC.o -lm

-lpthread -lnsl

 

 

 

 

Makefile
0.00MB

#if(1)
    if(____type==0)  //처음 한번은 전체출력으로 하고, 다음부터는 변한부분만 출력하도록 한다.
{
        for(i=0; i<MAPY; i++)
{
            for(k=0; k<MAPX; k++)
                {
if(hexa[i][k] == 10)
{
continue;
}
else if(hexa[i][k] == 0)
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, "□", 2);
}
else
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, design[ hexa[i][k] ], 2);
}
}
}
____type=1;
}
else
{
for(i=0; i<MAPY; i++)
{
for(k=0; k<MAPX; k++)
{
if(hexa[i][k] == ____hexa[i][k]) continue;
else if(hexa[i][k] == 0)
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, "□", 2);
}
else
{
TextOut(hdc, screenxpos + 8 * 2 * k, screenypos + 8 * 2 * i, design[ hexa[i][k] ], 2);
}
}
}
}
#endif

#include <time.h>
struct tm *localtime_r(const time_t *timep, struct tm *result);



----DESCRIPTION
localtime_r 함수는 time_t type의 초단위의 시간을 지역시간(locale정보)의 struct tm type으로 변환하는 함수입니다.
localtime()함수가 변환된 결과를 local static변수에 저장하는것과 달리 localtime_r()함수는 data를 변환한 결과값을
result에 저장하기때문에 multi-thread에서도 안전한 thread-safe함수입니다.





#include <time.h>
#include <stdio.h>

struct tm *localtime_r(const time_t *timep, struct tm *result);

int main(int argc, char **argv[])
{
    time_t t;
    struct tm lt;
 
    if((t=time(NULL))==-1) {
        printf("time() call error\n");
        return -1;
    }
    if(localtime_r(&t, &lt)==NULL) {
        printf("localtime_r() call error\n");
        return -1;
    }
    printf("NOW TIME:%04d-%02d-%02d %02d:%02d:%02d\n",
    lt.tm_year + 1900,
    lt.tm_mon + 1,
    lt.tm_mday,
    lt.tm_hour,
    lt.tm_min,
    lt.tm_sec);
 
    return 0;

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

#define LEAP(y) ((y % 4 == 0 && y % 100 != 0 || y % 400 == 0) ? 1 : 0)

 

static void ha_ltona0(int idx, int length, char *answer);

static int ha_antol(char *request, int length);

static void cb1_compute_date (char *odate, char *idate, int addval);

static int getRemainDay(char *odate, char *idate);

 

int main(int argc, char *argv[])

{

    int rc,mm,dd;    char begin_date[10] = "20190101";

   char end_date [10];

   for(mm=1; mm<=12; mm++)

   {

      for(dd=1; dd<=31; dd++)

      {

         memset(end_date,0x00,sizeof(end_date));

         sprintf(end_date, "2019%.2d%.2d", mm, dd);

         rc = getRemainDay(end_date,begin_date);

         if(rc<0) printf("(%s)(%s):(%s)\n", begin_date, end_date, " is not valid day!! error");

         else printf("(%s)(%s):(%d)\n", begin_date, end_date, getRemainDay(end_date,begin_date));

      }

   }

for(mm=1; mm<=12; mm++) { for(dd=1; dd<=31; dd++)

{

memset(end_date,0x00,sizeof(end_date));

sprintf(end_date, "2019%.2d%.2d", mm, dd);

rc = getRemainDay(end_date,begin_date);

if(rc<0) printf("(%s)(%s):(%s)\n", begin_date, end_date, " is not valid day!! error");

}

}

   return 0;

}

 

/*- ------------------------------------------------ -*

 *- ha_ltona0

 *- ------------------------------------------------ -*/

void ha_ltona0(int idx, int length, char *answer)

{

    if(length==1)

    {

        sprintf(answer,"%.1d",idx);

    }

    else if(length==2)

    {

        sprintf(answer,"%.2d",idx);

    }

    else if(length==3)

    {

        sprintf(answer,"%.3d",idx);

    }

    else if(length==4)

    {

        sprintf(answer,"%.4d",idx);

    }

}

 

/*- ------------------------------------------------ -*

 *- ha_antol

 *- ------------------------------------------------ -*/

int ha_antol(char *request, int length)

{

char answer[100];

 

memset(answer,0x00,sizeof(answer));

 

memcpy(answer,request,length);

 

return(atoi(answer));

}

 

/*- ------------------------------------------------ -*

 *- cb1_compute_date

 *- ------------------------------------------------ -*/

void cb1_compute_date (odate, idate, addval)

char *odate;

char *idate;

int addval;

{

int yy;

int mm;

int dd;

int leap;

static int mmt[2] [13] =

{ {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

   {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} };

 

yy = ha_antol(idate, 4);

mm = ha_antol(idate+4, 2);

dd = ha_antol(idate+6, 2) + addval;

leap = LEAP(yy);

if (addval == 0) {

sprintf(odate, "%.8s", idate);

return;

    }

else

if (addval > 0) {

     for ( ; dd > mmt[leap][mm]; mm++)

     {

     dd -= mmt[leap] [mm];

     if (mm >= 12)

     {

         mm = 0;

         yy++;

         leap = LEAP(yy);

     }

     }

}

else {

     mm--;

     if (mm == 0)

     {

     mm = 12;

     yy--;

     leap = LEAP(yy);

     }

 

     for ( ; dd < 1; mm--)

     {

     dd += mmt [leap] [mm];

     if (mm <= 1)

     {

         mm = 13;

         yy--;

         leap = LEAP(yy);

     }

     }

     mm++;

     if (mm > 12)

     {

     mm = 1;

     yy++;

     }

}

 

ha_ltona0(yy, 4, odate);

ha_ltona0(mm, 2, odate+4);

ha_ltona0(dd, 2, odate+6);

}

 

/*- ------------------------------------------------ -*

 *- getRemainDay

 *- ------------------------------------------------ -*/

int getRemainDay(char *odate, char *idate)

{

int k;

char begin_date[10];

 

if(strcmp(odate,idate)<0) return(-1);

 

if(memcmp(odate,idate,strlen("YYYYMMDD"))==0) return 1;

 

    for(k=1; k<9999; k++)

{

     memset(begin_date,0x00,sizeof(begin_date));

     cb1_compute_date(begin_date,idate,k);

 

if(memcmp(begin_date,odate,strlen("YYYYMMDD"))==0) break;

}

 

if(k==9999) return(-1);

return k+1;

}

 

/*RESULT

Microsoft Windows [Version 6.1.7601]

Copyright (c) 2009 Microsoft Corporation. All rights reserved.

 

C:\Users\Downloads>10

,,

,,

,,

,,

(20190101)(20190818):(230)

(20190101)(20190819):(231)

(20190101)(20190820):(232)

(20190101)(20190821):(233)

(20190101)(20190822):(234)

(20190101)(20190823):(235)

(20190101)(20190824):(236)

(20190101)(20190825):(237)

(20190101)(20190826):(238)

(20190101)(20190827):(239)

(20190101)(20190828):(240)

(20190101)(20190829):(241)

(20190101)(20190830):(242)

(20190101)(20190831):(243)

(20190101)(20190901):(244)

(20190101)(20190902):(245)

(20190101)(20190903):(246)

(20190101)(20190904):(247)

(20190101)(20190905):(248)

(20190101)(20190906):(249)

(20190101)(20190907):(250)

(20190101)(20190908):(251)

(20190101)(20190909):(252)

(20190101)(20190910):(253)

(20190101)(20190911):(254)

(20190101)(20190912):(255)

(20190101)(20190913):(256)

(20190101)(20190914):(257)

(20190101)(20190915):(258)

(20190101)(20190916):(259)

(20190101)(20190917):(260)

(20190101)(20190918):(261)

(20190101)(20190919):(262)

(20190101)(20190920):(263)

(20190101)(20190921):(264)

(20190101)(20190922):(265)

(20190101)(20190923):(266)

(20190101)(20190924):(267)

(20190101)(20190925):(268)

(20190101)(20190926):(269)

(20190101)(20190927):(270)

(20190101)(20190928):(271)

(20190101)(20190929):(272)

(20190101)(20190930):(273)

(20190101)(20190931):( is not valid day!! error)

(20190101)(20191001):(274)

(20190101)(20191002):(275)

(20190101)(20191003):(276)

(20190101)(20191004):(277)

(20190101)(20191005):(278)

(20190101)(20191006):(279)

(20190101)(20191007):(280)

(20190101)(20191008):(281)

(20190101)(20191009):(282)

(20190101)(20191010):(283)

(20190101)(20191011):(284)

(20190101)(20191012):(285)

(20190101)(20191013):(286)

(20190101)(20191014):(287)

(20190101)(20191015):(288)

(20190101)(20191016):(289)

(20190101)(20191017):(290)

(20190101)(20191018):(291)

(20190101)(20191019):(292)

(20190101)(20191020):(293)

(20190101)(20191021):(294)

(20190101)(20191022):(295)

(20190101)(20191023):(296)

(20190101)(20191024):(297)

(20190101)(20191025):(298)

(20190101)(20191026):(299)

(20190101)(20191027):(300)

(20190101)(20191028):(301)

(20190101)(20191029):(302)

(20190101)(20191030):(303)

(20190101)(20191031):(304)

(20190101)(20191101):(305)

(20190101)(20191102):(306)

(20190101)(20191103):(307)

(20190101)(20191104):(308)

(20190101)(20191105):(309)

(20190101)(20191106):(310)

(20190101)(20191107):(311)

(20190101)(20191108):(312)

(20190101)(20191109):(313)

(20190101)(20191110):(314)

(20190101)(20191111):(315)

(20190101)(20191112):(316)

(20190101)(20191113):(317)

(20190101)(20191114):(318)

(20190101)(20191115):(319)

(20190101)(20191116):(320)

(20190101)(20191117):(321)

(20190101)(20191118):(322)

(20190101)(20191119):(323)

(20190101)(20191120):(324)

(20190101)(20191121):(325)

(20190101)(20191122):(326)

(20190101)(20191123):(327)

(20190101)(20191124):(328)

(20190101)(20191125):(329)

(20190101)(20191126):(330)

(20190101)(20191127):(331)

(20190101)(20191128):(332)

(20190101)(20191129):(333)

(20190101)(20191130):(334)

(20190101)(20191131):( is not valid day!! error)

(20190101)(20191201):(335)

(20190101)(20191202):(336)

(20190101)(20191203):(337)

(20190101)(20191204):(338)

(20190101)(20191205):(339)

(20190101)(20191206):(340)

(20190101)(20191207):(341)

(20190101)(20191208):(342)

(20190101)(20191209):(343)

(20190101)(20191210):(344)

(20190101)(20191211):(345)

(20190101)(20191212):(346)

(20190101)(20191213):(347)

(20190101)(20191214):(348)

(20190101)(20191215):(349)

(20190101)(20191216):(350)

(20190101)(20191217):(351)

(20190101)(20191218):(352)

(20190101)(20191219):(353)

(20190101)(20191220):(354)

(20190101)(20191221):(355)

(20190101)(20191222):(356)

(20190101)(20191223):(357)

(20190101)(20191224):(358)

(20190101)(20191225):(359)

(20190101)(20191226):(360)

(20190101)(20191227):(361)

(20190101)(20191228):(362)

(20190101)(20191229):(363)

(20190101)(20191230):(364)

(20190101)(20191231):(365)

(20190101)(20190229):( is not valid day!! error)

(20190101)(20190230):( is not valid day!! error)

(20190101)(20190231):( is not valid day!! error)

(20190101)(20190431):( is not valid day!! error)

(20190101)(20190631):( is not valid day!! error)

(20190101)(20190931):( is not valid day!! error)

(20190101)(20191131):( is not valid day!! error)

*/

 

#include <stdio.h>

 

#if(1)

#pragma pack(1)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

};

#pragma pack()

#endif

 

#if(0)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

} __attribute__((aligned(1), packed));

#endif

 

#if(0)

struct PacketHeader {

    char flags;    // 1 BYTE

    int seq;       // 4 BYTE

};

#endif

 

int main()

{

    struct PacketHeader header;

 

    printf("%d\n", sizeof(header.flags));

    printf("%d\n", sizeof(header.seq));  

    printf("%d\n", sizeof(header));      

 

    return 0;

}

 

//정상적인 경우는 1+4=8바이트의 크기로 구조체크기가 결정되지만

//#pragma pack(1)를 사용함으로써 구조체 정렬 크기조정할수 있다.

 

/*

strtok_r

 

1.설명

strtok_r은 str문자열을 delim에 포함된 문자들 중에서 하나를 만나는 곳을 null-terminated 문자열로 변경하여 return합니다. 

str문자열이 NULL이면 그 다음 delimiter까지의 문자열을 return합니다. 

saveptr은 문자열을 strtok_r의 내부에서 관리하던 static 변수 대신에 외부 변수를 사용하도록 변경하여 multi-thread에 안전하도록 변경되었습니다.

 

strtok은 multi-thread 프로그램에서 오류를 유발할 수 있으므로, 이 strtok_r함수를 사용하는 것이 좋습니다.

 

※주의: delimiter가 연속으로 있는 경우에는 delimiter와 delimiter 사이의 값인 ""가 return되지 않습니다.

delimter로 시작하거나 delimiter로 끝나는 경우에도 ""를 return하지 않습니다.

예를들면, Comma(,)로 분리된 데이터를 에서 a,,b,c의 경우 "a", "", "b", "c"로 분리되지 않고 "a", "b","c"로 분리됩니다.

 

※주의: strtok_r함수는 파라미터 type(const가 빠짐)을 보면 알 수 있듯이

원본 문자열인 str 문자열의 값이 변경되므로 strtok_r함수를 실행하기전에

원본 훼손이 되면 안되는 경우에는 다른 변수에 복제하여 본제된 문자열을 사용하여야 합니다.

 

 

2.파라미터

str

    - delimiter단위로 분리할 문자열.

    - NULL이면 saveptr 변수에서 저장하고 있던 이전에 호출한 위치 다음부터 분리작업을 진행합니다.

 

  ※주의 : str문자열은 변경이 일어나기 때문에 원본 문자열을 보존하려면 

          임시변수에 복사한 후 임시변수를 사용하기 바랍니다.

delim

    - 문자열을 분리할 delimiter 문자들. delim에 포함된 아무 문자라도 만나면 분리함.

saveptr

    - 다음처리를 위한 위치를 저장하는 pointer

    - 이 변수는 직접 handling하지 않습니다

 

 

3.RETURN

NULL 아님

    - 정상적으로 delimiter로 분리하였으며, 분리된 문자열의 시작 pointer를 return합니다.

    

NULL

    - 분리할 데이터가 더 이상없습니다.

 

4.TYPE(보통 WINDOWS gcc에는 포함이 안되어 있는것 같다. 리눅스OS의 gcc에서 작동함)

#include <string.h> 

char *strtok_r(char *str, const char *delim, char **saveptr);

 

*/

 

#include <string.h>

#include <stdio.h>

 

/* /또는 - 또는 : 또는 space를 delimiter로 사용합니다. */ 

#define DELIM_CHARS "/-: " 

 

int main(int argc, char **argv) 

char time[1024] = "2017-02-12 10:25:30"; 

char *ret_ptr; 

char *next_ptr; 

 

printf("time : [%s]\n", time); 

ret_ptr = strtok_r(time, DELIM_CHARS, &next_ptr); 

while(ret_ptr) 

printf("ret_ptr = [%s]\n", ret_ptr); 

ret_ptr = strtok_r(NULL, DELIM_CHARS, &next_ptr); 

return 0; 

 

//wincommon.c

//wincommon.c

//wincommon.c  공통라이브러리

 

#include "wincommon.h"

 

extern char design[6][2+1];

 

int f_rightkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

     if(check(hexa, *x + 1, *y, 0) == 1)

    {

       hexa[*y+0][*x] = 0;

        hexa[*y+1][*x] = 0;

        hexa[*y+2][*x] = 0;

 

        *x = *x + 1;

 

       hexa[*y+0][*x] = __des[0];

        hexa[*y+1][*x] = __des[1];

        hexa[*y+2][*x] = __des[2];

 

       return 1;

    }

    else

    {

       return 0;

    }

}

int f_leftkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

    if(check(hexa, *x - 1, *y, 0) == 1)

    {

      hexa[*y+0][*x] = 0;

       hexa[*y+1][*x] = 0;

       hexa[*y+2][*x] = 0;

 

       *x = *x - 1;

 

       hexa[*y+0][*x] = __des[0];

       hexa[*y+1][*x] = __des[1];

       hexa[*y+2][*x] = __des[2];

 

       return 1;

    }

    else

    {

       return 0;

    }

}

int f_downkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

    if(check(hexa, *x, *y + 1, 1)==1)

   {

      hexa[*y+0][*x] = 0;

       hexa[*y+1][*x] = 0;

       hexa[*y+2][*x] = 0;

 

       *y = *y + 1;

 

      hexa[*y+0][*x] = __des[0];

      hexa[*y+1][*x] = __des[1];

      hexa[*y+2][*x] = __des[2];

 

      return 1;

   }

   else

   {

      return 0;

   }

}

int f_enterkey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

    return 1;

}

int f_spacekey(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

   int tmp;

 

   tmp = __des[0];

   __des[0] = __des[1];

   __des[1] = __des[2];

   __des[2] = tmp;

 

   hexa[*y+0][*x] = __des[0];

   hexa[*y+1][*x] = __des[1];

   hexa[*y+2][*x] = __des[2];

 

    return 1;

}

void f_quitmsg(int idx)

{

printf(

"----------------------------------------------------------------------\n"

"MinGW provides a complete Open Source programming tool set            \n"

"which is suitable for the development of native MS-Windows appications\n"

"and which do not depend on any 3rd-party C-Runtime DLLs.              \n"

"(It does depend on a number of DLLs provided by Microsoft themselves, \n"

"as components of the operating system; most notable among these is MSV\n"

"the Microsoft C runtime library. Additionally, threaded applications m\n"

"with a freely distributable thread support DLL, provided as part of Mi\n"

"                                                                      \n"

"MinGW compilers provide access to the functionality of the Microsoft C\n"

"and some language-specific runtimes. MinGW, being Minimalist,         \n"

"does not, and never will, attempt to provide a POSIX runtime environme\n"

"for POSIX application deployment on MS-Windows.                       \n"

"If you want POSIX application deployment on this platform, please cons\n"

"DATE    :                                                             \n"

"AUTHOR  :                                                             \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"SCORE   :[%.4d]                                                       \n"

"----------------------------------------------------------------------\n", idx, idx, idx, idx, idx, idx, idx);

}

int check(int hexa[MAPY][MAPX], int x, int y, int idx)

{

   int result;

 

   result = 0;

 

    if(idx == 0)

   {

        if(hexa[y+0][x]>0) result = 1;

       if(hexa[y+1][x]>0) result = 1;

       if(hexa[y+2][x]>0) result = 1;

   }

   if(idx == 1)

    {

      if(hexa[y+2][x] >0) result = 1;

   }

 

   if(result == 1) return -1;

   return 1;

}

void gotoxy(int x, int y)

{

    COORD Pos = {x - 1, y - 1};

    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Pos);

}

void init(int hexa[MAPY][MAPX], int *x, int *y, int __des[3])

{

   int i, k;

 

   //char design[6][2+1] = {"", "●","◆","■","◀","▶"};

   strcpy(design[0], "");

   strcpy(design[5], "●");

   strcpy(design[1], "◆");

   strcpy(design[2], "■");

   strcpy(design[3], "◀");

   strcpy(design[4], "▶");

 

   for(i=0; i<MAPY; i++)

   {

      for(k=0; k<MAPX; k++)

      {

         hexa[i][k] = 0;

      }

  }

 

   for(i=0; i<MAPY; i++)

   {

      hexa[i][0]      = 10;

      hexa[i][MAPX-1] = 10;

   }

   for(k=0; k<1 + MAPX + 1; k++)

    {

      hexa[MAPY-1][k] = 10;

   }

 

 

   *x = MAPX / 2;

   *y = 0;

 

   __des[0] = 1 + ( rand() % 5 );

   __des[1] = 1 + ( rand() % 5 );

   __des[2] = 1 + ( rand() % 5 );

 

   hexa[*y+0][*x] = __des[0];

   hexa[*y+1][*x] = __des[1];

   hexa[*y+2][*x] = __des[2];

}

void f_delete_column( int hexa[MAPY][MAPX], int x, int y )

{

    int k;

 

    for(k = y; k >= 1; k--)

    {

        hexa[ k][ x ] = hexa[ ( k - 1 ) ][ x ];

    }

int f_check_horizontal(int hexa[MAPY][MAPX], int *sc)

{

    int i, k, j, idx;

 

    for(i = 0; i <MAPY - 1; i++ )

    {

        for(k = 1; k <MAPX - 3; k++ )

        {

            idx = 0;

            while( 1 )  

            {

                if( hexa[ i][ k + idx ] != 0 )

                {

                    if( hexa[ i][ k + idx ] == hexa[ i][ k + idx + 1 ] )

                    {

                        idx = idx + 1;

                    }

                    else break;

                }

                else break; 

            }

 

            if( idx >= 2 )

            {

              (*sc)++;

                for( j = k; j <= k + idx; j++ )

                {

                    f_delete_column( hexa, j, i );

                }

                return 1;

            }

        }

    }

    return 0;

}

int f_check_vertical(int hexa[MAPY][MAPX], int *sc)

{

    int i, k, j, idx;

 

    for( k = 1; k < MAPX - 1; k++ )

    {

        for( i = MAPY - 2; i >= 0; i-- ) 

        {

            idx = 0;

            while( 1 )

            {

                if( hexa[ ( i - idx )][k ] != 0 )

                {

                    if( hexa[ ( i - idx )][k ] == hexa[ ( i - idx - 1 )][k ] )

                    {

                        idx = idx + 1;

  

                    }

                    else break;

                }

                else break; 

            }

 

            if( idx >= 2 )

            {

              (*sc)++;

                for( j = i; j >= i - idx; j-- )

                {

                    f_delete_column( hexa, k, i );

                }

 

                return 1;

            }

        }

    }

    return 0;

int f_check_left_to_right(int hexa[MAPY][MAPX], int *sc)

{

    int i, k, j, idx;

 

    for(k = 1; k <MAPX - 1; k++ )

    {

        for(i = 0; i <MAPY - 1; i++ )

        {

            idx = 0;

            while( 1 )

            {

                if( hexa[ ( i + idx ) ][k + idx ] != 0 )

                {

                    if( hexa[ ( i + idx )][( k + idx ) ] == hexa[ ( i + idx + 1 )][( k + idx + 1 ) ] )

                    {

                        idx = idx + 1;

            }

                    else break;

                }

                else break;

            }

 

            if( idx >= 2 )

            {

              (*sc)++;

                for( j = 0; j <= idx; j++ )

                {

                    f_delete_column( hexa, k + j, i + j );

                }

 

                return 1;

            }

        }

    }

    return 0;

}  

int f_check_right_to_left(int hexa[MAPY][MAPX], int *sc)

{

    int i, k, j, idx;

 

    for(k = MAPX - 2; k >= 1; k--)

    {

        for(i = 0; i < MAPY - 1; i++)

        {

            idx = 0;

            while( 1 )

            {

                if( hexa[ (i + idx )][k - idx ] != 0 )

                {

                    if( hexa[ (i + idx )][(k - idx ) ] == hexa[ (i + idx + 1 )][(k - idx - 1 ) ] )

                    {

                        idx = idx + 1;

                  }

                    else break;

                }

                else break;

            }

 

            if( idx >= 2 )

            {

              (*sc)++;

                for( j = 0; j <= idx; j++ )

                { 

                    f_delete_column(hexa, k - j, i + j );

                }

                return 1;

            }

        }

    }

    return 0;

}

+ Recent posts