Tortoise rabbit running game

xiaoxiao2021-03-06  91

The following code simulates the situation of the Turtle and Rage Racing, where there is a clock trigger set up a cycle per second, the rules of the turtle are: 50% of the opportunity to go (right shift three); 20% chance decline (left shift Sixth); 30% of the opportunity to go slowly (right shift one).

The rabbit rules are: 20% of the opportunity to sleep (not moving); 20% chance to jump (right-shifted); 10% chance big slip (left shift 12 grid); 30% opportunity small jump (right Move one); 20% of the chance slide (left shift two grid).

One of the firsts of the whole 70 grid, more than 70 grids start; the program prints the trajectory of the turtle rabbit moving on one line, and when the two coincides up, the turtle is used to reply with T.

***********************************************

#include

#include

#include

Void Guitu (void);

Main ()

{

SRAND (Time (null);

Guitu ();

Return 0;

}

Void Guitu ()

{

INT I, J, COUNT = 0, Coun = 0, Number;

Char PrintFun [71];

While (1) {

For (j = 0; j <70; j )

PRINTFUN [J] = '';

PrintFun [71] = '';

Number = rand ()% 10 1;

Printf ("n");

IF (1 <= Number && Number <= 5) {

Count = count 3;

IF (count> 70) count = 0;

Printfun [count] = 'g';

}

IF (6 <= Number && Number <= 7) {

count = count-6;

IF (count <0) count = 0;

Printfun [count] = 'g';

}

IF (8 <= Number && Number <= 10) {

Count = count 1;

IF (count> 70) count = 0;

Printfun [count] = 'g';

}

IF (1 <= Number && Number <= 2) {

Coul = cou 0;

PRINTFUN [Cou] = 'T';

}

IF (3 <= Number && Number <= 4) {

Coul = cou 9;

IF (co> 70) cou = 0;

PRINTFUN [Cou] = 'T';

}

IF (Number == 5) {

Coul = COU-12;

IF (cou <0) cou = 0;

PRINTFUN [Cou] = 'T';

}

IF (6 <= Number && Number <= 8) {

Coul = cou 1;

IF (co> 70) cou = 0;

PRINTFUN [Cou] = 'T';

}

IF (9 <= Number && Number <= 10) {

Coul = COU-2;

IF (cou <0) cou = 0;

PRINTFUN [Cou] = 'T';

}

IF (count == COU)

Printfun [count] = 'p'; Printf ("% s", printfun);

Printf ("nn");

IF (count == 70) {

Printf ("GUI WIN !!! NN");

Break;

}

IF (cou == 70) {

Printf ("tu win !!! nn");

Break;

}

Sleep (1);

}

}

转载请注明原文地址:https://www.9cbs.com/read-124035.html

New Post(0)