
 [ AI AVALON CommunicationString ]
                          Copyright (c) 2022 Hidetoshi NAGAI
                          Copyright (c) 2022 Kyutech AI AVALON Team

Supported Protocol Version: 0.9.0 and above


The communication between the client controlling the communication with
the server and the agent (AI player) is carried out using bidirectional
pipes assigned to standard input and output.
Typically, the communication format between the client and the agent uses
the binary format employed in communication between the server and the
client. This is to reduce processing costs associated with data conversion
and extraction. However, if a text format is desired due to agent processing
considerations or other reasons, a text format can also be selected between
the client and the agent.

The text format is essentially a single line of information separated by
spaces. Therefore, there is a newline character at the end of the format.
Reading data from the pipe can be done by line-by-line reading. The client
process and the agent process are assumed to be running on the same OS, so
differences in newline characters dependent on the OS should not be an issue.

In the following format descriptions, expressions enclosed in "< >" are
fields that should be filled in with specific numerical data or components
of claims and explanations. Since `[ ]` is used in the claim/description
format, `{ }' is used to indicate optional information to avoid confusion.
Items that are not enclosed in any parentheses should be use the string as is.


*********************************************
Communication Format
*********************************************
In communication, the server and client exchange roles between sending and
receiving, repeatedly performing the process of "sending a message" followed
by "returning a status in response to the message."

Communication in text format is performed on a per-line basis.

Message-Sending:
MessageFormatString<newline>


*********************************************
Message Format
*********************************************
---------------------------------------------
>> Exit Command
exit <status>

---------------------------------------------
>> Receiving Status

# status == 0x00 : Unknown error
status UnknownErr<newline>

# status == 0x01 : Transmission format error (header or footer invalid)
status ErrFormat<newline>

# status == 0x02 : Message size error
status ErrSize<newline>

# status == 0x03 : Message error: Unknown code
status ErrCode<newline>

# status == 0x04 : Message error: Inappropriate structure (element count)
status ErrStruct<newline>

# status == 0x05 : Message error: Abnormal parameter value
status ErrParam<newline>

# status == 0x0C : Timeout (communication interrupted before reading the
#                           specified data size)
status ErrBroken<newline>

# status == 0x0D : Timeout (expected message not received)
status ErrTimeout<newline>

# status == 0x0E : QUERY received
status AcceptQuery<newline>

# status == 0x0F : Successfully received
status OK<newline>

---------------------------------------------
>> Game Progression

"role" message:
role <assigned_pnum> <role> {<pnum> ... }

"construct" message:
construct <quest> <member_cnt> <trial> <leader>

"require"+"team" message:
require team <leader> <member_cnt>

"team" message:
team <leader> <pow> <pnum> ...

"team" information message:
ID <ID> team <quest> <trial> <leader> <pow> <pnum> ...

"require"+"vote" message:
require vote <pnum> <ID>

"vote" message:
vote <pnum> <ID> accept
vote <pnum> <ID> deny

"vote" information message:
ID <ID> vote <pnum> <ID> accept
ID <ID> vote <pnum> <ID> deny

"victroy" message:
victory evil
victory justice

"quest" message:
quest <quest> <ID> <pnum> ...

"require"+"action" message:
require action <pnum> <to_fail>

"action" message:
action <pnum> success
action <pnum> failure

"result" information message:
ID <ID> result success <fail_cnt> <quest> <ID> <pnum> ...
ID <ID> result failure <fail_cnt> <quest> <ID> <pnum> ...

"assassination" information message:
assassination <pow> <pnum> ...

"require"+"assassinate" message:
require assassinate <pnum>

"assassinate" message:
assassinate <pnum:Assassin> <pnum:Merlin>

"assassinate" information message:
ID <ID> assassinate <pnum:Assassin> <pnum:Merlin> success
ID <ID> assassinate <pnum:Assassin> <pnum:Merlin> failure

"require"+"quit" message:
require quit <pnum>

"quit" message:
quit <pnum> <pow>

"quit" information message:
ID <ID> quit <pnum> <pow>

"require"+"claim" message:
require claim <pnum> <ID>

"claim" message:
claim <pnum> <pow> <targetID> <content>
# The format of <content> is described below.

"claim" information message:
ID <ID> claim <pnum> <pow> <targetID> <content>
# The format of <content> is described below.

"require"+"request" message:
require request <pnum>

"request" message:
request <pnum> <pow> accept <ID> <pnum> ...
request <pnum> <pow> deny <ID> <pnum> ...

"request" information message:
ID <ID> request <pnum> <pow> accept <targetID> <pnum> ...
ID <ID> request <pnum> <pow> deny <targetID> <pnum> ...

"require"+"inquiry" message:
require inquiry <pnum>

"inquiry" message:
inquiry <pnum> <pow> <target_pnum> <targetID>

"inquiry" information message:
ID <ID> inquiry <pnum> <pow> <target_pnum> <targetID>

"require"+"reason" message:
require reason <pnum> <ID>

"reason" message:
reason <pnum> <pow> <targetID> <content>
# The format of <content> is described below.

"reason" information message:
ID <ID> reason <pnum> <pow> <targetID> <content>
# The format of <content> is described below.

"voice" message:
voice <pnum> <status> <remain> <depth> <point>

"point" message:
point <pnum> <point>

"require"+"interrupt" message:
require interrupt <pnum> <rights> <point> <increment> <exchange>

"interrupt" message:
interrupt <pnum> <point>

"interrupt" information message:
ID <ID> interrupt <player_cnt> <point> ...

"finish" message:
finish <quest> <trial> <leader>


=============================================
# Format of <content> in "claim" etc.

In the text format, each component of `<content>` in claims/explanations is
represented as a sequence of information separated by spaces or commas and
enclosed within "[ ]". It's important to note that spaces before or after
the "[ ]" symbols are optional and do not affect the formatting.

---------------------------------------------
>> Claim component

"hunch","omit":
[ hunch ]
[ omit ]

"agree","disagree":
[ agree <pow> <ID> ]
[ disagree <pow> <ID> ]

"justice","evil",role-name:
[ justice <pow> <pnum> ]
[ evil <pow> <pnum> ]
[ Servant <pow> <pnum> ]
[ Merlin <pow> <pnum> ]
[ Percival <pow> <pnum> ]
[ Minion <pow> <pnum> ]
[ Assassin <pow> <pnum> ]
[ Mordred <pow> <pnum> ]
[ Morgana <pow> <pnum> ]
[ Oberon <pow> <pnum> ]

"trust","distrust","include","exclude","confidence","nonconfidence":
[ trust <pow> <pnum> ]
[ distrust <pow> <pnum> ]
[ include <pow> <pnum> ]
[ exclude <pow> <pnum> ]
[ confidence <pow> <pnum> ]
[ nonconfidence <pow> <pnum> ]

"consistent","inconsistent":
[ consistent <pow> <ID> <ID> ]
[ inconsistent <pow> <ID> <ID> ]

"succeed","fail","win","lose":
[ succeed <pow> <ID> ]
[ fail <pow> <ID> ]
[ win <pow> <ID> ]
[ lose <pow> <ID> ]

"servants","minions":
[ servants <pow> <min> <max> <pnum> ... ]
[ minions <pow> <min> <max> <pnum> ... ]

"endeavor","obstruct":
[ endeavor <pow> <pnum> <ID> ]
[ obstruct <pow> <pnum> <ID> ]

---------------------------------------------
>> Logical structure

"AT":
[ at <ID> <content> ]

"OR","AND":
[ or <content> <content> ... ]
[ and <content> <content> ... ]

"IF"(with else clause):
[ if <content> <content> <content> ]

"IF"(without else clause):
[ if <content> <content> ]

---------------------------------------------
>> Direct reference

"FACT":
[ fact <ID> ]

---------------------------------------------
>> Presume structure

"PRESUME":
[ presume <pow> <pnum> <content> ]


=============================================
>> Format related to "query"

(to_server) "query"+"get" message:
query get

(from_server) "query"+"get" message:
query get <quest> <trial> <message>
# <message> is passed the data of the target ID as it is.

(to_server) "query"+"range" message:
query range <quest> { <trial> }

(from_server) "query"+"range" message:
query range <minID> <maxID>

(to_server) "query"+"last_trial" message:
query last_trial <quest>

(from_server) "query"+"last_trial" message:
query last_trial <trial>
[code:8][code:8][trial:8]

(to_server) "query"+"team" message:
query team <quest> <trial>

(from_server) "query"+"team" message:
query team <quest> <trial> <message>
# <message> is passed the data of the target ID as it is.

(to_server) "query"+"vote" message:
query vote <quest> <trial> <pnum>

(from_server) "query"+"vote" message:
query vote <quest> <trial> <message>

(to_server) "query"+"result" message:
query result <quest>

(from_server) "query"+"result" message:
query result <quest> <trial> <message>

(to_server) "query"+"point" message:
query point

(from_server) "query"+"point" message:
query point <rights> <point> <increment> <exchange>


-----------------------------------------------------------------------------
end of document
-----------------------------------------------------------------------------
