Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-28-2006, 09:15 PM   #1
Seanx
Flash Dilettante
 
Join Date: Jul 2006
Posts: 369
Default every possible two-card combination

lets say I had:
ActionScript Code:
deckA = ["1", "2", "3", "4"...] deckB = ["1", "2", "3", "4"...]

both arrays had the same 52 numbers, corresponding to playing cards in a regular deck, is it possible to loop through the first array, matching each element up with each element of the other array, and trace out every possible two-card combination? with this script I could rule the world.
Seanx is offline   Reply With Quote
Old 11-28-2006, 11:40 PM   #2
FlashMech
Flashmech.net
 
FlashMech's Avatar
 
Join Date: Nov 2006
Location: Singapore
Posts: 261
Default

Hi Seanx, looping through 52 cards is not a good idea! It hung my computer!

I had to shorten the deck to 5 cards. But hope it gives you some direction.

Code:
 
stop();
var deckA:Array = new Array();
var deckB:Array = new Array();
function populateDeck (ary:Array):Void {
 for ( var i:Number = 1; i <= 5; i++ ) {
  ary.push(i);
 }
}
function traceCombi(ary1:Array, ary2:Array):Void {
 for ( var i:Number = 0; i < ary1.length; i++ ) {
  for ( var j:Number = 0; j < ary2.length; j++ ) {
   trace("card"+ary1[i]+" of ary1 with card"+ary2[j]+" of ary2");
  }
 }
}
populateDeck(deckA);
populateDeck(deckB);
traceCombi(deckA, deckB);
Just put this on the first frame of a new document.
__________________
Lionel Low
Flash Platform Consultant | Trainer | Speaker
http://www.flashmech.net/
http://www.linkedin.com/in/flashmech
FlashMech is offline   Reply With Quote
Old 11-29-2006, 02:01 AM   #3
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,140
Default

Quote:
Originally Posted by FlashMech View Post
Hi Seanx, looping through 52 cards is not a good idea!
I disagree. This runs just fine.

ActionScript Code:
// // var deckA:Array = new Array(); var deckB:Array = new Array(); for (var i:Number=0; ++i<53;) deckA.push(i); deckB = deckA; for (var i:Number=0; i<deckA.length; i++) {     for (var j:Number=0; j<deckB.length; j++) {         trace("possible combination = " + deckA[i] + "  " + deckB[j]);     } } // //
__________________
trace("Good bye Flash.") Log.i(TAG, "Hello Droid");
Flash Gordon is offline   Reply With Quote
Old 11-29-2006, 02:12 AM   #4
FlashMech
Flashmech.net
 
FlashMech's Avatar
 
Join Date: Nov 2006
Location: Singapore
Posts: 261
Default

Quote:
Originally Posted by Flash Gordon
I disagree. This runs just fine.
Yup you're right. It does runs fine!

It's just weird when I was doing on my other computer. Now it seems to work fine!

Hooray!
__________________
Lionel Low
Flash Platform Consultant | Trainer | Speaker
http://www.flashmech.net/
http://www.linkedin.com/in/flashmech
FlashMech is offline   Reply With Quote
Old 11-29-2006, 02:44 AM   #5
Seanx
Flash Dilettante
 
Join Date: Jul 2006
Posts: 369
Default

that's beautiful. thank you flashGordon

