ANTWAR C++ SDK
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
io.hpp File Reference

A module for communicating with Judger. More...

#include <vector>
#include <string>
#include <utility>
#include <iostream>
#include "common.hpp"

Go to the source code of this file.

Classes

struct  RoundInfo
 A combination of deserialized information about current round state received from judger. More...
 

Typedefs

using InitInfo = std::pair< int, unsigned long long >
 

Functions

InitInfo read_init_info ()
 Read information for initialization.
 
std::vector< Operationread_opponent_operations ()
 Read your opponent's operations and deserialize them. The time to call this function depends on your player ID.
 
RoundInfo read_round_info ()
 Read information at the beginning of a round and deserialize.
 
std::size_t object_length (int x)
 Calculate the length of the serialized result of a non-negative integer, without actually serializing it (i.e. no string is ever constructed). Here we convert the integer to a string of its decimal representation to serialize it.
 
std::size_t object_length (const std::string &str)
 Calculate the length of the serialized result of a string of ASCII characters, which is just the length of the string, of course.
 
std::size_t object_length (const Operation &op)
 Calculate the length of the serialized result of an Operation object, without actually serializing it (i.e. no string is ever constructed). The serialized result includes the type and arguments of the operation, the spaces between these integers and the trailing line break.
 
std::size_t object_length (const std::vector< Operation > &ops)
 Calculate the length of the serialized result of some Operation objects, without actually serializing them (i.e. no string is ever constructed). the serialized result is simply the sum of each serialized Operation object.
 
void convert_to_big_endian (const void *src, std::size_t size, void *dest)
 Convert an object into big-endian representation.
 
void print_header (int size)
 Print the header, i.e. the total size in big-endian binary representation.
 
void send_string (const std::string &str)
 Send raw string with header to judger.
 
void send_operations (const std::vector< Operation > &ops)
 Send some serialized operations with header to judger.
 

Detailed Description

A module for communicating with Judger.

Author
Yufei Li, Jingxuan Liu
Date
2023-04-01

Function Documentation

◆ convert_to_big_endian()

void convert_to_big_endian ( const void *  src,
std::size_t  size,
void *  dest 
)
inline

Convert an object into big-endian representation.

Parameters
srcPointer to the memory of the object to be converted.
sizeSize of the object in bytes.
destBuffer area for converted result.

◆ object_length() [1/4]

std::size_t object_length ( const Operation op)
inline

Calculate the length of the serialized result of an Operation object, without actually serializing it (i.e. no string is ever constructed). The serialized result includes the type and arguments of the operation, the spaces between these integers and the trailing line break.

Parameters
opThe Operation object to serialize.
Returns
Number of bytes of the result.

◆ object_length() [2/4]

std::size_t object_length ( const std::string str)
inline

Calculate the length of the serialized result of a string of ASCII characters, which is just the length of the string, of course.

Parameters
strThe string to serialize.
Returns
The number of bytes of the result.

◆ object_length() [3/4]

std::size_t object_length ( const std::vector< Operation > &  ops)
inline

Calculate the length of the serialized result of some Operation objects, without actually serializing them (i.e. no string is ever constructed). the serialized result is simply the sum of each serialized Operation object.

Parameters
opsA vector of Operation objects to serialize.
Returns
Number of bytes of the result.

◆ object_length() [4/4]

std::size_t object_length ( int  x)
inline

Calculate the length of the serialized result of a non-negative integer, without actually serializing it (i.e. no string is ever constructed). Here we convert the integer to a string of its decimal representation to serialize it.

Parameters
xThe non-negative integer to serialize.
Returns
Number of bytes of the result.

◆ print_header()

void print_header ( int  size)
inline

Print the header, i.e. the total size in big-endian binary representation.

Parameters
sizeThe total size of everything to be sent.

◆ read_init_info()

InitInfo read_init_info ( )
inline

Read information for initialization.

Returns
Your player ID and the seed for random number generator, together in a pair.

◆ read_opponent_operations()

std::vector< Operation > read_opponent_operations ( )
inline

Read your opponent's operations and deserialize them. The time to call this function depends on your player ID.

Returns
A vector of Operation objects.

◆ read_round_info()

RoundInfo read_round_info ( )
inline

Read information at the beginning of a round and deserialize.

Returns
A RoundInfo object with everything received and deserialized.

◆ send_operations()

void send_operations ( const std::vector< Operation > &  ops)
inline

Send some serialized operations with header to judger.

Parameters
opsA vector of Operation objects to be sent.

◆ send_string()

void send_string ( const std::string str)
inline

Send raw string with header to judger.

Parameters
strString to be sent.