| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 398 人关注过本帖
标题:六子棋问题
只看楼主 加入收藏
chaizhi
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-12-27
收藏
 问题点数:0 回复次数:0 
六子棋问题
六子棋问题,那位高手帮我改一下?

下面是源程序:
#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]]
2007-12-27 18:54
快速回复:六子棋问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017721 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved