PREP 2014 Question Authoring - Archived

Constructing arrays in PGML, and short answer blocks

Constructing arrays in PGML, and short answer blocks

by Adam Graham-Squire -
Number of replies: 1
I have the following code for a Game Theory question, and it works fine (almost).  Right now the table is made using BEGIN_TEXT ... END_TEXT, because I could not figure out how to make it in PGML.  Is there an easy way to do it in PGML?  And in general, is there any issue with mixing the TEXT form and the PGML form as I do in this question?  Lastly, I think I made the essay answer box correct (it seems to work), but I would like for someone else to check it to out. Here is the code: 

##DESCRIPTION
##  Game Theory, basic Nash Equilibria
##ENDDESCRIPTION

##KEYWORDS('Game Theory, Nash Equilibria')

## DBsubject('Game Theory')
## DBchapter('Simultaneous Move Games')
## DBsection('Nash Equilibria')
## Date('6/25/2014')
## Author('Adam Graham-Squire')
## Institution('High Point University')
## TitleText1('Games Of Strategy')
## EditionText1('2')
## AuthorText1('Dixit, Skeath')
## Chapter('4')
## Problem1('2a')

########################################################################

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "PGunion.pl",
  "MathObjects.pl",
  "PGcourse.pl",
  "PGML.pl",
  "PGessaymacros.pl"
);

TEXT(beginproblem);

##############################
#
#  Setup
#


Context("Numeric");
$a = non_zero_random(1,2,1);
$b = non_zero_random(3,4,1);
$c = non_zero_random(5,6,1);
$d = non_zero_random(7,10,1);




##############################
#
#  Main text
#

BEGIN_TEXT

Find all Nash equilibria in pure strategies for the zero-sum game given below.
$PAR
$BCENTER
\{ begintable(3) \}
\{ row( "", "Left", "Right" ) \}
\{ row( "Up", "$a, -$a", "$d, -$d" ) \}
\{ row( "Down", "$b, -$b", "$c, -$c" ) \}
\{ endtable() \}
$ECENTER
END_TEXT

BEGIN_PGML
If both players play their optimal strategy, the Row player will have a payout of [________]{"[$b]"}.  
Explain your reasoning for your answer above.
[@ ANS(essay_cmp()); ans_box(5,40) @]*
END_PGML



##############################

ENDDOCUMENT();      
In reply to Adam Graham-Squire

Re: Constructing arrays in PGML, and short answer blocks

by Davide Cervone -
Unfortunately, tables is one of the features that still needs to be added to PGML (there are versions of Markdown that include tabling, so there are specifications that could be used).

On the other hand, you can still use the PG macros that you are using from within PGML. In PGML, [@ ... @]* acts like \{...\} does in BEGIN_TEXT/END_TEXT, so you could simply replace \{ with [@ and \} by @]* (the star at the end is to prevent PGML from altering the results by quoting special characters; you want the results of the tabling macros to be inserted verbatim). Or you could do them all in one block by concatenating the results of each command using perl's "dot" operator, as in:

BEGIN_PGML
Find all Nash equilibria in pure strategies for the zero-sum game given below.

>> [@ 
  begintable(3) .
  row( " ", "Left", "Right" ) .
  row( "Up", "$a, -$a", "$d, -$d" ) .
  row( "Down", "$b, -$b", "$c, -$c" ) .
  endtable()
@]* <<

If both players play their optimal strategy, the Row player will have a payout of [________]{"[$b]"}.  
Explain your reasoning for your answer above. 
[@ ANS(essay_cmp()); ans_box(5,40) @]*
END_PGML