Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

basic maze problem with turtle

126 views
Skip to first unread message

bauj...@gmail.com

unread,
Oct 13, 2013, 5:52:50 PM10/13/13
to
Hi everyone, I'm trying to create a simple maze program. When the user finishes the maze, I want to print in big letters "You Win!" and when the user hits a wall, I want the user to go back to the beginning of the maze. The problem is "collision detection" which is an advanced topic and I'm only in a beginning programming class. Is there anyway I can force the user back to the starting point when the turtle hits the wall? Thank you in advance.

bauj...@gmail.com

unread,
Oct 13, 2013, 5:53:36 PM10/13/13
to

Denis McMahon

unread,
Oct 13, 2013, 6:03:04 PM10/13/13
to
On Sun, 13 Oct 2013 14:53:36 -0700, baujacob wrote:

> Is there anyway I can force the user back to the starting point
> when the turtle hits the wall?

Yes, however, do not expect us to code it for you.

Rather, discuss your method, and how you think it should be coded, or
even better your solution, and why it doesn't do what you expect, and we
will attempt to lead you to solving your problem.

At present, with no idea of how your maze is represented in terms of data
structure, it would be near on impossible for anyone here, no matter how
expert they are in coding python, to write code that interacts with it.

Except perhaps Nikos. Nikos can probably write you extremely elegant one
line python solutions to any coding problem you describe to him. His
solutions might suffer the very minor flaw of not working, but they're
guaranteed to be Nikos certified aesthetically pure, and hence far
superior to any solution more mundane coders might produce.

--
Denis McMahon, denismf...@gmail.com

bauj...@gmail.com

unread,
Oct 13, 2013, 6:18:27 PM10/13/13
to
On Sunday, October 13, 2013 2:52:50 PM UTC-7, bauj...@gmail.com wrote:
> Hi everyone, I'm trying to create a simple maze program. When the user finishes the maze, I want to print in big letters "You Win!" and when the user hits a wall, I want the user to go back to the beginning of the maze. The problem is "collision detection" which is an advanced topic and I'm only in a beginning programming class. Is there anyway I can force the user back to the starting point when the turtle hits the wall? Thank you in advance.


Sorry about that, I realized I forgot to include the code.
So basically I have one turtle that draws the maze at the beginning and then another turtle(userTurtle) that completes the maze. When the userTurtle hits any point on the wall, I want to force userTurtle back to the start of the maze.
Here it is:

import turtle
userTurtle = turtle.Turtle()
draw = turtle.Turtle()
scr = turtle.Screen()

def drawMaze():
draw.pencolor("gold")
draw.pensize(3)
draw.penup()
draw.goto(0,-180)
draw.pendown()
draw.speed(10)
draw.setheading(180)
draw.fd(180)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.backward(120)
draw.setheading(90)
draw.fd(300)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(120)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.setheading(-90)
draw.fd(120)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(-90)
draw.fd(60)
draw.backward(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.penup()
draw.setheading(180)
draw.fd(60)
draw.pendown()
draw.setheading(90)
draw.fd(60)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.setheading(0)
draw.fd(120)
draw.setheading(-90)
draw.fd(60)
draw.backward(60)
draw.setheading(0)
draw.fd(60)
draw.setheading(-90)
draw.fd(240)
draw.setheading(180)
draw.fd(60)
draw.setheading(-90)
draw.fd(60)
draw.setheading(180)
draw.fd(120)
draw.setheading(90)
draw.fd(60)
draw.setheading(180)
draw.fd(60)
draw.setheading(90)
draw.fd(60)
draw.backward(60)
draw.setheading(180)
draw.fd(60)
draw.penup()
draw.setheading(0)
draw.fd(300)
draw.pendown()
draw.setheading(-90)
draw.fd(120)
draw.setheading(180)
draw.fd(120)
draw.ht()

userTurtle.penup()
userTurtle.goto(-30,180)
userTurtle.setheading(-90)

def mazeGame():
scr.bgcolor("#0070ff")

def m1():
userTurtle.setheading(90)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())

