I am doing a project about the simulation of an elevator and ran into this problem. I have a listbox for users to choose the floor that they want to go to but I don't know how to make the door of the elevator opens in the proper order.
For example, the first person want to go to the 1st floor and the second person wants to go to the 3rd floor. They would select 1 first and then 3, but when I do this Matlab always opens the 3rd floor first and then the 1st floor.
I am thinking about storing the value of the listbox in a matrix and then use for loop to open the elevator's door according to its floor in a correct order.
This is the GUI of my project.
GUI
Under the listbox1_Callback . I tried to do this but my array only has one element.
A = [];
listValue = get(handles.listbox1,'Value');
A = [A,listValue];
I want A to holds a sequence of values so that I could apply foor loop to A and execute element by element.
Thanks for your help.
Say, for example, that you have a function called open that takes one argument, the floor number, and opens that floor's elevator door. To loop over each selected floor, do:
handles.listbox1 = uicontrol('Style', 'listbox', ...
'String', [1 2 3 4], ...
'Position', [10 10 40 100], ...
'Max', 2);
selectedFloor = get(handles.listbox1, 'Value');
for ii = 1:length(selectedFloor)
open(selectedFloor(ii));
end
Your project is probably over, but I will nevertheless contribute something. Not about programming code per se, but about elevator principles, which may help you and others conceive the system correctly the next time.
Elevator doors only open at a specific floor when the cab is at or very near (< 8 cm typically) that floor. The reason is simple: the motor and mechanism to open the doors is on the cab. The landing door is actually moved by the cab door, using a clutch with skates and pick-up rollers. Therefore, what you have to be concerned about in you program is the position of the cab, which is a simple object that moves sequentially from floor to floor.
So, when calls are registered, you have to compare them to the position of the cab. Then you decide which way to go, up or down (or just open the door if the position is already right). You keep a preferred direction until you've reached the farthest call, then you change direction or wait for new calls. Simply add or subtract 1 from the actual position (let a few seconds elapse between each operation, to make look real), compare the position with the corresponding index of the call array, and then decide to stop and open the door (if a call exists) or continue (if none exists). Don't forget to stop at the extremities, even if for some reason no call exists.
If you want to introduce landing calls in the mix, you have to take into account if they are up or down calls. You stop only for up calls while going up, and only for down calls while going down.
Related
He only moves a little bit and not moves forever
The (move 10 steps) block will only move your player by a tiny bit. It moves in the direction that your sprite is facing.
If you would like to have it moving for a longer period of time, (and smoother), I'd recommend using a loop of some kind.
Putting a Forever() loop around it will have it always move forward.
Repeat(number of times to repeat) will move it forward however many times you want.
Try to experiment with more of these loops and see which one best fits your project and goals.
You have multiple options. The first is to put the 'move 10 steps' block into a forever loop, so you code goes like the first one in the image and that will make your sprite move 10 blocks until the stop button is pressed.
Or alternatively, you could use a repeat (no. of times to repeat) block, like the second one:
Two Block Options
That's all!
I've been looking for awhile now for someone who had created a good example of making good physics in JavaFX, or even just a 'basic jumping mechanic' as the title says. I can't really find any information on it and I'm not really sure how to implement the idea.
All I want is a basic example, or just an explanation, or even just a point in the direction of what element of JFX I'm going to use.
Any help is appreciated.
Thanks
I'm assuming you already have some sort of game loop that ticks 60 times a second such as the AnimationTimer. If you want the jump height to be something like 200 pixels, you need to set and objects y-velocity (velocity is added to the objects location every tick) to a large negative number (as the object is moving upwards) and add a smaller amount every tick to this velocity until it hits zero, (this will be the top of the jump) and then keep adding this value to the y-velocity until it reaches the ground or collides with something. (This value will be your gravity constant)
In essence, you need to set the y-velocity to a high value then take away small increments every tick to slow the jump until the y-velocity hits 0, then begin adding the gravity constant again until the object hits the ground, hope this helps :)
How can i make a rootnode of a scene spawn duplicates of itself in a position (For example: x: 10,y: 10,z: 10)
then move in a direction until they are completely off screen and then dissappear.
I'm not asking for code, but i am asking for how to do this(For example what do i use for duplicating a rootnode?
How do i make that node disappear?
How do i generate a random number between 1 and 10 that will determine when to spawn the duplicate?)
And How do i make my post meet the quality standards?
You'll want to use a generalized class of nodes and spawn instances randomly.
Here's an answer on how to make random numbers in Swift. Use that to make three different random numbers between 1 and 10, and use the node class constructor with the three random numbers as input.
Finally, to move the node in a random direction, you need to have some movement function in the node class and feed it random numbers.
This is how you ask a good question.
Here is an answer:
You could:
First copy the rootnode using "node.clone" or "node.copy".
Clone duplicates the whole node tree (the node and children) whereas copy duplicates just that node.
Next assign the copy to a variable (so you can access it).
Then add any actions if you need to (refer below).
Then in your spawning loop or whatever you use to spawn objects, make a clone of the clone (the variable we made in step 2) and set it's position, with a random number.
To generate a random number that can be positive or negative use something like:
((((Float(arc4random()) / Float(UINT32_MAX))*2)-1)*5)//five is the important
//number here because it means you will get a number ranging from
// -5 to 5
Then add any actions you need to (refer below).
Finaly call scene.rootNode.addChildNode(theNodeYouJustPositioned)
To remove a node call node.removeFromParentNode.
Actions:
Alternitavely, to deleting the node yourself, and positioning the node yourself in a loop or such, and moving the node yourself, you could use SCNAction.
To use SCNAction simply call node.runAction(SCNAction).
There are many different ways of using SCNAction so please visit the docs for a whole list.
To make your node position itself (sort of) try running a runblock:^node:SCNNode{} and setting the node's position to a random number in there.
The node now positions it self so you can skip step 4.
Now if you want to move the node by a fixed direction (I mean "not random") you could just add a moveBy:xyz action in step 3.
But if it had to be a random direction you could do this action in step 5 and feed random numbers into it.
To delete you nodes using a time delay you could use a sequence: action and feed in an array containing, first, a waitForDuration:Seconds action, and last, a removeFromParentNode action.
Please visit the docs for SCNAction and any other class I mentioned that you may not have understood.
I don't know swift (at all) so I am sure there are a few syntax errors in the code. (sorry)
Post comments below if your confused.
Thanks!
I have two separate levels for my maze game for the ti-84 calculator, which both have identical code. Although, one of the levels does not complete when the character reaches the end, and treats the final spot as a wall.
ClrHome
1→A
1→B
For(y,1,8
For(x,1,16
Output(y,x,sub(" XD", 1+[F](y,x),1
End:End
Repeat K=21 or [F](A,B)=2
getkey→K
If Ans
Output(A,B," ")
sum(△List(Ans={25,34}))
A+Ans([F](A+Ans,B)≠1)→A
sum(△List(K={24,26}))
B+Ansnot([F](A,B+Ans)→B
Output(A,Ans,"Θ")
End
ClrHome
Display "You Win"
Pause
Goto 99
The problem is in your logic for horizontal movement, and I would be willing to bet that in the maze that works, you move either up or down onto the goal, while in the maze that doesn't work, you move right or left onto the goal.
Your vertical movement coefficient of Ans, ([F](A+Ans,B)≠1), evaluates to true whenever the current cell is not 1, a wall. On the other hand, your horizontal movement coefficient of Ans, not([F](A,B+Ans), evaluates to true whenever the current cell is not 1 or 2, a wall or the goal. Change it to be similar to the vertical logic, ([F](A,B+Ans)≠1),and your game should be fixed.
Edit:
Also, for the sake of performance, I would recommend enclosing most of the logic in an if then statement, because it doesn't need to run if a key is not pressed.
If K
Then
[Game Logic]
End
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.