\documentclass[11pt]{article}
\usepackage{fixltx2e}
\usepackage{slashbox}
\usepackage{courier}
\usepackage{lmodern}
\usepackage{titlesec}
\usepackage{chngcntr}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{mathtools}
\usepackage{epstopdf}
\usepackage[table]{xcolor}
\usepackage[normalem]{ulem}
\usepackage[authoryear]{natbib}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}


\textwidth = 6.5 in
\textheight = 9 in
\oddsidemargin = 0.0 in
\evensidemargin = 0.0 in
\topmargin = 0.0 in
\headheight = 0.0 in
\headsep = 0.0 in
\parskip = 0.01in
\parindent = 0.0in

\bibliographystyle{gsabull}

\newcommand\tab[1][1cm]{\hspace*{#1}}

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}{Definition}

\renewcommand\thesection{\arabic{section}}
\renewcommand\thesubsection{\arabic{subsection}}
\renewcommand\thesubsubsection{\alph{subsubsection}.}

%\makeatletter
%\renewcommand\subsection{\@startsection{subsection}{3}{\z@}%
%                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
%                                     {-1.5ex \@plus -.2ex}% Formerly 1.5ex \@plus .2ex
%                                     {\normalfont\large\bfseries}}
%\renewcommand\subsubsection{\@startsection{subsubsection}{3}{\z@}%
%                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
%                                     {-1.5ex \@plus -.2ex}% Formerly 1.5ex \@plus .2ex
%                                     {\normalfont\large\bfseries}}
%\makeatother

\counterwithin{subsection}{section}

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{lightyellow}{rgb}{1,1,0.75}

\lstset{frame=tb,
  backgroundcolor = \color{lightyellow},
  language=C,
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle=\ttfamily,
  numbers=left,
  numberstyle=\ttfamily,
  keywordstyle=\ttfamily,
  commentstyle=\color{red}\ttfamily,
  stringstyle=\ttfamily,
  emph={sim, Game, strat, function, int, bool, float, if, else, expected, cycle, default},
  emphstyle=\bf\ttfamily,
  breaklines=true,
  breakatwhitespace=true,
  tabsize=6,
  escapeinside={<@}{@>}
}

\begin{document}

% Title
\begin{center}
\huge {\ttfamily replay}

\includegraphics[width=2 cm]{replay_icon.pdf}

% Subtitle
\large A language for simple repeated games
\vspace{0.2 in}

% Proposal
\large \textsc{Proposal}
\vspace{0.2 in}

% Name
\large Eric Bolton - edb2129
\vspace{0.2 in}

% Date
\normalsize COMS W4115 - Programming Languages and Translators

Fall 2016 - CVN

September 28, 2016
\vspace{0.2 in}

\end{center}

\section{Motivation}

Game theory is treacherous for humans. Looks can be deceptive: even the simplest games are tricky to analyze, and it's easy to make silly mistakes. Repeated versions of games compound these problems, adding layers of complexity and confusion. A natural answer is to turn to a computer program for help. However, programming languages embraced by game theorists, such as {\ttfamily MATLAB}, {\ttfamily Python}, or {\ttfamily R}, do little to simplify the task at hand, as they weren't natively designed for these analyses.

{\ttfamily replay} is an imperative programming language that makes finitely and infinitely repeated games easier to represent and analyze. The syntax provides a clear and straightforward way to specify the various parameters of simple games: basic strategies, payoffs, as well as more complicated variants of strategies. Then, the language enables simple, yet powerful analyses on these games, such as determining the set of dominated strategies, or discovering whether a strategy profile is a Nash equilibrium. Finally, {\ttfamily replay} makes it possible to string simple games together, enabling analyses of more complicated games - including finitely and infinitely repeated games.

\section{Background}

A repeated game is a version of a simple game that is played more than once. Oftentimes, the optimal strategy in the repeated version of a game is radically different from the one in the base game. For example, in the Prisoner's Dilemma, optimal play dictates that the players do not cooperate. But in the repeated version of the game, depending on the number of repetitions and the value players attribute to their future payoffs, the threat of punishment could encourage collaboration.

Another feature of games is information. Players may know differing amounts about what others in the game have played. An example is the distinction between simultaneous games and sequential games: in a simultaneous game such as Rock-Paper-Scissors, Player 2 does not know what Player 1 has played when she makes her move. This is not the case in a sequential game like Chess.

Finally, while games are typically described by the payoffs yielded by pure strategies, players may choose not to play a pure strategy. That is, they may play different moves with different odds. This is important in games of imperfect information such as simultaneous games. For example, in Rock-Paper-Scissors, it's a bad idea to always play Rock; it is better to attribute a probability of $\frac{1}{3}$ to each move.

\section{Sample code}

\subsection{A simple game}

Rock Paper Scissors can be described using two statements.

\begin{lstlisting}
strat Shape  {Rock | Paper | Scissors};
Game g = sim Shape * Shape ->	[[(0, 0); (-1, 1); (1, -1)];
						[(1, -1); (0, 0); (-1, 1)];
						[(-1, 1); (1, -1); (0, 0)]];
\end{lstlisting}

This sample contains objects of the two key types of {\ttfamily replay}: {\ttfamily Game} and {\ttfamily Strategy}.  {\ttfamily g} is of type  {\ttfamily Game}, while {\ttfamily Rock},  {\ttfamily Paper}, and  {\ttfamily Scissors} are of type {\ttfamily Strategy}, a subtlety that is explained by the {\ttfamily strat} keyword (see below).
$\\$
Other data types available in {\ttfamily replay} are integers ({\ttfamily int}), booleans ({\ttfamily bool}), and floating point numbers ({\ttfamily float}).

$\\$
The sample also demonstrates {\ttfamily replay}'s support for tuples, which are here used to designate the payoffs for each outcome of the game.

$\\$
The sample introduces two keywords:

\begin{tabular}{ll}
$\bullet$ & {\bf\ttfamily strat}: Similar in function to an enum, this keyword helps designate a set of pure strategies. \\
& The strategy set {\ttfamily Shape} describes the set of basic strategies in a game of Rock, Paper, \\
& Scissors.  \\
$\bullet$ & {\bf\ttfamily sim}: This keyword specifies that the players play simultaneously, an important distinction. \\
& Had this keyword been omitted, player 2 would have 27 available pure strategies rather than \\
& 3: each describing three different responses for each of player 1's potential moves.
\end{tabular}

$\\$
It also demonstrates the use of parentheses {\ttfamily ()}, brackets {\ttfamily []}, and curly braces {\ttfamily \{\}}. Parentheses are reserved for tuples, functions, and arithmetic, while curly braces are reserved for block delimitation and strategy enumerations (using bars {\ttfamily |} to separate elements). Meanwhile, brackets define arrays (using semi-colons ; to separate elements), and can be nested to define arrays of arrays.

$\\$
Finally, note that a {\ttfamily Game} can specified using the {\ttfamily ->} constructor, which maps a set of strategy profiles to a set of payoffs. The "{\ttfamily Shape * Shape}" expression is a shorthand for the set of each combination of two strategies, such as {\ttfamily (Rock, Scissors)}. Had the  {\bf\ttfamily sim} keyword been omitted, the lefthand "{\ttfamily Shape}" would have been interpreted to mean the strategy set of the player who plays second. This shorthand essentially represents a Cartesian product of the elements in {\ttfamily Shape}. The {\ttfamily ->} operator demands two requirements:

\begin{tabular}{ll}
1. & The arrays on each side of the operator must have the same size and dimension \\
2. & The payoff tuples and strategy profiles must have the same size \\
\end{tabular}

\subsection{Flow control and functions}

{\ttfamily replay} supports basic flow control with {\ttfamily if...else} statements and {\ttfamily for}-loops. This is principally helpful for writing user-defined payoff functions, which can then be used to describe objects of type {\ttfamily Game}.

$\\$
Here is the matching pennies game described in this manner:

\begin{lstlisting}
strat Side {Heads | Tails};

function match(Side s1, Side s2) {
	if (s1 == s2) {
		return (1, -1);
	}
	else {
		return (-1, 1);
	}
}

Game g = sim Side * Side -> match();

\end{lstlisting}

Pairs generated from the left side of the {\ttfamily ->} are passed as arguments to the payoff function {\ttfamily match()}.

$\\$
{\ttfamily replay} supports the basic boolean operators {\ttfamily \&\&, ||, !},  as well as the basic arithmetic operators {\ttfamily +, -, *, /} and comparison operators {\ttfamily ==, !=, <, >, <=, >=}. It also supports exponentiation with {\ttfamily **}.

\subsection{Repeated games}

Finally, we examine the crux of {\ttfamily replay}: infinitely repeated games.

\begin{lstlisting}
/* Prisoner's Dilemma. C means collaboration, N means no collaboration */
strat Option {C | N};

Game pd = sim Option * Option ->
[[(-1,-1) (-3, 0)];
[( 0,-3) (-2,-2)]];

Game infrep = pd ** inf;
infrep.p[1].delta = 0.5; // Default discount factor is 1. Change to 0.5.
infrep.p[2].delta = 0.5;

Strategy grim =	cycle:	C ** inf
			| N:		N ** inf;

Strategy[] p = [grim; grim];

// The following statement prints true: this is a Nash Equilibrium
print(expected(grim, p, infrep) >= expected(N ^ inf, p, infrep));
\end{lstlisting}

This sample introduces the two crucial keywords for describing infinite games and strategies: {\ttfamily inf} and {\ttfamily cycle}, as well as the built-in functions {\ttfamily print} and {\ttfamily expected}.

$\\$
The expression "{\ttfamily pd ** inf}" indicates that the game {\ttfamily pd} is to be repeated infinitely. Likewise, {\ttfamily C ** inf} indicates that the strategy {\ttfamily N} is to be played for infinite periods. In both cases, {\ttfamily inf} could be replaced by a finite integer to indicate finite repetitions. 

$\\$
The keyword "{\ttfamily cycle}" indicates that the strategy involves a cycle of a certain number of periods. For it to be applicable to a game, this cycle must not only consist of available moves, but it must also fully describe the player's strategy. In the case of repeated games, this means that it must have a strategy for each repetition of the game.

$\\$
The "{\ttfamily cycle: N ** inf | C: C ** inf;}" construction enables strategies to be defined as responses to certain moves. In this case, the default behavior is to play {\ttfamily N} infinitely, but if the other player plays a {\ttfamily C} during one period, then this behavior will change to playing {\ttfamily C} infinitely. For example, a tit-for-tat strategy would be defined by "{\ttfamily cycle: N ** inf | C: C ** inf | N: N ** inf;}"

$\\$
Finally, {\ttfamily replay} enables printing with the built-in functions {\ttfamily print} and {\ttfamily println}, and enables the calculation of the expected payoff of a strategy given the opponent's strategy profile using {\ttfamily expected}.


%\section{References}
%Aumann, R. J.; Maschler, M. (1995). Repeated Games with Incomplete Information. Cambridge London: MIT Press.

%Osborne, Martin J.; Rubinstein, Ariel (1994). A Course in Game Theory. Cambridge: MIT Press. ISBN 0-262-15041-7.

%\begin{center}
%\includegraphics[width=5 cm]{HW2_1_7e.pdf}
%\end{center}


%\begin{center}
%\begin{tabular}{|c|c|c|}
%\hline
%\multicolumn{3}{|c|}{Player 3 plays $D$} \\
%\hline
%\backslashbox{1}{2} & L & R \\
%\hline
%T & \cellcolor[HTML]{888888} \underline{2},1\underline{1} & \underline{3},\underline{3},1 \\
%\hline
%B & \cellcolor[HTML]{888888} 0,0,2 & 1,\underline{1},-3 \\
%\hline
%\end{tabular}
%\end{center}


\end{document}