- 追加された行はこの色です。
- 削除された行はこの色です。
[[2004/C1/練習問題]]
担当:フジサワ
int t=0,y=0;
void go_straight()
{
OnFwd(OUT_A+OUT_C);
Wait(t);
Off(OUT_A+OUT_C);
}
void Light()
{
int tmax=0,tpoint=0,lightmax=0;
SetSensor(SENSOR_1, SENSOR_LIGHT);
if(y == 0){
ClearTimer(0);
OnFwd(OUT_A);
OnRev(OUT_C);
Wait(t);
if(SENSOR_1 >= lightmax){
lightmax=SENSOR_1;
tmax=Timer(0);
}
if(SENSOR_1 >= 40){
tpoint=t-tmax;
OnFwd(OUT_C);
OnRev(OUT_A);
Wait(t);
Off(OUT_A+OUT_C);
}
}else{
ClearTimer(0);
OnFwd(OUT_C);
OnRev(OUT_A);
Wait(t);
if(SENSOR_1 >= lightmax){
lightmax=SENSOR_1;
tmax=Timer(0);
}
if(SENSOR_1 >= 40){
tpoint=t-tmax;
OnFwd(OUT_C);
OnRev(OUT_A);
Wait(t);
Off(OUT_A+OUT_C);
}
}
}
sub run()
{
int x=0;
SetSensor(SENSOR_1, SENSOR_LIGHT);
while(true){
if(SENSOR_1 >= 40){
x=0;
t=300;
go_straight();
}else if((SENSOR_1 < 40)&&(x == 0)){
t=150;
Light();
y++;
t=300;
Light();
y--;
t=150;
Light();
x++;
}else{
t=340;
Light();
}
}
}
task main()
{
t=340;
Light();
if(SENSOR_1 >= 40){
run();
}
}