% ------------------------------------------------------------------------------
% Copyright (c) 2019, 2025 Contributors to the Eclipse Foundation
%
% See the NOTICE file(s) distributed with this work for additional
% information regarding copyright ownership.
%
% This program and the accompanying materials are made available under the terms
% of the MIT License which is available at https://opensource.org/licenses/MIT
%
% SPDX-License-Identifier: MIT
% ------------------------------------------------------------------------------
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, arrows, automata, positioning, shapes, shapes.misc}
\usepackage[paperwidth=40in, paperheight=20in]{geometry}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[
    auto,
    ->,
    node distance=5cm,
    every state/.style={ellipse, semithick, fill=black!5, minimum size=2cm, font=\Large},
    initial distance=1.2cm,
    every initial by arrow/.style={-{Stealth[scale=1.4]}},
    initial text=,
    transform shape,
    double distance=2pt,
    every loop/.style={min distance=10mm}
]

\node[label={[align=center]$\mathtt{yc} = 225$\\$\mathtt{sc} = 0$\\$\mathtt{ps} = 5$\\$\mathtt{given} = 0$\\$\mathtt{cha} = 0$\\$\mathtt{hand} = 0$}] (I) {};
\node[state, right=2cm of I] (A) {\emph{Paying}};
\node[state, right=5cm of A] (B) {\emph{Checking}};
\node[state, below=2cm of B] (C) {\emph{Getting}};

\path[-{Stealth[scale=1.4]}]
    (I) edge[] node[align=center] {} (A)
    (A) edge[loop above,above] node[align=center] {\texttt{pfive}\\$\mathtt{hand} := \mathtt{hand} + 5$} (A)
    (A) edge[loop below,out=230,in=200,looseness=8] node[align=center,xshift=-20pt,yshift=-2pt] {\texttt{pten}\\$\mathtt{hand} := \mathtt{hand} + 10$} (A)
    (A) edge[loop below,out=300,in=270,looseness=8] node[align=center] {\texttt{ptwenty}\\$\mathtt{hand} := \mathtt{hand} + 20$} (A)
    (A) edge[bend left=10] node[align=center] {\texttt{give\_money}\\$\mathtt{yc} := \mathtt{yc} - \mathtt{hand}$\\$\mathtt{sc} := \mathtt{sc} + \mathtt{hand}$\\$\mathtt{given} := \mathtt{given} + \mathtt{hand}$\\$\mathtt{hand} := 0$} (B)
    (B) edge[bend left=10] node[align=center] {$\mathtt{given} < 45$\\\texttt{ask\_more}} (A)
    (B) edge[right] node[align=center] {$\mathtt{given} \geq 45$\\\texttt{get\_product}\\$\mathtt{ps} := \mathtt{ps} - 1$\\$\mathtt{cha} := \mathtt{given} - 45$} (C)
    (C) edge[below] node[align=center,xshift=20pt,yshift=-24pt] {\texttt{deliver}\\$\mathtt{sc} := \mathtt{sc} - \mathtt{cha}$\\$\mathtt{yc} := \mathtt{yc} + \mathtt{cha}$\\$\mathtt{given} := 0$\\$\mathtt{cha} := 0$} (A)
;

\end{tikzpicture}
\end{document}
