为了账号安全,请及时绑定邮箱和手机立即绑定

作业社区

探索学习新天地,共享知识资源!

0 提交作业
0 布置作业
0 满分作业
得分 100
学习任务

cjozGV 的学生作业:

#ifndef _JUDEG_HEAD_H #define _JUDEG_HEAD_H #include "Player.hpp" #include "ChessBoard.hpp" class Judeg { public: bool isWin(Player *player) { bool ok; ok = isHorizontalWin(player->getColor()); if(ok){true;} ok = isVerticalWin(player->getColor()); if(ok){true;} ok = isUphillWin(player->getColor()); if(ok){true;} ok = isDownhillWin(player->getColor()); if(ok){true;} return false; } bool isHorizontalWin(const string &color) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); // 向右判断 for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line, column + i); if (ok) { count++; } else { break; } } // 提前胜利判断 if (count >= 5) { return true; } // 向左判断 for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line, column - i); if (ok) { count++; } else { break; } } // 去重处理 if (count - 1 >= 5) { return true; } return false; } // 判断垂直方向是否五子连珠 bool isVerticalWin(const string &color) { int count = 0; // 获取棋盘对象和当前落子的位置 ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); // 向下检查 行号增加 列不变 for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line + i, column); if (ok) { count++; } else { break; } } // 如果向下已经连成五子 直接返回胜利 if (count >= 5) { return true; } // 向上检查 (行号减少,列不变) for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line + i, column); if (ok) { count++; } else { break; } } // 当前落子点被重复统计了一次,减去 1 if (count - 1 >= 5) { return true; } return false; } // 判断上坡方向是否五子连珠(↗,从左下到右上) bool isUphillWin(const string &color) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); // 向右上检查 (行号减少,列号增加) for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line - i, column + i); if (ok) { count++; } else { break; } } // 如果右上方向已经连成五子,直接返回胜利 if (count >= 5) { return true; } // 向左下检查(行号增加,列号减少) for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line + i, column - i); if (ok) { count++; } else { break; } } return false; } // 判断下坡方向是否五子连珠(↘,从左上到右下) bool isDownhillWin(const string &color) { int count = 0; ChessBoard *chessBoard = ChessBoard::getChessBoard(); int line = chessBoard->getCurrentLine(); int column = chessBoard->getCurrentColumn(); // 向右下检查(行号增加,列号增加) for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line + i, column + i); if (ok) { count++; } else { break; } } // 如果右下方向已经连成五子,直接返回胜利 if (count >= 5) { return true; } // 向左上检查(行号减少,列号减少) for (int i = 0; i < 5; i++) { bool ok = chessBoard->isSameColorChess(color, line - i, column - i); if (ok) { count++; } else { break; } } // 当前落子点重复统计一次,减去 1 if (count - 1 >= 5) { return true; } return false; } private: }; #endif

得分 100
学习任务

zhuluoc 的学生作业:

