Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56779 > unrolled thread
| Started by | baujacob@gmail.com |
|---|---|
| First post | 2013-10-13 14:52 -0700 |
| Last post | 2013-10-14 23:58 +0100 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
basic maze problem with turtle baujacob@gmail.com - 2013-10-13 14:52 -0700
Re: basic maze problem with turtle baujacob@gmail.com - 2013-10-13 15:18 -0700
Re: basic maze problem with turtle Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-10-13 21:53 -0400
Re: basic maze problem with turtle Joshua Landau <joshua@landau.ws> - 2013-10-14 23:58 +0100
| From | baujacob@gmail.com |
|---|---|
| Date | 2013-10-13 14:52 -0700 |
| Subject | basic maze problem with turtle |
| Message-ID | <4c8e9740-25ef-4531-89db-467eb18c673f@googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | baujacob@gmail.com |
|---|---|
| Date | 2013-10-13 15:18 -0700 |
| Message-ID | <cf3c97fc-2761-41f7-b98a-9083f96bb57c@googlegroups.com> |
| In reply to | #56779 |
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()
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-10-13 21:53 -0400 |
| Message-ID | <mailman.1057.1381715643.18130.python-list@python.org> |
| In reply to | #56782 |
On Sun, 13 Oct 2013 15:18:27 -0700 (PDT), baujacob@gmail.com declaimed the
following:
>
>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.
Still seems rather harsh to me... After all, one of the common
suggestions for solving a maze is to "always follow [right/left] hand" (put
said hand on said wall -- walk keeping that hand in contact with the wall
-- if you hit a dead end, the 180 turn-around will pick up the other wall
and carry our around the branch that lead to that dead-end). But you are
postulating "hit a dead end, through out all progress, start over"
Is "userTurtle" being guided by a real user? If so, resetting to the
start on each dead-end is a major penalty, the user should have the option
of back-tracking and picking another turn.
If "userTurtle" is a separate algorithm it should still have a
back-track ability. The difference is whether the algorithm uses a wall
following scheme, or a random direction at any intersection. Note that,
without memorizing choices for each intersection, the random direction mode
can result in repeating a failed path.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua@landau.ws> |
|---|---|
| Date | 2013-10-14 23:58 +0100 |
| Message-ID | <mailman.1083.1381791532.18130.python-list@python.org> |
| In reply to | #56782 |
On 13 October 2013 23:18, <baujacob@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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web