Menu

DeveloperReadme

Miha Vitorovic
There is a newer version of this page. You can find it here.

1. Developer information

1.1. Documentation

Developed and built using Netbeans 8

Mars interpreter (I hope) finally works correctly, or at least it runs the "validate.red" warrior (part of pMARS distribution) the way it should. It's not "lightning speed" fast, but I was more interested in the correct results as speed. I intend to optimize later.

Found a nice collection of warriors at http://cristal.inria.fr/~doligez/corewar/rc/

Done so far:

package mars.mike5
  • basic data structures: MemCell, MemArray, Warrior
  • basic enum definitions: OpCode, AddressingMode, Modifier
  • Application: CoreWars
  • MARS options: Options
  • MemArray
    • MemCell[] core
    • List warriors
    • dump(Writer file)
    • execute(warrior) - interprets the next instruction of the warrior
package mars.mike5.util
  • CommandLine : command line parser
  • TokenizedExpression:
    • The type of the expression parsed is determined by the class implementing the ExpressionParser interface
    • CompilerParser parses expressions for the compiler and support for labels, and expression evaluation
    • operator priority
    • parentheses
  • ExpressionParser parses expressions to evaluate GA fitness function. Each function evaluates to a real number (double) result. The mode for binary operations is the same as Java, i.e. if one of the operands is a real number, the result is a real number, otherwise it is an integer. The fitness evaluation supports scalar variables and 1-D array variables. These are always provided by the system and cannot be changed.
  • ExpressionParser and CompilerParser operators & priority:

    Arithmetic:
        +   addition or unary plus
        -   subtraction or unary minus
        *   multiplication
        /   division
        %   modulo (remainder of division) Works only on Integers!
    
    Comparison:
        ==  equality
        !=  inequality
        <   less than
        >   greater than
        <=  less than or equal
        >=  greater than or equal
    
    Logical:
        &&  and
        ||  or
        !   unary negation
    
    Comparison and logical operators return 1 for true and 0 for false.
    Parentheses can be used to override this precedence order:
    
    1) ! - + (unary)
    2) * / %
    3) - + (binary)
    4) == != < > <= >=
    5) &&
    6) ||
    
package mars.mike5.exceptions
  • CompileErrorException
  • InvalidParamException
  • TooManyParamsException
package mars.mike5.compiler
  • Compiler:
    • basic compiler,
    • supports redcode,
    • comments, 'org' and 'end' meta-instructions
    • ;assert
    • ;name
    • ;author
    • EQU support, including multiline.
    • FOR/ROF loops
    • multiple labels per instruction supported (each label in its own line)
  • CompiledWarrior: contains memory cells for compiled warrior, its id and name. This is temporary only, and is later copied into core.

    • Support classes:
      • SymbolicMemCell
  • passes pMars 'validate.red' ;)

package mars.mike5.debugger:
- a simple debugger interface, capable of opening multiple memory inspection windows, and
one window for each warrior. Marks selected memory location, or the next warrior
instruction. Also a P-space dump window for each warrior may be opened. It is possible
to edit core/P-space contents in place.

package mars.mike5.ga:
- this package contains all the GA stuff and the handling of the generations. Each generation can
be archived for analysis. The type of archive is folder or Zip. The contents of the archive are:
* MARS settings
* all the warriors that were used for this generation
* their scores
* all the warriors that are created through GA crossover and mutation

package mars.mike5.ga.eval:
- this package contains the code to evaluate GA fitness function. Each function evaluates to a real number (double) result. The mode for binary operations is the same as Java, i.e. if one of the operands is a real number, the result is a real number, otherwise it is an integer. The fitness evaluation supports scalar variables and 1-D array variables. These are always provided by the system and cannot be changed.

+ operators & priority:
     Arithmetic:
         +   addition or unary plus
         -   subtraction or unary minus
         *   multiplication
         /   division
         %   modulo (remainder of division) Works only on Integers!

     Comparison:
         ==  equality
         !=  inequality
         <   less than
         >   greater than
         <=  less than or equal
         >=  greater than or equal

     Logical:
         &&  and
         ||  or
         !   unary negation

     Comparison and logical operators return 1 for true and 0 for false.
     Parentheses can be used to override this precedence order:

     1) ! - + (unary)
     2) * / %
     3) - + (binary)
     4) == != < > <= >=
     5) &&
     6) ||
  • variables are the statistics collected during the warrior execution, and can be used to
    calculate a fitness function. This section lists variables and gives some examples
    on how to used them
    • size - the initial size of the warrior
    • cycles - the number of cycles the warrior ran
      • With randomly generated warriors, for the first "couple" of generations one
        of the few things worth testing is, how long can the warrior run at all
      • warrior starts on a DAT command; score -500:
        (cycles < 1)*(-500)
      • warrior runs for less than 10% of it's size and then dies; score -100:
        ((cycles1.0/size)<0.1)(-100)
      • warrior runs for 10%-40% of it's size; score 100:
        (((cycles1.0/size)>=0.1)&&((cycles1.0/size)<0.4))*100
      • warrior runs goes through a major part of it's instructions; score 300:
        (((cycles1.0/size)>=0.4)&&((cycles1.0/size)<1.0))*300
      • warrior actually contains a loop; score 1000:
        ((cycles1.0/size)>1.0)1000
      • A fitness function covering all of the above cases would just have to add all
        these equations
    • id - the ID (number) if the current warrior. Nonzero number.

1.2. Plans

Still to do (order of preference):

All GA stuff:
- create configuration handling. Entire generation can be stuffed into a ZIP file.
- Action 'Break after this generation and dump all data to resume later'
- warrior fitness evaluation ('Original writer' and 'Last modifier' should be helpful)
- enable creation of entire state dump after each generation. Must allow resume:
+ Dump all warriors
+ Dump all necessary information, their score, survival rate, etc. into XML file

MemArray.java:
- make interpreter faster (maybe)

Debugger.java
- add 'Finish round' button

CoreWars.java
- add pMARS (and maybe KoTH) compatible output
- add other other ICWS language variants as well

Write great documentation and comment everything ;)

2. Changelog:

Version 0.5:
- Added CLI parameter -GC (--generate-config) which generates XML configuration for GA. The name/location
of the XML file is passed as a parameter. The configuration also includes any warrior files found in the same
folder as XML file.

Version 0.4:
* Added all pMars supported operators
- added ;assert
- multiple labels per instruction
- SPL honors the MAXPROCESSES setting
- Assignment and variables added
- Added P-space to warriors
- Added P-space inspection window to debugger
- LDP and STP implemented
- CLI option -S and hide P-space inspection in debugger when necessary
- debug option changed to '-e'
- addresses larger than 75% of CORESIZE are now displayed as negative in debugger
- load the first warrior at address 0
- Core/P-space editing in debugger
- Added CLI option -F
- Added CLI options -c and -p
- Debugger now dumps each warrior
- Added CLI options -b and -l
- Debugger assembly warrior dump flushes with every println
- pMARS compatible warrior assembly dump
- added inspect size spinner to Debugger window
- added support for multiline EQU (preprocessor)
- added support for FOR/ROF loops
- added CLI parameter -r
- added CLI parameter -=