From shasha@access1.cims.nyu.edu  Tue Nov 24 06:23:05 2009
Received: from mx.cims.nyu.edu (mx.cims.nyu.edu [128.122.80.107])
	by mail.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAOBN5kL009766
	for <shasha@mail.cims.nyu.edu>; Tue, 24 Nov 2009 06:23:05 -0500 (EST)
Received: from access1.cims.nyu.edu (access1.cims.nyu.edu [128.122.49.15])
	by mx.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAOBMwDg027719
	for <shasha@cs.nyu.edu>; Tue, 24 Nov 2009 06:22:58 -0500 (EST)
Received: from access1.cims.nyu.edu (localhost [127.0.0.1])
	by access1.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAOBMwm9021271;
	Tue, 24 Nov 2009 06:22:58 -0500 (EST)
Received: (from shasha@localhost)
	by access1.cims.nyu.edu (8.13.8+Sun/8.13.8/Submit) id nAOBMw3C021270;
	Tue, 24 Nov 2009 06:22:58 -0500 (EST)
Date: Tue, 24 Nov 2009 06:22:58 -0500 (EST)
From: Dennis Shasha <shasha@courant.nyu.edu>
Message-Id: <200911241122.nAOBMw3C021270@access1.cims.nyu.edu>
To: msmendelson@hotmail.com, shasha@cs.nyu.edu
Subject: Re: Maze program problem
X-Scanned-By: MIMEDefang 2.58 on 128.122.80.107
X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (mx.cims.nyu.edu [128.122.80.107]); Tue, 24 Nov 2009 06:23:05 -0500 (EST)
Content-Length: 14279


Matthew,
When someone gives you software, please try to understand it before
using it. 
You have to do more than just add to it. 
I will give you some hints, but you will have to work to use them.


* winflag is undefined in the main program because it is a "local" variable
in the printscreen function. That means its value is not known outside
that function. To convey information outside, you have to return something.

* Also printscreen and the main routine do very similar things
in that they determine winning and losing.
That is bad practice. printscreen should do  screen work by itself.

* Finally, printscreen resets vpos and hpos. That's why the o doesn't move.

Best,
Dennis

#!/usr/bin/env python
#
# while statement
#
import time
import datetime

print "Your objective is to guide your 'o' through this maze. "
print "The stars that you see are actually spinning ninja stars. "
print "If you run into one, it will kill you. "
print "If you do not complete the maze in 60 seconds, the gates at the start and the "
print "finish will close and you will be trapped inside the maze to die of starvation. "
print "You have 5 chances to make it out of the maze alive. Good luck."
 
arr = "    ****************************************************************** \
*                                     *                              * \
*       **    *****            ***           ********      ********  * \
*   **       ***     ********   *****     *    ********      *****   * \
***     ***    ************       *****       **********             * \
******    **         ******          *************          ********** \
*****    ********                    ********       *******      ***** \
***     *********        ***          ***********  ************* ***** \
*****                 *************        ****** *************    *** \
***       *****************************                 *********    * \
***                   ***********                *****************   * \
********       ******        ******          **************         ** \
***********   ******************************************************** \
************                ********           *********             * \
**********************                ****                **********  "
hpos = 0 # horizontal position
vpos = 0  # vertical position
lifecount = 5
 
origscreen = [] # screen without a "o"
def formscreen():
   len = 70
   origscreen.append(arr)
 
def printscreen():
   screen = []
   mylen = len(origscreen)
   i = 0
   loseflag = 0
   winflag = 0
   hpos = 0
   vpos = 0
   while (i < mylen):
	x = origscreen[i]
	screen.append(x)
	if i == vpos:
		if (x[hpos] == "*"):
			loseflag = 1
	        if (x[vpos] == 14) and (x[hpos] == 69):
                        winflag = 1
		x = x[:hpos] + ("o") + x[hpos+1:]
		screen[i] = x
	i = i+1
   for s in screen:
	print s
   if loseflag == 1:
        lifecount = lifecount - 1
        if lifecount > 0:
            print "You died. Try again."
            hpos = 0
            vpos = 0
            i = 0
            loseflag = 0
        if lifecount == 0:
            print "You failed to complete the maze. That means you suck. Go waste someone else's time."
            i = mylen + 1
   if winflag == 1:
      print "Congratulations! For surviving my maze with " + lifecount + " lives, I will award you " + lifecount + ",000 awesomeness points."
      print "These points may not be real, but you can still brag about them if you wish."
      i = mylen + 1
      
