0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

【地平线旭日X3派试用体验】保姆级配置git与使用+C语言编写贪吃蛇

地平线机器人 2022-08-09 16:27 次阅读

安装配置git

一、更新软件源

  • sudo apt update

二、安装git

  • sudo apt install git -y
pYYBAGLyE4uAQSB6AAArFHt6CzA433.png

  • 成功安装git如图:
pYYBAGLyE4uAPS_WAAEbNiRmpBg353.png

三、配置git

1、设置账号

  • git config --global user.name "name" (github官网注册的用户名)

2、设置邮箱

  • git config --global user.email "email" (gitub官网注册绑定的邮箱)

3、查看配置

  • git config --list

4、生成SSH秘钥

  • ssh-keygen -t rsa -C "注册绑定的邮箱"

(输入两次密码后,提示的地方直接按Enter,成功生成如下图所示)

poYBAGLyE4uAb4oeAACfB5RXrQE463.png

5、查看生成的秘钥

  • cd
  • cat id_rsa.pub (秘钥命名可能有不同,但一定要是pub文件)

poYBAGLyE4yAbP0CAAB6RCbihMg334.png

6、github配置SSH公钥

  • 登录github官网,网址:https://github.com/
  • 右上角登陆后点击settings->SSH and GPS keys->New SSH key
poYBAGLyE4uAfp1-AAD1BzlKZXM334.png
  • 将id_rsa.pub文件中的生成的内容全部复制到key中,输入title,点击Add SSH key即可
poYBAGLyE4uAbCGXAADdSupH6qI408.png

下载代码

  • git clone “仓库地址"
pYYBAGLyE4yAUA0OAABP_Lze-0s821.png

本地文件推送到远程仓库

1、查询状态

  • git status

2、添加文件到缓存区

  • git add *

3、再次查询状态(文件由红变成绿色,说明已转移至缓存区)

  • git status
pYYBAGLyE4yABU5BAABktsc4qQ0337.png

4、提交到本地仓库

  • git commit -m "source"(”source“是注释)

5、添加本地仓库推送至远程仓库的地址

  • git remote add origin +仓库地址

6、核实远程仓库地址

  • git remote -v

7、推送至远程仓库

  • git push -u origin master
poYBAGLyE4yAFq5DAADxZmxabe8055.jpg

pYYBAGLyE42AC6EOAABnD1-0qlk178.png

注:上文提到的仓库地址需要自行创建获取。

pYYBAGLyE42ARh-4AABSAPrMgUY926.png

C语言编写贪吃蛇程序

1、编写代码

  • vim tanchishe.c (使用vim工具编辑,进入后按esc按键后再按i或者l切换编辑模式)
  • 编辑完成后,按下esc按键,再依次输入:wq保存并推出
