\input{6001mac}
\begin{document}
\psetheader{Fall Semester, 1996-97}{Problem Set 7 Solutions}

\section{Laboratory Problems -- The Election Game}
\subsection{Lab exercise 1.}
\newpage
\subsection{Lab exercise 2.}
{\small
\begin{lisp}
(define make-reporter ;; reporter is special kind of person
  (lambda (voting-location noisy?)
    (let ((person (make-person 'ANONYMOUS-REPORTER voting-location))) ;; create person  
      (define (reporter message) ;; dipatch procedure for reporter
        (case message
          ((REPORTER?) (lambda (self) true))
          ((INSTALL)
           (lambda (self)
             (delegate person self 'INSTALL))) ;; person will do install
          ((INTERVIEW)
           (lambda (self pol)
             (cond (noisy?
                    (ask self 'SAY
                         (list (ask pol 'name) ", could you please tell me why you think people should vote for you?"))
                    (ask pol 'SAY
                         (list (select-pithy))))))) ;; get random pithy saying 
           (else (get-method message person)))) ;; default case inherits other behaviors
      reporter))) ;; return the dispatch procedure

(define (make\&install-reporter voting-location noisy?)
  (make\&install-object make-reporter voting-location noisy?))

\end{lisp}
} % end of small
\subsection{Lab exercise 3.}
{\small
\begin{lisp}
(define *pithy-sayings*                   ;; some apolitical quotes
  (list "It's the economy, stupid"
        "Read my lips -- No new taxes"
        "Ted, I think when Americans grasp the broad, 
         rippling possibilities of my tax plan, when they 
         feel the soothing yet insistent
         implications of my capital-gains tax cut, 
         they will open to my candidacy like a rose"
         "We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it"
         "I mean, it seems
         to me, and I'm not trying to be judgmental, but if the
         American people really care and really are concerned about
         who's in charge, something ought to get their attention sooner
         or later" 
         "He's no Jack Kennedy!"))

(define (select-pithy) 
  (pick-random *pithy-sayings*))

(populate-reporters 2 *all-real-places*) ;; install a set of reporters

\end{lisp}
} % end small

\subsection{Lab exercise 4.}
In principle a voter is a person and so making a reporter into a voter
would allow inheritance of all properties with no added work. However,
unintentionally this creates a situation where reporters are {\tt
ANONYMOUS-VOTER}s and it would be nicer (though not mandatory) to have
them as {\tt ANONYMOUS-REPORTER}.  There were various ways of fixing
this and making a reporter be a voter and also have the name {\tt
ANONYMOUS-REPORTER} instead of a voters standard name {\tt
ANONYMOUS-VOTER}. The easiest and definitely not the most elegant is
to make the reporter install both an {\tt ANONYMOUS-REPORTER} person
and an {\tt ANONYMOUS-VOTER} person.

{\small
\begin{lisp}
(define make-reporter
  (lambda (voting-location noisy?) ;; choose random influencability
    (let ((voter (make-voter voting-location (/ (random 10000) 10000.0) noisy?))
          (reporter-person (make-person 'ANONYMOUS-REPORTER voting-location)))
      (define (reporter message) 
        (case message
          ((REPORTER?) (lambda (self) true))
          ((INSTALL)
           (lambda (self)
             (delegate voter self 'INSTALL) ;; am a voter and thus a person
             (delegate reporter-person self 'INSTALL))) ;; added to name 
                                                        ;; me as a reporter 
      ((INTERVIEW)
           (lambda (self pol)
             (cond (noisy?
                    (ask self 'SAY
                         (list (ask pol 'name) ", could you please tell me why you think people should vote for you?"))
                    (ask pol 'SAY
                         (list (select-pithy)))))))
           (else (get-method message reporter-person voter)))) ;; use reporter to name 
                                                               ;; me as a reporter
      reporter))) 
                  
              
(define (make\&install-reporter voting-location noisy?)
  (make\&install-object make-reporter voting-location noisy?))

\end{lisp}
} % end of small
\newpage
\subsection{Lab exercise 5.}
Add the following method to voter:
{\small
\begin{lisp}

            ((WATCH-SOUNDBITE)
              (lambda (self pol)
               (cond ((eq? my-vote 'UNDECIDED) ;; if undecided reconsider politician 
                      (if noisy?
                          (ask self 'SAY
                               (list "Huh -- that's interesting.")))
                      (ask self 'RECONSIDER pol 0.3))
                     ((eq? pol my-vote)     ;; make voter less influencable 
                      (if noisy?
                          (ask self 'SAY
                               (list "Hey, my candidate sure sounds smart!")))
                      (set! how-influencable (/ how-influencable 2.0)))
                     (else
                      (if noisy?            ;; voter is not supporting this politician 
                          (ask self 'SAY    ;; make him more influencable
                               (list
                                "Huh, my candidate doesn't look as good as this guy.")))
                      (set! how-influencable (min 1.0 (* how-influencable 2.0)))
                      (ask self 'RECONSIDER pol 0.3)))
               true))
            
\end{lisp}
} % end small
\newpage
\subsection{Lab exercise 6.}
We increased the minimal number of reporters created per city 
to 2 in the {\tt populate-reporters} procedure to assure that they provide 
outputs to the script. Otherwise, only cities with more than two 
contribute to the output.
{\tiny
\begin{lisp}
(define (script1)
(run-clock 1)
(ask *the-registrar-of-voters* 'ELECTION))

(script1)

---Tick 0---

At kalamazoo : anonymous-reporter says -- j , could you please tell me why you think people should vote for you? 
If we're not, and we're little lambs lost in the woods, but we
         would be good if we had someone in Washington to look
         after us; we are going down the tubes, because the average life
         of a democracy is 200 years. 
At denver : anonymous-reporter says -- i , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At denver : anonymous-reporter says -- Huh -- that's interesting. 
At denver : anonymous-reporter says -- Huh -- that's interesting. 
At denver : anonymous-voter says -- Wow! I can't believe I'm talking to i !!!  They've got my vote for sure. 
At denver : anonymous-voter says -- Huh, my candidate doesn't look as good as this guy. 
At denver : anonymous-voter says -- I've decided to change my vote to undecided 
At denver : anonymous-reporter says -- Wow! I can't believe I'm talking to h !!!  They've got my vote for sure. 
At denver : anonymous-voter says -- Wow! I can't believe I'm talking to h !!!  They've got my vote for sure. 
At denver : anonymous-reporter says -- g , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At denver : anonymous-reporter says -- Wow! I can't believe I'm talking to g !!!  They've got my vote for sure. 
At denver : anonymous-voter says -- Huh, my candidate doesn't look as good as this guy. 
At paloalto : anonymous-reporter says -- e , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At paloalto : anonymous-reporter says -- Huh -- that's interesting. 
At paloalto : anonymous-reporter says -- I've decided to change my vote to e 
At paloalto : anonymous-reporter says -- Huh -- that's interesting. 
At paloalto : anonymous-reporter says -- I've decided to change my vote to e 
At paloalto : anonymous-reporter says -- d , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At paloalto : anonymous-reporter says -- d , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At paloalto : anonymous-reporter says -- Huh, my candidate doesn't look as good as this guy. 
At paloalto : anonymous-reporter says -- I've decided to change my vote to undecided 
At paloalto : anonymous-voter says -- Huh -- that's interesting. 
At paloalto : anonymous-voter says -- I've decided to change my vote to d 
At cambridge : anonymous-reporter says -- c , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At cambridge : anonymous-reporter says -- Huh -- that's interesting. 
At cambridge : anonymous-reporter says -- Wow! I can't believe I'm talking to c !!!  They've got my vote for sure. 
At cambridge : anonymous-reporter says -- b , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At cambridge : anonymous-reporter says -- a , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At cambridge : anonymous-reporter says -- Huh -- that's interesting. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to a 
At cambridge : anonymous-reporter says -- Huh, my candidate doesn't look as good as this guy. 
At cambridge : anonymous-reporter says -- Wow! I can't believe I'm talking to a !!!  They've got my vote for sure. 
There are  4  candidates in  denver ;  2  will debate. 
h  won the debate. 
At denver : anonymous-reporter says -- Hey, my candidate just won the debate! 
There are  2  candidates in  paloalto ;  2  will debate. 
d  won the debate. 
There are  3  candidates in  cambridge ;  2  will debate. 
c  won the debate. 
At cambridge : anonymous-reporter says -- Hey, my candidate just won the debate! 

At washingtondc : *registrar* says -- Election between (j i h g f e d c b a) 
At washingtondc : *registrar* says -- And the winner is .... d with  8.06 percent of the votes cast, with 53.22 percent turnout. 
;Value: nuf-said

\end{lisp}
} % end tiny
\subsection{Lab exercise 7.}
{\small
\begin{lisp}
(define (make-pacster name initial-location restlessness candidate)
  (let ((traveller (make-traveller name initial-location))
        (ticks-to-go restlessness))
    (lambda (message) 
      (case message
        ((PACSTER?) (lambda (self) true))
        ((CLOCK-TICK)
         (lambda (self)
           (cond ((ask self 'TRAVELLING?) 'done)
                 ((zero? ticks-to-go)
                  (set! ticks-to-go restlessness) ;; set time for next travel
                  (ask self 'TRAVEL))             ;; travel 
                 (else (set! ticks-to-go (- ticks-to-go 1))
                       (ask self 'GREASE))))) ;; when not traveling offer bribes
        ((TRAVEL)
         (lambda (self)
           (ask self 'TELEPORT))) ;; go somewhere 
        ((INSTALL)
         (lambda (self)
           (delegate traveller self 'INSTALL) ;; traveller will do installation 
           (add-to-clock-list self)))
        ((GREASE)             ;; here is how the pacster offers bribes
         (lambda (self)
           (let ((where-am-i (ask self 'location))) ;; fraction of voters to bribe
             (let ((voters ((find-some 0.10) where-am-i 'VOTER?))) 
               (for-each
                (lambda (voter) (ask voter 'TAKE-BRIBE candidate)) ;; offer the bribe
                voters)))))
        (else (get-method message traveller))))))


(define (make\&install-pacster name initial-location restlessness candidate)
  (make\&install-object
   make-pacster name initial-location restlessness candidate))

\end{lisp}
} % end small
\subsection{Lab exercise 8.}
Add the following method to voter:
{\small
\begin{lisp}
((TAKE-BRIBE)
             (lambda (self pol)
               (cond ((eq? my-vote 'UNDECIDED) ;; if undecided reconsider politician 
                      (if noisy?
                          (ask self 'SAY
                               (list "Hey -- this guy has interesting ideas about money.")))
                      (ask self 'RECONSIDER pol 0.3))
                     ((eq? pol my-vote) ;; make voter less influencable 
                      (if noisy?
                          (ask self 'SAY
                               (list "Hey, my candidate sure knows his pork!")))
                      (set! how-influencable (/ how-influencable 2.0)))
                     (else
                      (if noisy?          ;; voter is not supporting this politician 
                          (ask self 'SAY  ;; make him more influencable
                               (list
                                "Huh, my candidate doesn't know pork like this guy.")))
                      (set! how-influencable (min 1.0 (* how-influencable 2.0)))
                      (ask self 'RECONSIDER pol 0.3)))
               true))
\end{lisp}
} % end small
\subsection{Lab exercise 9.}
{\tiny
\begin{lisp}
(define (script2)
(for-each make\&install-pacster
          '(a-pac b-pac c-pac d-pac e-pac f-pac g-pac h-pac i-pac j-pac k-pac)
          (list Cambridge Cambridge Cambridge PaloAlto PaloAlto
                Denver Denver Denver Denver Kalamazoo)
          (list 5 2 3 1 5 6 2 5 3 4 6)
          *all-politicians*)
(run-clock 1)
(ask *the-registrar-of-voters* 'ELECTION))

(script2)

---Tick 0---

At denver : anonymous-voter says -- Hey -- this guy has interesting ideas about money. 
At paloalto : anonymous-reporter says -- Hey -- this guy has interesting ideas about money. 
At paloalto : anonymous-reporter says -- I've decided to change my vote to d 
At paloalto : anonymous-voter says -- Hey -- this guy has interesting ideas about money. 
At cambridge : anonymous-voter says -- Hey -- this guy has interesting ideas about money. 
At cambridge : anonymous-voter says -- I've decided to change my vote to c 
At cambridge : anonymous-reporter says -- Hey -- this guy has interesting ideas about money. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to a 
At cambridge : anonymous-voter says -- Huh, my candidate doesn't know pork like this guy. 
At cambridge : anonymous-voter says -- I've decided to change my vote to undecided 
At kalamazoo : anonymous-reporter says -- Huh -- that's interesting. 
At kalamazoo : anonymous-reporter says -- I've decided to change my vote to j 
At denver : anonymous-reporter says -- Wow! I can't believe I'm talking to i !!!  They've got my vote for sure. 
At denver : anonymous-repoter says -- h , could you please tell me why you think people should vote for you? 
It's the economy, stupid 
At denver : anonymous-reporter says -- Huh -- that's interesting. 
At denver : anonymous-reporter says -- I've decided to change my vote to h 
At denver : anonymous-reporter says -- g , could you please tell me why you think people should vote for you? 
Ted, I think when Americans grasp the broad, 
         rippling possibilities of my tax plan, when they feel the soothing yet insistent
         implications of our capital-gains tax cut, 
         they will open to my candidacy like a rose 
At denver : anonymous-reporter says -- Huh, my candidate doesn't look as good as this guy. 
At denver : anonymous-reporter says -- f , could you please tell me why you think people should vote for you? 
It's the economy, stupid 
At denver : anonymous-reporter says -- f , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At paloalto : anonymous-reporter says -- e , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At paloalto : anonymous-voter says -- Huh -- that's interesting. 
At paloalto : anonymous-voter says -- I've decided to change my vote to e 
At paloalto : anonymous-reporter says -- Huh -- that's interesting. 
At cambridge : anonymous-reporter says -- c , could you please tell me why you think people should vote for you? 
It's the economy, stupid 
At cambridge : anonymous-reporter says -- c , could you please tell me why you think people should vote for you? 
Ted, I think when Americans grasp the broad, 
         rippling possibilities of my tax plan, when they feel the soothing yet insistent
         implications of our capital-gains tax cut, 
         they will open to my candidacy like a rose 
At cambridge : anonymous-reporter says -- Huh -- that's interesting. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to c 
At cambridge : anonymous-reporter says -- b , could you please tell me why you think people should vote for you? 
Read my lips -- No new taxes 
At cambridge : anonymous-reporter says -- b , could you please tell me why you think people should vote for you? 
Ted, I think when Americans grasp the broad, 
         rippling possibilities of my tax plan, when they feel the soothing yet insistent
         implications of our capital-gains tax cut, 
         they will open to my candidacy like a rose 
At cambridge : anonymous-reporter says -- Huh, my candidate doesn't look as good as this guy. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to undecided 
At cambridge : anonymous-reporter says -- a , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At cambridge : anonymous-reporter says -- a , could you please tell me why you think people should vote for you? 
We know we have these huge
         problems. Neither party will admit
         that they did it, but they were the
         only two people around, so maybe
         they both did it 
At cambridge : anonymous-reporter says -- Huh -- that's interesting. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to a 
At cambridge : anonymous-reporter says -- Hey, my candidate sure sounds smart! 
At cambridge : anonymous-reporter says -- Wow! I can't believe I'm talking to a !!!  They've got my vote for sure. 
There are  4  candidates in  denver ;  2  will debate. 
g  won the debate. 
At denver : anonymous-reporter says -- My candidate can't even win a silly debate. 
There are  2  candidates in  paloalto ;  2  will debate. 
e  won the debate. 
There are  3  candidates in  cambridge ;  2  will debate. 
c  won the debate. 
At cambridge : anonymous-reporter says -- My candidate wasn't invited to debate here. 
At cambridge : anonymous-reporter says -- I've decided to change my vote to undecided 

At washingtondc : *registrar* says -- Election between (j i h g f e d c b a) 
At washingtondc : *registrar* says -- And the winner is .... g with  10.43 percent of the votes cast, with 61.53 percent turnout. 
;Value: nuf-said


\end{lisp}
} % end tiny
\end{document}