I did some research on combinatorial analysis, and was looking for ways to plug their convoluted equations into flash, but your method is quite a bit simpler and easier on the eye. |[
Seanx is offline   Reply With Quote
Old 11-29-2006, 02:51 AM   #6
Seanx
Flash Dilettante
 
Join Date: Jul 2006
Posts: 369
Default

what if I wanted to do the same thing, but with five cards, and four players?

in other words, despite there being some 2,000,000 possible combinations for a five-card hand of poker, I'm making a hold'em game, so three of the cards are common to all players - and, of course, once you pull a hole card from the deck it is no longer available as a hole card to others, and, of course again, the 2,000,000 combinations doesn't take into account suits/values of hands. so it's all pretty mind-numbing when you think of there only being 52 cards, and extremely complicated if you want to create a one-number variable for every possible 2*4+1+1+1+1+1 card-dealing scenario. impossible really, but it would be a nice way to analyze how well the decision-making algorithm works for various players - simulating a few hundred thousand hands, and then looking at betting patterns and such.

so, maybe I should get in touch with someone at MIT or something - somebody who knows combinatorial math well enough to whip up my formula for every scenario [i]++

it's not necessary, but would be something fun in any case. later and thanks again
Seanx is offline   Reply With Quote
Old 11-29-2006, 03:24 AM   #7
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,140
Default

Dude, making a card game is a rather difficult task. You need to spend a lot of time planning. Don't take that stage very lightly, this isn't something you can just jump into like a contact forum.

Not to mention the combinations, but you need to plan if this is multiplayer. And if so, you are going to need electroserver or some socket.

Take a lot of time and diagram your plan.
Good luck
__________________
trace("Good bye Flash.") Log.i(TAG, "Hello Droid");
Flash Gordon is offline   Reply With Quote
Old 11-29-2006, 03:24 AM   #8
FlashMech
Flashmech.net
 
FlashMech's Avatar
 
Join Date: Nov 2006
Location: Singapore
Posts: 261
Default

I love your idea~

If you ever get it done in flash, please post it up so we can take a looK~
__________________
Lionel Low
Flash Platform Consultant | Trainer | Speaker
http://www.flashmech.net/
http://www.linkedin.com/in/flashmech
FlashMech is offline   Reply With Quote
Old 11-29-2006, 04:29 AM   #9
Seanx
Flash Dilettante
 
Join Date: Jul 2006
Posts: 369
Default

well, I'm well on my way guys. I have some 3,000 lines of code, mostly because I'm not familiar enough with actionscript to know how to condense statements and the way I store variables and such.

as of right now I can:

1. deal the hole cards
2. tell flash (on behalf of the computer players) to analyze the hole cards
3. place bets/check according to hand/percentage and some randomness I build in ie - variables that move around according to hands won/money et cetera (simulate ai)
4. deal the flop
5. repeat step 3
6. deal turn
7. repeat step 3
8. deal river
9. repeat step 3
10. figure out who has the best hand
11. start the next hand....

flash autodeals if after the button moves, antes are placed, and blinds are in it sees that the dealer is not P1

there are some problems I'm still working out, mostly because of my inexperience with if/else stuff - like, I haven't figure out a way to tell if a player has a straight, straight flush, and royal flush.

I have a feeling that's another marvelously short piece of code that will elude me for some time, or in the short-term a really long set of complicated if/else statements

once I get that worked out, it's just a question of animating the card dealing instead of having them magically appear, putting in some bg sounds, adding chip noises, animating chip piles

down the road I'll add keep adding to the nuances of the pseudo-AI, and add new characters.

oh yeah - big thing, I still haven't figured out how to make a player go away after losing, so losers will have to just go negative for a while until I figure out what conditionals to add to my existing code to allow for fewer/more players than the default 4

Last edited by Seanx; 11-29-2006 at 04:33 AM.
Seanx is offline   Reply With Quote
Old 11-29-2006, 04:36 AM   #10
Seanx
Flash Dilettante
 
Join Date: Jul 2006
Posts: 369
Default

to show you an example of how my inexperience is running into lots of lines of code:

ActionScript Code:
deck2[1] = {value:1, text:"Ace of Clubs", clubs:1, spades:0, hearts:0, diamonds:0, ones:1, twos:0, threes:0, fours:0, fives:0, sixes:0, sevens:0, eights:0, nines:0, tens:0, jacks:0, queens:0, kings:0, aces:1};

that is one of 52 lines that I'm only using for this bit of code later:
ActionScript Code:
_root.P4HCLUBS += deck2[answer4].clubs;         _root.P4HSPADES += deck2[answer4].spades;         _root.P4HHEARTS += deck2[answer4].hearts;         _root.P4HDIAMONDS += deck2[answer4].diamonds;         _root.P4HONES += deck2[answer4].ones;         _root.P4HTWOS += deck2[answer4].twos;         _root.P4HTHREES += deck2[answer4].threes;         _root.P4HFOURS += deck2[answer4].fours;         _root.P4HFIVES += deck2[answer4].fives;         _root.P4HSIXES += deck2[answer4].sixes;         _root.P4HSEVENS += deck2[answer4].sevens;         _root.P4HEIGHTS += deck2[answer4].eights;         _root.P4HNINES += deck2[answer4].nines;         _root.P4HTENS += deck2[answer4].tens;         _root.P4HJACKS += deck2[answer4].jacks;         _root.P4HQUEENS += deck2[answer4].queens;         _root.P4HKINGS += deck2[answer4].kings;         _root.P4HACES += deck2[answer4].aces;

I have that last set repeated for all four players - with P4HJACKS or P1HACES corresponding to new number variables I set to 0 on frame 1, and reset at the end of every hand.... so that's my blunt-skulled approach to keeping track of how many clubs/sevens... et cetera each player has...
Seanx is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[AS2] card game black jack Kiandoshi Gaming and Game Development 1 10-17-2006 04:25 PM
Complex drag and drop problem - nested 'if's' (card game) waarbs Gaming and Game Development 1 02-07-2006 01:54 PM
[AS1] Card Game Help blatex24 Gaming and Game Development 0 07-16-2004 12:48 AM
card game: designing Deck class and good OOP? pigpen Gaming and Game Development 1 11-26-2002 11:41 AM


All times are GMT. The time now is 10:32 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.