(defun new-random-spider-agent (&key problem)
  "Return an agent that avoids new-row unless there is no choice."
  (make-agent
   :program (let ()
	      (defun random-spider-agent (percept) 
		(let ((actions (actions problem percept)))
		  (cond ((null actions) :stop)
			((and (length=1 actions) (eq (first actions) 'new-row))
			 'new-row)
			(t (random-element (delete 'new-row actions))))))
	      #'random-spider-agent)))

(defun new-expectimax-spider-agent (&key mdp eval-fn (k 1) (algorithm #'expectimax-cutoff-decision))
  "Return an agent that uses an expectimax algorithm for Spider MDPs, which searches to depth k 
   (including through chance nodes) and applies eval-fn to leaves. Note that this is slightly different
   from the standard expectimax-mdp-agent because the Spider percept does not include the reward
   and terminal signal."
  (make-agent
   :program (let ()
	      (defun expectimax-spider-agent (percept) 
		(funcall algorithm mdp percept eval-fn k))
	      #'expectimax-spider-agent)))