Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
AiParser.cpp
Go to the documentation of this file.
1#include "AiParser.hpp"
2
3std::optional<Ai::Command> AiParser::parse(std::string_view line)
4{
5 if (line == "Incantation") return Ai::Incantation{};
6 if (line == "Forward") return Ai::Forward{};
7 if (line == "Right") return Ai::Right{};
8 if (line == "Left") return Ai::Left{};
9 if (line == "Look") return Ai::Look{};
10 if (line == "Fork") return Ai::Fork{};
11 if (line == "Eject") return Ai::Eject{};
12 if (line == "Inventory") return Ai::Inventory{};
13 if (line == "Connect_nbr") return Ai::ConnectNbr{};
14
15 if (line.starts_with("Broadcast ")) return Ai::Broadcast{std::string(line.substr(10))};
16 if (line.starts_with("Take ")) {
17 auto res = Resources::fromName(line.substr(5));
18 if (!res) return std::nullopt;
19 return Ai::Take{*res};
20 }
21 if (line.starts_with("Set ")) {
22 auto res = Resources::fromName(line.substr(4));
23 if (!res) return std::nullopt;
24 return Ai::Set{*res};
25 }
26
27 return std::nullopt;
28}
static std::string res(const Resources &r)
Definition Serializer.cpp:5
static std::optional< Ai::Command > parse(std::string_view line)
Parse one line from an AI client (no trailing newline).
Definition AiParser.cpp:3
static std::optional< ResourceType > fromName(std::string_view name)
Definition Resources.hpp:55