使用算法包编写了一个伪代码算法,但出现以下错误...有什么想法吗?
\begin{figure}[H]
\begin{minipage}[t]{0.96\textwidth}
\begin{algorithm}[H]
\centering
% \caption{Pruning Table Generation Function}\label{pseudo:pruninggeneration}
\footnotesize
\begin{algorithmic}
\Function{Generate Pruning Table}
% \State{pruning_table = [size]}
\State{Initialise moves}
\State{Initialise \texttt{depth} = 0 \texttt{ , totalStates} = 0 \texttt{ , newStates} = 1}
\State{Initialise new cube object}
\For{each element in pruning_table}
\State{pruning_table[i] = -1}
\EndFor
\State{table[\Call{c.encode_cube_state}] = 0} \Comment{Encode function retrieves index correlating with current cube state}
\While{New states are still being discovered}
\State{\texttt{newStates} = 0}
\For{Every element i in pruning_table}
\If{element i != -1} \Continue
\EndIf
\For{Every available move in moves}
\State{\Call{c.decode_cube_state}{i}}
\State{\Call{ApplyMoves}{move}}
\If{\texttt{pruning_table[}\Call{c.encode_cube_state}\texttt{]} = -1}
\State{\texttt{pruning_table[\Call{c.encode_cube_state}]} = depth + 1}
\State{Increment newStates by 1}
\EndIf
\State{Re-initialise cube object}
\EndFor
\EndFor
\State{Increment depth by 1}
\EndWhile
\State{Save pruning_table to file}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure}
我被这些错误困扰,我不知道该如何纠正它们。它阻止我的 pdf 编译...任何帮助都非常感谢!谢谢!
答案1
\Function
需要两个参数,而你只提供了一个参数。从algorithmicx
文档它提供了语法:
\Function{<name>}{<params>}
%<body>
\EndFunction
由于您只提供了一个参数,因此该<params>
参数被视为\State
(下一个标记),这是不起作用的。
此外,\State
不带参数,因此您不需要将其括在括号中。只需使用
\State <statement>