• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Randomize a deck of Cards help!

Status
Not open for further replies.
Level 2
Joined
Sep 10, 2008
Messages
8
I'll explain the whole thing. I'm making a card game. My goal is to set a deck of cards to a variable (each card is a unit-type). and program that variable of 40 cards to get a random card draw when you click an ability on a unit (the ability on the unit being "draw a card")
The next part i'm trying to do is remove the card picked so that I don't randomize the card again! I have added the attachment of my trigger to this post.
Basically I have set the unit-type variables:
unittype variable1 = card1, unittype variable2 = card2 ect. to card 40.
Then when the ability is clicked on the unit - create 1 unit-type variable of random integer 1-40 for player at location "your cards"
I just don't get how to remove the picked card using a unit-type variable.
 

Attachments

  • Card Draw Triggers.jpg
    Card Draw Triggers.jpg
    58.9 KB · Views: 117

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Store all your cards in an array, which you then randomize from.

When you get one you remove it from the array by overwriting it with the one located at the end of the array and reduce the randomed number's range by 1. Thus technically the chances remain the same (fully random) and it is randomized efficently with no dupplicates.
 
Use variables. Store each unit as it's created in an array, and when you're done, loop through the array and remove each unit.

  • -------- Create a card--------
  • Set MyUnitArray[0] = (Last created unit)
  • -------- Create another card--------
  • Set MyUnitArray[1] = (Last created unit)
  • -------- Blah blah---------
  • For (Integer A) from 0 to 6 do (Actions)
    • Unit - Remove MyUnitArray[(Integer A)]
 
Level 2
Joined
Sep 10, 2008
Messages
8
Here is my new Trigger.... I posted the full thing.
The new Trigger is removing my cards instantly as soon as they're created.
It's not picking the number its picking the unit. I wonder how i would convert it to pick the integer randomed number, instead of the unit?

Edit: sorry i don't know how to remove the other post!
 

Attachments

  • New Draw.jpg
    New Draw.jpg
    64.9 KB · Views: 156
  • deck.jpg
    deck.jpg
    68.8 KB · Views: 118
OH. Sorry, I misunderstood.

Basically, make a boolean array, size 40. Each time, pick a random number, and if integerArray[number] = false, then set it to true and use that card. But if integerArray[number] = true, pick another number and try again.

In the future, please use
  • tags instead of posting pictures.
 
Level 2
Joined
Sep 10, 2008
Messages
8
Sorry I have no idea how to go about randomizing a number and picking it using boolean i've tried. The problem is I don't know how to set the variables in this situation. I'm not good with variables at all.

I don't think the editor is setting the boolean to the randomed number to make it true or false.
Do I need Integer variables as well?
 
