{"id":25746384,"url":"https://github.com/pilgrimlyieu/antsvssomebees-cppver","last_synced_at":"2025-02-26T11:33:20.963Z","repository":{"id":273188933,"uuid":"899297255","full_name":"pilgrimlyieu/AntsVsSomeBees-CPPver","owner":"pilgrimlyieu","description":"南京大学 2024~2025《C++ 高级程序设计》期末项目大作业——Ants Vs. SomeBees (C++ version)","archived":false,"fork":false,"pushed_at":"2025-02-22T13:46:33.000Z","size":9580,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-22T14:35:45.959Z","etag":null,"topics":["cpp","cs61a","game","homework","nanjing-university","nju","project"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pilgrimlyieu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-06T01:35:35.000Z","updated_at":"2025-02-22T13:46:37.000Z","dependencies_parsed_at":"2025-01-19T10:31:21.498Z","dependency_job_id":"8868ae7f-6e74-478e-b297-6167cfab95d8","html_url":"https://github.com/pilgrimlyieu/AntsVsSomeBees-CPPver","commit_stats":null,"previous_names":["pilgrimlyieu/antsvssomebees-cppver"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgrimlyieu%2FAntsVsSomeBees-CPPver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgrimlyieu%2FAntsVsSomeBees-CPPver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgrimlyieu%2FAntsVsSomeBees-CPPver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pilgrimlyieu%2FAntsVsSomeBees-CPPver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pilgrimlyieu","download_url":"https://codeload.github.com/pilgrimlyieu/AntsVsSomeBees-CPPver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240843625,"owners_count":19866799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cs61a","game","homework","nanjing-university","nju","project"],"created_at":"2025-02-26T11:32:09.208Z","updated_at":"2025-02-26T11:33:20.838Z","avatar_url":"https://github.com/pilgrimlyieu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ants Vs. SomeBees (C++ version)\n\n\u003e 项目介绍见博文 [**Ants Vs. SomeBees (C++ 版本) 介绍**](https://pilgrimlyieu.github.io/2025/02/ants-vs-somebees)。\n\u003e 项目开发历程见博文 [**C++ 项目 Avsb 回顾与总结**](https://pilgrimlyieu.github.io/2025/02/ants-vs-somebees-development)。\n\n\u003e 这是一个用于验收的临时简单的 README，更多细节有待完善。\n\u003e 稍微详细一点的内容、随意的演示、评分细则，同时也是视频中用的文档（修正前），可见 [doc/demo.md](doc/demo.md)。\n\n## 项目简介\n\n这是一个基于 CS61A 项目作业 [**A**nts **V**s. **S**ome**B**ees](https://cs61a.org/proj/ants)、使用了 C++ 重新实现、并添加了一些新的功能的项目。\n\n软工 I 课程就已经了解过这个项目作业的大体情况了，因此细节不在此过多展开。原版游戏的全部功能基本上都实现了。\n\n另外其实 Avsb 有多个版本，例如说[我完成的版本](https://github.com/pilgrimlyieu/SEC-Homework/tree/main/Python/proj3/240-2024spring_softwareengineering_python_proj3)就和上面的链接给出的不一样。起初我是基于我自己完成的版本来写的，因此上面链接中没有提及的各种 Bee 基本都有得到实现[^except]。不过在完成游戏逻辑的实现，即将着手 Web GUI 的实现时，因为上面的新版使用了 Flask，前端更为简洁，因此也将部分游戏逻辑进行了修改，以适应新版的 Python 原代码。\n\n[^except]: 除了 Hornet，因为这个没有资源，而且会引入菱形继承。\n\n命令行参数如下：\n\n```\n$ ./Avsb --help\nUsage: Ants vs. SomeBees [--help] [--version] [[--difficulty DIFFICULTY]|[--plan PLAN]] [--water] [--open] [--food FOOD] [--log LEVEL] [--port PORT] [--config CONFIG] [--save]\n\nOptional arguments:\n  -h, --help                   shows help message and exits\n  -v, --version                prints version information and exits\n  -d, --difficulty DIFFICULTY  sets difficulty of game (test/easy/normal/hard/extra-hard) [default: \"normal\"]\n  -a, --plan PLAN              path to custom assault plan JSON file\n  -w, --water                  loads a full layout with water\n  -o, --open                   automatically open the game in a browser (maybe not work in your OS!)\n  -f, --food FOOD              number of food to start with when testing [default: 2]\n  -l, --log LEVEL              sets log level (0:TEST, 1:INFO, 2:ERROR, 3:NONE) [default: 1]\n  -p, --port PORT              sets the port for the server [default: 18080]\n  -c, --config CONFIG          path to config file [default: \"./config.json\"]\n  -s, --save                   save game configuration to file and exit\n```\n\n## 编译运行\n\n本项目原则上是跨平台的，我成功在 Windows 和 Linux[^linux] 上编译并运行。由于我没有 macOS 设备，并未为其添加支持，不过理论上是可以通过修改构建脚本来支持的。\n\n[^linux]: WSL2 Ubuntu x86_64\n\n本项目采用 [XMake](https://xmake.io) 作为构建工具，构建脚本位于项目根目录下的 `xmake.lua` 文件中。\n\n同时本项目采用的是 **clang** 工具链而非 gcc 工具链，在 Windows 下用的是 [MSYS2](https://www.msys2.org) 的 clang，Linux 下用的是安装包管理器安装的 clang，版本分别为：\n\n```shell\n$ clang --version\nclang version 19.1.6\nTarget: x86_64-w64-windows-gnu\nThread model: posix\nInstalledDir: D:/Software/msys64/clang64/bin\n```\n\n```shell\n$ clang --version\nUbuntu clang version 18.1.3 (1ubuntu1)\nTarget: x86_64-pc-linux-gnu\nThread model: posix\nInstalledDir: /usr/bin\n```\n\n经过实测，附带 LLVM 的 WinLibs 的 MinGW64 无法完成编译。工具链的安装与配置不在此展开，下面假定已经正确完成了工具链的安装与配置。\n\n在讲述步骤之前还需要提及一些需要注意的部分：\n\n没想到吧，其实项目还提供了测试支持，只是我没时间写了。使用的是 catch2 包。我这里安装 catch2 包需要一些鬼畜的操作。如果需要启用测试，可以将 `xmake.lua` 开头部分的 `enable_test` 改为 `true`。同时相关测试的构建目标也已经在构建脚本中定义好了。\n\n此外在 Windows 中，我始终无法安装 crow 包，因此我将 crow 包（以及 asio 包）直接放在了 `dependencies` 目录下，而非通过 XMake 进行管理。`dependencies` 目录以加入 `.gitignore`，因此如果在 Windows 下编译，要么修改编译脚本，使用 XMake 进行包管理并成功，要么就是自己去找 [crow](https://github.com/CrowCpp/Crow) 和 [asio](https://github.com/chriskohlhoff/asio) 包，并按照构建脚本中的路径放置。\n\n好消息是，Linux 中上面的问题都不存在。\n\n两个平台的构建命令均为\n\n```shell\n$ xmake f -m release \u0026\u0026 xmake build\n```\n\n含义为，设置构建模式为 release，然后构建项目。\n\n构建完成后，可执行文件位于 `build` 目录下，名称为 `Avsb.exe`（Windows）或 `Avsb`（Linux），与静态资源与模板文件一起，位置正确运行即可。\n\n由于游戏本体文件与资源文件分开的，因此还需要打包成压缩包比较合适。这个在 Windows 的 VS Code 下有相关任务配置，需要安装 [PowerShell](https://github.com/PowerShell/PowerShell)[^pwsh] 和 XMake，然后执行 Pack Release 任务即可。\n\n[^pwsh]: 不是 5 这个老古董，是 7 的新版。\n\n此外还有代码文档的构建，除了 Windows 的 VS Code 有 Generate Document 等相关任务外，还可以手动通过命令行进行构建。前置要求是安装了 [Doxygen](https://www.doxygen.nl)，同时还要有 [Graphviz](https://graphviz.org) 的支持（也可以修改 `Doxyfile` 以禁用 Dot）。构建命令为\n\n```shell\n$ xmake doxygen -o doc\n```\n\n构建完成后，HTML 文档位于 `doc/html` 目录下，可以通过打开 `doc/html/index.html` 查看。\n\n## 项目结构\n\n项目的结构如下：\n\n```\n Avsb\n├──  .vscode\n├──  .xmake\n├──  build\n├──  dependencies\n├──  doc\n├──  include\n├──  material\n├──  src\n├──  static\n├──  templates\n├──  test\n├──  .clang-format\n├──  .clang-tidy\n├──  .clangd\n├──  .gitignore\n├──  Doxyfile\n├── 󰂺 README.md\n└──  xmake.lua\n```\n\n- `.vscode`：VS Code 配置文件夹\n- `.xmake`：XMake 缓存文件夹\n- `build`：构建输出文件夹\n- `dependencies`：依赖包文件夹\n- `doc`：文档文件夹\n- `include`：头文件文件夹\n- `material`：游戏参考资料文件夹（指要求的 PDF）\n- `src`：源代码文件夹\n- `static`：静态资源文件夹\n- `templates`：模板文件夹\n- `test`：测试文件夹\n- `.clang-format`：Clang 格式化配置文件\n- `.clang-tidy`：Clang 静态分析配置文件\n- `.clangd`：Clangd 配置文件\n- `.gitignore`：Git 忽略文件\n- `Doxyfile`：Doxygen 配置文件\n- `README.md`：项目说明文件\n- `xmake.lua`：XMake 构建脚本\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilgrimlyieu%2Fantsvssomebees-cppver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpilgrimlyieu%2Fantsvssomebees-cppver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpilgrimlyieu%2Fantsvssomebees-cppver/lists"}