def m2():
userTurtle.setheading(180)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())

def m3():
userTurtle.setheading(360)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())

def m4():
userTurtle.setheading(-90)
userTurtle.fd(30)
userTurtle.pos()
print(userTurtle.pos())

scr.onkeypress(m1, "Up")
scr.onkeypress(m2, "Left")
scr.onkeypress(m3, "Right")
scr.onkeypress(m4, "Down")

scr.listen()

drawMaze()
mazeGame()

Gary Herron

unread,
Oct 13, 2013, 7:44:19 PM10/13/13
to pytho...@python.org
On 10/13/2013 03:03 PM, Denis McMahon wrote:
> Except perhaps Nikos. Nikos can probably write you extremely elegant one
> line python solutions to any coding problem you describe to him. His
> solutions might suffer the very minor flaw of not working, but they're
> guaranteed to be Nikos certified aesthetically pure, and hence far
> superior to any solution more mundane coders might produce.

That was uncalled for. There is already too much Nikos-bashing and
Nikos-basher-bashing (and so on) in this newsgroup without dredging up
even more in this completely unrelated request.

Gary Herron


Steven D'Aprano

unread,
Oct 13, 2013, 7:54:34 PM10/13/13
to
On Sun, 13 Oct 2013 22:03:04 +0000, Denis McMahon wrote:

> On Sun, 13 Oct 2013 14:53:36 -0700, baujacob wrote:
>
>> Is there anyway I can force the user back to the starting point when
>> the turtle hits the wall?

[skip useful advise to a beginner]

> Except perhaps [skip completely uncalled for baiting of somebody not
> even remotely collected to this thread.]

Was that really necessary?



--
Steven
Message has been deleted

Antoon Pardon

unread,
Oct 14, 2013, 4:16:37 AM10/14/13
to pytho...@python.org
Op 14-10-13 00:03, Denis McMahon schreef:

> Except perhaps Nikos. Nikos can probably write you extremely elegant one
> line python solutions to any coding problem you describe to him. His
> solutions might suffer the very minor flaw of not working, but they're
> guaranteed to be Nikos certified aesthetically pure, and hence far
> superior to any solution more mundane coders might produce.

I don't think including this was a smart move. It risks turning this
totally unrelated thread into a Nikos-like thread. I don't think
baujacob did anything that deserves that his question will be used
as an opportunity to have a jab at Nikos which may turn this thread
into something totally unhelpful for baujacob himself.

--
Antoon Pardon

Alister

unread,
Oct 14, 2013, 7:29:42 AM10/14/13
to
On Sun, 13 Oct 2013 14:53:36 -0700, baujacob wrote:

returning the user to the start is a simple case of resetting the user's
coordinates.

unless you are referring to a true turtle in a physical maze in which
case your requirement is probably not a good idea (What happens if you
bump a wall on your way back)

more details of the exact scenario may enable some more pointers in the
right direction.



--
Stop searching forever. Happiness is just next to you.

Denis McMahon

unread,
Oct 14, 2013, 8:54:21 AM10/14/13
to
On Sun, 13 Oct 2013 23:54:34 +0000, Steven D'Aprano wrote:

(and Gary Herron wrote similar)

> Was that really necessary?

Am I still pissed at being told my solution was crap because it had too
many lines?

--
Denis McMahon, denismf...@gmail.com

Sam Fourman Jr.

unread,
Oct 14, 2013, 9:02:52 AM10/14/13
to Gary Herron, pytho...@python.org
On Sun, Oct 13, 2013 at 11:44 PM, Gary Herron <gary....@islandtraining.com> wrote:
On 10/13/2013 03:03 PM, Denis McMahon wrote:
Except perhaps Nikos. Nikos can probably write you extremely elegant one
line python solutions to any coding problem you describe to him. His
solutions might suffer the very minor flaw of not working, but they're
guaranteed to be Nikos certified aesthetically pure, and hence far
superior to any solution more mundane coders might produce.

