查看: 1334|回复: 8

[原创] RT1052中国象棋

[复制链接]
  • TA的每日心情
    奋斗
    昨天 20:05
  • 签到天数: 753 天

    [LV.10]以坛为家III

    23

    主题

    1366

    帖子

    4

    金牌会员

    Rank: 6Rank: 6

    积分
    5311
    最后登录
    2024-5-1
    发表于 2022-3-29 17:11:49 | 显示全部楼层 |阅读模式
    中国象棋是由两人轮流走子,分执红黑棋子,以“将死”或“困毙”对方将(帅)为胜,双方子力相同,每方各16颗(7)棋子,在9*10的交叉线上交战,其中的开局套路、中局搏杀、残局破解变化无穷。
    因为本次活动只考虑界面,故算法极为简陋(最大最小值)。先show一下界面:
    IMG_20220327_132323.jpg
    RT1052做SoC,勉强可以执行
    摘出象棋的棋子走法
    bool canMoveJu(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            if (getStoneNum(mystone[id].row,mystone[id].col,dstrow,dstcol)==0){
                    return true;
            }else{
                    return false;
            }
    }
    bool canMoveShuai(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            if (mystone[getStoneId(dstrow,dstcol)].type==0){
                    return canMoveJu(id,dstrow,dstcol);
            }
            if (dstcol>5 || dstcol<3) return false;
            int r = relation(mystone[id].row, mystone[id].col, dstrow, dstcol);
      if (r != 1 && r != 10) return false;
            if (mystone[id].isred && dstrow<7) return false;
            if (!mystone[id].isred && dstrow>2) return false;
            return true;
    }
    bool canMovePao(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            if (getStoneId(dstrow,dstcol)==-1){
                    return canMoveJu(id,dstrow,dstcol);
            }else{
                    if (mystone[getStoneId(dstrow,dstcol)].isexist && getStoneNum(mystone[id].row,mystone[id].col,dstrow,dstcol)==1 && mystone[id].isred!=mystone[getStoneId(dstrow,dstcol)].isred){
                            return true;
                    }else{
                            return false;
                    }
            }
    }
    bool canMoveMa(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            int r = relation(mystone[id].row, mystone[id].col, dstrow, dstcol);
      if (r != 12 && r != 21) return false;
            if (r==12 && getStoneId(mystone[id].row,(mystone[id].col+dstcol)/2)>=0) return false;
            if (r==21 && getStoneId((mystone[id].row+dstrow)/2,mystone[id].col)>=0) return false;
            return true;
    }
    bool canMoveXiang(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            int r = relation(mystone[id].row, mystone[id].col, dstrow, dstcol);
      if(r != 22) return false;
            if(mystone[id].isred && dstrow<5) return false;
            if(!mystone[id].isred && dstrow>4) return false;
            if(getStoneId((mystone[id].row+dstrow)/2,(mystone[id].col+dstcol)/2)>=0) return false;
            return true;
    }
    bool canMoveShi(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            int r = relation(mystone[id].row, mystone[id].col, dstrow, dstcol);
      if(r != 11) return false;
            if(dstcol>5 || dstcol<3) return false;
            if(mystone[id].isred && dstrow<7) return false;
            if(!mystone[id].isred && dstrow>2) return false;
            return true;
    }
    bool canMoveBing(uint8_t id,uint8_t dstrow,uint8_t dstcol){
            if (dstrow>9) return false;
            if (dstcol>8) return false;
            if (getStoneId(dstrow,dstcol)>=0 && mystone[id].isred==mystone[getStoneId(dstrow,dstcol)].isred) return false;
            int r = relation(mystone[id].row, mystone[id].col, dstrow, dstcol);
      if (r != 10 && r !=01) return false;
            if (mystone[id].isred){
                    if(mystone[id].row<dstrow) return false;
                    if(mystone[id].row>4 && mystone[id].row<=dstrow) return false;               
            }else{
                    if(mystone[id].row>dstrow) return false;
                    if(mystone[id].row<5 && mystone[id].row>=dstrow) return false;
            }
            return true;
    }
    bool canMove(uint8_t dstrow,uint8_t dstcol){
            if(selectedId==-1){
                    //PRINTF("no selected\r\n");
                    return false;
            }
            if(redturn!=mystone[selectedId].isred){
                    return false;
            }
            switch (mystone[selectedId].type){
                    case 0:
                            return canMoveShuai(selectedId,dstrow,dstcol);
                    case 1:
                            return canMoveShi(selectedId,dstrow,dstcol);
                    case 2:
                            return canMoveXiang(selectedId,dstrow,dstcol);
                    case 3:
                            return canMoveMa(selectedId,dstrow,dstcol);
                    case 4:
                            return canMoveJu(selectedId,dstrow,dstcol);
                    case 5:
                            return canMovePao(selectedId,dstrow,dstcol);
                    case 6:
                            return canMoveBing(selectedId,dstrow,dstcol);
                    default:
                            //PRINTF("default false\r\n");
                            return false;
            }
    }

    drawboard-加时钟.rar

    3.79 MB, 下载次数: 1, 下载积分: 威望 1

    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3303

    主题

    6550

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32055
    最后登录
    2024-4-30
    发表于 2022-3-29 17:48:43 | 显示全部楼层
    象棋还真的来了
    签到签到
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3303

    主题

    6550

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32055
    最后登录
    2024-4-30
    发表于 2022-3-29 17:59:07 | 显示全部楼层
    能对战一把吗?1052做这个是不是有点大材小用了?
    签到签到
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    昨天 15:27
  • 签到天数: 1336 天

    [LV.10]以坛为家III

    88

    主题

    4293

    帖子

    12

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    9054
    最后登录
    2024-5-2
    发表于 2022-3-29 18:00:27 | 显示全部楼层
    厉害了

    学习了
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 07:31
  • 签到天数: 597 天

    [LV.9]以坛为家II

    51

    主题

    2230

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    7095
    最后登录
    2024-5-1
    发表于 2022-3-29 18:52:34 | 显示全部楼层
    腻害 膜拜
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情

    前天 14:02
  • 签到天数: 1481 天

    [LV.10]以坛为家III

    203

    主题

    2万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    92876
    最后登录
    2024-4-30
    发表于 2022-3-29 21:06:41 | 显示全部楼层
    厉害了,这个带计算引擎吗? 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10.png
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    擦汗
    3 小时前
  • 签到天数: 1786 天

    [LV.Master]伴坛终老

    65

    主题

    7550

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    12774
    最后登录
    2024-5-2
    发表于 2022-3-30 08:20:33 | 显示全部楼层
    大佬大佬。。。。。
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    昨天 11:02
  • 签到天数: 1945 天

    [LV.Master]伴坛终老

    61

    主题

    1万

    帖子

    3

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    17341
    最后登录
    2024-5-1
    发表于 2022-3-30 11:53:46 | 显示全部楼层
    大佬厉害,对战一局
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    前天 10:27
  • 签到天数: 486 天

    [LV.9]以坛为家II

    8

    主题

    1360

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2925
    最后登录
    2024-4-30
    发表于 2022-7-7 13:00:02 | 显示全部楼层
    大佬厉害
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-5-2 14:14 , Processed in 0.154948 second(s), 28 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表