Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP!!

MouseMouse Member Posts: 2
I know I posted this in another board, but I'm not sure if people read that one, so here goes...

I'm really looking for some serious help. I have a program to write that has completely stumped me. I'm trying to learn on my own and found an interesting "beginner" code, at least it is supposed to me. But it doesn't look like anything I've done before. I'm up to arrays and have done loops. Nothing involving graphics or anything.

Here's the criteria for the code:

Array size = 10, 10
Variable called Mouse
Four functions should used to move the mouse up, down, right and left.
Start position 5,5
Exit positions = 10,10 and 1,1
Initialize the array to zero.
A cell cannot be visited by a mouse more than once.
A 1 should be placed in the cell to indicate it has been visited.
You must follow the path of the mouse. Your output should reflect this.
Once you have reached an exit position, print "The mouse has made it through the maze" Start position, exit position.
Keep track of the number of cells that the mouse had to visit before it exited the maze.
Keep track of each cell location visited
You should define how you are going to display your output.

I am completely lost. People have given me pointers, but I'm still kinda confused. Is there anyone that has a basic skeleton of the program that I might manipulate into what I need? Or even the code for this maze so that I might study it and learn how and what it did.

Feel free to just email me any help you can offer, or just post here.

Thanks much!
Da Mouse

Comments

  • billywm664billywm664 Member Posts: 176
    Hm... I think I kinda got an idea of what you're asking. However, are there any further restrictions?
    I gather from your message that this will be a maze, so some blocks will be obstacles.. Well, what if the mouse reaches a dead end of the maze (since the mouse isn't allowed to retrace its steps - it can "visit each cell only once") does the program restart fresh with a clean maze and the mouse back in the beginning?
    Also, why does it say "[b]A[/b] variable named mouse." Personally, I would use two. one for the X position of the mouse (if you consider the maze a grid), and one for the Y position.


    I can help you get started on it anyhow. A complete program can't be made without knowing those things.
    So here goes:


    From the line "Array size: 10,10", this infers that you are to use a double subscripted array to store the locations of places the mouse has visited. Such an array can be created like so:
    [code]
    DIM SHARED Maze(1 TO 10,1 TO 10)
    [/code]
    The SHARED will make sense further on.
    That's looked upon as poor coding practice (using the TO keyword in an array declaration), but it suits the purpose and is easiest to think about, so to hell with convention :)

    Each element of the array should already be initialized to 0, but let's do so anyway.
    [code]
    For a = 1 to 10
    For b = 1 to 10
    Maze(a,b) = 0
    next b
    next a
    [/code]

    Now, to make a maze. I think it would be easiest, as you said you've not worked with graphics, to make the output text.
    Let's imagine a maze where 0 means the space is empty, 1 (as given in the guidlines) means the space has been visited, 2 means the cell is a wall, and 3 means the cell is an exit.
    I don't know your programming background... you may or may not be familiar with DATA statements. I hope so. Anyway, we can use DATA statements to store the maze. Again, I'm just randomly throwing in arbitrary conventions and arrangements. Feel free to change the maze design to however you see fit.
    [code]
    REM Maze data. Put this at the end of your code.
    MazeData:
    DATA 3,2,2,2,2,2,2,2,2,2
    DATA 0,0,0,0,0,0,0,0,0,2
    DATA 2,2,2,2,2,2,0,0,2,2
    DATA 0,2,0,0,0,2,0,0,2,2
    DATA 0,2,0,0,0,2,0,0,0,0
    DATA 0,2,0,0,0,0,0,0,0,2
    DATA 0,2,2,2,2,2,2,2,0,0
    DATA 0,2,2,0,0,0,0,0,0,0
    DATA 0,0,0,0,2,2,2,2,2,2
    DATA 2,2,2,0,0,0,0,0,0,3
    [/code]

    If you look real hard, and ignore the commas, it might almost look like a maze.....
    This is just to code the maze. We'll probably want to use a more attractive notation in displaying the maze on the screen, such as a space for unoccupied cells, maybe Xs for walls, and so on.

    Now, there's two problems to tackle when moving the mouse around the maze. 1) moving the mouse 2) hit detection.
    As defined in the set of rules, four FUNCTIONS should be used for movement. Since functions generally have a "return value" while subs do not, we could make four subs in which the mouse first attempts to move. If it can successully move into the cell, a 1 is returned. If it cannot (such as it runs into a wall) a 0 is returned. In BASIC, as in other languages, 0 is defined to mean "false" while any [b]non-zero[/b] number means true.

    Before writing the functions, they must have a maze to look at, and the mouse must exist in order to move around the maze. Therefore, use this in your declaraions:
    [code]
    DIM SHARED Mousex, Mousey
    Mousex = 5 'start values, places mouse in middle of maze
    Mousey = 5
    [/code]
    We'll use this to store the mouse's coords on the grid. SHARED makes the variables available to the main module as well as all subroutines and functions in the module.
    Then, the grid must be loaded. This would probably come at almost the beginning of your program, right after the variable declarations seen above.
    [code]
    For a = 1 to 10
    For b = 1 to 10
    READ cell
    maze(a,b) = cell
    next b
    next a
    [/code]

    Now that the grid exists, and the mouse exists, we write the functions to make the mouse move around on the grid.
    4 functions as stated in the rules.
    [code]
    FUNCTION MoveMouseUp()
    If maze(mousey - 1, mousex) = 0 then
    mousey = mousey - 1 'move mouse
    Maze(mousey, mousex) = 1 'mark cell as traveled
    MoveMouseUp = 1 'moved sucessfully, return true (1)
    Else
    MoveMouseUp = 0 'failed to move, return false (0)
    End if
    END FUNCTION

    FUNCTION MoveMouseDown()
    If maze(mousey + 1, mousex) = 0 then
    mousey = mousey + 1 'move mouse
    Maze(mousey, mousex) = 1 'mark cell as traveled
    MoveMouseDown = 1 'moved sucessfully, return true (1)
    Else
    MoveMouseDown = 0 'failed to move, return false (0)
    End if
    END FUNCTION

    FUNCTION MoveMouseLeft()
    If maze(mousey, mousex - 1) = 0 then
    mousex = mousex - 1 'move mouse
    Maze(mousey, mousex) = 1 'mark cell as traveled
    MoveMouseLeft = 1 'moved sucessfully, return true (1)
    Else
    MoveMouseLeft = 0 'failed to move, return false (0)
    End if
    END FUNCTION

    FUNCTION MoveMouseRight()
    If maze(mousey, mousex + 1) = 0 then
    mousex = mousex + 1 'move mouse
    Maze(mousey, mousex) = 1 'mark cell as traveled
    MoveMouseRight = 1 'moved sucessfully, return true (1)
    Else
    MoveMouseRight = 0 'failed to move, return false (0)
    End if
    END FUNCTION
    [/code]


    Well, that should get you started anyhow.
    I wrote this off the top of my head, and didn't test any code, so there's probably typos, ill-refined logic, or some other mistakes.
    Also, I didn't really bother to explain the ideas that went into the code. If you don't understand anything, or need clarifaction on something, don't hestitate to ask.

    Hope this helps at least little.

    : I know I posted this in another board, but I'm not sure if people read that one, so here goes...
    :
    : I'm really looking for some serious help. I have a program to write that has completely stumped me. I'm trying to learn on my own and found an interesting "beginner" code, at least it is supposed to me. But it doesn't look like anything I've done before. I'm up to arrays and have done loops. Nothing involving graphics or anything.
    :
    : Here's the criteria for the code:
    :
    : Array size = 10, 10
    : Variable called Mouse
    : Four functions should used to move the mouse up, down, right and left.
    : Start position 5,5
    : Exit positions = 10,10 and 1,1
    : Initialize the array to zero.
    : A cell cannot be visited by a mouse more than once.
    : A 1 should be placed in the cell to indicate it has been visited.
    : You must follow the path of the mouse. Your output should reflect this.
    : Once you have reached an exit position, print "The mouse has made it through the maze" Start position, exit position.
    : Keep track of the number of cells that the mouse had to visit before it exited the maze.
    : Keep track of each cell location visited
    : You should define how you are going to display your output.
    :
    : I am completely lost. People have given me pointers, but I'm still kinda confused. Is there anyone that has a basic skeleton of the program that I might manipulate into what I need? Or even the code for this maze so that I might study it and learn how and what it did.
    :
    : Feel free to just email me any help you can offer, or just post here.
    :
    : Thanks much!
    : Da Mouse
    :

  • MouseMouse Member Posts: 2
    Thanks so much for the help, I think I get a general idea of what I need to do. I found nothing that stated there was blocks, so i imagine it doesn't matter if there is obstacles or not. It's more of an "AI" thing. There was also nothing about what happens if it hits a deadend. I would imagine a freeze screen with "Mouse has failed to exit the maze" would print and I could do a simple question Y to try again, N to exit program. And I think the A variable called Mouse just meant the object getting out of the maze should be called mouse, I can't imagine you could write many programs with one variable.

    Again, thanks for your help, now i have something to go by. The movement thing is still iffy to me. With what you set up, does that make it automatically try it, or does it make you move the mouse yourself? As far as I can tell, it's supposed to just go PC user free. I haven't really done functions so they are kinda strange to me.





    : Hm... I think I kinda got an idea of what you're asking. However, are there any further restrictions?
    : I gather from your message that this will be a maze, so some blocks will be obstacles.. Well, what if the mouse reaches a dead end of the maze (since the mouse isn't allowed to retrace its steps - it can "visit each cell only once") does the program restart fresh with a clean maze and the mouse back in the beginning?
    : Also, why does it say "[b]A[/b] variable named mouse." Personally, I would use two. one for the X position of the mouse (if you consider the maze a grid), and one for the Y position.
    :
    :
    : I can help you get started on it anyhow. A complete program can't be made without knowing those things.
    : So here goes:
    :
    :
    : From the line "Array size: 10,10", this infers that you are to use a double subscripted array to store the locations of places the mouse has visited. Such an array can be created like so:
    : [code]
    : DIM SHARED Maze(1 TO 10,1 TO 10)
    : [/code]
    : The SHARED will make sense further on.
    : That's looked upon as poor coding practice (using the TO keyword in an array declaration), but it suits the purpose and is easiest to think about, so to hell with convention :)
    :
    : Each element of the array should already be initialized to 0, but let's do so anyway.
    : [code]
    : For a = 1 to 10
    : For b = 1 to 10
    : Maze(a,b) = 0
    : next b
    : next a
    : [/code]
    :
    : Now, to make a maze. I think it would be easiest, as you said you've not worked with graphics, to make the output text.
    : Let's imagine a maze where 0 means the space is empty, 1 (as given in the guidlines) means the space has been visited, 2 means the cell is a wall, and 3 means the cell is an exit.
    : I don't know your programming background... you may or may not be familiar with DATA statements. I hope so. Anyway, we can use DATA statements to store the maze. Again, I'm just randomly throwing in arbitrary conventions and arrangements. Feel free to change the maze design to however you see fit.
    : [code]
    : REM Maze data. Put this at the end of your code.
    : MazeData:
    : DATA 3,2,2,2,2,2,2,2,2,2
    : DATA 0,0,0,0,0,0,0,0,0,2
    : DATA 2,2,2,2,2,2,0,0,2,2
    : DATA 0,2,0,0,0,2,0,0,2,2
    : DATA 0,2,0,0,0,2,0,0,0,0
    : DATA 0,2,0,0,0,0,0,0,0,2
    : DATA 0,2,2,2,2,2,2,2,0,0
    : DATA 0,2,2,0,0,0,0,0,0,0
    : DATA 0,0,0,0,2,2,2,2,2,2
    : DATA 2,2,2,0,0,0,0,0,0,3
    : [/code]
    :
    : If you look real hard, and ignore the commas, it might almost look like a maze.....
    : This is just to code the maze. We'll probably want to use a more attractive notation in displaying the maze on the screen, such as a space for unoccupied cells, maybe Xs for walls, and so on.
    :
    : Now, there's two problems to tackle when moving the mouse around the maze. 1) moving the mouse 2) hit detection.
    : As defined in the set of rules, four FUNCTIONS should be used for movement. Since functions generally have a "return value" while subs do not, we could make four subs in which the mouse first attempts to move. If it can successully move into the cell, a 1 is returned. If it cannot (such as it runs into a wall) a 0 is returned. In BASIC, as in other languages, 0 is defined to mean "false" while any [b]non-zero[/b] number means true.
    :
    : Before writing the functions, they must have a maze to look at, and the mouse must exist in order to move around the maze. Therefore, use this in your declaraions:
    : [code]
    : DIM SHARED Mousex, Mousey
    : Mousex = 5 'start values, places mouse in middle of maze
    : Mousey = 5
    : [/code]
    : We'll use this to store the mouse's coords on the grid. SHARED makes the variables available to the main module as well as all subroutines and functions in the module.
    : Then, the grid must be loaded. This would probably come at almost the beginning of your program, right after the variable declarations seen above.
    : [code]
    : For a = 1 to 10
    : For b = 1 to 10
    : READ cell
    : maze(a,b) = cell
    : next b
    : next a
    : [/code]
    :
    : Now that the grid exists, and the mouse exists, we write the functions to make the mouse move around on the grid.
    : 4 functions as stated in the rules.
    : [code]
    : FUNCTION MoveMouseUp()
    : If maze(mousey - 1, mousex) = 0 then
    : mousey = mousey - 1 'move mouse
    : Maze(mousey, mousex) = 1 'mark cell as traveled
    : MoveMouseUp = 1 'moved sucessfully, return true (1)
    : Else
    : MoveMouseUp = 0 'failed to move, return false (0)
    : End if
    : END FUNCTION
    :
    : FUNCTION MoveMouseDown()
    : If maze(mousey + 1, mousex) = 0 then
    : mousey = mousey + 1 'move mouse
    : Maze(mousey, mousex) = 1 'mark cell as traveled
    : MoveMouseDown = 1 'moved sucessfully, return true (1)
    : Else
    : MoveMouseDown = 0 'failed to move, return false (0)
    : End if
    : END FUNCTION
    :
    : FUNCTION MoveMouseLeft()
    : If maze(mousey, mousex - 1) = 0 then
    : mousex = mousex - 1 'move mouse
    : Maze(mousey, mousex) = 1 'mark cell as traveled
    : MoveMouseLeft = 1 'moved sucessfully, return true (1)
    : Else
    : MoveMouseLeft = 0 'failed to move, return false (0)
    : End if
    : END FUNCTION
    :
    : FUNCTION MoveMouseRight()
    : If maze(mousey, mousex + 1) = 0 then
    : mousex = mousex + 1 'move mouse
    : Maze(mousey, mousex) = 1 'mark cell as traveled
    : MoveMouseRight = 1 'moved sucessfully, return true (1)
    : Else
    : MoveMouseRight = 0 'failed to move, return false (0)
    : End if
    : END FUNCTION
    : [/code]
    :
    :
    : Well, that should get you started anyhow.
    : I wrote this off the top of my head, and didn't test any code, so there's probably typos, ill-refined logic, or some other mistakes.
    : Also, I didn't really bother to explain the ideas that went into the code. If you don't understand anything, or need clarifaction on something, don't hestitate to ask.
    :
    : Hope this helps at least little.
    :
    : : I know I posted this in another board, but I'm not sure if people read that one, so here goes...
    : :
    : : I'm really looking for some serious help. I have a program to write that has completely stumped me. I'm trying to learn on my own and found an interesting "beginner" code, at least it is supposed to me. But it doesn't look like anything I've done before. I'm up to arrays and have done loops. Nothing involving graphics or anything.
    : :
    : : Here's the criteria for the code:
    : :
    : : Array size = 10, 10
    : : Variable called Mouse
    : : Four functions should used to move the mouse up, down, right and left.
    : : Start position 5,5
    : : Exit positions = 10,10 and 1,1
    : : Initialize the array to zero.
    : : A cell cannot be visited by a mouse more than once.
    : : A 1 should be placed in the cell to indicate it has been visited.
    : : You must follow the path of the mouse. Your output should reflect this.
    : : Once you have reached an exit position, print "The mouse has made it through the maze" Start position, exit position.
    : : Keep track of the number of cells that the mouse had to visit before it exited the maze.
    : : Keep track of each cell location visited
    : : You should define how you are going to display your output.
    : :
    : : I am completely lost. People have given me pointers, but I'm still kinda confused. Is there anyone that has a basic skeleton of the program that I might manipulate into what I need? Or even the code for this maze so that I might study it and learn how and what it did.
    : :
    : : Feel free to just email me any help you can offer, or just post here.
    : :
    : : Thanks much!
    : : Da Mouse
    : :
    :
    :

  • Justin BibJustin Bib USAMember Posts: 0

    _____ / http://forcoder.org / free ebooks and video tutorials about \ Java, Assembly, JavaScript, Perl, Go, Swift, Visual Basic .NET, Objective-C, MATLAB, PL/SQL, C++, Python, Scratch, Visual Basic, R, C, PHP, Delphi, C#, Ruby Rust, Logo, F#, COBOL, Awk, Scheme, SAS, Fortran, Julia, Ada, Scala, Dart, ML, D, ABAP, Bash, Kotlin, Clojure, Alice, VBScript, Erlang, Hack, Transact-SQL, Crystal, Apex, Lisp, Prolog, FoxPro, Lua, LabVIEW \ ___________

Sign In or Register to comment.