Netlogo - making a row of turtles stop when the first one comes to a halt - netlogo

I'm new to NetLogo, so I apologise if this is a dumb question.
I have a row of turtles representing people walking in single file along a path. Occasionally one of the turtles will pause. I need all the turtles immediately behind the turtle to stop at the same time so they don't pile up on one another. Is there is a simple way of doing this?
So...
ooooo - line of people walking along
xxxxx - first one stops
and
ooooo - another line of people walking along
xxx oo - middle one stops, everyone behind him stops, people in front keep walking
and
ooo oo - line of people walking along with a gap between them
ooo xx - front of line stops, people behind keep walking
Many thanks for any help you can give.
Mike.

Related

Netlogo - Turtles crossing Line

i want to count the turtles which cross the line - i tried with "turtle on patch" but if the turtle stop it counts twice. If the turtle moves more then 1 patch it counts nothing...
any ideas? Thanks Peter
Line
From the picture you added it looks like you are running a single-lane traffic model with a very narrow "finish line" that turtles can cross entirely in one tick.
To catch crossings:
One thing you could do is make a thicker "line" on the far side of the finish line. Maybe make it 5 patches wide. You could color it yellow while you're testing, and change it to hidden when you're sure it is working. If a turtle is on that patch, it has crossed the line. If you make it wide enough it should be impossible to leap over at any speed. It should be easy to test using only one turtle and running the model slowly.
To count stopped cars:
Without seeing your code it's hard to tell why you are counting stopped cars twice. Can you post your code or the relevant section of it here? I'm guessing you have some global that you are incrementing each time you find a new stopped car.
It's less efficient, but much more reliable to let the cars own a variable like "stopped?" that you initialize to false and set to true when the car crosses the line. Then at any time you can get the accurate count of stopped cars with
count cars with [ stopped? = true ]
Assuming you have a variable called my-count of stopped cars, and you want to see when that goes wrong, you could insert a line of code like
if mycount != count cars with [stopped? = true] [user-message "count is wrong!"]
If the line is definitely going to be vertical (as in your diagram) then the easiest way may be simply to count the turtles with pxcor larger than whatever coordinate the line is at plus something for the car size.

Cloning Sprites in MIT-Scratch

Recently, in a project for school. I have come across an increasingly frustrating and what seems to be an unsolvable problem. Whilst attempting to create a diving game, in which the sprite of a diver (sprite x) touches clones of a fish sprite (referred to as y by me) to rack up scores as high as 25. While the mechanisms for diver movement appear to be completely fine. However, loading the game would result in no reaction from the fish and its clones. I had already programmed the clones of the fish sprites to hide and delete themselves if touching sprite x. However, the fish refused to clone itself even after many attempts at rewriting the script. I would like to know if there was anything I missed or screwed up. Thank you. And these are the images of the respective scripts of the sprites in links below. Thank you.
Here's your problem:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
CREATE CLONE OF "myself"
WAIT (6) SECS
BROADCAST "game over"
You're starting the game, waiting 2 seconds, cloning the fish 25 times, and then ending the game.
There's at least one issue here, and probably another.
First of all, you're cloning all of the sprites into the exact same spot. The clones are piling on top of each other, giving the appearance of only being one fish, since they're all in the exact same space. I'd advise moving to a random x and y on the stage in between each clone.
Second, you have BROADCAST "game over" immediately there. This works if this is the way you're implementing a time limit on the game, but otherwise, you're just ending the game 6 seconds after the last fish appears.
So, correcting these two things, you end up with something like this:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
GO TO X: ([RANDOM PICK (-200) TO (200)]) Y: ([RANDOM PICK (-150) TO (150)])
CREATE CLONE OF "myself"
WAIT (6) SECS
If you want each fish to disappear after 6 seconds, then add a DELETE THIS CLONE to the above script.
You can delete this script:
That's now covered by the other script, above, and is also slightly buggy. It's kinda useless now.
And, in your other script, the one starting WHEN GREEN FLAG CLICKED... to have the fish disappear when touching the diver, replace the WHEN GREEN FLAG clicked with a WHEN I START AS A CLONE.

How should i make infinte ground ?

