Difference between revisions of "Core War"

From Programming Games Wiki
Jump to: navigation, search
(Created page with "'''Core War''' is a game played between two or more computer programs in the memory of the Memory Array Redcode Simulator (MARS) virtual computer. The aim is to out survive al...")
 
m
Line 1: Line 1:
 
'''Core War''' is a game played between two or more computer programs in the memory of the Memory Array Redcode Simulator (MARS) virtual computer. The aim is to out survive all opponents while attempting to disable all opponents.
 
'''Core War''' is a game played between two or more computer programs in the memory of the Memory Array Redcode Simulator (MARS) virtual computer. The aim is to out survive all opponents while attempting to disable all opponents.
  
===History===
+
==History==
 
In March 1984 A. K. Dewdney and David Jones wrote the Core War Guidelines which suggested how to implement a simple version of Core War. Shortly after, Dewdney published his first Core War article in Scientific American inspiring a number of programmers to implement their own version.
 
In March 1984 A. K. Dewdney and David Jones wrote the Core War Guidelines which suggested how to implement a simple version of Core War. Shortly after, Dewdney published his first Core War article in Scientific American inspiring a number of programmers to implement their own version.
  
 
The following year a society was formed to standardise Redcode and organise an annual tournament. The International Core Wars Society (ICWS) issued a standard in May 1986 and organised the first tournament at Boston's Computer Museum in September 1986.
 
The following year a society was formed to standardise Redcode and organise an annual tournament. The International Core Wars Society (ICWS) issued a standard in May 1986 and organised the first tournament at Boston's Computer Museum in September 1986.
  
===Redcode===
+
==Redcode==
  
 
Core War programs are written in a language called Redcode. The original instruction set had 8 opcodes but with the publication of the '94 standard the number increased to 18.
 
Core War programs are written in a language called Redcode. The original instruction set had 8 opcodes but with the publication of the '94 standard the number increased to 18.
Line 12: Line 12:
 
Each location in memory contains an instruction and two values A and B. A and B are used as address pointers when the instruction is executed. A and B may also be used as data when referenced by another instruction.
 
Each location in memory contains an instruction and two values A and B. A and B are used as address pointers when the instruction is executed. A and B may also be used as data when referenced by another instruction.
  
====Opcodes====
+
===Opcodes===
  
 
Opcodes can be divided into five groups:
 
Opcodes can be divided into five groups:
Line 49: Line 49:
 
* NOP - do nothing
 
* NOP - do nothing
  
====Modifiers====
+
===Modifiers===
  
 
Each opcode has a modifier which describes which values should be used from each address:  
 
Each opcode has a modifier which describes which values should be used from each address:  
Line 61: Line 61:
 
* .I - use the entire instruction
 
* .I - use the entire instruction
  
====Addresses====
+
===Addresses===
  
 
Each address has an addressing mode and a pointer. All pointers are relative to where the address is stored. 0 refers to the current location. 1 refers to the next location and -1 to the previous. There are 8 addressing modes:
 
Each address has an addressing mode and a pointer. All pointers are relative to where the address is stored. 0 refers to the current location. 1 refers to the next location and -1 to the previous. There are 8 addressing modes:
Line 78: Line 78:
 
All values are taken modulo the size of memory (CORESIZE). Values range from 0 to CORESIZE-1. For example if the CORESIZE is 8000, -3 is stored as 7997 (CORESIZE-3).
 
All values are taken modulo the size of memory (CORESIZE). Values range from 0 to CORESIZE-1. For example if the CORESIZE is 8000, -3 is stored as 7997 (CORESIZE-3).
  
====P-Space====
+
===P-Space===
  
 
P-space is an area of private non-volatile memory which can only be accessed via LDP and STP. Each program has its own area of private memory. The contents of p-space are preserved between rounds in a multi-round battle.
 
P-space is an area of private non-volatile memory which can only be accessed via LDP and STP. Each program has its own area of private memory. The contents of p-space are preserved between rounds in a multi-round battle.
Line 92: Line 92:
 
P-space is often used by programs to switch between two or more strategies based on the performance in previous rounds.
 
P-space is often used by programs to switch between two or more strategies based on the performance in previous rounds.
  
===Example===
+
==Example==
  
 
  ;redcode
 
  ;redcode
Line 105: Line 105:
 
When the imp executes it copies itself from the current location to the next location. When the next location is executed, it contains an exact copy of the imp and so the process repeats.
 
When the imp executes it copies itself from the current location to the next location. When the next location is executed, it contains an exact copy of the imp and so the process repeats.
  
===Inspiration for===
+
==Inspiration for==
  
 
[[CROBOTS]]
 
