IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
agent Struct Reference

Represents an agent, i.e. an AI. More...

#include <agent.hpp>

Classes

struct  parameters
 Represents the caracteristics of an agent. More...
 

Public Types

enum  opcode {
  OP_NOP, OP_ADD, OP_MINUS, OP_MAX,
  OP_MIN, OP_UMINUS, OP_MUL, OP_DIV,
  OP_LOG, OP_EXP, OP_COS, OP_SIN,
  OP_POPCOUNT, OP_IF, OP_IF_GOTO, OP_SIZE
}
 Enumeration of all the operation available for an agent. More...
 
using instruction = uint64_t
 
using reg = double
 

Public Member Functions

 agent ()=default
 Standard constructor (Empty agent) More...
 
 agent (const parameters &params)
 Construct an agent with parameters. More...
 
int get_action (const std::vector< unsigned char > &screen)
 Execute the program on a particular frame and choose an action. More...
 
void serialize (Archive &ar, const unsigned int)
 Save/Load agent with archive. More...
 
void reset_registers ()
 Fills the registers "temporary" and "outputs" files with 0. More...
 
void reset ()
 Fills all the registers files with 0 and set nb_steps and current_part to 0. More...
 
void execute_instruction (const std::vector< unsigned char > &screen, int &pc)
 Perform the operation corresponding to this instruction. More...
 
auto begin_outputs ()
 Access the beginning of the register file "outputs". More...
 
auto end_outputs ()
 Access the end of the register file "outputs". More...
 
std::string reg_to_string (int reg) const
 Represent a register as a string. More...
 
void print_instruction (std::ostream &, instruction ins) const
 Display an instruction as a String through a outputStream. More...
 

Public Attributes

parameters params
 
std::vector< instructionprogram
 
std::vector< regregisters
 
int nb_steps = 0
 
int current_part = 0
 

Detailed Description

Represents an agent, i.e. an AI.

Member Typedef Documentation

◆ instruction

using agent::instruction = uint64_t

◆ reg

using agent::reg = double

Member Enumeration Documentation

◆ opcode

Enumeration of all the operation available for an agent.

Enumerator
OP_NOP 
OP_ADD 
OP_MINUS 
OP_MAX 
OP_MIN 
OP_UMINUS 
OP_MUL 
OP_DIV 
OP_LOG 
OP_EXP 
OP_COS 
OP_SIN 
OP_POPCOUNT 
OP_IF 
OP_IF_GOTO 
OP_SIZE 

Constructor & Destructor Documentation

◆ agent() [1/2]

agent::agent ( )
default

Standard constructor (Empty agent)

◆ agent() [2/2]

agent::agent ( const parameters params)

Construct an agent with parameters.

Initializes params, but also the program size and the register files size.

Parameters
paramsParameters of this agent

Member Function Documentation

◆ begin_outputs()

agent::begin_outputs ( )
inline

Access the beginning of the register file "outputs".

Returns
An iterator pointing to the beginning of the register file "outputs"

◆ end_outputs()

agent::end_outputs ( )
inline

Access the end of the register file "outputs".

Returns
An iterator pointing to the end of the register file "outputs"

◆ execute_instruction()

agent::execute_instruction ( const std::vector< unsigned char > &  screen,
int &  pc 
)
inline

Perform the operation corresponding to this instruction.

Parameters
screenThe register file corresponding to the reduced screen
pcThe program counter, corresponds to an instruction

◆ get_action()

agent::get_action ( const std::vector< unsigned char > &  screen)

Execute the program on a particular frame and choose an action.

Parameters
screenRegister file corresponding to the reduced screen
Returns
The index corresponding to the highest value in register file "outputs"

◆ print_instruction()

agent::print_instruction ( std::ostream &  os,
instruction  ins 
) const

Display an instruction as a String through a outputStream.

Parameters
osThe output stream used to display
insThe instruction to be displayed

◆ reg_to_string()

agent::reg_to_string ( int  reg) const

Represent a register as a string.

Parameters
regThe index of a register
Returns
A string representing the corresponding register among all the register files

◆ reset()

agent::reset ( )

Fills all the registers files with 0 and set nb_steps and current_part to 0.

◆ reset_registers()

agent::reset_registers ( )

Fills the registers "temporary" and "outputs" files with 0.

◆ serialize()

agent::serialize ( Archive &  ar,
const unsigned int   
)
inline

Save/Load agent with archive.

Parameters
[in,out]arArchived agent
Remarks
The second parameter is unused, as we don't ensure retrocompatibility.
Warning
Don't use it. This function is automatically called when (un)serializing with boost.

Member Data Documentation

◆ current_part

int agent::current_part = 0

Number corresponding to the currently executed part

◆ nb_steps

int agent::nb_steps = 0

Total number of execution of the current part

◆ params

parameters agent::params

Caracteristics of this agent

◆ program

std::vector<instruction> agent::program

List of instructions representing the program

◆ registers

std::vector<reg> agent::registers

Register files of this agent


The documentation for this struct was generated from the following files: