Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Javascript help!

Name: Anonymous 2013-05-31 13:16

Could someone please help me with this javascript? I've asked just about everywhere and I've gotten no response. Why is this deal function returning undefined?

//Creates the deck as an array and logs it to the console.
Ace = 1;
deck = [0-51];
deck[0] = Ace;
deck[1] = 2;
deck[2] = 3;
deck[3] = 4;
deck[4] = 5;
deck[5] = 6;
deck[6] = 7;
deck[7] = 8;
deck[8] = 9;
deck[9] = 10;
deck[10] = 10;
deck[11] = 10;
deck[12] = 10;
deck[13] = Ace;
deck[14] = 2;
deck[15] = 3;
deck[16] = 4;
deck[17] = 5;
deck[18] = 6;
deck[19] = 7;
deck[20] = 8;
deck[21] = 9;
deck[22] = 10;
deck[23] = 10;
deck[24] = 10;
deck[25] = 10;
deck[26] = Ace;
deck[27] = 2;
deck[28] = 3;
deck[29] = 4;
deck[30] = 5;
deck[31] = 6;
deck[32] = 7;
deck[33] = 8;
deck[34] = 9;
deck[35] = 10;
deck[36] = 10;
deck[37] = 10;
deck[38] = 10;
deck[39] = Ace;
deck[40] = 2;
deck[41] = 3;
deck[42] = 4;
deck[43] = 5;
deck[44] = 6;
deck[45] = 7;
deck[46] = 8;
deck[47] = 9;
deck[48] = 10;
deck[49] = 10;
deck[50] = 10;
deck[51] = 10;
console.log(deck);
//Creates the player and bot as objects. Hit and fold are booleans where as all of the hands are numeraric values.
function player(hit, stay, card1, card2, card3, card4, card5) {
    hit = hit;
    stay = stay;
    card1 = card1;
    card2 = card2;
    card3 = card3;
    card4 = card4;
    card5 = card5;
}

function bot(hit, stay, card1, card2, card3, card4, card5) {
    hit = hit;
    stay = stay;
    card1 = card1;
    card2 = card2;
    card3 = card3;
    card4 = card4;
    card5 = card5;
}
//creates a function that shuffles the deck. This will be the first step in the while loop.
shuffle = function(list) {
  var i, j, t;
  for (i = 1; i < list.length; i++) {
    j = Math.floor(Math.random()*(1+i)); 
    if (j != i) {
      t = list[i];                       
      list[i] = list[j];
      list[j] = t;
    }}};
//This will deal a new card to either the player or bot.
deal = function(pob, val) {
    pob = deck[val];
};
//This while loop is the actual game, it calls on the functions created above in a specific order, simulating the order of operations in a game, then breaks when the game is over.
while(1) {
    shuffle(deck);
    deal(player.card1, 0);
    console.log(deck, player.card1);
    break;
}

Name: Anonymous 2013-05-31 13:18

The jews are after me

Name: Anonymous 2013-05-31 13:25

What kind of decks do you have? Four tens?

Name: Anonymous 2013-05-31 13:30

>>3
Please don't bait the nigger.

Name: Anonymous 2013-05-31 13:32

>>1
jesus christ, please be a troll

Name: Anonymous 2013-05-31 13:34

What's going on here?

Name: Anonymous 2013-05-31 13:43

>>3
10, Jack, Queen, and King.
>>5
What's wrong with my post?

Name: Anonymous 2013-05-31 13:44

考えるな、感じるんだ

Name: Anonymous 2013-05-31 13:45

>>7
More like what's right with your post? nothing

Name: Anonymous 2013-05-31 13:50

===
Lispers like to pick on JavaScript. It makes sense, because Common Lisp has everything that JavaScript lacks.
===

Except what it matters: an vibrant ecosystem, jobs, libraries of useful code, connectivity with external systems, those kinds of things.

Plus you can run 2-3 different Lisp variants on top of the JavaScript, which makes the whole “Common Lisp” and “Racket” point moot.

Not to mention spending 80% of your time writing code that exists as is in JavaScript libraries but is not available as a CL module, or trying to hand-craft interfacing to some external system.

Seriously, Lisp is not all it’s cranked up to be. Very few actual success stories (i.e stuff that people loves and uses) for such a hyped language family. Basically, Emacs, some in-app scripting (AutoCAD), and some internal systems. And the whole FAIL that was 70′s-80′s AI research.

The things we like from Lisp (garbage collection, closures, reflexivity etc), most modern languages already have them. And the unique features of LISP (writing “DSL”s, data is code, macro system etc) are more trouble than they are worth in actual use. Haven’t seen any Lisp(ish) programmer team actually running circles around the 3242342342 other languages/environment out there. Graham touts ViaWeb as an example of Lisp’s competitive advantage, but being there first, at the right time, and doing some right moves was more of an advantage than the language used. Lots of other web ventures got quite huge in plain old Perl, if not PHP, and some even in hand-crafted C CGI, thank you very much.

Btw, Paul Graham essays under serious consideration are mostly trite observations with some extravagant claims and bad style thrown in for good measure (read a few good essayists for comparison). Might want to read this:

http://www.idlewords.com/2005/04/dabblers_and_blowhards.htm

Name: Anonymous 2013-05-31 13:50

>>6
What's going on here?
/prog/ is getting trolled.

Name: Anonymous 2013-05-31 13:57

Can anyone here actually answer my question?

Name: Anonymous 2013-05-31 14:04

>>12
A long standing bug in JS is that you cannot simulate dealing a card out of a deck.

Name: Anonymous 2013-05-31 14:15

>>13
But I can, I just don't know how to make it into a function.

Name: Anonymous 2013-05-31 14:52

>>14
That's right, you don't know. Go read your SICP.

Name: Anonymous 2013-05-31 14:56

Fuck you guys

Name: Anonymous 2013-05-31 15:55


my @suits  = <♣ ♢ ♡ ♠>;
my @ranks  = 2..10, <J Q K A>;

# concatenate each rank with each suit (2♣ 2♢ 2♡ ... A♠)
my @deck = @ranks X~ @suits;

# build a hash of card names to point values
my %points = @deck Z @( (2..10, 10, 10, 10, 11) Xxx 4 );

@deck .= pick(*); # shuffle the deck
my @hand = @deck.splice(0, 5); # grab first five cards
say ~@hand; # display my hand
say [+] %points{@hand}; # tell me how many points it's worth

Name: Anonymous 2013-05-31 15:59

Why the fuck are you using Javashit? Go fuck a sandnigger, kike.

Name: Anonymous 2013-05-31 17:30


//This will deal a new card to either the player or bot.
deal = function(fnc, pob, val) {
    fnc.call(pob, deck[val]);
};
//This while loop is the actual game, it calls on the functions created above in a specific order, simulating the order of operations in a game, then breaks when the game is over.
player.prototype.set_card1 = function(card1)
{
    this.card1 = card1;
}
p = new player();

while(1) {
    shuffle(deck);
    deal(p.set_card1, p, 0);
    console.log(deck, player.card1);
    break;
}

Name: Anonymous 2013-05-31 17:32

>>19

console.log(deck, p.card1);

Name: Anonymous 2013-05-31 19:07

>>17 is that perl?

Name: Anonymous 2013-05-31 19:09

>>21
Of course it is. Are you braindead or something? How can't you know that?

Name: Anonymous 2013-06-01 1:29

>>22
Actually I do have a mental disability, it's called being a goy.

Name: Anonymous 2013-06-01 1:32

Name: Anonymous 2013-06-01 6:06

use a loop to fill deck[1:52]=1:52
suit = (int) deck[i] / 13
val = deck[i] mod 13
deck[0] = current position in deck
....

Name: Anonymous 2013-06-01 6:16

it doesn't return() anything..?

Name: Anonymous 2013-06-01 6:41


int deck[52], hands[5][4], players, i;

function shuffle(){
  deck[0]=1;
  var ii, j, t;
  for (ii = 2; ii < 52; ii+=2) {
    j = Math.floor(Math.random()*25)*2+1;
    t = list[ii];                      
    deck[ii] = deck[j];
    deck[j] = t;
    }
}; 

function deal(numplayers){
int k,l;
players=numplayers;
for(k=0;k<5;k++)
  for(l=0;l<players;l++)
    hands[k][l] = deck[++deck[0]];
};

for(i=1;i<52;i++)
  deck[i]=i;

shuffle();

...

Don't change these.
Name: Email:
Entire Thread Thread List