PD-Home · Introduction · PDS-Instructions · PDS-Examples · PDS-Exercises · Tournament-Entries |
PDS Language design
|
Keywords / Reserved words |
|
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 |
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 NOTE: only one arithmetic operation allowed per statement (the language will not support complex arithmetic expressions). |
set tweedle 11 |
These variables will have the following values:
tweedle = 11 |
comp-op | Any one of the following comparison operators:
= equals NOTE: only one comparison operation allowed in an "if" statement (the language will not support complicated expressions) |
if dee >= 12 goto new-jersey if num-moves = 0 goto Surprise if last-move-other = coop |
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 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) 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 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
|
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 |
set f 12 ; this sets f to 12 ; start of the interesting part |
|
set |
sets a variable to a value |
set variable varnum |
ALLOWED:
NOT ALLOWED: |
- 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 1
report defect report coop |
|
if | make a decision |
if varnum comp-op varnum goto label |
if num-moves = 0 goto TheFirst if coop = move-other num-moves |
- 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 |
if harry is zero, then go directly to the label nirvana skipping the "set fred 12" statement |
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 either displays a string or the value of a variable (or special value). |