totaltime = 0
formscreen()
i = 0
x = ""
while x != "s":
    printscreen()
    arr = (" ") + arr
    mybeforetime = time.time()
    # print mybeforetime
    x = raw_input("Please hit u(up), d(down), l(left), r(right), or s(stop):")
    myaftertime = time.time()
    diff = myaftertime - mybeforetime
    print ("You hit the letter: ") + x
    if x == "u":
	vpos = vpos-1
    if x == "d":
	vpos = vpos+1
    if x == "l":
        hpos = hpos-1
    if x == "r":
        hpos = hpos+1
    totaltime = totaltime + diff
    print totaltime
    if totaltime >= int(60):
        loseflag = 1
        if loseflag == 1:
            lifecount = lifecount - 1
        if lifecount > 0:
            print "You died. Try again."
        if lifecount == 0:
            print "You failed to complete the maze. That means you suck. Go waste someone else's time."
            x = s
        if winflag == 1:
            print "Congratulations! For surviving my maze with " + lifecount + " lives, I will award you " + lifecount + ",000 awesomeness points."
            print "These points may not be real, but you can still brag about them if you wish."
            x = s
    i=i+1
 
print totaltime
 
 
 
>From msmendelson@hotmail.com  Mon Nov 23 23:47:58 2009
Received: from mx.cims.nyu.edu (mx.cims.nyu.edu [128.122.80.107])
	by mail.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAO4lwlY023691
	for <shasha@mail.cims.nyu.edu>; Mon, 23 Nov 2009 23:47:58 -0500 (EST)
Received: from col0-omc4-s3.col0.hotmail.com (col0-omc4-s3.col0.hotmail.com [65.55.34.205])
	by mx.cims.nyu.edu (8.13.8+Sun/8.13.8) with ESMTP id nAO4lu5W024406
	for <shasha@cs.nyu.edu>; Mon, 23 Nov 2009 23:47:56 -0500 (EST)
Received: from COL118-W3 ([65.55.34.200]) by col0-omc4-s3.col0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959);
	 Mon, 23 Nov 2009 20:47:49 -0800
Message-ID: <COL118-W32949310E21172C17A349A89D0@phx.gbl>
Content-Type: multipart/mixed;
	boundary="_17045ff2-8282-452f-bbe6-f3e715ad86dd_"
X-Originating-IP: [216.165.45.113]
From: Matthew Mendelson <msmendelson@hotmail.com>
To: <shasha@cs.nyu.edu>
Subject: Maze program problem
Date: Mon, 23 Nov 2009 23:47:49 -0500
Importance: Normal
MIME-Version: 1.0
X-OriginalArrivalTime: 24 Nov 2009 04:47:49.0074 (UTC) FILETIME=[45E71320:01CA6CC1]
X-Scanned-By: MIMEDefang 2.58 on 128.122.80.107
X-Greylist: Sender DNS name whitelisted, not delayed by milter-greylist-3.0 (mx.cims.nyu.edu [128.122.80.107]); Mon, 23 Nov 2009 23:47:58 -0500 (EST)
Status: R
Content-Length: 8266

--_17045ff2-8282-452f-bbe6-f3e715ad86dd_
Content-Type: multipart/alternative;
	boundary="_7f947e10-6495-40c2-81fa-9fd153778034_"

--_7f947e10-6495-40c2-81fa-9fd153778034_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Professor -=20

I'm doing well on my maze program=2C but I've come up with a few problems.
First of all=2C when the program reprints the screen=2C the "o" reappears i=
n the same place=2C so I can't tell if you get the desired result when you =
win.
Secondly=2C I tested it to see if it keeps the right time limit=2C and it d=
oes=2C but it tells me that "lifecount=2C" which I am using to keep track o=
f how many lives the player has left=2C is undefined.
I am attaching my program as it reads now. Please look it over and get back=
 to me as soon as possible with any suggestions you may have as to what I c=
an do or where I might find the solutions I need. Thank you very much!!

Regards=2C
Matthew
 		 	   		 =20