[[CROBOTS]]
  
===External Links===
+
==External Links==
  
 
* [http://corewar.co.uk Corewar - the Ultimate Programming Game]
 
* [http://corewar.co.uk Corewar - the Ultimate Programming Game]

Revision as of 08:25, 16 May 2019

Core War is a game played between two or more computer programs in the memory of the Memory Array Redcode Simulator (MARS) virtual computer. The aim is to out survive all opponents while attempting to disable all opponents.

History

In March 1984 A. K. Dewdney and David Jones wrote the Core War Guidelines which suggested how to implement a simple version of Core War. Shortly after, Dewdney published his first Core War article in Scientific American inspiring a number of programmers to implement their own version.

The following year a society was formed to standardise Redcode and organise an annual tournament. The International Core Wars Society (ICWS) issued a standard in May 1986 and organised the first tournament at Boston's Computer Museum in September 1986.

Redcode

Core War programs are written in a language called Redcode. The original instruction set had 8 opcodes but with the publication of the '94 standard the number increased to 18.

Each location in memory contains an instruction and two values A and B. A and B are used as address pointers when the instruction is executed. A and B may also be used as data when referenced by another instruction.

Opcodes

Opcodes can be divided into five groups:

Copying:

  • MOV - copy the contents of A to B
  • STP - copy the contents of A to p-space location B
  • LDP - copy the contents of p-space location A to B

Simple Maths:

  • ADD - add the contents of A to the contents of B
  • SUB - subtract the contents of A from the contents of B
  • MUL - multiply the contents of A by the contents of B
  • DIV - divide the contents of B by the contents of A
  • MOD - divide the contents of B by the contents of A, taking the remainder

Flow Control:

  • JMP - transfer control to A
  • JMZ - transfer control to A if the contents of B are zero
  • JMN - transfer control to A if the contents of B are non-zero
  • DJN - decrement the contents of B then transfer control to A if non-zero
  • SEQ - skip the next instruction if the contents of A and B are equal
  • SNE - skip the next instruction if the contents of A and B are not equal
  • SLT - skip the next instruction if the contents of A is less than B

Process Control:

  • SPL - create a new process at A
  • DAT - the process executing DAT is terminated

Miscellaneous:

  • NOP - do nothing

Modifiers

Each opcode has a modifier which describes which values should be used from each address:

  • .A - use the A values
  • .B - use the B values
  • .AB - use the A value from the A address and the B value from the B address
  • .BA - use the B value from the A address and the A value from the B address
  • .F - use both values
  • .X - use both values, exchanging the values from A address
  • .I - use the entire instruction

Addresses

Each address has an addressing mode and a pointer. All pointers are relative to where the address is stored. 0 refers to the current location. 1 refers to the next location and -1 to the previous. There are 8 addressing modes:

  • $ - direct - address is the location at pointer ($ is the default addressing mode and can be omitted)
  • # - immediate - address is the current instruction
  • @ - B indirect - the B value of the location at pointer points to the address
  • < - pre decrement B indirect - decrement the B value of the location at pointer then use B indirect addressing
  • > - post increment B indirect - use B indirect addressing then increment the B value of the location at pointer
  • * - A indirect - the A value of the location at pointer points to the address
  • { - pre decrement A indirect - decrement the A value of the location at pointer then use A indirect addressing
  • } - post increment B indirect - use A indirect addressing then increment the A value of the location at pointer

All values are taken modulo the size of memory (CORESIZE). Values range from 0 to CORESIZE-1. For example if the CORESIZE is 8000, -3 is stored as 7997 (CORESIZE-3).

P-Space

P-space is an area of private non-volatile memory which can only be accessed via LDP and STP. Each program has its own area of private memory. The contents of p-space are preserved between rounds in a multi-round battle.

Location 0 in p-space contains a flag indicating the result of the previous round:

  • -1 - no previous round, the current round is the first
  • 0 - the program lost the previous round
  • 1 - the program won the previous round
  • 2 - the program was part of a two way tie in the previous round
  • N - the program was part of a N way tie in the previous round

P-space is often used by programs to switch between two or more strategies based on the performance in previous rounds.

Example

;redcode
;name imp
;author A. K. Dewdney

        MOV.I $ 0, $ 1


The imp is one of the simplest Core War programs. MOV.I copies an entire instruction from A to B. A is $ 0 and points directly to the imp in the current location. B is $ 1 and points directly to the next location.

When the imp executes it copies itself from the current location to the next location. When the next location is executed, it contains an exact copy of the imp and so the process repeats.

Inspiration for

CROBOTS

External Links