#include #include #include #include #include #include #include #include #include #define MOVEUP(x) printf("\033[%dA", (x)) static struct termios ori_attr,cur_attr;static inline int tty_reset();static inline int kbhit();static inline int tty_set();#define ROW_MAX 20#define COL_MAX 50#define SPEED_MAX 500#define SPEED_MIN 125#define SNAKELEN 3#define SNAKE_HEAD '@'#define SNAKE_BODY '#'#define FOOD '$'#define LEFT 'a'#define RIGHT 'd'#define UP 'w'#define DOWN 's'#define EAT_SPACE 1#define EAT_FOOD 2#define EAT_BODY 0char dc = '0';char bodyDc = '0'; float speed = SPEED_MAX ;//ms int snake_length = 0; int grade  = 1;  struct Location {     int row;     int col; };  typedef struct ske {     struct Location place;     struct ske *next; }Snake;  struct Location food; Snake *head = NULL;  char str[ROW_MAX][COL_MAX]; void Init_str();void Display();void Init_food();void Init_snake();void Wait_game();int Snake_move();void moveToUp();void moveToDown();void moveToLeft();void moveToRight();void snakeShow();void foodShow();void reDisplay();void GameOver();void addBody(int,int);void moveBody(int,int);void Delay();int isUpgrade();int Upgrade();void releaseSnake();void PrintRule(); int main() {     int again = 0;         do     {//printf("\033[2J");         int flag = 0;again = 0;         Init_str();         Init_snake();         Init_food();         Display();         Wait_game();         while(1)         {             flag = Snake_move() ;     if(flag == EAT_BODY)     {GameOver();     }             reDisplay();             Delay();                          if(isUpgrade())             {again = Upgrade();                      break;             }         }     }while( again == 1); }void PrintRule(){    printf("**************************************************\n");    printf("* 游戏规则:【@】表示蛇头,【$】表示食物,【#】  *\n");    printf("* 表示蛇的身体。每吃到一个食物蛇的身体加长一个, *\n");    printf("* 吃到蛇身或撞到墙,则游戏结束                   *\n");    printf("* 按wsad可以控制蛇移动方向,分别表示上下左右方向 *\n");    printf("* 请按wsad键开始游戏                             *\n");    printf("**************************************************\n");}void GameOver(){    printf("Game Over!!!\n");    printf("you play %d grade,and score is :%d\n",grade,(grade-1)*2000+(snake_length-1)*100);    exit(1);}int Upgrade(){    if( speed <= SPEED_MIN)    {printf("Congratulations!!! you win.\n");exit(1);    }    else    { printf("Play next grade ? < y / n >\n");printf("Else press  to exit.\n ");grade ++ ;char ch ;do{    ch = getch();    ch = tolower(ch);    if(ch == 'y' )    {releaseSnake();snake_length = 0;speed /= 2;      return 1;    }    else if(ch == 'n')    {printf("Play this grade.\n");return 1;    }    else if(ch == 27)exit(1);}while(ch != 'y' || ch != 'n');    }}void releaseSnake(){    Snake *p = head;    while(head != NULL)     {p = head;head = head->next;free(p);    }}int isUpgrade(){    return snake_length == SNAKELEN ? 1:0;}void Delay(){    unsigned long int tick1 = clock();    char ch;    while(1000*(clock() - tick1 )/CLOCKS_PER_SEC <= speed)    {ch = control();ch = tolower(ch);if(ch == UP){    if(dc != DOWN)    {    dc = ch;        break;    }}else if(ch == DOWN){    if(dc != UP)    { dc = ch ;break;    }}else if( ch == LEFT){    if(dc != RIGHT)    {dc = ch;break;    }}else if(ch == RIGHT){    if(dc != LEFT)    { dc = ch;break;    }}    }}void addBody(int x, int y){    Snake *p = (Snake *)malloc(sizeof(Snake));    if(p == NULL)    {printf("Error!!!Apply Snake *p failed\n");exit(1);    }    p->place.row = x;    p->place.col = y;    p->next = head->next;    head->next = p;    snake_length ++;   }void foodShow(){    str[food.row][food.col] = FOOD;}void snakeShow(){    Snake *p = head;    while(p != NULL)    {if(p == head)    str[p->place.row][p->place.col] = SNAKE_HEAD ; else    str[p->place.row][p->place.col] = SNAKE_BODY ; p = p->next;     }}void reDisplay(){    Init_str();    foodShow();    snakeShow();     Display(); }int Snake_move(){    int x = head->place.row;    int y = head->place.col;    switch(dc)    {case UP :    if(dc != DOWN )moveToUp();    break;case DOWN :    if(dc != UP )moveToDown();    break;case LEFT :    if(dc != RIGHT )moveToLeft();    break;case RIGHT :    if(dc != LEFT)moveToRight();    break;    }    bodyDc = dc;    int i = head->place.row;    int j = head->place.col;    if(str[i][j] == SNAKE_BODY )    {return EAT_BODY;    }    else if(str[i][j] == FOOD )    {addBody(x,y);Init_food();return EAT_FOOD;    }    else if(str[i][j] == ' ')    {moveBody(x,y);return EAT_SPACE;    }}void moveBody(int x,int y){    Snake *p = head ,*pre = NULL;    if(head->next != NULL)    {while(p->next != NULL){       pre = p;    p = p->next; }if(pre != head){    p->place.row = x;    p->place.col = y;    p->next = head->next;    head->next = p;    pre->next  = NULL ;    }else{    p->place.row = x;    p->place.col = y;}    }}void moveToRight(){    int i = head->place.row;    int j = head->place.col;    dc = RIGHT ;    if(str[i][j+1] != '|')    {j++ ;    }    else      {GameOver();    }    head->place.row = i;    head->place.col = j;}void moveToLeft(){    int i = head->place.row;    int j = head->place.col;    dc = LEFT ;    if(str[i][j-1] != '|')    {j-- ;    }    else      {GameOver();    }    head->place.row = i;    head->place.col = j;}void moveToUp(){    int i = head->place.row;    int j = head->place.col;    dc = UP ;    if(str[i-1][j] != '-')    {i-- ;    }    else      {GameOver();    }    head->place.row = i;    head->place.col = j;}void moveToDown(){    int i = head->place.row;    int j = head->place.col;    dc = DOWN ;    if(str[i+1][j] != '-')    {i++ ;    }    else      {GameOver();    }    head->place.row = i;    head->place.col = j;}/*void moveToRight(){    int i = head->place.row;    int j = head->place.col;    dc = RIGHT ;    if(str[i][j+1] != '|')    {j++ ;    }*void moveToRight(){    int i = head->place.row;    int j = head->place.col;    dc = RIGHT ;    if(str[i][j+1] != '|')    {j++ ;    }*void moveToRight(){    int i = head->place.row;    int j = head->place.col;    dc = RIGHT ;    if(str[i][j+1] != '|')    {j++ ;    }    else      {j = 1;    }    head->place.row = i;    head->place.col = j;}void moveToLeft(){    int i = head->place.row;    int j = head->place.col;    if(str[i][j-1] !=  '|')    {dc = LEFT ;j--;    }    else    {dc = LEFT ;j = COL_MAX - 2;    }    head->place.row = i;    head->place.col = j;}void moveToDown(){    int i = head->place.row;    int j = head->place.col;    if(str[i+1][j] != '-')    {dc = DOWN ;i++;    }    else     {dc = DOWN ;i = 1;    }    head->place.row = i;    head->place.col = j;    }void moveToUp(){    int i = head->place.row;    int j = head->place.col;    if(str[i-1][j] != '-')    {dc = UP;i--;    }    else    {dc = UP ;i = ROW_MAX -2;    }    head->place.row = i;    head->place.col = j;}*/void Wait_game() {     char ch ;     do     {         ch = getch();         ch = tolower(ch);     }while(ch != UP && ch != DOWN && ch != LEFT && ch != RIGHT );     dc = ch;     bodyDc = dc; } void Init_food() {     unsigned long int seed = time(NULL);     srand(seed+1);     while(1)     {food.row = rand() % ( ROW_MAX - 2) + 1;food.col = rand() % ( COL_MAX - 2) + 1;Snake *p = head;int flag = 1;while(p != NULL){    if(food.row == p->place.row && food.col == p->place.col)    {flag = 0;break;    }    p = p->next;}if(flag == 1)     break;     }     str[food.row][food.col] = FOOD; } void Init_str() {     int i,j;     for(i=0;iplace.row = rand() % ( ROW_MAX - 2) + 1;head->place.col = rand() % ( COL_MAX - 2) + 1;head->next = NULL;str[head->place.row][head->place.col] = SNAKE_HEAD ;snake_length ++ ;     } } /***********   about string handle function  ***********/int control(){int flag = tty_set();int key = 0;if(kbhit())key = getchar();if(flag == 0)tty_reset();return key;}static inline int tty_reset(){if(tcsetattr(STDIN_FILENO,TCSANOW,&ori_attr) != 0)return -1;return 0;}static inline int tty_set(){if(tcgetattr(STDIN_FILENO,&ori_attr))return -1;memcpy(&cur_attr,&ori_attr,sizeof(cur_attr));cur_attr.c_lflag &= ~ICANON;cur_attr.c_lflag &= ~ECHO;cur_attr.c_cc[VMIN] = 1;cur_attr.c_cc[VTIME] = 0;if(tcsetattr(STDIN_FILENO,TCSANOW,&cur_attr) != 0)return -1;return 0;}static inline int kbhit(){fd_set rfds;struct timeval tv;int retval;FD_ZERO(&rfds);FD_SET(0,&rfds);tv.tv_sec = 0;tv.tv_usec = 0;retval = select(1,&rfds,NULL,NULL,&tv);if(retval == -1){perror("select()");return 0;}else if(retval)return 1;elsereturn 0;}int getch(void) {        int c=0;        struct termios org_opts, new_opts;        int res=0;        //-----  store old settings -----------        res=tcgetattr(STDIN_FILENO, &org_opts);        //---- set new terminal parms --------        memcpy(&new_opts, &org_opts, sizeof(new_opts));        new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL);        tcsetattr(STDIN_FILENO, TCSANOW, &new_opts);        c=getchar();            //------  restore old settings ---------        res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts);        return c;}