_________________________________________________________________
Windows 7: I wanted simpler=2C now it's simpler. I'm a rock star.
http://www.microsoft.com/Windows/windows-7/default.aspx?h=3Dmyidea?ocid=3DP=
ID24727::T:WLMTAGL:ON:WL:en-US:WWL_WIN_myidea:112009=

--_7f947e10-6495-40c2-81fa-9fd153778034_
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<head>
<style><!--
.hmmessage P
{
margin:0px=3B
padding:0px
}
body.hmmessage
{
font-size: 10pt=3B
font-family:Verdana
}
--></style>
</head>
<body class=3D'hmmessage'>
Professor - <br><br>I'm doing well on my maze program=2C but I've come up w=
ith a few problems.<br>First of all=2C when the program reprints the screen=
=2C the "o" reappears in the same place=2C so I can't tell if you get the d=
esired result when you win.<br>Secondly=2C I tested it to see if it keeps t=
he right time limit=2C and it does=2C but it tells me that "lifecount=2C" w=
hich I am using to keep track of how many lives the player has left=2C is u=
ndefined.<br>I am attaching my program as it reads now. Please look it over=
 and get back to me as soon as possible with any suggestions you may have a=
s to what I can do or where I might find the solutions I need. Thank you ve=
ry much!!<br><br>Regards=2C<br>Matthew<br> 		 	   		  <br /><hr />Windows 7=
: I wanted simpler=2C now it's simpler. <a href=3D'http://www.microsoft.com=
/Windows/windows-7/default.aspx?h=3Dmyidea?ocid=3DPID24727::T:WLMTAGL:ON:WL=
:en-US:WWL_WIN_myidea:112009' target=3D'_new'>I'm a rock star.</a></body>
</html>=

--_7f947e10-6495-40c2-81fa-9fd153778034_--

--_17045ff2-8282-452f-bbe6-f3e715ad86dd_
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="mendelsonmazescreengame.py"

