Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: Raylin on April 12, 2010, 08:46:29 pm

Title: Turn order based on value in AppVar?
Post 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...

Code: (vCake) [Select]
15
26
48
71
65
56
12

Code: (Turn Order) [Select]
6
5
4
1
2
3
7
Title: Re: Turn order based on value in AppVar?
Post by: calc84maniac on April 12, 2010, 08:58:26 pm
A simple algorithm I just thought up is this (A points to appvar, B points to output list)
Code: [Select]
: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.
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on April 12, 2010, 09:07:50 pm
My calc rewarded me with a kick in the face. (RAM clear)
Title: Re: Turn order based on value in AppVar?
Post by: DJ Omnimaga on April 12, 2010, 11:08:58 pm
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.
Title: Re: Turn order based on value in AppVar?
Post by: Quigibo on April 12, 2010, 11:21:13 pm
That definitely shouldn't cause a RAM clear.  What is the other code you put around it?
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on April 13, 2010, 07:06:54 am
Code: (TEST) [Select]
:"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
Title: Re: Turn order based on value in AppVar?
Post by: calc84maniac on April 13, 2010, 07:36:47 am
The problem is that you didn't initialize B to the place where you want your 7-byte output list.
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on April 13, 2010, 08:11:21 am
Oh?
I thought that the Fill( command did that!

:P

My fault.
Title: Re: Turn order based on value in AppVar?
Post by: Quigibo on April 13, 2010, 03:10:56 pm
Everywhere in that sample where you used "B" just replace it with "L1".
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on April 13, 2010, 07:38:03 pm
It works.

Thank you, sir. :)
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on May 11, 2010, 11:29:06 pm
I've got problems with duplicates in my list.
I'm working on remedies now but help would be appreciated.
Title: Re: Turn order based on value in AppVar?
Post by: DJ Omnimaga on May 11, 2010, 11:45:43 pm
mhmm what do you mean? Does the data unintentionnally duplicates, or do you actually want to duplicate it?
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on May 11, 2010, 11:51:26 pm
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.
Title: Re: Turn order based on value in AppVar?
Post by: _player1537 on May 11, 2010, 11:53:40 pm
hmmm, I haz an idea, give me a sec ok?  (or anyone else try it too)
Title: Re: Turn order based on value in AppVar?
Post by: Quigibo on May 12, 2010, 12:04:56 am
Well, what should the behavior be in the event of a tie?  Just arbitrarily pick one to be more than the other?
Title: Re: Turn order based on value in AppVar?
Post by: Raylin on May 12, 2010, 08:13:40 am
Yes.
If there is a tie, assign a random value to be the one to go first.