xxxxxxxxxx
300
deck=[];
deck2=[]; // true order deck;
var ndeck=[]; // Deck after dealing
var count=0; // How many times we have gone
var indx;
var same=false; // turns true if deck is in order
var found=[]; // Keeps track of positions
var addit; // Flag to tell us to add it or not
//through the deck
var showonce=true; // show tracking only once
var before=0;
var after=0;
var limit=509;
var findme=103; // number we are tracking
deckx=5;
decky=5;
var numShuff=0;
var numdeal=1; // Number of card to deal each time
cw=65;
ch=100;
var dl=13; // deck length
function setup() {
//frameRate(.1)
createCanvas(1100, 2000);
initializeDeck();
}
function initializeDeck()
{
deck=newDeck(dl); //Create unshuffled deck of 52 cards
deck2=newDeck(dl);
//deck[0].name=7;
// console.log(deck.pop());
for(var i=0; i<numShuff; i++) // Shuffle a lot
{
deck=shuffleDeck(deck); // Shuffle deck just created
}
//console.table(deck);
}
function draw() {
indx=dl-1;
//console.log("NELL");
background(0);
row=0;
col=0;
for(var i=0; i<deck.length; i++)
{
//if(deck[indx].value==1)
showCard(col*cw,((10+ch)*row)+10, deck[indx]);
if(col==12)
{
col=0;
row++;
}
else
{
col++;
}
indx--;
}
fill("white");
text("Cycles: " + count, width-200, 50);
text("Deck Size: " + dl, width-200, 70);
// same=true;
// for(var f=0; f<deck.length && same; f++)
// {
// if(deck[f].value!=deck2[f].value)
// {
// same=false;
// }
// }
// //if(count<limit)
// if(!same || count==0)
// {
// count++;
// execute();
// }
// else
// {
// if(showonce)
// {
// console.log(found);
// showonce=false;
// }
// }
}
function newDeck(n) // Creates a new deck of 52 cards.
{
var val=n;
tdeck=[]; // Temporary Deck used for builing
for(var i=n; i>0; i--)
{
tdeck.push(new Card(val));
val--;
}
return tdeck;
}
function shuffleDeck (inDeck){
var unshuffled=inDeck;
var temp=0;
for(var i=0; i<unshuffled.length; i++)
{
temp=unshuffled[i];
swap=floor(random(unshuffled.length));
unshuffled[i]=unshuffled[swap];
unshuffled[swap]=temp;
}
return unshuffled;
}
function showCard(x,y,incard)
{
fill('white');
stroke('black');
textSize(20);
push();
translate(x,y);
rect(0,0, cw,ch);
fill(0);
text(incard.value, 0+5,0+20);
rotate(radians(180));
//rect(0,0, cw,ch);
text(incard.value, -cw+5, 25-ch);
//text(incard.pic, -cw+25, 25-ch);
pop();
}
function drawBoard()
{
background(0);
}
// This function takes the deck and
// deals one down, then one to the back
// of the deck until the entire deck has been
// distributed to the new deck
function execute()
{
var ct=0; // Number of cards we have cycled;
var temp; // Temporary card
ndeck.length=0;
count++;
do{
temp==undefined;
ndeck.push(deck.pop());
//console.log(deck.pop());
//console.log(ndeck);
ct++;
if(deck.length)
{
temp=deck[deck.length-1];
}
for(var d=deck.length-1; d>0; d--)
{
deck[d]=deck[d-1];
}
if(deck.length)
{
deck[0]=temp;
ct++;
}
}while(deck.length);
for(var e=0; e<ndeck.length; e++)
{
deck[e]=ndeck[e];
}
before=found.length;
findcard(findme);
after=found.length;
if((before==after) && (showonce))
{
//console.log(found);
showonce=false;
}
}
function keyPressed()
{
// frameRate(1);
execute();
//console.table(ndeck);
//console.log(keyCode);
switch(keyCode)
{
// case 38:dl++;
// initializeDeck();
// count=0;
// break;
// case 40: dl--;
// initializeDeck();
// count=0;
// break;
}
}
function findcard(c)
{
for(var i=0; i<deck.length; i++)
{
if(deck[i].value==c)
{
addit=true;
for(f=0; f<found.length && addit; f++)
{
if(found[f]==i+1)
{
addit=false;
}
}
if(addit)
{
found.push(i+1);
console.log(i+1);
}
else
{
console.log(found);
}
}
}
//console.log(found);
}