123
返回列表 发新帖
楼主: geraint0923
跳转到指定楼层
上一主题 下一主题
收起左侧

M$ on-site

🔗
 楼主| geraint0923 2015-3-1 14:27:17 | 只看该作者
全局:
harry528 发表于 2015-3-1 07:31
可以给我看看你的code吗~

具体的代码不记得了,大概的代码是:

enum EDIR {
        DIR_UP = 0,
        DIR_DOWN,
        DIR_LEFT,
        DIR_RIGHT,
        DIR_COUNT
};

bool findPath(Mouse *m, int x, int y, unordered_set<string> &points) {
        if(m->AtCheese())
                return true;
        for(int i = 0; i < DIR_COUNT; i++) {
                EDIR backDir;
                int nx, ny;
                switch(i) {
                        case DIR_UP:
                                nx = x;
                                ny = y + 1;
                                backDir = DIR_DOWN;
                                break;
                        case DIR_DOWN:
                                nx = x;
                                ny = y - 1;
                                backDir = DIR_UP;
                                break;
                        case DIR_LEFT:
                                nx = x - 1;
                                ny = y;
                                backDir = DIR_RIGHT;
                                break;
                        case DIR_RIGHT:
                                nx = x + 1;
                                ny = y;
                                backDir = DIR_LEFT;
                                break;
                }
                string newPoint = to_string(nx) + "," + to_string(ny);
                if(points.count(newPoint))
                        continue;
                points.insert(newPoint);
                if(m->Move(i)) {
                        bool res = findPath(m, nx, ny, points);
                        if(res)
                                return true;
                        m->Move(backDir);
                }
        }
        return false;
}

bool findCheese(Mouse *m) {
        unordered_set<string> points;
        points.insert("0,0");
        return findPath(m, 0, 0, points);
}
回复

使用道具 举报

🔗
 楼主| geraint0923 2015-3-1 14:44:20 | 只看该作者
全局:
cvfox4fun 发表于 2015-3-1 13:27
能不能把交通灯那个东西多说一说?
不是很懂怎么做?

(1) 我觉得至少要有initialize(), start(), stop(), finalize()这几个函数吧
(2) controller通过broadcast来通知硬件改变状态
(3) 要能切换算法,就必须要暴露一些能够控制硬件的接口给scheduler这个类,比如setColor之类的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

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