I'm having some difficulty with my code for a bigger program in net logo that i am working on! I'm attempting to start at a count at 15 and then count down to zero, with cell death occurring at zero. For some reason, my turtles each start off at a different number and then instead of decreasing by 1 count per tick, they decrease by various increments until zero. i'm sure its a silly mistake that i should be catching but i'v been staring at the screen for a long time and am getting frustrated so figured i would reach out to my fellow programmers
You do not provide much context for you question, but here is an example that seems to meet your needs. Enter the code below in the Code tab and then enter setup go show [lifespan] of turtles at the command line.
turtles-own [lifespan]
to setup
ca
crt 20 [init-turtle]
end
to go
ask turtles [age]
end
to init-turtle
set lifespan 15
fd 5
end
to age
set lifespan (lifespan - 1)
if (lifespan <= 0) [die]
end
Related
I am trying to define a function that returns a value indicating whether the winner of my game has been determined, if yes, who the winner is, and after the player's turn, update the remaining number of sticks and use the function defined above to check if a winner has been determined and if the game should continue.
I am creating a game in VB.NET that's called pick up sticks, it involves two players who take turns to play. Players can start with any number of sticks that they both agree upon before game. At each player’s turn, the player must pick at least one stick and at most half the sticks. Whoever picks up the last stick loses the game. I need to implement this game so that a player can play against the computer
This is me trying to write the computer's turn:
Private Sub ComputerTurn() 'change 6 with setNum whatever sticks number was agreed upon
Dim ComputerNum As Integer
'ComputerNum = Int((SetNumInputTB * Rnd()) - SetNumInputTB / 2)
MsgBox("The computer picked " & ComputerNum & " sticks")
End Sub
I think I should use an if statement or a for loop but I'm not sure how to implement the right mathmatics in it
Well you are going to need a lot more that just that in the computer turn. You will need to update how many sticks are left in the pile. Also depending on if you want the computer to play optimal strategy then you will have to add logic into the function.
Umm I do think that the game is pretty silly because the person who goes first wins every time. They pick up one less than half (ex start with 30). So they pick up 14 and 16 are left. Next turn the other player can pick up at most 15 and at least 1 stick so the next turn player one can clear the board except one stick
If you mean they can only pick up half the remaining pile the the logic will be a little more complicated but still not too bad.
I created a textbox in VBA that has msoAnimEffectCredits. If I create such an animation manually, I can select several repeat settings in timing, one of them being until next click. I can not find any documentation on how to set this in VBA. I can set repeat to a number, such as
ThisEff.Timing.RepeatCount = 10
When I set the repeat to until next click manually, and then use VBA to read the value of RepeatCount, it displays -2147483648. But if I try to SET the value of RepeatCount to -2147483648 in VBA, I get an error saying RepeatCount cannot be negative.
Leaving it set to 10 for now (can't imagine user wanting to see the credits that long anyway)… just frustrating that after hours of googling, I couldn't find a way to duplicate this manual animation option in VBA.
See attached screenshot.
I ran the code, stopped it at a break point, and F11 the steps until the line ccs2 = ccs2_2.
I checked both of these variables have the same dimensions, same number of elements that actually have value (they are both 6x6x10000 and only the first 6x6x219 elements have values).
I have ran this algorithm before and I have never had this problem. What you see in the screenshot is the visual studio stuck at this point with no error and no notifications for what seems like forever (been at least 10 minutes for each time I tried) when I pressed F11 to try to execute ccs2 = ccs2_2.
I checked I don't have any memory or CPU problems. When I pause the execution from the top, the progress marker goes back to the line and when I checked the variables, I find the first 6x6x219 values now match up, but the program won't advance forward.
Updates: I attempted to limit the range to just the elements that have values such as ccs2(1:6,1:6,1:219) = ccs2_2(1:6,1:6,1:219). It still takes a long time, but for some reason, visual studio reports that it only took 2059 ms, but the actual time was definitely way more than 20 seconds. I changed heap arrays from 0 back to nothing and the new time is supposedly 1978 ms but it definitely took more than 19 seconds.
I tried using an explicit loop to assign only the elements with value and it took less than 1 ms.
When you step over a huge array assignment statement, the debugger, internally, does single step by instruction until the statement number changes. I see your arrays are very large, and the debugger isn't "stuck", it is just taking a long time to step over.
Try as an alternative setting a breakpoint on the next statement and hitting Go.
I have a single clip on the stage with an instance name of testShape. In frame 1 I have the following code:
createjs.Tween.get(this.testShape, {loop:true}).to({y:240}, 1000);
When I run this it loops infinitely as expected but what I want is for it to loop three time then stop and fire a complete event.
The docs say that the loop param...
Indicates the number of times to loop. If set to -1, the tween will loop continuously.
Which suggests I should be able to set {loop: 3} to achieve my desired result but any number value other than 0 just causes it to loop endlessly.
Can anyone advise on what I'm doing wrong or how to make a Tween loop n times before completing?
Cheers all
It looks like TweenJS 0.6.2 and earlier used a Boolean value for loops, so while you can set it to true or false, you can not put it as a number of loops. If you set it to a number, it will be converted to true.
createjs.Tween.get(obj, {loop:true}).to(…).to(…);
This behaviour was updated in version 1.0.0 of TweenJS, in September, 2017.
createjs.Tween.get(obj, {loop:3}).to(…).to(…);
I am glad you found a solution:
I got it working in the end by making each tween set up the next as it completes.
Ok I am not completing understand this. I am suppose to only Find the total of each column in the last row. Find the grand total in the last cell (the bottom right corner)
Ok i have tried to do the grandtotal but i am not getting what she wants done I have also tried to reverse the arrays but that was wrong to. I am only suppose to add two line one line is find the total of each colums in the last row and to find the grandtotal. Can someone please explain to me what i am doing wrong thank you.
Module Module1
Sub Main()
Dim sum(5, 4) As Integer
Dim row, col As Integer
Dim grandtotal As Integer
For row = 0 To 4
For col = 0 To 3
sum(row, col) = row + col
sum(row, 4) += row + col
Next col
Next row
For row = 0 To 5
For col = 0 To 4
Console.Write(sum(row, col) & vbTab)
Next col
Console.WriteLine()
Next row
End Sub
End Module
It looks like you have a pretty good grasp of the code you need to use, but I think the main issue here is that you're getting a bit confused with what you actually want the code to do. I too am having a hard time deciding what your actual goal here is, as you say one thing but then have code for something slightly different. I'm assuming this is a homework assignment, so I'm not going to give you the code (especially since I'm not 100% sure what code you might need), but I'm more than happy to go through this stepwise as clearly as I can, and hopefully we'll get to the bottom of your confusion.
To clarify your requirements:
You say you're supposed to find the total of each column, and place that total in the last row. According to your code, that would be row 5 (actually the 6th row).
You then say you need the grand total in the last cell, the bottom-right corner. Since you have 5 columns (0-4), that would be a total of the first 4 columns of row 5.
If we imagine the 2D sum array as a matrix, the problem as stated should yield the following:
Desired Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixDesired.jpg
Where the "x's" are blank (technically 0), since that column is reserved as the "grand total" column (only the bottom-right should be filled in). For reference, this array/matrix will have the following coordinates:
Coordinate Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixCoords.jpg
However, as you currently have it coded, your sum array will look like this:
Actual Matrix http://dl.dropbox.com/u/1497850/Hosted%20Images%20for%20Websites/MatrixActual.jpg
What you've done in your code is made the final column the "total column" and ignored the final row. In this case, the bottom-right cell would still be the grand total, but you'd be summing the numbers in column 4 rather than in row 5. This goes against what you stated you want to happen, but is pretty easy to correct (especially now that you can see what's actually happening compared to what you want to happen).
However, maybe this is what you actually meant to happen, and you just misphrased the question a bit? (Or maybe this is what you meant by saying you tried to reverse the arrays?) The point is, rows and columns in even semi-large arrays/matrices are generally easily transposed, so it's important to make sure you're using the right terminology at all times.
Edit: Sorry, I misread your second For loop when I first answered, I apologize. I see now that you're printing the sum array out, but your problem was still probably due to the fact that you weren't filling in the array as you expected. Once you fill the array the way you actually want, your printing statement should work just fine.