lc@ubuntu:~$ sudo apt-get update 命中:1 http://archive.ubuntu.com/ubuntu noble InRelease 命中:2 http://security.ubuntu.com/ubuntu noble-security InRelease 命中:3 http://archive.ubuntu.com/ubuntu noble-updates InRelease 正在读取软件包列表… 完成 lc@ubuntu:~$ sudo apt-get install btanks 正在读取软件包列表… 完成 正在分析软件包的依赖关系树… 完成 正在读取状态信息… 完成 将会同时安装下列软件: btanks-data liblua5.1-0 libsdl-image1.2 libsdl1.2debian libsdl2-2.0-0 libsmpeg0t64 下列【新】软件包将被安装: btanks btanks-data liblua5.1-0 libsdl-image1.2 libsdl1.2debian libsdl2-2.0-0 libsmpeg0t64 升级了 0 个软件包,新安装了 7 个软件包,要卸载 0 个软件包,有 289 个软件包未被升级。 需要下载 29.7 MB 的归档。 解压缩后会消耗 39.4 MB 的额外空间。 您希望继续执行吗? [Y/n] y 获取:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 liblua5.1-0 amd64 5.1.5-9build2 [120 kB] 获取:2 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 libsdl2-2.0-0 amd64 2.30.0+dfsg-1ubuntu3.1 [686 kB] 获取:3 http://archive.ubuntu.com/ubuntu noble/universe amd64 libsdl1.2debian amd64 1.2.68-2 [101 kB] 获取:4 http://archive.ubuntu.com/ubuntu noble/universe amd64 libsdl-image1.2 amd64 1.2.12-13build4 [30.7 kB] 获取:5 http://archive.ubuntu.com/ubuntu noble/universe amd64 libsmpeg0t64 amd64 0.4.5+cvs20030824-9.1build1 [110 kB] 获取:6 http://archive.ubuntu.com/ubuntu noble/universe amd64 btanks-data all 0.9.8083-9build1 [26.4 MB] 获取:7 http://archive.ubuntu.com/ubuntu noble/universe amd64 btanks amd64 0.9.8083-9build1 [2,220 kB] 已下载 29.7 MB,耗时 16秒 (1,900 kB/s) 正在选中未选择的软件包 liblua5.1-0:amd64。 (正在读取数据库 … 系统当前共安装有 192958 个文件和目录。) 准备解压 …/0-liblua5.1-0_5.1.5-9build2_amd64.deb … 正在解压 liblua5.1-0:amd64 (5.1.5-9build2) … 正在选中未选择的软件包 libsdl2-2.0-0:amd64。 准备解压 …/1-libsdl2-2.0-0_2.30.0+dfsg-1ubuntu3.1_amd64.deb … 正在解压 libsdl2-2.0-0:amd64 (2.30.0+dfsg-1ubuntu3.1) … 正在选中未选择的软件包 libsdl1.2debian:amd64。 准备解压 …/2-libsdl1.2debian_1.2.68-2_amd64.deb … 正在解压 libsdl1.2debian:amd64 (1.2.68-2) … 正在选中未选择的软件包 libsdl-image1.2:amd64。 准备解压 …/3-libsdl-image1.2_1.2.12-13build4_amd64.deb … 正在解压 libsdl-image1.2:amd64 (1.2.12-13build4) … 正在选中未选择的软件包 libsmpeg0t64:amd64。 准备解压 …/4-libsmpeg0t64_0.4.5+cvs20030824-9.1build1_amd64.deb … 正在解压 libsmpeg0t64:amd64 (0.4.5+cvs20030824-9.1build1) … 正在选中未选择的软件包 btanks-data。 准备解压 …/5-btanks-data_0.9.8083-9build1_all.deb … 正在解压 btanks-data (0.9.8083-9build1) … 正在选中未选择的软件包 btanks。 准备解压 …/6-btanks_0.9.8083-9build1_amd64.deb … 正在解压 btanks (0.9.8083-9build1) … 正在设置 btanks-data (0.9.8083-9build1) … 正在设置 liblua5.1-0:amd64 (5.1.5-9build2) … 正在设置 libsdl2-2.0-0:amd64 (2.30.0+dfsg-1ubuntu3.1) … 正在设置 libsdl1.2debian:amd64 (1.2.68-2) … 正在设置 libsdl-image1.2:amd64 (1.2.12-13build4) … 正在设置 libsmpeg0t64:amd64 (0.4.5+cvs20030824-9.1build1) … 正在设置 btanks (0.9.8083-9build1) … 正在处理用于 hicolor-icon-theme (0.17-2) 的触发器 … 正在处理用于 gnome-menus (3.36.0-1.1ubuntu3) 的触发器 … 正在处理用于 libc-bin (2.39-0ubuntu8.6) 的触发器 … 正在处理用于 man-db (2.12.0-4build2) 的触发器 … 正在处理用于 desktop-file-utils (0.27-2build1) 的触发器 … lc@ubuntu:~$

得分 100
学习任务

慕工程6300203 的学生作业:

