wormsimple.cpp
来自「人工智能最简单问题的示例代码」· C++ 代码 · 共 63 行
CPP
63 行
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int strcmp1(char *a,char *b) {
int res=0;
while (*a==*b) {
if (a=='\0') break;
res++;a++;b++;
}
return res;
}
int main() {
char str[100];
srand((unsigned)time(NULL));
while (true) {
gets(str);
if (strcmp1(str,"check_status")>=12) {
cerr<<"ready"<<flush;
continue;
}
else if (strcmp1(str,"beetlemove")>=10) {
switch (rand()%4) {
case 0:
cerr<<"action up"<<flush;
break;
case 1:
cerr<<"action down"<<flush;
break;
case 2:
cerr<<"action left"<<flush;
break;
case 3:
cerr<<"action right"<<flush;
}
continue;
}
else if (strcmp1(str,"snailmove")>=9) {
switch (rand()%4) {
case 0:
cerr<<"action up"<<flush;
break;
case 1:
cerr<<"action down"<<flush;
break;
case 2:
cerr<<"action left"<<flush;
break;
case 3:
cerr<<"action right"<<flush;
}
continue;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?