PD-Home   ·   Introduction   ·   PDS-Instructions    ·   PDS-Examples    ·   PDS-Exercises    ·   Tournament-Entries

PDS Instruction Set

PDS Language design

  • This is a small language, with few keywords 

  • There is only one datatype: integers.

  • A program starts by executing the first statement, and continues until either report 1 or a report 0 is executed.  1 means "cooperate" and 0 means "defect".

  • All operators must be surrounded by spaces (as in NetLogo).

  • Comments start with the ";" (semi-colon) character and continue until the end of the line.

  • Blank lines and lines with only comments are fine.

Keywords / Reserved words

  • coop
  • defect
  • defects-mine
  • defects-other
  • goto
  • if
  • last-move-mine
  • last-move-other
  • move-mine
  • move-other
  • num-moves
  • print
  • random
  • report
  • score-mine
  • score-other
  • set

Definitions

What Definition Examples Meaning of examples
variable an identifier for an integer value -- identifiers start with a letter and consist of letters, numbers and dashes. set voldemort 12

set v12-fred voldemort + 3

Sets the value of the variable "voldemort" to 12

Sets the value of the variable "v12-fred" to the value of the expression "voldemort + 3" which is 15.

varnum This indicates 
- number
- variable
- special-value
- special-function

set variable varnum 
arith-op varnum

This is shorthand notation indicating that setting the value of a variable can be accomplished with any one of the following types of statements:
set hagrid 12 + 5
set hagrid 12 * voldemort
set hagrid random 50
set hagrid 12 + random 50
set hagrid move-other num-moves
arith-op Any one of the following  arithmetic operations:

+ addition
- subtraction
* multiplication
/ integer division
% modulo (remainder)

NOTE: only one arithmetic operation allowed per statement (the language will not support complex arithmetic expressions).

set tweedle 11
set dee 4
set harry dee * tweedle
set hagrid tweedle / dee
set voldemort tweedle % dee

These variables will have the following values:

tweedle = 11
dee = 4
harry = 44
hagrid = 2
voldemort = 3

comp-op Any one of the following comparison operators:

= equals
!= not equals
>= greater than or equals
> greater than
< less than
<= less than or equals

NOTE: only one comparison operation allowed in an "if" statement (the language will not support complicated expressions)

if dee >= 12 goto new-jersey
report coop
new-jersey:
report defect

if num-moves = 0 goto Surprise

if last-move-other = coop 
goto somewhere

First example: if dee is greater than or equal to 0, then defect, otherwise cooperate.

 

PDS special values and functions

What Definition Format Examples Meaning of examples
special-value There are 5 special values:

defect = 0
coop = 1

num-moves = number of moves so far (starts at 0)

last-move-mine = my last move (error will occur if you try to evaluate this before any moves are made).

last-move-other = the other's last move (error will occur, explained above).

defect

coop

num-moves

last-move-mine

last-move-other

set harry coop

report defect

if last-move-other = defect goto ...

 
sets harry to 1

reports 0

if the other has just defected, then do something...

 

special-function There are 7 special functions:

move-mine = one of my previous moves (counting backwards)

move-other = one of other's previous moves (counting backwards)

random  = choose defect or coop at random

defects-mine = number of times I've defected in the last n moves

defects-other = number of times the other player has defected in the last n turns

score-mine = my total score for the last n turns

score-other = the other's total score for the last n turns

move-mine varnum

move-other varnum

random varnum

defects-mine varnum

defects-other varnum

score-mine varnum

score-other varnum

set fred move-mine 1
set george last-move-mine

set harry move-other num-moves 

set craig Random 90

set p score-mine 1

set q score-other num-moves

set s defects-mine num-moves

set t defects-other 1

set a defects-other num-moves
set partner-coop num-moves - a

 

sets both fred and george to my last move

sets harry to my partner's first move

sets craig to1 with 90% probability, and 0 with 10% probability

sets p to what I earned in the last turn

sets q to what my partner earned so far

sets s to how many times I've defected so far

sets t to 1 if my partner defected on the last turn, otherwise 0

calculates and sets partner-coop to how many times my partner has cooperated so far 

 

PDS Statements

What Definition Format Examples Meaning of examples
comment starts with the ";" character, and ends at the end of the line

;comment

statement ; comment

set f 12 ; this sets f to 12

; start of the interesting part

 

set

sets a variable to a value

set variable varnum

set variable varnum arith-op 
     varnum

set variable 
   special-function varnum

ALLOWED:
set fred 12
set harry fred
set george defect
set mary num-moves
set craig move-mine 2
set larson move-other 8
set parsnip random 30
set fleep fred + harry
set blurp 12 - num-moves

NOT ALLOWED:
set david random 30 - num-moves
(because special-function 
"random" cannot be involved in
an arithmetic expression)

- sets fred to 12
- sets harry to the current value of fred
- sets george to 0
- sets mary to the number of moves so far
- sets craig to the move before last (two moves ago) in this round
- sets larson to my partner's eighth move before last (8 moves ago)
- sets parsnip to 1 with 30% probability, and to 0 otherwise
report indicates your decision for this move, and ends the program for this move

Note: must be 0 (or defect) or 1 (or coop)

report varnum
report defect
report coop

report 1

report defect

report coop

 
if make a decision

if varnum comp-op varnum goto label

if num-moves = 0 goto TheFirst
; do something
TheFirst:
report defect

if coop = move-other num-moves
    goto FirstMoveWasCoop
; etc.

- defect on your first move, otherwise do something

- if the other's first move was coop, then goto FirstMoveWasCoop

label statement label -- a place to jump to from a goto  statement

here:

(an identifier followed by a colon)

   
goto jump to the place in the program where the label is

goto label:

if harry = 0 goto nirvana
set fred 12
nirvana:
set george 18

if harry is zero, then go directly to the label nirvana skipping the "set fred 12" statement
print print a string or the value of a variable (this works only in "trial-mode", not during a tournament)

print "a string"

print varnum


  print Num-moves

print either displays a string or the value of a variable (or special value).