#ifndef IMOOC_EMBEDDED_LEARNING_REFEREE_H #define IMOOC_EMBEDDED_LEARNING_REFEREE_H #include #include "ChessBoard.hpp" #include "Player.hpp" using namespace std; class Referee { public: bool isWin(Player *player) { bool win = false; /*horizontal*/ win = isHorizontalWin(player->getColor()); if (win) { return true; } /* vertical */ win = isVerticalWin( player->getColor() ); if (win) { return true; } /* uphill */ win = isUphillWin( player->getColor() ); if (win) { return true; } /* downhill */ win = isDownhillWin( player->getColor() ); if (win) { return true; } return false; } private: static bool isHorizontalWin(const string &color) { int count = 0; ChessBoard* chessBoard = ChessBoard::getChessBoard(); int currentLine = chessBoard->getCurrentLine(); int currentColumn = chessBoard->getCurrentColumn(); for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine, currentColumn + i, color)) { count++; } else { break; } } if (count >= 5) { return true; } for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine, currentColumn - i, color)) { count++; } else { break; } } count -= 1; if (count >= 5) { return true; } return false; } static bool isVerticalWin(const string &color) { int count = 0; ChessBoard* chessBoard = ChessBoard::getChessBoard(); int currentLine = chessBoard->getCurrentLine(); int currentColumn = chessBoard->getCurrentColumn(); for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine + i, currentColumn, color)) { count++; } else { break; } } if (count >= 5) { return true; } for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine - i, currentColumn, color)) { count++; } else { break; } } count -= 1; if (count >= 5) { return true; } return false; } static bool isUphillWin(const string &color) { int count = 0; ChessBoard* chessBoard = ChessBoard::getChessBoard(); int currentLine = chessBoard->getCurrentLine(); int currentColumn = chessBoard->getCurrentColumn(); for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine + i, currentColumn - i, color)) { count++; } else { break; } } if (count >= 5) { return true; } for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine - i, currentColumn + i, color)) { count++; } else { break; } } count -= 1; if (count >= 5) { return true; } return false; } static bool isDownhillWin(const string &color) { int count = 0; ChessBoard* chessBoard = ChessBoard::getChessBoard(); int currentLine = chessBoard->getCurrentLine(); int currentColumn = chessBoard->getCurrentColumn(); for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine + i, currentColumn + i, color)) { count++; } else { break; } } if (count >= 5) { return true; } for (int i = 0; i < 5; i++) { if (chessBoard->isSameColorChess(currentLine - i, currentColumn - i, color)) { count++; } else { break; } } count -= 1; if (count >= 5) { return true; } return false; } }; #endif

得分 100
学习任务

慕工程6300203 的学生作业:

#ifndef IMOOC_EMBEDDED_LEARNING_PLAYER_H #define IMOOC_EMBEDDED_LEARNING_PLAYER_H #include using namespace std; class Player { public: Player(const string &name, const string &color) : name(name), color(color) { } string getName() const { return name; } string getColor() const { return color; } virtual bool placeChess(int x, int y) = 0; private: string name; string color; }; #endif #ifndef IMOOC_EMBEDDED_LEARNING_BLACK_PLAYER_H #define IMOOC_EMBEDDED_LEARNING_BLACK_PLAYER_H #include #include "Player.hpp" #include "ChessBoard.hpp" #include "BlackChess.hpp" using namespace std; class BlackPlayer : public Player { public: BlackPlayer(const string &name) : Player(name, "black"){} bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->verifyChessPos(x, y); if (ok) { chessBoard->placeChess(new BlackChess(x, y)); } return ok; } }; #endif #ifndef IMOOC_EMBEDDED_LEARNING_WHITE_PLAYER_H #define IMOOC_EMBEDDED_LEARNING_WHITE_PLAYER_H #include #include "Player.hpp" #include "ChessBoard.hpp" #include "WhiteChess.hpp" using namespace std; class WhitePlayer : public Player { public: WhitePlayer(const string &name) : Player(name, "white"){} bool placeChess(int x, int y) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); bool ok = chessBoard->verifyChessPos(x, y); if (ok) { chessBoard->placeChess(new WhiteChess(x, y)); } return ok; } }; #endif #include "BlackChess.hpp" #include "BlackPlayer.hpp" #include "WhiteChess.hpp" #include "ChessBoard.hpp" #include "WhitePlayer.hpp" int main(int argc, char* argv[]) { ChessBoard *chessBoard = ChessBoard::getChessBoard(); chessBoard->showChessBoard(); WhitePlayer *whitePlayer = new WhitePlayer("zhangsan"); whitePlayer->placeChess(1, 1); BlackPlayer *blackPlayer = new BlackPlayer("lisi"); blackPlayer->placeChess(5, 3); blackPlayer->placeChess(9, 3); return 0; } 【图片】

