Omnimaga
Calculator Community => TI Calculators => Axe => Topic started by: Raylin on April 12, 2010, 08:46:29 pm
-
Basically, there are seven values (1-99) in an AppVar.
What I'm trying to figure out is how to make a turn order based on these values.
Highest value goes first in the turn order.
So...
15
26
48
71
65
56
12
6
5
4
1
2
3
7
-
A simple algorithm I just thought up is this (A points to appvar, B points to output list)
:Fill(0->{B},6
:For(X,0,6
: {A+X}->Z
: For(Y,0,6
: If {A+Y}>=Z
: {B+Y}+1->{B+Y}
: End
: End
:End
Haven't tested it, but it should work in theory.
-
My calc rewarded me with a kick in the face. (RAM clear)
-
Would this be for a turn-based RPG? For turns, I generally have the character and enemy have a speed attribute, usually from 1 to 99, and when battle begins, the char/enemy turn counters are set to a random value from LV to 2*LV. Then there's a loop where those two values increments. Once your char reaches 255, it's his turn to attack, and his value is reset to his speed LV. Same for enemy turns. In TI-BASIC this can be quite slow if you have 3vs3 battles, though.
Btw remember to archive or backup your stuff before testing random routines, so you won't lose too much if an error occurs.
-
That definitely shouldn't cause a RAM clear. What is the other code you put around it?
-
:"vCake->Str1
:GetCalc(Str1,7)->A
:For(X,0,6
:rand->{A+X
:End
:Fill(0->{B},6
:For(X,0,6
:{A+X}->Z
:For(Y,0,6
:If {A+Y}>=Z
:{B+Y}+1->{B+Y}
:End
:End
:End
:For(C,0,6
:Disp {B+C}>Dec,i
:End
-
The problem is that you didn't initialize B to the place where you want your 7-byte output list.
-
Oh?
I thought that the Fill( command did that!
:P
My fault.
-
Everywhere in that sample where you used "B" just replace it with "L1".
-
It works.
Thank you, sir. :)
-
I've got problems with duplicates in my list.
I'm working on remedies now but help would be appreciated.
-
mhmm what do you mean? Does the data unintentionnally duplicates, or do you actually want to duplicate it?
-
I mean that I want a list of values (1-100) that DOES NOT have repeats.
The method above doesn't create such a list.
-
hmmm, I haz an idea, give me a sec ok? (or anyone else try it too)
-
Well, what should the behavior be in the event of a tie? Just arbitrarily pick one to be more than the other?
-
Yes.
If there is a tie, assign a random value to be the one to go first.