I'm trying to make a simplified version of crazy taxi . For the first step i need to make an infinite ground . I'VE searched online but couldn't find any examples .
Can i find any example of how to do this ?
https://www.youtube.com/watch?v=rhTPxrJICVg&list=PLLH3mUGkfFCXQcNBz_FZDpqJfQlupTznd
N3K makes an infinite runner in Subway Surfers style, meaning ground coming from the back and going towards the camera.
The above link is to his tutorial series.
This is a very broad question I try to give a very simplified answer to get you going.
To create endless road you need some sort of procedural function that generates corners for your track. If you do not need to backtrack you can cook something up yourself like (in X distance turn X degrees to the right). If you do need to backtrack you need something like perlin/simplex noise that always generates the same value based on 1 or more other values. You could use total distance to get the curve in the road.
You simply keep generating the world on the fly and unload pieces of the world you don't need any more. If the player can alter the world like destroying street furniture or leaving skitmarks you need to implement a chunk system. When you backtrack and generate a cerain part of the world with your procedural function you can have permanent changes the player made in that specific part by saving and loading to the chunk. Much like Minecraft does it actually.

A specific PathFinding approach

I am working on Unity, using C# for a project that should be quite simple.
I am stuck to pathFinding .
I have Looked at Dikjstra's and A* for reference, but for some reason I still can't adopt them to work in my case. I guess my brain :=while(1);
Here is the Idea:
From a textfile I import a "map" where each "*" means Wall, and each " " walkarea. In the map there area randomly placed 2 objects: a bomb and an agent.
The agent must investigate the map (which forms a maze) and discover the bomb. The agent may move to his 8 neighbour tiles if they are NOT Wall. In my code , the agent class hold his own map. for every tile that he visits, he asks the "world map" for info, about his 8 neighbour tiles.
On his own map then he takes a note of the known tiles type(wall / walkpath) , and if it is a walkpath, he also notes, how many times he has visited it. The agent also has a "Prefered direction " list. This tells which tile to choose next to move to, if more than 1 have not been visited.
Up to this point, I have set it up all good and running, and if I let it run, he eventually finds the bomb. The Issue is that because he only runs on a Prefered direction according to the least visited tile , he has to re-visit some tiles too many times like a moron. So what
I must do is this:
If the agent reaches a tile for which, every nighbour is either wall or already visited, then he should investigate his own map, and the notes from the past to find an unvisited tile , and walk to there. Every walk direction has the same weight/cost, so we don't need to consider cost of path.
In my opinion, Dijkstra's is the closest to apply , but I still can't get it right .
Any Ideas or help would be much appreciated.
Thank You
Alex
Part of the issue is how much information you want to allow your agent. If you're willing to let him know where the target is, or at least its general direction in relation to himself, then you can use that to help influence the agent's decisions. This would allow you him to always favor moving in the direction that gets him closest to the goal while taking the least visited path.
Otherwise I'd keep track of each place he visited in a separate map, as well as the 8 neighboring tiles since he has "seen" them, with something like -1 indicating a wall that has been seen, -2 indicating an unseen location, and 0 indicating seen but unvisited. I'd then use A* or a variant on it that would move him to the closest unvisited point based on number of tiles traversed, breaking ties randomly. This would lead to a more trial and error rat in a maze approach.

NetLogo - Checkers(Draughts) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
This year I need to finish my bachelor theses, and my task is to create a game known as checkers(or draughts). It wouldn't be a problem, but I have to write it in NetLogo using the Mutli-agent approach. So I cant use those well-known algorithms as Min-max or alfa-beta pruning. As I said, I have to use the Multi-agent approach, because in NetLogo every single piece is an agent, and they can communicate with each other. So as my teacher said me, I have to create a completely new algorithm. Could someone give me any advice or suggestion how to start, or describe it how it should work?
You can get ideas from this model and get started to develop your own:
CHECKERS by ALBERT LEE MCS1 PD. 5
This is the board game checkers. It follows the same rules as regular checkers, but without double-jumps, or triple-jumps, etc. The goal of the game is to jump every single of your opponent's pieces. Jumping pieces is done by jumping diagonally, over an opponent's piece. Only one color of the board is used for moving. Players take turns moving. On a regular move, when you don't want to jump an opponents piece, movement of one diagonal space is allowed. A red piece can only move in the direction toward the black pieces when the board is set up, and the black pieces do likewise. However, when either player's pieces get to the other end of the board, they become a king, known as "kinging," and either color king can move both forwards and backwards. The same one diagonal space rule applies, unless the king jumps, which it can jump also either forwards or backwards.
In my program, there are two steps to moving. First, you select the piece with your mouse. Then, you select the patch that you want to move the piece to. If you select a piece and select another piece instead of the patch, instead of moving the initially selected piece to that new piece, the new piece becomes selected, and the same rule of moving applies. To jump a piece, select the piece you want to jump with, and if the piece you want to jump is "jumpable," which means that the piece you want to jump with is one space diagonally with the piece you want to jump, and the next patch in that direction has no pieces. After selecting the piece you want to jump with, select that patch with no pieces. The "jumped" piece leaves the board.