Увидели сообщение с непонятной ссылкой, спам, непристойность или оскорбление?Воспользуйтесь ссылкой «Сообщить модератору» рядом с сообщением!
0 Пользователей и 1 Гость просматривают эту тему.
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓│ ╭╮ ││ ╭╾╮ ╽╽ ││ ╭╮ ╰╮╽╭╾╮╽╰╾╮ ││ ╭╯╰╾╾╯╽╽ ╰╯╭╮╰╮ ││ ╭╯ ╽╽ ╭╾╯╽╭╯ ││ ╽ ╽╽╭╯╭*╰╯ ││╭╾╾╾╾╯ ╭╯╽╰╾╯ ││╽╭╾╾╮ ╰╾╯ ││╽╰╾╮╰╾╾╮ ││╰╾╾╯X╾╾╯ │┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛87 year
// test_lab_to.c// "maze until death, your yo."// victor00000 (c) 2018#include <stdio.h>#include <string.h>#include <unistd.h>#include <stdlib.h>#include <pthread.h>#include <locale.h>#include <sys/ioctl.h>// ~$ gcc test_lab_to.c -o test_lab_to -lpthread// ~$ ./test_lab_to// exit - 'Enter'int aa[4];int cnt = 0;int exit_0 = 0;const char *cls_c = "\e[1;1H\e[2J";int cvadr[] = { L'┏', L'━', L'┓', L'│', L'┛',L'━', L'┗', L'│', 0};int *lt = (int *)L"╾╭╮╯╰╽";typedef struct {int w, h;} wht;int **xy, yy, xx, r = 100;//===================exit ebtervoid *tp1(void *a){char cb;while (fread(&cb, 1, 1, stdin) != 1) {}exit_0 = 1;return 0;}//==============aa null to 4void aa_null(){int i;for (i = 0; i < 4; i++)aa[i] = 0;}//=================clsvoid cls(){fwrite(cls_c, 1, strlen(cls_c), stdout);}//=====================get w hint getwhterm(int *wt, int *ht){int e;struct winsize wl;e = ioctl(STDOUT_FILENO, TIOCGWINSZ, &wl);*ht = wl.ws_row;*wt = wl.ws_col;return e;}//=================xy_rndvoid xy_rnd(wht wh){int i = 0, r1 = r, d, x, y;aa_null();x = xx;y = yy;while (1) {// i++;for (i = 0; i < 4; i++) {if (aa[i] == 0)break;}if (i == 4) {// printf("%d year\n", cnt);exit_0 = 1;break;// exit(0);}r = rand() % 4;aa[r] = 1;if (r == 0)yy--;if (r == 1)xx++;if (r == 2)yy++;if (r == 3)xx--;if (xx > wh.w - 2 || xx < 1) {yy = y;xx = x; /*wh.w - 2 */ ;continue;}// if (xx<1) { xx = 1; continue; }if (yy > wh.h - 2 || yy < 0) {xx = x;yy = y; /*wh.h - 2 */ ;continue;}// if (yy < 1) { yy = 1; continue; }if (!(xy[yy][xx] == L'X' || xy[yy][xx] == L' ')) {xx = x;yy = y;continue;}break;}if (exit_0 == 1)return;d = lt[0];if (r1 == 100)d = L'*';else {if (r1 == 0) {if (r == 0)d = lt[5];if (r == 1)d = lt[1];if (r == 3)d = lt[2];}if (r1 == 1) {if (r == 0)d = lt[3];if (r == 1)d = lt[0];if (r == 2)d = lt[2];}if (r1 == 2) {if (r == 2)d = lt[5];if (r == 1)d = lt[4];if (r == 3)d = lt[3];}if (r1 == 3) {if (r == 3)d = lt[0];if (r == 0)d = lt[4];if (r == 2)d = lt[1];}}xy[y][x] = d;xy[yy][xx] = L'X';cnt++;//==============2}//===================xy_downvoid xy_down(wht wh){int x, y;for (x = 1; x < wh.w - 2; x++) {for (y = 1; y < wh.h - 1; y++) {//xy [y] [x] = L'.';xy[y][x] = xy[y][x + 1];}}}//===================xy_clearvoid xy_clear(wht wh){int x, y;for (y = 0; y < wh.h; y++) {for (x = 0; x < wh.w; x++) {if (x == 0 || x == wh.w - 1)xy[y][x] = cvadr[3];elsexy[y][x] = L' ';if (y == 0) {xy[y][x] = cvadr[1];if (x == 0)xy[y][x] = cvadr[0];if (x == wh.w - 1)xy[y][x] = cvadr[2];}if (y == wh.h - 1) {xy[y][x] = cvadr[1];if (x == 0)xy[y][x] = cvadr[6];if (x == wh.w - 1)xy[y][x] = cvadr[4];//===================1}}}}//====================xy_initint **xy_init(wht wh){int **x_y = 0;x_y = malloc(sizeof(int) * wh.h);int i;for (i = 0; i < wh.h; i++) {x_y[i] = malloc(sizeof(int) * wh.w);}return x_y;}//=================tpvoid *tp(void *a){wht *wh = (wht *) a;int x, y;while (1) {xy_rnd(*wh);// xy_down(*wh);cls();for (y = 0; y < wh->h; y++) {for (x = 0; x < wh->w; x++) {printf("%lc", xy[y][x]);}// if (y != wh->h - 1) puts("");}if (exit_0 == 1)break;usleep(1000 * 300);}return 0;}//==================m0int main(){//cls();//return 0;srand(time(0));setlocale(LC_ALL, getenv("LANG"));int wt, ht, e;e = getwhterm(&wt, &ht);if (e != 0) {perror("Err");return 1;}pthread_t t, t1;wht wh;wh.w = wt;wh.h = ht - 1;yy = wh.h - 2;xy = xy_init(wh);xy_clear(wh);// xy[wh.h - 2][wh.w - 2] = lt[0];// xy_down(wh);xx = wh.w / 2;yy = wh.h / 2;pthread_create(&t, 0, tp, &wh);pthread_create(&t1, 0, tp1, 0);// char cb;while (1) {usleep(1000 * 1000);if (exit_0 == 1)break;//fread(&cb, 1, 1, stdin) != 1) {}pthread_cancel(t1);pthread_join(t1, 0);// exit_0 = 1;pthread_join(t, 0);for (e = 0; e < wh.h; e++)free(xy[e]);free(xy);printf("%d year\n", cnt);return 0;}
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓│ ╭╾╾╾╮╭╮╭╮ ╭╮╭╾╾╮ ││ ╭╯ ╭╮╰╯╰╯╰╾╾╯╰╯ ╭╯ ││ ╽ ╭╯╰╾╾╾╮ ╭╾╾╾╮ ╽ ││ ╽ ╽ ╭╮╭╮╰╾╯╭╾╾╯ ╽ ││ ╰╮╽╭╯╰╯╽X╭╾╯ ╭╯ ││ ╽╰╯ ╭╾╯╽╽* ╭╾╾╯ ││ ╰╮ ╽ ╰╯╽╭╯ ││ ╰╮╭╯ ╽╰╾╾╮ ││ ╰╯ ╰╮╭╮╽ ││ ╰╯╰╯ │┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛113 year
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓│ ╭╾╾╮ ╭╮ ╭╮ ││ ╭╾╮ ╰╾╮╽ ╭╯╰╮╭╾╯╽ ││╭╯X╽ ╽╽ ╽╭╮╽╽ ╰╮ ││╽╭╯╰╮ ╭╯╰╾╾╾╾╾╾╾╾╮╰╯╽╰╯ ╽ ││╽╽╭╾╯ ╰╾╾╮╭╾╾╾╮╭╮╽ ╭╯ ╽ ││╰╯╽╭╾╮ ╰╯ ╭*╰╯╽╰╾╯ ╭╮╽ ││ ╽╰╮╽ ╭╮╭╮ ╭╾╾╯╭╾╾╯╭╾╮ ╭╯╰╯ ││ ╰╾╯╰╾╾╯╽╽╰╮╰╾╾╾╯ ╭╯ ╽ ╭╮╽ ││ ╰╯╭╯ ╭╮ ╽ ╭╯╭╯╽╽ ││ ╰╾╾╾╾╾╯╰╾╯ ╰╾╯ ╰╯ │┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛170 year
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓│ ╭╾╾╾╾╮ ││ ╰╮X╭╾╯ ││ ╭╯╰╯ ││ ╽ ││ ╽ ││ ╰* ││ ││ ││ ││ │┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛1538844162 = 19 year
./test_lab_to 1538844162
// test_lab_to.c// "maze until death, your yo."// victor00000 (c) 2018#include <stdio.h>#include <string.h>#include <unistd.h>#include <stdlib.h>#include <pthread.h>#include <locale.h>#include <sys/ioctl.h>// ~$ gcc test_lab_to.c -o test_lab_to -lpthread// ~$ ./test_lab_to// exit - 'Enter'time_t tt;int aa[4];int cnt = 0;int exit_0 = 0;const char *cls_c = "\e[1;1H\e[2J";int cvadr[] = { L'┏', L'━', L'┓', L'│', L'┛',L'━', L'┗', L'│', 0};int *lt = (int *)L"╾╭╮╯╰╽";typedef struct {int w, h;} wht;int **xy, yy, xx, r = 100;void xy_clear(wht wh);//=================xy nullvoid xy_null (wht wh){cnt = 0;xx = wh.w / 2;yy = wh.h / 2;xy_clear (wh);r = 100;}//===================exit ebtervoid *tp1(void *a){char cb;while (fread(&cb, 1, 1, stdin) != 1) {}exit_0 = 2;return 0;}//==============aa null to 4void aa_null(){int i;for (i = 0; i < 4; i++)aa[i] = 0;}//=================clsvoid cls(){fwrite(cls_c, 1, strlen(cls_c), stdout);}//=====================get w hint getwhterm(int *wt, int *ht){int e;struct winsize wl;e = ioctl(STDOUT_FILENO, TIOCGWINSZ, &wl);*ht = wl.ws_row;*wt = wl.ws_col;return e;}//=================xy_rndvoid xy_rnd(wht wh){int i = 0, r1 = r, d, x, y;aa_null();x = xx;y = yy;while (1) {// i++;for (i = 0; i < 4; i++) {if (aa[i] == 0)break;}if (i == 4) {// printf("%d year\n", cnt);exit_0 = 1;break;// exit(0);}r = rand() % 4;aa[r] = 1;if (r == 0)yy--;if (r == 1)xx++;if (r == 2)yy++;if (r == 3)xx--;if (xx > wh.w - 2 || xx < 1) {yy = y;xx = x; /*wh.w - 2 */ ;continue;}// if (xx<1) { xx = 1; continue; }if (yy > wh.h - 2 || yy < 0) {xx = x;yy = y; /*wh.h - 2 */ ;continue;}// if (yy < 1) { yy = 1; continue; }if (!(xy[yy][xx] == L'X' || xy[yy][xx] == L' ')) {xx = x;yy = y;continue;}break;}if (exit_0 != 0){if (exit_0 == 2) {exit_0 = 1;return;}// if (cnt > 200)return;exit_0 = 0;xy_null (wh);return;}d = lt[0];if (r1 == 100)d = L'*';else {if (r1 == 0) {if (r == 0)d = lt[5];if (r == 1)d = lt[1];if (r == 3)d = lt[2];}if (r1 == 1) {if (r == 0)d = lt[3];if (r == 1)d = lt[0];if (r == 2)d = lt[2];}if (r1 == 2) {if (r == 2)d = lt[5];if (r == 1)d = lt[4];if (r == 3)d = lt[3];}if (r1 == 3) {if (r == 3)d = lt[0];if (r == 0)d = lt[4];if (r == 2)d = lt[1];}}xy[y][x] = d;xy[yy][xx] = L'X';cnt++;//==============2}//===================xy_downvoid xy_down(wht wh){int x, y;for (x = 1; x < wh.w - 2; x++) {for (y = 1; y < wh.h - 1; y++) {//xy [y] [x] = L'.';xy[y][x] = xy[y][x + 1];}}}//===================xy_clearvoid xy_clear(wht wh){int x, y;for (y = 0; y < wh.h; y++) {for (x = 0; x < wh.w; x++) {if (x == 0 || x == wh.w - 1)xy[y][x] = cvadr[3];elsexy[y][x] = L' ';if (y == 0) {xy[y][x] = cvadr[1];if (x == 0)xy[y][x] = cvadr[0];if (x == wh.w - 1)xy[y][x] = cvadr[2];}if (y == wh.h - 1) {xy[y][x] = cvadr[1];if (x == 0)xy[y][x] = cvadr[6];if (x == wh.w - 1)xy[y][x] = cvadr[4];//===================1}}}}//====================xy_initint **xy_init(wht wh){int **x_y = 0;x_y = malloc(sizeof(int) * wh.h);int i;for (i = 0; i < wh.h; i++) {x_y[i] = malloc(sizeof(int) * wh.w);}return x_y;}//=================tpvoid *tp(void *a){wht *wh = (wht *) a;int x, y;while (1) {xy_rnd(*wh);// xy_down(*wh);cls();for (y = 0; y < wh->h; y++) {for (x = 0; x < wh->w; x++) {printf("%lc", xy[y][x]);}// if (y != wh->h - 1) puts("");}if (exit_0 == 1)break;usleep(1000 * 300 );}return 0;}//==================m0int main(int ia, char *ca[]){//cls();//return 0;tt = time (NULL);if (ia == 2 )tt = atoi (ca[1]);srand(tt);setlocale(LC_ALL, getenv("LANG"));int wt, ht, e;e = getwhterm(&wt, &ht);if (e != 0) {perror("Err");return 1;}pthread_t t, t1;wht wh;wh.w = wt;wh.h = ht - 1;yy = wh.h - 2;xy = xy_init(wh);xy_clear(wh);// xy[wh.h - 2][wh.w - 2] = lt[0];// xy_down(wh);xx = wh.w / 2;yy = wh.h / 2;pthread_create(&t, 0, tp, &wh);pthread_create(&t1, 0, tp1, 0);// char cb;while (1) {usleep(1000 * 1000);if (exit_0 == 1)break;//fread(&cb, 1, 1, stdin) != 1) {}pthread_cancel(t1);pthread_join(t1, 0);// exit_0 = 1;pthread_join(t, 0);for (e = 0; e < wh.h; e++)free(xy[e]);free(xy);printf("%d = %d year\n",(int) tt, cnt);return 0;}
Страница сгенерирована за 0.026 секунд. Запросов: 22.