Last edited:
Level 2
Joined
Sep 10, 2008
Messages
8
Here is my attempt so far.... its not working correctly the randomized number is working. but it creates the same unit every time in specific locations. Basically I get the same cards every time to specific locations. Also I made the display text to show so I know if the numbers are working. Sometimes I get the same number twice and both units are there

  • Events
    • Unit - A unit owned by Player 1 (Red) Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Draw Seven Cards
    • Actions
      • Set random1 = 1
      • Set random2 = 5
      • Set random3 = (Random integer number between random1 and random2)
      • Game - Display to (All players) the text: (String(random3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random3 Equal to 1
          • boolean[1] Equal to True
        • Then - Actions
          • Set boolean[1] = False
          • Unit - Create 1 GreenCards[1] for (Triggering player) at (Center of Red Card 1 <gen>) facing (Position of (Triggering unit))
        • Else - Actions
      • Set random3 = (Random integer number between random1 and random2)
      • Game - Display to (All players) the text: (String(random3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random3 Equal to 2
          • boolean[2] Equal to True
        • Then - Actions
          • Set boolean[2] = False
        • Else - Actions
          • Unit - Create 1 GreenCards[2] for (Triggering player) at (Center of Red Card 2 <gen>) facing (Position of (Triggering unit))
      • Set random3 = (Random integer number between random1 and random2)
      • Game - Display to (All players) the text: (String(random3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random3 Equal to 3
          • boolean[3] Equal to True
        • Then - Actions
          • Set boolean[3] = False
        • Else - Actions
          • Unit - Create 1 GreenCards[3] for (Triggering player) at (Center of Red Card 3 <gen>) facing (Position of (Triggering unit))
      • Set random3 = (Random integer number between random1 and random2)
      • Game - Display to (All players) the text: (String(random3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random3 Equal to 4
          • boolean[4] Equal to True
        • Then - Actions
          • Set boolean[4] = False
        • Else - Actions
          • Unit - Create 1 GreenCards[4] for (Triggering player) at (Center of Red Card 4 <gen>) facing (Position of (Triggering unit))
      • Set random3 = (Random integer number between random1 and random2)
      • Game - Display to (All players) the text: (String(random3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • random3 Equal to 5
          • boolean[5] Equal to True
        • Then - Actions
          • Set boolean[5] = False
        • Else - Actions
          • Unit - Create 1 GreenCards[25] for (Triggering player) at (Center of Red Card 5 <gen>) facing (Position of (Triggering unit))
      • Player - Disable Draw Seven Cards for (Owner of (Triggering unit))
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Creating this without while loops is really lame. Too bad you don't have while loops in GUI, haha, I laugh at all the GUI'ers!

And yea, seriously this will be lame without a conditional loop. Couldn't find any non integer loops, which suck anyways.

I guess you could just add two custom scripts and it will solve all of this.
You'll simply need to check if the boolean (referring to what Pyritie said) is true and "while it is true" (don't think you can do this in GUI as I said) you check again and again.

You could of course just loop 10 times or so and it will sure get a unique index, but then again, can you exit loops in GUI?

In conclusion: learn Jass. Don't limit yourself with the crappy GUI.
 
Level 2
Joined
Sep 10, 2008
Messages
8
I almost got it to work but no success:( I don't believe its even possible to do this in GUI I've spent 6 hours on this one trigger and haven't figured it out. It randomizes fine, I also found a way to pick the randomized number and remove it (boolean = [integer of randomed number] and boolean of number = false. But I have found no mathematical way to tell the program to "re" randomize once it picks a number that is already = to false
Example - Lets say the Random number integer draws us a 1 in a 2 card deck
Conditions: Each Boolean representing a card.
Boolean1 = False , Boolean2 = True, Boolean1 = Randomed number1
Actions: Anyone know how to tell this program to Keep randomizing until you get 2?
Another example - Random # comes up 5 in a 60 card deck. every card in the deck is used except for the #60. Obviously we don't want to keep picking randomed numbers and get multiples of 1,s 8,s 50,s we want to to go straight to the next available card! anyone know of a way to do this please!
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Yes, that is exactly what I said. You can't exit with a condition with the crappy GUI loops.

You can do something like this, though
  • // Put this at the start of your code, right after the conditions block
  • Custom script: local integer i = 0
  • // And this is the loop itself
  • Custom script: loop
  • Custom script: i = GetRandomInt(1,40)
  • Custom script: exitwhen udg_Boolean_Array[i] == false
  • Custom script: endloop
You can use a global integer as well, of course.
 
Last edited:
For clarification on ghostwolf's post...

[trigger=""]Custom script: exitwhen udg_Boolean_Array == false[/trigger]

Whatever your global boolean array is called, you have to put "udg_" in front of it. It's how WE works.

[trigger=""]Events
Blah
Conditions
Blah
Actions
Custom script: local integer i = 0
-------- Everything else --------[/trigger]
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Best thing to do for randomizing array members is
for X times pick 2 random array indexes and swap them
so it gets randomized
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
Or you can transfer them from array to array (again fully randomly) which assures that every element undergoes some kind of random selection. Althou probably as demanding as Need_O2s way, I believe it might be more efficent as each random opperation is assured to affect a different item (never randomizes the location of the same item twice) and so needs only loop throu all items once to assure a decent randomzation level as apposed to Need_O2's method which is still good but after being preformed number of items times might still have unaffected parts of the array (as it is random).

Variables
random index
data array 1 = your array with your data (using index 0 to store as well)
data array 2 = empty array
array 1 max = the index of the last item in data array 1
array 2 max = 0

1. repeat below actions
2. random index = random number between 0 and array 1 max.
3. set data array 2(array 2 max) = data array 1(random index).
4. set array 2 max = array 2 max + 1.
5. set data array 1(random index) = data array 1(array 1 max).
6. set array 1 max = array 1 max - 1.
7. stop repeating when array 1 max < 0
8. end repeat

Such an idea could be combined with Need_O2's way where it loops throu the array and swaps the data of that index with that of a random index (itself included as a possiable index), again assuring all items in the array undergo randomization.
 
Level 15
Joined
Dec 18, 2007
Messages
1,098
There is a tutorial on how to make -AR or -random like that in dota. I know its abit different from what you want buy you can learn how to make the basics from there. But you will need to change some things.
Hero Taverns for Selling Your Heroes
It teaches you how to make a -random system like that in DotA, as I said above, you can learn how to make a system that gives you random things which can't be the same.
 
Status
Not open for further replies.
Top