得分 100
学习任务

慕工程6300203 的学生作业:

#ifndef IMOOC_EMBEDDED_LEARNING_CHESS_H #define IMOOC_EMBEDDED_LEARNING_CHESS_H #include using namespace std; class Chess { public: Chess(const string &color, int x, int y) : color(color), x(x), y(y) {} int getX() const { return x; } int getY() const { return y; } string getColor() const { return color; } virtual void show() const = 0; private: int x; int y; string color; }; #endif //IMOOC_EMBEDDED_LEARNING_CHESS_H #ifndef IMOOC_EMBEDDED_LEARNING_BLACK_CHESS_H #define IMOOC_EMBEDDED_LEARNING_BLACK_CHESS_H #include #include #include "Chess.hpp" using namespace std; class BlackChess : public Chess { public: BlackChess(int x, int y) : Chess("black", x, y) {} void show() const { fprintf(stderr,"\033[%d;%dH\033[43;35m[☻ ]\033[0m", getY(),getX() - 1); fprintf(stderr,"\033[%d;%dH",getY(),getX()); } }; #endif #ifndef IMOOC_EMBEDDED_LEARNING_WHITE_CHESS_H #define IMOOC_EMBEDDED_LEARNING_WHITE_CHESS_H #include #include #include "Chess.hpp" using namespace std; class WhiteChess : public Chess { public: WhiteChess(int x, int y) : Chess("white", x, y) {} void show() const { fprintf(stderr,"\033[%d;%dH\033[44;36m[☺ ]\033[0m", getY(),getX() - 1); fprintf(stderr,"\033[%d;%dH",getY(),getX()); } }; #endif #include "BlackChess.hpp" #include "WhiteChess.hpp" int main(int argc, char* argv[]) { fprintf(stderr, "\033[2J"); for (int i = 1; i show(); } for (int i = 1; i show(); } printf("\n"); return 0; } 【图片】

得分 100
学习任务

zhuluoc 的学生作业:

练习1: // 写代码实现求二叉树的深度。 int tree_deepness(bitree_t *root) { int ildep = 0, irdep = 0; if (NULL == root) return 0; // 左孩子深度 ildep = tree_deepness(root->lch); // 右孩子深度 irdep = tree_deepness(root->rch); if (ildep < irdep) ildep = irdep; return ildep + 1; } 练习2 // 在单向链表中实现冒泡排序 void sort_linklist(linknode_t *h) { linknode_t *p = NULL, *q = NULL; p = h->next; while (NULL != p->next) { q = h->next; while (NULL != q->next) { if (q->data > q->next->data) { q->data ^= q->next->data; q->next->data ^= q->data; q->data ^= q->next->data; } q = q->next; } p = p->next; } } 练习3: // 将两个有序链表合成一个有序链表 linknode_t *and_linklist(linknode_t *h1, linknode_t *h2) { // p--指向链表h1; t--用于将链表2节点脱离出来; // h--用于记录有序链表1当前插入节点的位置,以减少循环次数 linknode_t *p = NULL, *t = NULL, *h = NULL; if (NULL == h1) return h2; if (NULL == h2) return h1; h = h1; while (NULL != h2->next) { p = h; while (NULL != p->next) { if (p->next->data > h2->next->data) { // 将链表2的节点脱离链表2 t = h2->next; h2->next = t->next; // 将脱离的节点插入到链表1 t->next = p->next; p->next = t; h = p; // 记录下当前位置 // 退出循环 break; } // 若下一个节点的值小于要比较的值,但下下一个节点的值大于要比较的值,插入比较值节点 else if (p->next->data < h2->next->data && (NULL == p->next->next || p->next->next->data >= h2->next->data)) { // 将链表2的节点脱离链表2 t = h2->next; h2->next = t->next; // 将脱离的节点插入到链表1 t->next = p->next->next; p->next->next = t; h = p; // 记录下当前位置 // 退出循环 break; } p = p->next; } // End of "while (NULL != p->next)" } // End of "while (NULL != h2->next)" return h1; } 练习4:【图片】

首页上一页1234567下一页尾页
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号