IyEvdXNyL2Jpbi9lbnYgcHl0aG9uCiMKIyB3aGlsZSBzdGF0ZW1lbnQKIwppbXBvcnQgdGltZQpp
bXBvcnQgZGF0ZXRpbWUKCnByaW50ICJZb3VyIG9iamVjdGl2ZSBpcyB0byBndWlkZSB5b3VyICdv
JyB0aHJvdWdoIHRoaXMgbWF6ZS4gIgpwcmludCAiVGhlIHN0YXJzIHRoYXQgeW91IHNlZSBhcmUg
YWN0dWFsbHkgc3Bpbm5pbmcgbmluamEgc3RhcnMuICIKcHJpbnQgIklmIHlvdSBydW4gaW50byBv
bmUsIGl0IHdpbGwga2lsbCB5b3UuICIKcHJpbnQgIklmIHlvdSBkbyBub3QgY29tcGxldGUgdGhl
IG1hemUgaW4gNjAgc2Vjb25kcywgdGhlIGdhdGVzIGF0IHRoZSBzdGFydCBhbmQgdGhlICIKcHJp
bnQgImZpbmlzaCB3aWxsIGNsb3NlIGFuZCB5b3Ugd2lsbCBiZSB0cmFwcGVkIGluc2lkZSB0aGUg
bWF6ZSB0byBkaWUgb2Ygc3RhcnZhdGlvbi4gIgpwcmludCAiWW91IGhhdmUgNSBjaGFuY2VzIHRv
IG1ha2UgaXQgb3V0IG9mIHRoZSBtYXplIGFsaXZlLiBHb29kIGx1Y2suIgogCmFyciA9ICIgICAg
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqIFwKKiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAqICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgKiBcCiogICAgICAgKiogICAgKioqKiogICAgICAgICAg
ICAqKiogICAgICAgICAgICoqKioqKioqICAgICAgKioqKioqKiogICogXAoqICAgKiogICAgICAg
KioqICAgICAqKioqKioqKiAgICoqKioqICAgICAqICAgICoqKioqKioqICAgICAgKioqKiogICAq
IFwKKioqICAgICAqKiogICAgKioqKioqKioqKioqICAgICAgICoqKioqICAgICAgICoqKioqKioq
KiogICAgICAgICAgICAgKiBcCioqKioqKiAgICAqKiAgICAgICAgICoqKioqKiAgICAgICAgICAq
KioqKioqKioqKioqICAgICAgICAgICoqKioqKioqKiogXAoqKioqKiAgICAqKioqKioqKiAgICAg
ICAgICAgICAgICAgICAgKioqKioqKiogICAgICAgKioqKioqKiAgICAgICoqKioqIFwKKioqICAg
ICAqKioqKioqKiogICAgICAgICoqKiAgICAgICAgICAqKioqKioqKioqKiAgKioqKioqKioqKioq
KiAqKioqKiBcCioqKioqICAgICAgICAgICAgICAgICAqKioqKioqKioqKioqICAgICAgICAqKioq
KiogKioqKioqKioqKioqKiAgICAqKiogXAoqKiogICAgICAgKioqKioqKioqKioqKioqKioqKioq
KioqKioqKiogICAgICAgICAgICAgICAgICoqKioqKioqKiAgICAqIFwKKioqICAgICAgICAgICAg
ICAgICAgICoqKioqKioqKioqICAgICAgICAgICAgICAgICoqKioqKioqKioqKioqKioqICAgKiBc
CioqKioqKioqICAgICAgICoqKioqKiAgICAgICAgKioqKioqICAgICAgICAgICoqKioqKioqKioq
KioqICAgICAgICAgKiogXAoqKioqKioqKioqKiAgICoqKioqKioqKioqKioqKioqKioqKioqKioq
KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqIFwKKioqKioqKioqKioqICAgICAgICAgICAg
ICAgICoqKioqKioqICAgICAgICAgICAqKioqKioqKiogICAgICAgICAgICAgKiBcCioqKioqKioq
KioqKioqKioqKioqKiogICAgICAgICAgICAgICAgKioqKiAgICAgICAgICAgICAgICAqKioqKioq
KioqICAiCmhwb3MgPSAwICMgaG9yaXpvbnRhbCBwb3NpdGlvbgp2cG9zID0gMCAgIyB2ZXJ0aWNh
bCBwb3NpdGlvbgpsaWZlY291bnQgPSA1CiAKb3JpZ3NjcmVlbiA9IFtdICMgc2NyZWVuIHdpdGhv
dXQgYSAibyIKZGVmIGZvcm1zY3JlZW4oKToKICAgbGVuID0gNzAKICAgb3JpZ3NjcmVlbi5hcHBl
bmQoYXJyKQogCmRlZiBwcmludHNjcmVlbigpOgogICBzY3JlZW4gPSBbXQogICBteWxlbiA9IGxl
bihvcmlnc2NyZWVuKQogICBpID0gMAogICBsb3NlZmxhZyA9IDAKICAgd2luZmxhZyA9IDAKICAg
aHBvcyA9IDAKICAgdnBvcyA9IDAKICAgd2hpbGUgKGkgPCBteWxlbik6Cgl4ID0gb3JpZ3NjcmVl
bltpXQoJc2NyZWVuLmFwcGVuZCh4KQoJaWYgaSA9PSB2cG9zOgoJCWlmICh4W2hwb3NdID09ICIq
Iik6CgkJCWxvc2VmbGFnID0gMQoJICAgICAgICBpZiAoeFt2cG9zXSA9PSAxNCkgYW5kICh4W2hw
b3NdID09IDY5KToKICAgICAgICAgICAgICAgICAgICAgICAgd2luZmxhZyA9IDEKCQl4ID0geFs6
aHBvc10gKyAoIm8iKSArIHhbaHBvcysxOl0KCQlzY3JlZW5baV0gPSB4CglpID0gaSsxCiAgIGZv
ciBzIGluIHNjcmVlbjoKCXByaW50IHMKICAgaWYgbG9zZWZsYWcgPT0gMToKICAgICAgICBsaWZl
Y291bnQgPSBsaWZlY291bnQgLSAxCiAgICAgICAgaWYgbGlmZWNvdW50ID4gMDoKICAgICAgICAg
ICAgcHJpbnQgIllvdSBkaWVkLiBUcnkgYWdhaW4uIgogICAgICAgICAgICBoc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ggPSBzCiAgICBp
PWkrMQogCnByaW50IHRvdGFsdGltZQogCiAKIAo=

--_17045ff2-8282-452f-bbe6-f3e715ad86dd_--

