Posts: 222
Threads: 10
Joined: Mar 2006
Just a suggestion, but couldn't you dim the array (0 to 12, 0 to 3) '0 to 3 for four types. Have it throw out a random card from there. This way you can use the first spot in that array (x, y) 'x in this case, to check the value of the card.
I hope this is somewhere NEAR what you are asking, otherwise I'm amazingly confused, or...More amazingly confused than I already am.
For example:
Code: 'Dim stuff here:
dim card_Deck (0 to 12, 0 to 3) 'This will be our card deck array
dim card(0 to 5) 'Six cards at hand
'Create the deck!
for load = 0 to 12
for load_2 = 0 to 3
card_deck(load, load_2) = load
next
next
'Make a hand
for card_throw = lbound(card) to ubound(card)
card_type = int(rnd * 3)
card_value = int(rnd * 12)
card(card_Throw) = card_deck(card_value, card_type)
next
'Print the Values of the hand:
for card_throw = lbound(card) to ubound(card)
print card(card_throw)
next
print "Total value is:", card(0) + card(1) + card(2) + card(3) + card(4) + card(5)
sleep
will Live Forever, or Die Trying >_<;;
Posts: 324
Threads: 12
Joined: Nov 2005
You could use an array, but that's a little inefficient. Here, you can rely on the fact that the numbers in your diagram are simply the reversed-ordered elements in an array (all we need to do is find the column the number would be in):
Code: '/ returns the column the element n would be in with an
'/ array width of highestPriority
function GetPriority(n as integer, highestPriority as integer) as integer
return (n-1) mod highestPriority
end function
'/ create an array to hold the random nums
const MaxSlots as integer = 5
dim slots(0 to MaxSlots-1) as integer
'/ fill slots with random numbers
'/ ...
'/ find the number with highest priority
dim highestPriority as integer = 0
dim slot as integer
for slot = 0 to MaxSlots-1
dim priority as integer = GetPriority(slots(slot),13)
if (highestPriority < priority) then
highestPriority = priority
end if
next
'/ highestPriority now contains the slot with
'/ the highest priority :)
stylin:
Posts: 324
Threads: 12
Joined: Nov 2005
My internet's borked, so I had to shorten my code above so I could post it. Just wanted to add that you should get rid of that literal '13' and replace it with a constant - or a var, if you'd like to change the array width (max priority) at run-time.
EDIT: and you'll have to actually save the slot along with the highest priority. (my code just keeps track of the priority) :o
stylin:
Posts: 21
Threads: 6
Joined: Jul 2004
I took a different route by using DIM commands,
but now I get a duplicate error
1 = 1
14 = 1
27 = 1
40 = 1
Posts: 324
Threads: 12
Joined: Nov 2005
Let me consult my crystal ball ... it tells me I need more information [IOW, nobody is a mind-reader here]. You might want to post some code. Sorry.
stylin:
Posts: 6,419
Threads: 74
Joined: Mar 2002
This is a shuffling problem.
Steps:
1.- Create an array with 52 indexes, one for each value.
2.- Assign each value to its array index, so the array will be A(X) = X.
3.- Do a loop iterating a number of times, i.e. 26 times. The more times, the more "shuffled".
4.- Each loop just swap two array elements selected at random:
X = INT(RND*52)+1
Y = INT(RND*52)+1
AUX = A(Y)
A(Y) = A(X)
A(X) = AUX
(or use SWAP A(X), A(Y) which is a BASIC command, look for it in the help).
Posts: 1
Threads: 0
Joined: Feb 2006
I think I got it ! .... I guess ... DOH ! this is same as Stylin... but i get something different for the card chooser...
I take the given example
17,40,12,28,48 then 12 is maxi and 40 is mini then :
The tip is to search for min and max of ((value-1) mod 13)
EDIT : Stylin already found it ... :oops:
Code: dim slot(5) as integer
' example choosen
slot(1) =17 : slot(2)= 40 : slot(3) = 12 : slot(4) = 28 : slot(5) = 48
' or to choose 5 DIFFERENTS number (between 1-52)
' here is a special quick shuffle algo
min = 0 : for i = 5 to 1 step -1 : min = int(rnd*(52-min+1)/i)+min+1 : slot(i) = min : next
' then search min max thanks to the given logic
minvalue = 100 : maxvalue = 0 : foundmin = 100 : foundmax = 0
for i = 1 to 5
v = (slot(i)-1) mod 13
if v < minvalue then
minvalue = v : foundmin = slot(i)
end if
if v > maxvalue then
maxvalue = v : foundmax = slot(i)
end if
next i
print "max = " ; foundmax,"min=";foundmin
end
not tested but should work ...
Have fun !
Posts: 324
Threads: 12
Joined: Nov 2005
Quote:I took a different route by using DIM commands,
but now I get a duplicate error
1 = 1
14 = 1
27 = 1
40 = 1
Your diagram has the numbers 1, 14, 27 and 40 having equal priority. If you want 1 < 14 < 27 < 40 then there's no sense in using your diagram at all. (just compare the numbers directly)
stylin:
the stoner knows what's going on... funny.
Code: Function priority( num As Integer ) As Integer
Dim As Integer res
'' 13 elements in a group in a deck of cards.
res = ( num Mod 13 )
If res = 0 Then res = 13
priority = res
End Function
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
a = 20
b = 35
c = 1
d = 52
? a; "'s priority is:"; priority( a )
? b; "'s priority is:"; priority( b )
? c; "'s priority is:"; priority( c )
? d; "'s priority is:"; priority( d )
Sleep
Posts: 21
Threads: 6
Joined: Jul 2004
The code comes in two parts, the first part is finished, because of this it will be dismissed, skipping the second part with a GOTO command.
The second will transform into the example below
1 = 13, 14 = 13, 27 = 13, 40 = 13
2 = 1, 15 = 1, 28 = 1, 41 = 1
3 = 2, 16 = 2, 29 = 2, 42 = 2
4 = 3, 17 = 3, 30 = 3, 43 = 3
5 = 4, 18 = 4, 31 = 4, 44 = 4
6 = 5, 19 = 5, 32 = 5, 45 = 5
7 = 6, 20 = 6, 33 = 6, 46 = 6
8 = 7, 21 = 7, 34 = 7, 47 = 7
9 = 8, 22 = 8, 35 = 8, 48 = 8
10 = 9, 23 = 9 36 = 9, 49 = 9
11 = 10, 24 = 10, 37 = 10, 50 = 10
12 = 11, 25 = 11, 38 = 11, 51 = 11
13 = 12, 26 = 12, 39 = 12, 52 = 12
What I need now is to solve each four set number groups to equal the final numbers that are set so that I no longer have the duplicate error during RUN TIMES.
|