六子棋问题
六子棋问题,那位高手帮我改一下?下面是源程序:
#include "stdio.h"
#include "SearchEngine.h"
BYTE position[GRID_NUM][GRID_NUM]; //棋盘
void main()
{
int ChessmanType; //记录棋子颜色
char Msg[500]; //保存接收到的消息
char name[] = "name BitStronger\n"; //队伍信息
char Move[] = "move AABB\n"; //走法
int x0,x1,y0,y1; //坐标
memset(position,NOSTONE,GRID_COUNT);//初始化棋盘
while (1)
{
//循环接收裁判平台发送的消息
//注意需要发送的字符串应该以'\n'结束,裁判平台才会认为是一次完整的输入
//发送完需要调用fflush(stdout)清空输出缓冲区,使字符串立刻输出到裁判平台
memset(Msg,0,500);
scanf("%s",Msg);
if (strcmp(Msg,"name?") == 0)
{
//name?
printf("%s",name);
fflush(stdout);
continue;
}
if (strcmp(Msg,"new") == 0)
{
//new
memset(position,NOSTONE,GRID_COUNT);//初始化棋盘
scanf("%s",Msg);
if (strcmp(Msg,"black") == 0)
{
//new black
Sleep(50); //延迟一段时间发送,经测试,立即发送可能造成平台无响应
printf("move JJ\n");
position[9][9] = BLACK;
fflush(stdout);
ChessmanType = BLACK;
continue;
}
else
{
//new white
ChessmanType = WHITE;
continue;
}
}
if (strcmp(Msg,"move") == 0)
{
//move
scanf("%s",Msg);
if (Msg[2] == '\0')
{
//move XX\n
y0 = (int)(Msg[0]) - (int)('A');
x0 = (int)('S') - (int)(Msg[1]);
position[x0][y0] = !ChessmanType;
}
else
{
//move XYXY\n
y0 = (int)(Msg[0]) - (int)('A');
x0 = (int)('S') - (int)(Msg[1]);
y1 = (int)(Msg[2]) - (int)('A');
x1 = (int)('S') - (int)(Msg[3]);
position[x0][y0] = !ChessmanType;
position[x1][y1] = !ChessmanType;
}
if (SearchAGoodMove(position,ChessmanType))
{
//获得着法的坐标
x0 = m_cmBestMove.StonePos[0].x;
y0 = m_cmBestMove.StonePos[0].y;
x1 = m_cmBestMove.StonePos[1].x;
y1 = m_cmBestMove.StonePos[1].y;
//将着法记录在棋盘中
position[x0][y0] = ChessmanType;
position[x1][y1] = ChessmanType;
//将着法转换成要发送的字符形式
y0 = (char)((int)('A') + y0);
x0 = (char)((int)('S') - x0);
y1 = (char)((int)('A') + y1);
x1 = (char)((int)('S') - x1);
//Move[] = "move AABB\n"
//修改 "AABB" 并发送
Move[5] = y0;
Move[6] = x0;
Move[7] = y1;
Move[8] = x1;
printf("%s",Move);
fflush(stdout);
}
}//move
}
[[italic] 本帖最后由 chaizhi 于 2007-12-27 18:56 编辑 [/italic]]