2、编译代码

  • gcc tanchishe.c
poYBAGLyE4yAGTQOAADgSFw9c5U314.png

3、运行代码

  • ./a.out
poYBAGLyE42AYr-gAACauv24qZ0059.png

小结:

经过了几周的试用,刚开始的时候固件可能还未完善,个别功能无法开启或例程无法使用,折腾了我好几天,这在后面的维护更新后都得到了解决。这里给地平线的工作人员点个赞,遇到问题他们会热心的解答,出现异常时也有及时处理。总体来说,旭日X3派是一块面向入门嵌入式非常不错的开发板,X3派具有不错的处理与易于扩展的能力,可以满足嵌入式的低功耗、无线连接和安全等特性。

本文转自地平线开发者社区

原作者:Zeee

原链接:https://developer.horizon.ai/forumDetail/98129540173361632

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • AI
    AI
    +关注

    关注

    87

    文章

    26443

    浏览量

    264038
  • 人工智能
    +关注

    关注

    1776

    文章

    43845

    浏览量

    230596
  • 地平线
    +关注

    关注

    0

    文章

    306

    浏览量

    14635
收藏 人收藏

    评论

    相关推荐

    地平线向港交所递交招股书

    智能驾驶计算方案领军者地平线,近日正式向港交所递交了招股书,高盛、摩根士丹利及中信建投为其联席保荐人。这并非地平线首次试水资本市场,早在2021年,地平线就计划科创板上市,并一度传出赴美IPO的消息,但受资本市场环境影响,其上市
    的头像 发表于 03-27 16:02 202次阅读

    基于51单片机的贪吃蛇设计

    电子发烧友网站提供《基于51单片机的贪吃蛇设计.rar》资料免费下载
    发表于 01-12 09:53 2次下载

    基于51单片机的贪吃蛇设计

    电子发烧友网站提供《基于51单片机的贪吃蛇设计.rar》资料免费下载
    发表于 01-03 10:26 0次下载

    基于51单片机的贪吃蛇游戏设计

    基于51单片机的贪吃蛇游戏设计(仿真+实物)
    发表于 01-02 09:38 2次下载

    基于51单片机的贪吃蛇游戏设计

    电子发烧友网站提供《基于51单片机的贪吃蛇游戏设计.pdf》资料免费下载
    发表于 10-25 10:38 2次下载
    基于51单片机的<b class='flag-5'>贪吃蛇</b>游戏设计

    软硬协同优化,地平线旭日3成功部署14亿参数大语言模型

    近日,地平线成功在旭日3中的BPU®️计算单元上,部署运行参数规模高达14亿的大语言模型(Large Language Model , LLM)。这不仅是业界在端侧成功部署大模型的一次突破性实践,更验证了BPU®️对先进神经网络
    的头像 发表于 09-12 13:36 998次阅读
    软硬协同优化,<b class='flag-5'>地平线</b><b class='flag-5'>旭日</b>3成功部署14亿参数大<b class='flag-5'>语言</b>模型

    地平线旭日3成功部署运行参数规模高达14亿的大语言模型

    近日,地平线成功在旭日3中的BPU计算单元上,部署运行参数规模高达14亿的大语言模型(Large Language Model , LLM)。这不仅是业界在端侧成功部署大模型的一次突破性实践,更验证
    的头像 发表于 09-12 09:24 509次阅读

    基于FPGA的贪吃蛇小游戏实现案例

    手机游戏时代始于 1997 年,当时诺基亚在 6110 机型上发布了第一款名为〈贪吃蛇〉的手机游戏。这可能是有史以来最受欢迎的手机游戏之一,全球有超过 3.5 亿部手机提供这款游戏。
    发表于 09-08 09:32 739次阅读
    基于FPGA的<b class='flag-5'>贪吃蛇</b>小游戏实现案例

    2023 IAA MOBILITY开展地平线亮相

    2023 IAA MOBILITY开展地平线亮相
    的头像 发表于 09-06 14:12 394次阅读
    2023 IAA MOBILITY开展<b class='flag-5'>地平线</b>亮相

    科沃斯最新款扫地机器人搭载地平线旭日3芯片上市

    近日,服务机器人领导品牌——科沃斯最新款扫地机器人“地宝DEEBOT X2”,全系产品搭载地平线旭日3芯片上市。 DEEBOT X2重新定义扫地机器人产品形态,率先采用方形机身设计,专为边角清扫而生
    的头像 发表于 08-25 09:50 1594次阅读

    地平线RDK X3语音算法通过Alexa ACM方案认证

    地平线RDK X3地平线基于自研的旭日3芯片,针对通用机器人开发场景打造的智能开发板,为各类算法的开发部署提供了坚实的硬件基础。地平线RD
    的头像 发表于 07-18 16:37 836次阅读
    <b class='flag-5'>地平线</b>RDK <b class='flag-5'>X3</b>语音算法通过Alexa ACM方案认证

    通过C语言设计的贪吃蛇游戏(控制台终端)

    当前通过控制台终端实现一个贪吃蛇小游戏,实现游戏的绘制、更新、控制等功能。
    的头像 发表于 06-30 09:53 505次阅读
    通过C<b class='flag-5'>语言</b>设计的<b class='flag-5'>贪吃蛇</b>游戏(控制台终端)

    全球招募新品体验官 | 30天玩转地平线RDK X3 Module

    作为与机器人开发者一路相伴、共同成长的开放社区,地平线开发者社区自发布TogetheROS.Bot机器人操作系统这一年时间,聚集起一批有想法有能力的活跃开发者,基于RDKX3(旭日X3派)的六足蜘蛛
    的头像 发表于 06-15 09:40 715次阅读
    全球招募新品体验官 | 30天玩转<b class='flag-5'>地平线</b>RDK <b class='flag-5'>X3</b> Module

    micro:bit贪吃蛇游戏开源分享

    电子发烧友网站提供《micro:bit贪吃蛇游戏开源分享.zip》资料免费下载
    发表于 06-13 10:58 2次下载
    micro:bit<b class='flag-5'>贪吃蛇</b>游戏开源分享

    ​使用旭日X3派实现手势检测

    本篇博客通过旭日X3搭载手势识别算法,实现实时检测,同时测试其运行性能。
    的头像 发表于 06-02 17:36 565次阅读
    ​使用<b class='flag-5'>旭日</b><b class='flag-5'>X3</b>派实现手势检测