查看: 3774|回复: 8
打印 上一主题 下一主题

[原创] RT1052中国象棋

[复制链接]
  • TA的每日心情
    开心
    昨天 09:00
  • 签到天数: 1368 天

    连续签到: 7 天

    [LV.10]以坛为家III

    39

    主题

    2万

    帖子

    4

    金牌会员

    Rank: 6Rank: 6

    积分
    18861
    最后登录
    2026-4-1
    跳转到指定楼层
    楼主
    发表于 2022-3-29 17:11:49 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
    中国象棋是由两人轮流走子,分执红黑棋子,以“将死”或“困毙”对方将(帅)为胜,双方子力相同,每方各16颗(7)棋子,在9*10的交叉线上交战,其中的开局套路、中局搏杀、残局破解变化无穷。
    因为本次活动只考虑界面,故算法极为简陋(最大最小值)。先show一下界面:
    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的每日心情
    开心
    2025-7-11 08:53
  • 签到天数: 301 天

    连续签到: 2 天

    [LV.8]以坛为家I

    4213

    主题

    7882

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    43300
    最后登录
    2026-4-1
    沙发
    发表于 2022-3-29 17:48:43 | 只看该作者
    象棋还真的来了
    qiandao qiandao
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2025-7-11 08:53
  • 签到天数: 301 天

    连续签到: 2 天

    [LV.8]以坛为家I

    4213

    主题

    7882

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    43300
    最后登录
    2026-4-1
    板凳
    发表于 2022-3-29 17:59:07 | 只看该作者
    能对战一把吗?1052做这个是不是有点大材小用了?
    qiandao qiandao
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    5 天前
  • 签到天数: 1555 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    98

    主题

    5237

    帖子

    12

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    10694
    最后登录
    2026-3-28
    地板
    发表于 2022-3-29 18:00:27 | 只看该作者
    厉害了

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

    使用道具 举报

  • TA的每日心情
    擦汗
    2026-2-23 14:25
  • 签到天数: 894 天

    连续签到: 1 天

    [LV.10]以坛为家III

    69

    主题

    3312

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    10532
    最后登录
    2026-3-17
    5#
    发表于 2022-3-29 18:52:34 | 只看该作者
    腻害 膜拜
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    前天 23:18
  • 签到天数: 2027 天

    连续签到: 8 天

    [LV.Master]伴坛终老

    203

    主题

    3万

    帖子

    64

    超级版主

    Rank: 8Rank: 8

    积分
    113875
    最后登录
    2026-3-31
    6#
    发表于 2022-3-29 21:06:41 | 只看该作者
    厉害了,这个带计算引擎吗?
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    擦汗
    昨天 10:59
  • 签到天数: 2254 天

    连续签到: 3 天

    [LV.Master]伴坛终老

    65

    主题

    9425

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    15308
    最后登录
    2026-4-1
    7#
    发表于 2022-3-30 08:20:33 | 只看该作者
    大佬大佬。。。。。
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 13:56
  • 签到天数: 2605 天

    连续签到: 35 天

    [LV.Master]伴坛终老

    87

    主题

    2万

    帖子

    3

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    24892
    最后登录
    2026-4-1
    8#
    发表于 2022-3-30 11:53:46 | 只看该作者
    大佬厉害,对战一局
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2026-3-18 11:47
  • 签到天数: 773 天

    连续签到: 1 天

    [LV.10]以坛为家III

    15

    主题

    2825

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    4969
    最后登录
    2026-3-18
    9#
    发表于 2022-7-7 13:00:02 | 只看该作者
    大佬厉害
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

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

    本版积分规则

    关闭

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

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

    GMT+8, 2026-4-2 00:49 , Processed in 0.099617 second(s), 27 queries , Redis On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

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