Zoadian 10 rokov pred
rodič
commit
b0d302adab
2 zmenil súbory, kde vykonal 61 pridanie a 29 odobranie
  1. 31 25
      README.md
  2. 30 4
      simulator.h

+ 31 - 25
README.md

@@ -52,31 +52,37 @@ A programming game based on RoboCom.
 
 
 # Variables
-| Variable / Constant  | Description                                                                                                        |
-|----------------------|--------------------------------------------------------------------------------------------------------------------|
-| #1 .. #20            | The twenty all-purpose standard integers. They cannot be accessed by remote programs                               |
-| #Pub                 | Public variable which is accessible from all programs on the field                                                 |
-| #Team                | Public variable which is accessible from all own programs on the field                                             |
-| #Active              | Determines if a current program is active (positive values) or not (zero or negative)                              |
-| %Active              | Determines if a remote program is active (positive values) or not (zero or negative)                               |
-| $Banks               | The number of banks which the current program has                                                                  |
-| %Banks               | The number of banks which the remote program has                                                                   |
-| $InstrSet            | The instruction set which the current program has                                                                  |
-| %InstrSet            | The instruction set which the remote program has                                                                   |
-| $Mobile              | Tells if the current program is mobile                                                                             |
-| %Mobile              | Tells if the remote program is mobile                                                                              |
-| $Age                 | The current program's age in cycles                                                                                |
-| %Age                 | The remote program's age in cycles                                                                                 |
-| $Own                 | The number of friendly programs on the board                                                                       |
-| $Others              | The number of enemy programs on the board                                                                          |
-| $Fields              | The size of the board                                                                                              |
-| $ElimTrigger         | The elimination trigger setting                                                                                    |
-| $Generation          | The generation of the current program                                                                              |
-| $ID                  | Identifier which is equal for each program of the same team<br> and initialized to random when the game is started |
-| $InstrPos            | The number of the current instruction (in its bank)                                                                |
-| $Time                | The game time in cycles                                                                                            |
-| $Timeout             | The automatic simulation timeout in cycles                                                                         |
-| $Tasks               | The number of tasks in the current program, incl. sleeping or seized tasks                                         |
+| Local Variable   | mutability | Description                                                                                                        |
+|------------------|------------|--------------------------------------------------------------------------------------------------------------------|
+| #1 .. #20        | mutable    | The twenty all-purpose standard integers. They cannot be accessed by remote programs                               |
+| #Pub             | mutable    | Public variable which is accessible from all programs on the field                                                 |
+| #Team            | mutable    | Public variable which is accessible from all own programs on the field                                             |
+| #Active          | mutable    | Determines if a current program is active (positive values) or not (zero or negative)                              |
+
+| Remote Variable | mutability  | Description                                                                                                        |
+|-----------------|-------------|--------------------------------------------------------------------------------------------------------------------|
+| %Active         | mutable     | Determines if a remote program is active (positive values) or not (zero or negative)                               |
+| %Banks          | immutable   | The number of banks which the remote program has                                                                   |
+| %InstrSet       | immutable   | The instruction set which the remote program has                                                                   |
+| %Mobile         | immutable   | Tells if the remote program is mobile                                                                              |
+| %Age            | immutable   | The remote program's age in cycles                                                                                 |
+| %Tasks          | immutable   | The number of tasks in the remote program, incl. sleeping or seized tasks                                          |
+
+| Constants       | mutability  | Description                                                                                                        |
+|-----------------|-------------|--------------------------------------------------------------------------------------------------------------------|
+| $Banks          | immutable   | The number of banks which the current program has                                                                  |
+| $InstrSet       | immutable   | The instruction set which the current program has                                                                  |
+| $Mobile         | immutable   | Tells if the current program is mobile                                                                             |
+| $Age            | immutable   | The current program's age in cycles                                                                                |
+| $Tasks          | immutable   | The number of tasks in the current program, incl. sleeping or seized tasks                                         |
+| $Own            | immutable   | The number of friendly programs on the board                                                                       |
+| $Others         | immutable   | The number of enemy programs on the board                                                                          |
+| $Fields         | immutable   | The size of the board                                                                                              |
+| $Generation     | immutable   | The generation of the current program                                                                              |
+| $ID             | immutable   | Identifier which is equal for each program of the same team<br> and initialized to random when the game is started |
+| $InstrPos       | immutable   | The number of the current instruction (in its bank)                                                                |
+| $Time           | immutable   | The game time in cycles                                                                                            |
+| $Timeout        | immutable   | The automatic simulation timeout in cycles                                                                         |
 
 
 # Execution Model

+ 30 - 4
simulator.h

@@ -95,6 +95,33 @@ enum Params : uint16_t {
     VV = VVV,
 };
 
+enum Variables {
+    LocalVar_0 = 0,
+    LocalVar_20 = 19,
+    PubVar,
+    TeamVar,
+    LocalActiveVar,
+    RemoteActiveVar,
+    LocalBanks,
+    RemoteBanks,
+    LocalInstrSet,
+    RemoteInstrSet,
+    LocalMobile,
+    RemoteMobile,
+    LocalAge,
+    RemoteAge,
+    Own,
+    Others,
+    Fields,
+    LocalGeneration,
+    TeamId,
+    InstrPos,
+    Time,
+    Timeout,
+    LocalTasks,
+    RemoteTasks,
+};
+
 enum Error {
     NoError, // No error
     EliminationTrigger, // Elimination Trigger released
@@ -259,13 +286,12 @@ struct Simulator {
                 int32_t* c = &c_safe;
 
                 auto decode = [&](int*& v) {
-                    if(*v >= 0 && *v <= 20) {
+                    if(*v >= VAR_0 && *v <= VAR_20) {
                         v = &program.vars[*v];
+                        return;
                     }
-                    else {
-                        switch(*v) {
+                    switch(*v) {
                         case 21: break;
-                        }
                     }
                 };