That was uncalled for.   There is already too much Nikos-bashing and Nikos-basher-bashing (and so on) in this newsgroup without dredging up even more in this completely unrelated request.

Who the hell is Nikos? I hear reference to this guy ALL the time, is he a troll or a python god?
this simply isn't clear.. I have only been on this list a few months.

--

Sam Fourman Jr.

Neil Cerutti

unread,
Oct 14, 2013, 9:13:15 AM10/14/13
to
On 2013-10-14, Sam Fourman Jr. <sfou...@gmail.com> wrote:
> Who the hell is Nikos? I hear reference to this guy ALL the
> time, is he a troll or a python god? this simply isn't clear..
> I have only been on this list a few months.

Check the archives for the last couple of months, and make your
own judgment.

https://mail.python.org/pipermail/python-list/

--
Neil Cerutti

Alister

unread,
Oct 14, 2013, 9:17:59 AM10/14/13
to
He is an excellent roll model for newbies.
(Do the opposite of Nicos at all times & you wont go far wrong)



--
The worst part of valor is indiscretion.

Chris Angelico

unread,
Oct 14, 2013, 9:16:19 AM10/14/13
to pytho...@python.org
On Tue, Oct 15, 2013 at 12:02 AM, Sam Fourman Jr. <sfou...@gmail.com> wrote:
> Who the hell is Nikos? I hear reference to this guy ALL the time, is he a
> troll or a python god?
> this simply isn't clear.. I have only been on this list a few months.

He's a troll, sometimes goes by the name "Ferrous Cranus", and he
really isn't worth polluting this thread about. Search python-list
archives for superhost.gr (his web site - be aware that he and it are
Greek, so some of his error messages and such are non-ASCII) and have
a read. Unfortunately he manages to drive a number of people to
frustration, which results in bad blood and spiralling unpleasantness,
which sometimes spills over into other threads, like this.

What we really should do is use multiple processes of conversation,
instead of threads. That way, if one goes rogue, it can't affect
memory used by other conversations...

ChrisA

Antoon Pardon

unread,
Oct 14, 2013, 9:22:46 AM10/14/13
to pytho...@python.org
Op 14-10-13 15:02, Sam Fourman Jr. schreef:
>
> Who the hell is Nikos? I hear reference to this guy ALL the time, is he
> a troll or a python god?
> this simply isn't clear.. I have only been on this list a few months.

He is the lists help vampire. He comes to the list when his programs
break and insists that we help him out. Advise to read up on a
particular subject is generally ignored as are links that explain what
is going on. When a correction is offered, he often enough rejects it
because it is somehow too many lines or such reasons. When he finnaly
accept a correction, that often enough reveals a new bug and the
cycle restarts.

--
Antoon Pardon

Tobiah

unread,
Oct 14, 2013, 1:48:08 PM10/14/13
to
Wait, doesn't this make you a Nikos-basher-basher? :()

> Gary Herron
>
>

Joshua Landau

unread,
Oct 14, 2013, 6:58:04 PM10/14/13
to bauj...@gmail.com, python-list
On 13 October 2013 23:18, <bauj...@gmail.com> wrote:
> import turtle
> userTurtle = turtle.Turtle()
> draw = turtle.Turtle()
> scr = turtle.Screen()
>
> def drawMaze():
> draw.pencolor("gold")
[lots of lines]
> print(userTurtle.pos())
>
> scr.onkeypress(m1, "Up")
> scr.onkeypress(m2, "Left")
> scr.onkeypress(m3, "Right")
> scr.onkeypress(m4, "Down")
>
> scr.listen()
>
> drawMaze()
> mazeGame()


You might realise that you don't actually have a "maze" in the sense
that you need something a *computer* can understand.

You need some data structure to hold the maze which you have drawn.
0 new messages