void puissance4(t_grid *grid) { int end; int move; int player; int result; int nbcoup; end = 0; move = -1; player = (ft_rand() % 2) + 1; result = 0; nbcoup = grid->width * grid->height; while (end == 0 && nbcoup > 0) { put_prompt(player, grid); if ((move = get_move(player, grid)) == -1) return ; if ((result = put_tocken(grid, move, player)) == 0) { player = (player == 1 ? 2 : 1); nbcoup--; } else if (result == 2) { victory(player, grid); end = 1; } } if (nbcoup == 0) ft_printf("Draw\n"); }
unsigned int color(int i, double n, t_env *env) { double color; static double a = 10; static double c = 1; n = sqrt(n); if (i == ITERM) return (0); color = i + 1 - log(log(n) / log(2)) / log(2); if (env->f.color == 1) { a = ft_rand(90); c = ft_rand(9); env->f.color = 0; } else if (env->f.color == 2) { ft_creset(&a, &c); env->f.color = 0; } return (hsv_to_rgb(0.50 + a * color, 0.6, c)); }
static void ft_dispatch(t_game *g, int *q, int y) { int x; while (q[0] + q[1] + q[2] + q[3] + q[4] + q[5] > 0) { x = ft_rand(g->width); y = ft_rand(g->height); if (q[0] > 0) g->map[y][x].linemate += ft_rand_q(q, 0); else if (q[1] > 0) g->map[y][x].deraumere += ft_rand_q(q, 1); else if (q[2] > 0) g->map[y][x].sibur += ft_rand_q(q, 2); else if (q[3] > 0) g->map[y][x].phiras += ft_rand_q(q, 3); else if (q[4] > 0) g->map[y][x].mendiane += ft_rand_q(q, 4); else if (q[5] > 0) g->map[y][x].thystame += ft_rand_q(q, 5); ft_graph_bct(g, 0, x, y); } }
int ft_rand_stone(int *q, int i, t_game *game) { static float chance = 10; float rolling; rolling = (int)(rand() % 100 + 1); if (rolling <= chance) { chance += 10 / (game->height * game->width); q[i] -= 1; if (q[i] > 2) return (ft_rand(2) + 1); else return (1); } return (0); }
static void ft_distrib(int x, int y, t_game *game) { int q[6]; q[0] = ((game->height * game->width) * Q_LI) / 100; q[1] = ((game->height * game->width) * Q_DE) / 100; q[2] = ((game->height * game->width) * Q_SI) / 100; q[3] = ((game->height * game->width) * Q_PH) / 100; q[4] = ((game->height * game->width) * Q_ME) / 100; q[5] = ((game->height * game->width) * Q_TH) / 100; if (q[0] > 0) game->map[y][x].linemate = ft_rand_stone(q, 0, game); if (q[1] > 0) game->map[y][x].deraumere = ft_rand_stone(q, 1, game); if (q[2] > 0) game->map[y][x].sibur = ft_rand_stone(q, 2, game); if (q[3] > 0) game->map[y][x].phiras = ft_rand_stone(q, 3, game); if (q[4] > 0) game->map[y][x].mendiane = ft_rand_stone(q, 4, game); if (q[5] > 0) game->map[y][x].thystame = ft_rand_stone(q, 5, game); game->map[y][x].nourriture = ft_rand(Q_FO); }
int ft_res_ia(int *nbr, int index, int len) { int nb; int r; ft_putstr("\033[36m\n## -> Computeur has remove : \033[0m"); if (len == 4 || len == 3 || len == 2) if (nbr[index - 1] <= 3 && nbr[index - 1] != 1) return (len - 1); if ((len == 3 || len == 2) && index != 0 && nbr[index - 1] % 4 == 1) return (len); if (len == 1) return (1); nb = (len % 4 == 0) ? 3 : 0; nb = (len % 4 == 3) ? 2 : 0; nb = (len % 4 == 2) ? 1 : 0; if (len % 4 == 1 || nb == 0) { while ((r = ft_rand(4)) == 0) ; return (r); } return (nb); }
void ft_init_map(t_game *g) { ft_rand(g); ft_rand(g); }
float ft_frand(void) { return (ft_rand() / MAX_RAND); }
int main(void) { t_set set; t_test *const nodes = NEW_N(t_test, TEST_SIZE); set = SET(&test_cmp, 0); { uint32_t i; uint32_t occur; i = 0; while (i < TEST_SIZE) { nodes[i] = TEST(ft_rand(-TEST_SIZE/2, TEST_SIZE/2)); occur = count_occur(&set, nodes[i].key); ft_set_insert(&set, &nodes[i], &nodes[i].key); ASSERT(occur == count_occur(&set, nodes[i].key) - 1, "INSERT ERROR"); i++; } } ASSERT(test_order_count(&set) == TEST_SIZE, "COUNT ERROR"); test_get(&set); test_begin(&set); ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR"); TRACE("INSERT OK"); t_vec2u range; range.x = ft_rand(0, TEST_SIZE / 2); range.y = ft_rand(TEST_SIZE / 2, TEST_SIZE); { uint32_t i; uint32_t occur; i = range.x; while (i < range.y) { occur = count_occur(&set, nodes[i].key); ft_set_remove(&set, &nodes[i]); ASSERT(occur == count_occur(&set, nodes[i].key) + 1, "REMOVE ERROR"); i++; } } test_order_count(&set); test_get(&set); test_begin(&set); ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR"); TRACE("REMOVE OK"); { uint32_t i; i = range.y; while (--i >= range.x) { nodes[i].key = range.x; ft_set_insert(&set, &nodes[i], &nodes[i].key); } } test_order_count(&set); test_get(&set); test_begin(&set); ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR"); TRACE("INSERT REV SORTED OK"); { uint32_t i; i = 0; while (i < TEST_SIZE) { ft_set_remove(&set, &nodes[0]); nodes[0].key = i; ft_set_insert(&set, &nodes[0], &nodes[0].key); i++; } } test_order_count(&set); test_get(&set); test_begin(&set); ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR"); TRACE("INSERT SORTED OK"); { #define DUP_COUNT 100000 uint32_t i; t_test *before; t_test *tmp; t_test *const insert = NEW_N(t_test, DUP_COUNT); before = ft_set_get(&set, &nodes[ft_rand(0, TEST_SIZE - 1)].key); i = 0; while (i < DUP_COUNT) { while ((tmp = ft_set_prev(before)) != NULL && tmp->key == before->key) before = tmp; insert[i] = TEST(before->key - 1); ft_set_insert_before(&set, &insert[i], before); tmp = ft_set_prev(before); ASSERT(tmp == &insert[i], "INSERT_BEFORE (prev) ERROR"); tmp = ft_set_next(&insert[i]); ASSERT(tmp == before, "INSERT_BEFORE (next) ERROR"); before = &insert[i]; i++; } } test_order_count(&set); test_get(&set); test_begin(&set); ASSERT(max_height(set.root) <= min_height(set.root) * 2, "BALANCE ERROR"); TRACE("INSERT_BEFORE OK"); // print_tree(set.root); // print_iter(&set); return (0); }