Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: Raphael
- *
- * Created on 25 septembre 2013, 21:04
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define FALSE 0
- #define TRUE 1
- #define SIZE_GRID 4
- #define NCOLOR 7
- int gagner = 0,
- defaite = 0;
- enum {
- RED,
- YELLOW,
- GREEN,
- BLUE,
- ORANGE,
- WHITE,
- PURPLE,
- FUCHSIA
- };
- int ball_color[SIZE_GRID] = {-1};
- int player_color[SIZE_GRID] = {-1};
- inline int
- _rand(int max) {
- return (rand() % max);
- }
- void
- rand_color(void) {
- int i;
- for (i = 0; i < SIZE_GRID; i++) {
- ball_color[i] = _rand(NCOLOR);
- }
- }
- void
- resolve(void) {
- int i = 0,
- j = 0;
- while (player_color[0] != ball_color[0] || player_color[1] != ball_color[1] || player_color[2] != ball_color[2] || player_color[3] != ball_color[3]) {
- if (player_color[0] != ball_color[0])
- player_color[0] = j;
- if (player_color[1] != ball_color[1])
- player_color[1] = j;
- if (player_color[2] != ball_color[2])
- player_color[2] = j;
- if (player_color[3] != ball_color[3])
- player_color[3] = j;
- j++;
- }
- if (j <= 12)
- gagner++;
- else
- defaite++;
- printf("%d %d %d %d\n", ball_color[0], ball_color[1], ball_color[2], ball_color[3]);
- printf("%d %d %d %d -> %d\n\n", player_color[0], player_color[1], player_color[2], player_color[3], j);
- }
- int main(int argc, char** argv) {
- int i = 0;
- (void)argc;
- (void)argv;
- srand(time(NULL));
- for (i = 0; i < 1000; i++) {
- rand_color();
- resolve();
- }
- printf("Gagnes: %d\nPerdues: %d", gagner, defaite);
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement