5

This is a follow-up from Drawing game tree - Tikz or Forest?

The sequential game tree I am trying to draw is this one: enter image description here

I am using tikz and forest to draw it, but I am still far from it. In particular: I would like to 1. include the names of different players (simply "Player 1" and "Player 2") in different nodes; 2. Create the second nodes for player 1 (with the information set) (in which the strategy is "Introduce Proposal"); 3. Draw the two last information sets (highlighted in blue and red) correctly).

I am sending the code I have so far below:

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+    (270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/r    adius})$) 
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rcon    nect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-    \pgfkeysvalueof{/tikz/rconnect/angle}] 
($(#2)+(90-    \pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius    })$) 
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-    \pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius    })
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-    \pgfkeysvalueof{/tikz/rconnect/angle}] 
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}

\begin{document}

\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}                {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}        {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
  [,label=above:Nature,alias=T
   [,alias=L
   [,alias=LL
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,alias=LR
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
   [,alias=R
    [,alias=RL
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,alias=RR
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
  ]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};  
\node[draw,dashed,rounded rectangle,fit=(LR) (RL)]{};  
\draw[dashed] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1] [rconnect=LL and RR];
\end{forest}

\end{document}
4

Another solution to use the istgame package:

enter image description here

\documentclass{standalone}

\usepackage{amsmath}
\usepackage{makecell}

\usepackage{istgame}

\NewDocumentCommand\mact{m}
{\makecell[c]{#1}}
\NewDocumentCommand\mpay{m}
{\begin{pmatrix}#1\end{pmatrix}}

\begin{document}

\begin{istgame}[font=\footnotesize]
\setistmathTF*001
\xtShowEndPoints
% top part
\xtdistance{25mm}{120mm}
\istroot(0)[chance node]{Nature}
  \istb{\mact{$R=O$\\(Cooperative\\Player)}}[above left,xshift=-10pt]
  \istb{\mact{$R=\bar R$\\(Competitive\\Player)}}[above right,xshift=10pt]  \endist
\xtdistance{25mm}{50mm}
\istroot(A)(0-1)%<180>{Player 1}
  \istb{\mact{Introduce\\Proposal}}[l]  \endist
\istroot(B)(0-2)%<0>{Player 1}
  \istb{\mact{Introduce\\Proposal}}[r]  \endist
% left part
\xtdistance{25mm}{60mm}
\istroot(A0)(A-1)<180>{Player 2}
  \istb{Go}[al]  \istb{Stay}[ar]  \endist
\xtdistance{25mm}{30mm}
\istroot(A1)(A0-1)<0>{$(B-C,O)$}
  \istb{\mact{Introduce\\Proposal\\(I)}}[al]  \istb{\mact{Delay\\(D)}}[ar]  \endist
\istroot(A2)(A0-2)<180>{$(B,X)$}
  \istb{I}[al]  \istb{D}[ar]  \endist
\xtdistance{25mm}{15mm}
\istroot(A3)(A1-1)<180>{Player 2}
  \istb{Go (G)}[l]{\mpay{B-C\\O}}  \istb{Stay (S)}[r]{\mpay{B\\X}}  \endist
\istroot(A4)(A1-2)<180>{Player 2}
  \istb{G}[l]{\mpay{B-L\\X-L}}     \istb{S}[r]{\mpay{B-C\\O}}       \endist
\istroot(A5)(A2-1)<180>{Player 2}
  \istb{G}[l]{\mpay{B\\X}}         \istb{S}[r]{\mpay{B-L\\X-L}}     \endist
\istroot(A6)(A2-2)<180>{Player 2}
  \istb{G}[l]{\mpay{B\\O}}         \istb{S}[r]{\mpay{L\\O}}         \endist
% right part
\xtdistance{25mm}{60mm}
\istroot(B0)(B-1)<180>{Player 2}
  \istb{Go}[al]  \istb{Stay}[ar]  \endist
\xtdistance{25mm}{30mm}
\istroot(B1)(B0-1)<0>{$(B-C,\bar R)$}
  \istb{I}[al]  \istb{D}[ar]  \endist
\istroot(B2)(B0-2)<180>{$(B,X)$}
  \istb{I}[al]  \istb{D}[ar]  \endist
\xtdistance{25mm}{15mm}
\istroot(B3)(B1-1)<180>{Player 2}
  \istb{G}[l]{\mpay{B\\-L}}        \istb{S}[r]{\mpay{B-L\\R-L}}  \endist
\istroot(B4)(B1-2)<180>{Player 2}
  \istb{G}[l]{\mpay{B\\\bar R}}    \istb{S}[r]{\mpay{B\\O}}      \endist
\istroot(B5)(B2-1)<180>{Player 2}
  \istb{G}[l]{\mpay{B\\\bar R}}    \istb{S}[r]{\mpay{B-L\\L}}    \endist
\istroot(B6)(B2-2)<180>{Player 2}
  \istb{G}[l]{\mpay{B-R\\\bar R}}  \istb{S}[r]{\mpay{B-L\\X-L}}  \endist
% information sets
\setxtinfosetstyle{dashed}
\xtInfosetO(A)(B){Player 1}(1.5em)
\xtCInfosetO[blue](A1)!.35!(B1)<1.15>{Player 1}(1.5em)
\xtCInfosetO[red](A2)!.5!(B2)<.75>{Player 1}(1.5em)
\end{istgame}

\end{document}
| improve this answer | |
  • I didn't know that istgame allows you to draw these shapes. +1 – user121799 Jun 25 '19 at 16:06
  • Also, in the last branches is it possible to remove the nodes? I mean: in the bottom of the figure, the branch that goes to the payoff \mpay{B-C\\O} has a node on it (the black dot in the end of the branch), is it possible to remove the node? – Thiago Jun 26 '19 at 9:51
  • 1
    @Thiago Yes. Just comment out \xtShowEndPoints. – InSung Cho Jun 26 '19 at 12:55
  • @marmot If you mean the shapes of bubble type curved information sets, yes, they are available with the istgame version 2. – InSung Cho Jun 26 '19 at 13:08
5

The main motivation for posting this is to eliminate the spaces you added in the rconnect style, and which cause errors in the above code. Apart from that, you can use labels to add the players. The other request I do not understand because I am not working on game theory, so I do not know what these terms mean.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+(270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
($(#2)+(90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}

\begin{document}

\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}                {circle,fill,inner sep=0pt,minimum size=2mm},
where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}        {edge
label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
  [,label=above:Nature,alias=T
   [,label=above left:Player 1,alias=L
   [,label=above left:Player 2,alias=LL
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,label=above right:Player 2,alias=LR
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
   [,label=above right:Player 1,alias=R
    [,label=above left:Player 2,alias=RL
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,label=above right:Player 2,alias=RR
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
  ]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};  
\draw[dashed,blue] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1]  [rconnect=LL and RL];
\draw[dashed,red] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1]  [rconnect=LR and RR];
\end{forest}
\end{document}

enter image description here

As for your comment: uisng this great answer one could do the following: store the items on the left or right in lists, and then attach the items according to the levels. (If you really need to, you can replace "Hibernate" by something else.;-)

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[edges]{forest}
\usepackage[outline]{contour}
\usetikzlibrary{fit,shapes.misc,arrows.meta,positioning}
\tikzset{rconnect/.style args={#1 and #2}{insert path={
($(#1)+(270+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(270+\pgfkeysvalueof{/tikz/rconnect/angle}:90+\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[out=\pgfkeysvalueof{/tikz/rconnect/angle},in=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
($(#2)+(90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})$)
arc(90-\pgfkeysvalueof{/tikz/rconnect/angle}:-90-\pgfkeysvalueof{/tikz/rconnect/angle}:\pgfkeysvalueof{/tikz/rconnect/radius})
to[in=\pgfkeysvalueof{/tikz/rconnect/angle},out=180-\pgfkeysvalueof{/tikz/rconnect/angle}]
cycle}},rconnect/.cd,radius/.initial=6.5pt,angle/.initial=-12}

\begin{document}
\edef\LstLeft{0,"$p$","Go","Wait","A"}
\edef\LstRight{0,"$1-p$","Stay","Hibernate","B"}
\begin{forest}
for tree={s sep=0.1cm,l sep=1.2cm,font=\scriptsize,
where n children=0{align=center,draw,edge={thick,-{Circle}}}{circle,fill,inner sep=0pt,minimum size=2mm},
before drawing tree={
        if level=0{}{
          if n'=1{
            edge label/.wrap pgfmath arg={node [midway, right=.5em]
            {\pgfmathparse{{\LstLeft}[#1]}\pgfmathresult}}{level()},
          }{
            edge label/.wrap pgfmath arg={node [midway, left=.5em] 
            {\pgfmathparse{{\LstRight}[#1]}\pgfmathresult}}{level()},
          },
        }{}
      },
%where n=1{edge label={node[midway,above left=0pt,font=\scriptsize]{S}}}{edge label={node[midway,above right=0pt,font=\scriptsize]{E}}},
edge={thick}
}
  [,label=above:Nature,alias=T
   [,label=above left:Player 1,alias=L
   [,label=above left:Player 2,alias=LL
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,label=above right:Player 2,alias=LR
     [
      [{$B-C$ \\ $0$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
   [,label=above right:Player 1,alias=R
    [,label=above left:Player 2,alias=RL
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
    [,label=above right:Player 2,alias=RR
     [
      [{$B-C$ \\ $\bar{R}$}]
      [{$B$ \\ $X$}]
     ]
     [
      [{$B-L$ \\ $R-L$}]
      [{$B-L$ \\ $X-L$}]
     ]
    ]
   ]
  ]
\node[draw,dashed,rounded rectangle,fit=(L) (R)] (F1){};  
\draw[dashed,blue] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1]  [rconnect=LL and RL];
\draw[dashed,red] let \p1=($(F1.north)-(F1.center)$) in
 [/tikz/rconnect/radius=\y1]  [rconnect=LR and RR];
\end{forest}
\end{document}

enter image description here

| improve this answer | |
  • This is great, Marmot. The two other things are 1. Instead of S and E (these are the strategies) in every branch, I would like to have different strategies. For example in the first two branches, instead of S and E, I would like p and 1-p for example. Then when player 2 is playing I would like to have Go or Stay (instead of S and E again). 2. The second thing is: If you see in the handmaid tree in the question, the order is Nature then Player 1, but Player 1 does not open in two branches (S and E) , player 1 will only have a straight line to player 2 with "Introduce Proposal"). – Thiago Jun 25 '19 at 7:36
  • @Thiago I added something along those lines. – user121799 Jun 25 '19 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.