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
3
std::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
}
AiParser.hpp
res
static std::string res(const Resources &r)
Definition
Serializer.cpp:5
AiParser::parse
static std::optional< Ai::Command > parse(std::string_view line)
Parse one line from an AI client (no trailing newline).
Definition
AiParser.cpp:3
Resources::fromName
static std::optional< ResourceType > fromName(std::string_view name)
Definition
Resources.hpp:55
Ai::Broadcast
Definition
AiParser.hpp:26
Ai::ConnectNbr
Definition
AiParser.hpp:29
Ai::Eject
Definition
AiParser.hpp:31
Ai::Fork
Definition
AiParser.hpp:30
Ai::Forward
Definition
AiParser.hpp:21
Ai::Incantation
Definition
AiParser.hpp:38
Ai::Inventory
Definition
AiParser.hpp:25
Ai::Left
Definition
AiParser.hpp:23
Ai::Look
Definition
AiParser.hpp:24
Ai::Right
Definition
AiParser.hpp:22
Ai::Set
Definition
AiParser.hpp:35
Ai::Take
Definition
AiParser.hpp:32
server
src
protocol
AiParser.cpp
Generated by
1.9.8