Rods

D

Divvy Bollocks

// A big 7 and three-quarters size "Hello" to all C++ programmers out there. This here is the second program what I've
// ever wrote, the first being a "**** off world you ****" program. It's a nice little poker patience program, poker
// patience being a patience game whereby 10 poker hands are placed on the table in a 5x5 square. Try it if you like.
// It's not really a C++ program as such, more of a SLOGic program heh heh. It writes results to a file results.txt
// and I just had to post it to this newsgroup because because because .....

// I'm sending it off to the BNFL with my CV in response to their advert:
//
// <<Programmer required to write "lowering of graphite rods into reactor core program" at Sizewell B.
// Good benefits package, nice pension (probably)>>


// Er .... If anyone's interested, compile it with the /O2 switch ... optimise for speed.



//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///// /////
///// Program: Poker Patience Program (ppp.cpp) /////
///// Writer: Peter Lambert using "Learn to Program with Borland C++ Builder 1.0" (£80) /////
///// which was a GUI C++ for Windows 95. Nice graphcs, bitmaps and all that. /////
///// And then rewritten for Microsoft Visual C++ Toolkit 2003 (a FREE compiler). /////
///// Date: 29th March 2006 between about 3pm and 3.45pm honest /////
///// John Huston: Filling straights is a sucker's game /////
///// Robert Duvall: 2 of Spades, 3 of Spades, 4 of Diamonds, 6 of Clubs, 8 of Spades /////
///// Instruction: Mince around with skore[] variables to improve play /////
///// Dealer: Your dealer tonight is Frankie Machinek /////
///// Note: Dealer can be a bit slow at beginning of each game because of validation /////
///// Version Number: You're yanking me off now right? /////
///// /////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// P R O G R A M N O T E S ////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
////
//// TO DO:
////
//// 1 .... Indenting ... Each "if" & "for" should be DIRECTLY above its associated "{" & "}".
//// 2 .... Check for redundant variables.
//// 3 .... Analyze those 136 odd "skore" variables that determine where cards are placed.
//// Can any improvements be made to up that average score per game?
//// 4 .... You could introduce some "CANNY LOGIC" so that placement of cards takes into
//// consideration ONLY the remaining cards in the deck. Hence if we're looking at a
//// pair of 7's and one or both of the other two 7's has awready been placed elsewhere
//// then that pair of 7's ain't ever gonna be a prial or a foursy. Same sorta thing
//// with potential straight flushes. If you're looking at 4,5,6,7 of clubs and either
//// or both of the other two cards (ie 3 & 8 of clubs) have already been placed
//// elsewhere then this can only ever become a flush or a straight. Etc etc etc.
//// Complex yes, but required.
//// 5 .... If you're really stuck for things to do you could try to "bitmapise" the whole
//// program so that for 100 games it writes 101 files, 001.jpg, 002.jpg, 003.jpg ...
//// 099.jpg, 100.jpg plus summary.txt.
////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma warning(disable: 4786)

#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <conio.h>

using namespace std; // VERY IMPORTANT!!!



//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////// R A N D O M N U M B E R F U N C T I O N //////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int RandInt(int lower,int higher)
{
return lower + rand() % (higher - lower + 1);
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////// F I N D T O P R O W I N T A B L E A R R A Y /////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int find_top(int harray[11][11])
{
int x, y, z;
z = 0;
bool kwit = false;
// Find top
for(x=0; x<=10; x++)
{
for(y=0; y<=10; y++)
{
if (harray[x][y] != 0)
{
z = x;
kwit = true;
break;
}
}
if (kwit) break;
}
return z;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////// F I N D B O T T O M R O W I N T A B L E A R R A Y //////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int find_bottom(int harray[11][11])
{
int x, y, z;
z = 0;
bool kwit = false;
// Find bottom
for(x=10; x>=0; x--)
{
for(y=0; y<=10; y++)
{
if (harray[x][y] != 0)
{
z = x;
kwit = true;
break;
}
}
if (kwit) break;
}
return z;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////// F I N D LEFTMOST COLUMN I N T A B L E A R R A Y ///////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int find_left(int harray[11][11])
{
int x, y, z;
z = 0;
bool kwit = false;
// Find left
for(x=0; x<=10; x++)
{
for(y=0; y<=10; y++)
{
if (harray[y][x] != 0)
{
z = x;
kwit = true;
break;
}
}
if (kwit) break;
}
return z;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////// F I N D RIGHTMOST COLUMN I N T A B L E A R R A Y ///////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int find_right(int harray[11][11])
{
int x, y, z;
z = 0;
bool kwit = false;
// Find right
for(x=10; x>=0; x--)
{
for(y=0; y<=10; y++)
{
if (harray[y][x] != 0)
{
z = x;
kwit = true;
break;
}
}
if (kwit) break;
}
return z;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////// T H E I D E N T I F Y H A N D F U N C T I O N ///////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int identify_hand(int hand[5])
{
int i = 0;
int pair01 = 0, pair02 = 0, pair03 = 0, pair04 = 0,
pair12 = 0, pair13 = 0, pair14 = 0,
pair23 = 0, pair24 = 0,
pair34 = 0;
bool no_pairs = false, single_pair = false, two_pairs = false, flush = false, prial = false, straight = false, schtraight = false, bum_schtraight = false, dog_schtraight = false, full_hand = false, fours = false;
int number_of_pairs = 0;
int number_of_cards = 0, hand_identifier = 0;
int the_number_5 = 5; // This is the size of the hand[] array ... required for the sort() function
int card1_pips=0, card1_suit=0, card2_pips=0, card2_suit=0, card3_pips=0, card3_suit=0, card4_pips=0, card4_suit=0, card5_pips=0, card5_suit=0;

//Right ... first up we need to sort this hand[] array
sort(hand, hand + the_number_5);

// Thus hand[] will contain ...
// {0,0,0,0,0} ... No cards
// {0,0,0,0,104} ... 1 card (AS)
// {0,0,0,104,401} ... 2 cards (AS & 4H)
// {0,0,0,501,502} ... 2 cards (5H & 5D)
// {0,0,101,102,1301} ... 3 cards (AH, AD & KH)
// {0,303,402,704,604} ... 4 cards (3C, 4D, 7S & 6S)

card5_suit = (hand[0] % 100);
card4_suit = (hand[1] % 100);
card3_suit = (hand[2] % 100);
card2_suit = (hand[3] % 100);
card1_suit = (hand[4] % 100);

card5_pips = (hand[0] - card5_suit)/100;
card4_pips = (hand[1] - card4_suit)/100;
card3_pips = (hand[2] - card3_suit)/100;
card2_pips = (hand[3] - card2_suit)/100;
card1_pips = (hand[4] - card1_suit)/100;


//cardn_suit will now contain the suit (1, 2, 3 or 4 - HDCS) for card n
//cardn_pips will now contain the pips (1=A, 2=2, 3=3, 4=4 ... etc etc etc ... 9=9, 10=10, 11=J, 12=Q and 13=K) for card n

// If hand[] = {0,0, 1.1, 3.3, 4.4} ... (AH, 3C, 4S) card1_pips = 4, card2_pips = 3, cards3_pips = 1 (the ace)
// If hand[] = {0, 1.1, 10.3, 12.4, 13.1} ... (AH, 10C, QS, KH) card1_pips = 13 (K), card2_pips = 12 (Q), cards3_pips = 10, cards4_pips = 1 (the ace)
// ie ... the cards are written to card1, card2, card3 ... etc is DESCENDING order KING HIGHEST (13) ACE LOWEST (1)


for(i=0; i<=4; i++)
{
if (hand != 0) number_of_cards++;
}

// Let's get this show on the road
if (number_of_cards == 0) hand_identifier = -2;
if (number_of_cards == 1) hand_identifier = -1;
if (number_of_cards == 2)
{
if (card1_pips == card2_pips) single_pair = true;
if (card1_suit == card2_suit) flush = true;
if ((card1_pips - card2_pips == 1) || ((card1_pips == 1) && (card2_pips == 13))) straight = true;
if ((card1_pips - card2_pips == 2) || ((card1_pips == 1) && (card2_pips == 12))) schtraight = true;
if ((card1_pips - card2_pips == 3) || ((card1_pips == 1) && (card2_pips == 11))) bum_schtraight = true;
if ((card1_pips - card2_pips == 4) || ((card1_pips == 1) && (card2_pips == 10))) dog_schtraight = true;
if (!single_pair && !flush && !straight && !schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 0;
if (single_pair) hand_identifier = 1;
if (flush && !straight && !schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 2;
if (!flush && straight && !schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 3;
if (!flush && !straight && schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 4;
if (!flush && !straight && !schtraight && bum_schtraight && !dog_schtraight) hand_identifier = 5;
if (!flush && !straight && !schtraight && !bum_schtraight && dog_schtraight) hand_identifier = 6;
if (flush && straight && !schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 7;
if (flush && !straight && schtraight && !bum_schtraight && !dog_schtraight) hand_identifier = 8;
if (flush && !straight && !schtraight && bum_schtraight && !dog_schtraight) hand_identifier = 9;
if (flush && !straight && !schtraight && !bum_schtraight && dog_schtraight) hand_identifier = 10;
}
if (number_of_cards == 3)
{
if (card1_pips == card2_pips) pair01 = 1;
if (card1_pips == card3_pips) pair02 = 1;
if (card2_pips == card3_pips) pair12 = 1;
number_of_pairs = pair01 + pair02 + pair12;
if (number_of_pairs == 0) no_pairs = true;
if (number_of_pairs == 1) single_pair = true;
if (number_of_pairs == 3) prial = true;
if (no_pairs)
{
if ((card1_suit == card2_suit) && (card1_suit == card3_suit) && (card2_suit == card3_suit)) flush = true;
if (((card1_pips - card2_pips == 1) && (card2_pips - card3_pips == 1)) || ((card1_pips == 13) && (card2_pips == 12) && (card3_pips == 1))) straight = true;
if ((card1_pips - card3_pips == 3) && ((card1_pips - card2_pips == 1) || (card2_pips - card3_pips == 1))) schtraight = true;
if (((card1_pips == 13) || (card1_pips == 12)) && ((card3_pips == 1) && (card2_pips == 11))) schtraight = true;
if ((card1_pips - card3_pips == 4) && ((card2_pips > card3_pips) && (card1_pips > card2_pips))) bum_schtraight = true;
if ((card3_pips == 1) && (card2_pips == 10) && ((card1_pips == 11) || (card1_pips == 12) || (card1_pips == 13))) bum_schtraight = true;
}
if (no_pairs && !flush && !straight && !schtraight && !bum_schtraight) hand_identifier = 11;
if (single_pair && !flush && !straight && !schtraight && !bum_schtraight) hand_identifier = 12;
if (flush && !straight && !schtraight && !bum_schtraight) hand_identifier = 13;
if (prial && !flush && !straight && !schtraight && !bum_schtraight) hand_identifier = 14;
if (!flush && straight && !schtraight && !bum_schtraight) hand_identifier = 15;
if (!flush && !straight && schtraight && !bum_schtraight) hand_identifier = 16;
if (!flush && !straight && !schtraight && bum_schtraight) hand_identifier = 17;
if (flush && straight && !schtraight && !bum_schtraight) hand_identifier = 18;
if (flush && !straight && schtraight && !bum_schtraight) hand_identifier = 19;
if (flush && !straight && !schtraight && bum_schtraight) hand_identifier = 20;
}
if (number_of_cards == 4)
{
if (card1_pips == card2_pips) pair01 = 1;
if (card1_pips == card3_pips) pair02 = 1;
if (card1_pips == card4_pips) pair03 = 1;
if (card2_pips == card3_pips) pair12 = 1;
if (card2_pips == card4_pips) pair13 = 1;
if (card3_pips == card4_pips) pair23 = 1;
number_of_pairs = pair01 + pair02 + pair03 +
pair12 + pair13 +
pair23;
if (number_of_pairs == 0) no_pairs = true;
if (number_of_pairs == 1) single_pair = true;
if (number_of_pairs == 2) two_pairs = true;
if (number_of_pairs == 3) prial = true;
if (number_of_pairs == 6) fours = true;
if (no_pairs)
{
if ((card1_suit == card2_suit) && (card1_suit == card3_suit) && (card1_suit == card4_suit) && (card2_suit == card3_suit) && (card2_suit == card4_suit) && (card3_suit == card4_suit)) flush = true;
if ((card1_pips - card2_pips == 1) && (card2_pips - card3_pips == 1) && (card3_pips - card4_pips == 1)) straight = true;
if ((card1_pips == 13) && (card2_pips == 12) && (card3_pips == 11) && (card4_pips == 1)) straight = true;
if ((card1_pips - card4_pips == 4) && ((card1_pips - card2_pips <= 2) && (card3_pips - card4_pips <= 2))) schtraight = true;
if ((card4_pips == 1) && (card3_pips == 10) && ((card1_pips == 13) || (card1_pips == 12)) && ((card2_pips == 12) || (card2_pips == 11))) schtraight = true;
}
if (no_pairs && !flush && !straight && !schtraight) hand_identifier = 21;
if (single_pair && !flush && !straight && !schtraight) hand_identifier = 22;
if (two_pairs && !flush && !straight && !schtraight) hand_identifier = 23;
if (flush && !straight && !schtraight) hand_identifier = 24;
if (prial && !flush && !straight && !schtraight) hand_identifier = 25;
if (!flush && straight && !schtraight) hand_identifier = 26;
if (!flush && !straight && schtraight) hand_identifier = 27;
if (fours && !flush && !straight && !schtraight) hand_identifier = 28;
if (flush && straight && !schtraight) hand_identifier = 29;
if (flush && !straight && schtraight) hand_identifier = 30;
}
if (number_of_cards == 5)
{
if (card1_pips == card2_pips) pair01 = 1;
if (card1_pips == card3_pips) pair02 = 1;
if (card1_pips == card4_pips) pair03 = 1;
if (card1_pips == card5_pips) pair04 = 1;
if (card2_pips == card3_pips) pair12 = 1;
if (card2_pips == card4_pips) pair13 = 1;
if (card2_pips == card5_pips) pair14 = 1;
if (card3_pips == card4_pips) pair23 = 1;
if (card3_pips == card5_pips) pair24 = 1;
if (card4_pips == card5_pips) pair34 = 1;
number_of_pairs = pair01 + pair02 + pair03 + pair04 +
pair12 + pair13 + pair14 +
pair23 + pair24 +
pair34;
if (number_of_pairs == 0) no_pairs = true;
if (number_of_pairs == 1) single_pair = true;
if (number_of_pairs == 2) two_pairs = true;
if (number_of_pairs == 3) prial = true;
if (number_of_pairs == 4) full_hand = true;
if (number_of_pairs == 6) fours = true;
if (no_pairs)
{
if ((card1_suit == card2_suit) && (card1_suit == card3_suit) && (card1_suit == card4_suit) && (card1_suit == card5_suit) &&
(card2_suit == card3_suit) && (card2_suit == card4_suit) && (card2_suit == card5_suit) &&
(card3_suit == card4_suit) && (card3_suit == card5_suit) &&
(card4_suit == card5_suit)) flush = true;
if ((card1_pips - card2_pips == 1) && (card2_pips - card3_pips == 1) && (card3_pips - card4_pips == 1) && (card4_pips - card5_pips == 1)) straight = true;
if ((card1_pips == 13) && (card2_pips == 12) && (card3_pips == 11) && (card4_pips == 10) && (card5_pips == 1)) straight = true;
}
if (no_pairs && !flush && !straight && !schtraight) hand_identifier = 31;
if (single_pair && !flush && !straight && !schtraight) hand_identifier = 32;
if (two_pairs && !flush && !straight && !schtraight) hand_identifier = 33;
if (flush && !straight && !schtraight) hand_identifier = 34;
if (prial && !flush && !straight && !schtraight) hand_identifier = 35;
if (full_hand && !flush && !straight && !schtraight) hand_identifier = 36;
if (!flush && straight && !schtraight) hand_identifier = 37;
if (fours && !flush && !straight && !schtraight) hand_identifier = 38;
if (flush && straight && !schtraight) hand_identifier = 39;
}


return hand_identifier;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// EVALUATE HANDS BEFORE UNT AFTER FUNCTION //////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
int evaluate_before_unt_after_hands(int before[5], int after[5])
{
int beforeski = 0, afterski = 0;
int igta = 0; // I'll give that a .... eg .... Adding a 4 of diamonds to a 2,3,5 of diamonds .... I'll give that a 40!!
int skore[136];

// -2 - 0 cards: you are holding onto a hand made of thin air

// -1 - 1 card: you have a card. But is it a hand?

// 0 - 2 cards: bum hand
// 1 - 2 cards: pair
// 2 - 2 cards: flush
// 3 - 2 cards: straight (A-2, 4-5, 6-7, 9-10, J-Q, K-A)
// 4 - 2 cards: "schtraight" (A-3, 4-6, 6-8, 9-J, Q-A ... one filler card required)
// 5 - 2 cards: bum "schtraight" (A-4, 4-7, 6-9, 9-Q, J-A ... two filler cards required)
// 6 - 2 cards: dog "schtraight" (A-5, 4-8, 6-10, 9-K, 10-A ... three filler cards required)
// 7 - 2 cards: straight flush
// 8 - 2 cards: "schtraight" flush
// 9 - 2 cards: bum "schtraight" flush
// 10 - 2 cards: dog "schtraight" flush

// 11 - 3 cards: bum hand
// 12 - 3 cards: pair
// 13 - 3 cards: flush
// 14 - 3 cards: prial
// 15 - 3 cards: straight (A-2-3, 6-7-8, Q-K-A)
// 16 - 3 cards: "schtraight" (A-2-4, A-3-4, 6-7-9, J-K-A ... one filler card required)
// 17 - 3 cards: bum "schtraight" (A-2-5, A-3-5, A-4-5, 6-8-10, 10-J-A .... two filler cards required)
// 18 - 3 cards: straight flush
// 19 - 3 cards: "schtraight" flush
// 20 - 3 cards: bum "schtraight" flush

// 21 - 4 cards: bum hand
// 22 - 4 cards: pair
// 23 - 4 cards: two pairs
// 24 - 4 cards: flush
// 25 - 4 cards: prial
// 26 - 4 cards: straight (A-2-3-4, 6-7-8-9, J-Q-K-A)
// 27 - 4 cards: "schtraight" (A-3-4-5, 6-8-9-10, 10-J-K-A ... one filler card required)
// 28 - 4 cards: fours
// 29 - 4 cards: straight flush
// 30 - 4 cards: "schtraight" flush

// 31 - 5 cards: bum hand
// 32 - 5 cards: pair
// 33 - 5 cards: two pairs
// 34 - 5 cards: flush
// 35 - 5 cards: prial
// 36 - 5 cards: full hand
// 37 - 5 cards: straight
// 38 - 5 cards: fours
// 39 - 5 cards: straight flush

// ================================================================================
// SCORE BEFORE AFTER COMMENT
// ================================================================================
skore[0] = -10; // -1 0 1 card made into a 2 card bum hand
skore[1] = 10; // -1 1 1 card made into a 2 card pair
skore[2] = 4; // -1 2 1 card made into a 2 card flush
skore[3] = 5; // -1 3 1 card made into a 2 card straight
skore[4] = 3; // -1 4 1 card made into a 2 card "schtraight"
skore[5] = 1; // -1 5 1 card made into a 2 card bum "schtraight"
skore[6] = -1; // -1 6 1 card made into a 2 card dog "schtraight"
skore[7] = 12; // -1 7 1 card made into a 2 card straight flush
skore[8] = 10; // -1 8 1 card made into a 2 card "schtraight" flush
skore[9] = 8; // -1 9 1 card made into a 2 card bum "schtraight" flush
skore[10] = 6; // -1 10 1 card made into a 2 card dog "schtraight" flush

skore[11] = -5; // 0 11 2 card bum hand not improved upon
skore[12] = 6; // 0 12 2 card bum hand improved to a 3 card pair
skore[13] = -15; // 1 12 2 card pair not improved upon
skore[14] = 50; // 1 14 2 card pair improved to a 3 card prial
skore[15] = -8; // 2 11 2 card flush buggered up
skore[16] = 8; // 2 12 2 card flush made into a 3 card pair
skore[17] = 15; // 2 13 2 card flush improved to a 3 card flush
skore[18] = -10; // 3 11 2 card straight buggered up
skore[19] = -2; // 3 12 2 card straight made into a 3 card pair
skore[20] = 20; // 3 15 2 card straight improved to a 3 card straight
skore[21] = 12; // 3 16 2 card straight improved to a 3 card "schtraight"
skore[22] = 4; // 3 17 2 card straight improved to a 3 card bum "schtraight"
skore[23] = -6; // 4 11 2 card "schtraight" buggered up
skore[24] = 0; // 4 12 2 card "schtraight" made into a 3 card pair
skore[25] = 25; // 4 15 2 card "schtraight" improved to a 3 card straight
skore[26] = 18; // 4 16 2 card "schtraight" improved to a 3 card "schtraight"
skore[27] = 8; // 4 17 2 card "schtraight" improved to a 3 card bum "schtraight"
skore[28] = -2; // 5 11 2 card bum "schtraight" buggered up
skore[29] = 2; // 5 12 2 card bum "schtraight" made into a 3 card pair
skore[30] = 24; // 5 16 2 card bum "schtraight" improved to a 3 card "schtraight"
skore[31] = 12; // 5 17 2 card bum "schtraight" improved to a 3 card bum "schtraight"
skore[32] = 2; // 6 11 2 card dog "schtraight" buggered up
skore[33] = 4; // 6 12 2 card dog "schtraight" made into a 3 card pair
skore[34] = 16; // 6 17 2 card dog "schtraight" improved to a 3 card bum "schtraight"
skore[35] = -20; // 7 11 2 card straight flush buggered up
skore[36] = -15; // 7 12 2 card straight flush made into a 3 card pair
skore[37] = -12; // 7 13 2 card straight flush made into a 3 card flush
skore[38] = 10; // 7 15 2 card straight flush made into a 3 card straight
skore[39] = 4; // 7 16 2 card straight flush made into a 3 card "schtraight"
skore[40] = -2; // 7 17 2 card straight flush made into a 3 card bum "schtraight"
skore[41] = 40; // 7 18 2 card straight flush improved to a 3 card straight flush
skore[42] = 25; // 7 19 2 card straight flush improved to a 3 card "schtraight" flush
skore[43] = 10; // 7 20 2 card straight flush improved to a 3 card bum "schtraight" flush
skore[44] = -18; // 8 11 2 card "schtraight" flush buggered up
skore[45] = -12; // 8 12 2 card "schtraight" flush made into a 3 card pair
skore[46] = -6; // 8 13 2 card "schtraight" flush made into a 3 card flush
skore[47] = -6; // 8 15 2 card "schtraight" flush made into a 3 card straight
skore[48] = -12; // 8 16 2 card "schtraight" flush made into a 3 card "schtraight"
skore[49] = -16; // 8 17 2 card "schtraight" flush made into a 3 card bum "schtraight"
skore[50] = 45; // 8 18 2 card "schtraight" flush improved to a 3 card straight flush
skore[51] = 30; // 8 19 2 card "schtraight" flush improved to a 3 card "schtraight" flush
skore[52] = 15; // 8 20 2 card "schtraight" flush improved to a 3 card bum "schtraight" flush
skore[53] = -16; // 9 11 2 card bum "schtraight" flush buggered up
skore[54] = -9; // 9 12 2 card bum "schtraight" flush made into a 3 card pair
skore[55] = 0; // 9 13 2 card bum "schtraight" flush made into a 3 card flush
skore[56] = -8; // 9 16 2 card bum "schtraight" flush made into a 3 card "schtraight"
skore[57] = 12; // 9 17 2 card bum "schtraight" flush made into a 3 card bum "schtraight"
skore[58] = 35; // 9 19 2 card bum "schtraight" flush improved to a 3 card "schtraight" flush
skore[59] = 20; // 9 20 2 card bum "schtraight" flush improved to a 3 card bum "schtraight" flush
skore[60] = -14; // 10 11 2 card dog "schtraight" flush buggered up
skore[61] = -6; // 10 12 2 card dog "schtraight" flush made into a 3 card pair
skore[62] = 12; // 10 13 2 card dog "schtraight" flush made into a 3 card flush
skore[63] = -8; // 10 17 2 card dog "schtraight" flush made into a 3 card bum "schtraight"
skore[64] = 25; // 10 20 2 card dog "schtraight" flush improved to a 3 card bum "schtraight" flush

skore[65] = 2; // 11 21 3 card bum hand not improved upon
skore[66] = 5; // 11 22 3 card bum hand improved to a 4 card pair
skore[67] = -6; // 12 22 3 card pair not improved upon
skore[68] = 45; // 12 25 3 card pair improved to a 4 card prial
skore[69] = 40; // 12 23 3 card pair improved to a 4 card two pair
skore[70] = -12; // 13 21 3 card flush buggered up
skore[71] = -8; // 13 22 3 card flush made into a 4 card pair
skore[72] = 25; // 13 24 3 card flush improved to a 4 card flush
skore[73] = -10; // 14 25 3 card prial not improved upon
skore[74] = 100; // 14 28 3 card prial improved to an all fours
skore[75] = -20; // 15 21 3 card straight buggered up
skore[76] = -16; // 15 22 3 card straight made into a 4 card pair
skore[77] = 26; // 15 26 3 card straight improved to a 4 card straight
skore[78] = 20; // 15 27 3 card straight improved to a 4 card "schtraight"
skore[79] = -16; // 16 21 3 card "schtraight" buggered up
skore[80] = -12; // 16 22 3 card "schtraight" made into a 4 card pair
skore[81] = 30; // 16 26 3 card "schtraight" improved to a 4 card straight
skore[82] = 22; // 16 27 3 card "schtraight" improved to a 4 card "schtraight"
skore[83] = -12; // 17 21 3 card bum "schtraight" buggered up
skore[84] = -8; // 17 22 3 card bum "schtraight" made into a 4 card pair
skore[85] = 24; // 17 27 3 card bum "schtraight" improved to a 4 card "schtraight"
skore[86] = -35; // 18 21 3 card straight flush buggered up
skore[87] = -30; // 18 22 3 card straight flush made into a 4 card pair
skore[88] = -20; // 18 24 3 card straight flush made into a 4 card flush
skore[89] = -12; // 18 26 3 card straight flush made into a 4 card straight
skore[90] = -20; // 18 27 3 card straight flush made into a 4 card "schtraight"
skore[91] = 45; // 18 29 3 card straight flush improved to a 4 card straight flush
skore[92] = 36; // 18 30 3 card straight flush improved to a 4 card "schtraight" flush
skore[93] = -30; // 19 21 3 card "schtraight" flush buggered up
skore[94] = -25; // 19 22 3 card "schtraight" flush made into a 4 card pair
skore[95] = -15; // 19 24 3 card "schtraight" flush made into a 4 card flush
skore[96] = -6; // 19 26 3 card "schtraight" flush made into a 4 card straight
skore[97] = -15; // 19 27 3 card "schtraight" flush made into a 4 card "schtraight"
skore[98] = 49; // 19 29 3 card "schtraight" flush improved to a 4 card straight flush
skore[99] = 40; // 20 21 3 card bum "schtraight" flush buggered up
skore[100] = -25; // 20 22 3 card bum "schtraight" flush made into a 4 card pair
skore[101] = -20; // 20 24 3 card bum "schtraight" flush made into a 4 card flush
skore[102] = -10; // 20 26 3 card bum "schtraight" flush made into a 4 card straight
skore[103] = -10; // 20 27 3 card bum "schtraight" flush made into a 4 card "schtraight"
skore[104] = 44; // 20 30 3 card bum "schtraight" flush improved to a 4 card "schtraight" flush

skore[105] = 3; // 21 31 4 card bum hand not improved upon
skore[106] = 4; // 21 32 4 card bum hand improved to a 5 card pair
skore[107] = -7; // 22 32 4 card pair not improved upon
skore[108] = 30; // 22 35 4 card pair improved to a 5 card prial
skore[109] = 29; // 22 33 4 card pair improved to a 5 card two pair
skore[110] = -5; // 23 33 4 card two pair not improved upon
skore[111] = 90; // 23 36 4 card two pair improved to a full hand
skore[112] = -30; // 24 31 4 card flush buggered up
skore[113] = -28; // 24 32 4 card flush made into a 5 card pair
skore[114] = 50; // 24 34 4 card flush improved to a 5 card flush
skore[115] = -10; // 25 35 4 card prial not improved upon
skore[116] = 100; // 25 38 4 card prial improved to an all fours
skore[117] = 90; // 25 36 4 card prial improved to a full hand
skore[118] = -70; // 26 31 4 card straight buggered up
skore[119] = -68; // 26 32 4 card straight made into a 5 card pair
skore[120] = 80; // 26 37 4 card straight improved to a 5 card straight
skore[121] = -65; // 27 31 4 card "schtraight" buggered up
skore[122] = -63; // 27 32 4 card "schtraight" made into a 5 card pair
skore[123] = 85; // 27 37 4 card "schtraight" improved to a 5 card straight
skore[124] = 0; // 28 38 4 card all fours not buggered up but strangely not improved upon either
skore[125] = -60; // 29 31 4 card straight flush buggered up
skore[126] = -58; // 29 32 4 card straight flush made into a 5 card pair
skore[127] = 48; // 29 34 4 card straight flush made into a 5 card flush
skore[128] = 10; // 29 37 4 card straight flush made into a 5 card straight
skore[129] = 200; // 29 39 4 card straight flush improved to a 5 card STRAIGHT FLUSH bejesus!
skore[130] = -55; // 30 31 4 card "schtraight" flush buggered up
skore[131] = -53; // 30 32 4 card "schtraight" flush made into a 5 card pair
skore[132] = 46; // 30 34 4 card "schtraight" flush made into a 5 card flush
skore[133] = 15; // 30 37 4 card "schtraight" flush made into a 5 card straight
skore[134] = 250; // 30 39 4 card "schtraight" flush improved to a 5 card STRAIGHT FLUSH bejesus!

beforeski = identify_hand(before);
afterski = identify_hand(after);

// Zeroise that cocksucker
igta = 0;

// I don't have it with "switch" statements
if (beforeski == -2) igta = 0;
if (beforeski == -1)
{
if (afterski == 0) igta = skore[0];
if (afterski == 1) igta = skore[1];
if (afterski == 2) igta = skore[2];
if (afterski == 3) igta = skore[3];
if (afterski == 4) igta = skore[4];
if (afterski == 5) igta = skore[5];
if (afterski == 6) igta = skore[6];
if (afterski == 7) igta = skore[7];
if (afterski == 8) igta = skore[8];
if (afterski == 9) igta = skore[9];
if (afterski == 10) igta = skore[10];
}
if (beforeski == 0)
{
if (afterski == 11) igta = skore[11];
if (afterski == 12) igta = skore[12];
}
if (beforeski == 1)
{
if (afterski == 12) igta = skore[13];
if (afterski == 14) igta = skore[14];
}
if (beforeski == 2)
{
if (afterski == 11) igta = skore[15];
if (afterski == 12) igta = skore[16];
if (afterski == 13) igta = skore[17];
}
if (beforeski == 3)
{
if (afterski == 11) igta = skore[18];
if (afterski == 12) igta = skore[19];
if (afterski == 15) igta = skore[20];
if (afterski == 16) igta = skore[21];
if (afterski == 17) igta = skore[22];
}
if (beforeski == 4)
{
if (afterski == 11) igta = skore[23];
if (afterski == 12) igta = skore[24];
if (afterski == 15) igta = skore[25];
if (afterski == 16) igta = skore[26];
if (afterski == 17) igta = skore[27];
}
if (beforeski == 5)
{
if (afterski == 11) igta = skore[28];
if (afterski == 12) igta = skore[29];
if (afterski == 16) igta = skore[30];
if (afterski == 17) igta = skore[31];
}
if (beforeski == 6)
{
if (afterski == 11) igta = skore[32];
if (afterski == 12) igta = skore[33];
if (afterski == 17) igta = skore[34];
}
if (beforeski == 7)
{
if (afterski == 11) igta = skore[35];
if (afterski == 12) igta = skore[36];
if (afterski == 13) igta = skore[37];
if (afterski == 15) igta = skore[38];
if (afterski == 16) igta = skore[39];
if (afterski == 17) igta = skore[40];
if (afterski == 18) igta = skore[41];
if (afterski == 19) igta = skore[42];
if (afterski == 20) igta = skore[43];
}
if (beforeski == 8)
{
if (afterski == 11) igta = skore[44];
if (afterski == 12) igta = skore[45];
if (afterski == 13) igta = skore[46];
if (afterski == 15) igta = skore[47];
if (afterski == 16) igta = skore[48];
if (afterski == 17) igta = skore[49];
if (afterski == 18) igta = skore[50];
if (afterski == 19) igta = skore[51];
if (afterski == 20) igta = skore[52];
}
if (beforeski == 9)
{
if (afterski == 11) igta = skore[53];
if (afterski == 12) igta = skore[54];
if (afterski == 13) igta = skore[55];
if (afterski == 16) igta = skore[56];
if (afterski == 17) igta = skore[57];
if (afterski == 19) igta = skore[58];
if (afterski == 20) igta = skore[59];
}
if (beforeski == 10)
{
if (afterski == 11) igta = skore[60];
if (afterski == 12) igta = skore[61];
if (afterski == 13) igta = skore[62];
if (afterski == 17) igta = skore[63];
if (afterski == 20) igta = skore[64];
}
if (beforeski == 11)
{
if (afterski == 21) igta = skore[65];
if (afterski == 22) igta = skore[66];
}
if (beforeski == 12)
{
if (afterski == 22) igta = skore[67];
if (afterski == 25) igta = skore[68];
if (afterski == 23) igta = skore[69];
}
if (beforeski == 13)
{
if (afterski == 21) igta = skore[70];
if (afterski == 22) igta = skore[71];
if (afterski == 24) igta = skore[72];
}
if (beforeski == 14)
{
if (afterski == 25) igta = skore[73];
if (afterski == 28) igta = skore[74];
}
if (beforeski == 15)
{
if (afterski == 21) igta = skore[75];
if (afterski == 22) igta = skore[76];
if (afterski == 26) igta = skore[77];
if (afterski == 27) igta = skore[78];
}
if (beforeski == 16)
{
if (afterski == 21) igta = skore[79];
if (afterski == 22) igta = skore[80];
if (afterski == 26) igta = skore[81];
if (afterski == 27) igta = skore[82];
}
if (beforeski == 17)
{
if (afterski == 21) igta = skore[83];
if (afterski == 22) igta = skore[84];
if (afterski == 27) igta = skore[85];
}
if (beforeski == 18)
{
if (afterski == 21) igta = skore[86];
if (afterski == 22) igta = skore[87];
if (afterski == 24) igta = skore[88];
if (afterski == 26) igta = skore[89];
if (afterski == 27) igta = skore[90];
if (afterski == 29) igta = skore[91];
if (afterski == 30) igta = skore[92];
}
if (beforeski == 19)
{
if (afterski == 21) igta = skore[93];
if (afterski == 22) igta = skore[94];
if (afterski == 24) igta = skore[95];
if (afterski == 26) igta = skore[96];
if (afterski == 27) igta = skore[97];
if (afterski == 29) igta = skore[98];
}
if (beforeski == 20)
{
if (afterski == 21) igta = skore[99];
if (afterski == 22) igta = skore[100];
if (afterski == 24) igta = skore[101];
if (afterski == 26) igta = skore[102];
if (afterski == 27) igta = skore[103];
if (afterski == 30) igta = skore[104];
}
if (beforeski == 21)
{
if (afterski == 31) igta = skore[105];
if (afterski == 32) igta = skore[106];
}
if (beforeski == 22)
{
if (afterski == 32) igta = skore[107];
if (afterski == 35) igta = skore[108];
if (afterski == 33) igta = skore[109];
}
if (beforeski == 23)
{
if (afterski == 33) igta = skore[110];
if (afterski == 36) igta = skore[111];
}
if (beforeski == 24)
{
if (afterski == 31) igta = skore[112];
if (afterski == 32) igta = skore[113];
if (afterski == 34) igta = skore[114];
}
if (beforeski == 25)
{
if (afterski == 35) igta = skore[115];
if (afterski == 38) igta = skore[116];
if (afterski == 36) igta = skore[117];
}
if (beforeski == 26)
{
if (afterski == 31) igta = skore[118];
if (afterski == 32) igta = skore[119];
if (afterski == 37) igta = skore[120];
}
if (beforeski == 27)
{
if (afterski == 31) igta = skore[121];
if (afterski == 32) igta = skore[122];
if (afterski == 37) igta = skore[123];
}
if (beforeski == 28)
{
if (afterski == 38) igta = skore[124];
}
if (beforeski == 29)
{
if (afterski == 31) igta = skore[125];
if (afterski == 32) igta = skore[126];
if (afterski == 34) igta = skore[127];
if (afterski == 37) igta = skore[128];
if (afterski == 39) igta = skore[129];
}
if (beforeski == 30)
{
if (afterski == 31) igta = skore[130];
if (afterski == 32) igta = skore[131];
if (afterski == 34) igta = skore[132];
if (afterski == 37) igta = skore[133];
if (afterski == 39) igta = skore[134];
}




return igta;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// M A I N F U N C T I O N ////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
int card_counter;
int table[11][11];
int i, j, k, x, y, z; // Multi-purpose variables
int row, column, orig_row, orig_col, right, left, top, bottom, high, wide;
int pozzish; // The positional counter ... goes from 0 to 7

int numeric_suit_identifier;
int the5cards_before[5];
int the5cards_after[5];
int random_number;
struct card
{
int numero;
char pips[3];
char suit[2];
int card_id;
};

int compass_score[8][4];
// The compass_score array
// compass_score[n][0] holds LEGAL POSITION: 0 is illegal, 1 is legal ....
// a legal position doesn't neccessarily mean that the game will be completble,
// it merely means that it's within the 5x5 matrix
//
// compass_score[n][1] holds VERTICAL SCORE for "n"th element
// compass_score[n][2] holds HORIZONTAL SCORE for "n"th element
// compass_score[n][3] holds TOTAL SCORE for "n"th element
bool tchbdf = false; // This card has been dealt before
bool legal_position = false; // Not a legal position guv'nor, I'm afraid
int sihl = 0; //stick it here luvva, place card at pozzish(sihl) for best score...
int slog = 0;
int p = 0;
int sorted_compass_score_array[8];
int total_score[8];
int the_number_8 = 8;
int skr = 0;
int element = 0;
bool pcot = false; //Place card on table?
int place_card_here = 0; // Please can I place the card on the table here? 0=E, 1=SE, 2=S, 3=SW, 4=W, 5=NW, 6=N, 7=NE .... compass point style
bool can_do = false;
int v_row, v_column, v_place_card_here, v_card_counter, copy_of_table[11][11];

bool card_placeable = false;
bool completable = false;
bool new_card = true;
bool resolved_it = false;
int crack[26][3];
int current_card = 0;
int pozzy = 0, backstop = 0, save_row = 0, save_column = 0;
int hygh = 0, wyde = 0, q_bottom = 0, q_top = 0, q_right = 0, q_left = 0;
int vertical_hand[5], horizontal_hand[5];
int identum = 0;
int current_game = 0;
int vertical_wall[5], horizontal_wall[5];
int scoot;
bool no_walls; // Sausages
int nogtp = 50; // Number of games to play
int vertical_score[5], horizontal_score[5];
int best_score_ever = 0, worse_score_ever = 0;
int best_game_ever = 0, worst_game_ever = 0;
int score_for_this_game = 0, score_tally = 0;
int bum_hands = 0, one_pairs = 0, two_pairs = 0, flushes = 0, prials = 0, full_hands = 0, straights = 0, fours = 0, straight_flushes = 0;
float average_score_per_game = 0;
float anpg_bum_hands = 0, anpg_one_pairs = 0, anpg_two_pairs = 0, anpg_flushes = 0, anpg_prials = 0, anpg_full_hands = 0, anpg_straights = 0, anpg_fours = 0, anpg_straight_flushes = 0; // anpg = average number per game
float start_time = 0, stop_time = 0, time_taken = 0, average_time_per_game = 0;

start_time = time(NULL);

ofstream phile ("results.txt");

//Seed rand() with current time
srand(unsigned(time(NULL)));


for(current_game=1; current_game <= nogtp; current_game++)
{

// A bit of screen output just to let ya know what gives
// cout<<"Game number - "<<current_game<<" ... Card number - "<<card_counter<<endl;

card the25[25];

//Zeroise card array
for(i=0; i != 25; i++)
{
the25.numero = 0;
strcpy(the25.pips, " ");
strcpy(the25.suit, " ");
the25.card_id = 0;
}

//Zeroise table array
for(x=0; x<=10; x++)
for(y=0; y<=10; y++)
table[x][y] = 0;


for(card_counter=0; card_counter <= 24; card_counter++)
{


// A bit of screen output just to let ya know what gives
cout<<"Game number - "<<current_game<<" ... Card number - "<<card_counter+1<<endl;


random_number = RandInt(1,52); // Will be between 1 & 52

// This is the first card dealt ... no need to check to see if it's a duplicate.
if (card_counter == 0) tchbdf = false;
// This is not the first card dealt.
// Need to check to see if the RNG has dealt this card previously.
if (card_counter != 0) tchbdf = true;
while (tchbdf)
{
for(j=0; j<=card_counter; j++)
{
tchbdf = false;
if (the25[j].numero == random_number)
// Alert! Card matches previously dealt card!
{
tchbdf = true;
// Deal me a PROPER card please Random Number Generator NOT a DUPLICATE.
random_number = RandInt(1,52); // Will be between 1 & 52
break;
}
}
}
// Okay, you have a unique card, friend, now crack on ...
// Writing card to array ...
the25[card_counter].numero = random_number;

//Okay, so here are the cards:
//Hearts.....(King o' Hearts is a lover and he give her everything)
//1=2H....2=3H...3=4H...4=5H...5=6H...6=7H...7=8H...8=9H....9=10H..10=JH..11=QH..12=KH..13=AH
//Diamonds...(King o' Diamonds is a wedding ring)
//14=2D..15=3D..16=4D..17=5D..18=6D..19=7D..20=8D..21=9D...22=10D..23=JD..24=QD..25=KD..26=AD
//Clubs......(King o' Clubs makes a dollar)
//27=2C..28=3C..29=4C..30=5C..31=6C..32=7C..33=8C..34=9C...35=10C..36=JC..37=QC..38=KC..39=AC
//Spades.....(King o' Spades he's a brother, doing his own thing)
//40=2S..41=3S..42=4S..43=5S..44=6S..45=7S..46=8S..47=9S...48=10S..49=JS..50=QS..51=KS..52=AS



if ((the25[card_counter].numero % 13) == 1) strcpy(the25[card_counter].pips, " 2");
if ((the25[card_counter].numero % 13) == 2) strcpy(the25[card_counter].pips, " 3");
if ((the25[card_counter].numero % 13) == 3) strcpy(the25[card_counter].pips, " 4");
if ((the25[card_counter].numero % 13) == 4) strcpy(the25[card_counter].pips, " 5");
if ((the25[card_counter].numero % 13) == 5) strcpy(the25[card_counter].pips, " 6");
if ((the25[card_counter].numero % 13) == 6) strcpy(the25[card_counter].pips, " 7");
if ((the25[card_counter].numero % 13) == 7) strcpy(the25[card_counter].pips, " 8");
if ((the25[card_counter].numero % 13) == 8) strcpy(the25[card_counter].pips, " 9");
if ((the25[card_counter].numero % 13) == 9) strcpy(the25[card_counter].pips, "10");
if ((the25[card_counter].numero % 13) == 10) strcpy(the25[card_counter].pips, " J");
if ((the25[card_counter].numero % 13) == 11) strcpy(the25[card_counter].pips, " Q");
if ((the25[card_counter].numero % 13) == 12) strcpy(the25[card_counter].pips, " K");
if ((the25[card_counter].numero % 13) == 0) strcpy(the25[card_counter].pips, " A");
if ((the25[card_counter].numero >= 1) && (the25[card_counter].numero <= 13))
{
strcpy(the25[card_counter].suit, "H");
numeric_suit_identifier = 1;
}
if ((the25[card_counter].numero >= 14) && (the25[card_counter].numero <= 26))
{
strcpy(the25[card_counter].suit, "D");
numeric_suit_identifier = 2;
}
if ((the25[card_counter].numero >= 27) && (the25[card_counter].numero <= 39))
{
strcpy(the25[card_counter].suit, "C");
numeric_suit_identifier = 3;
}
if ((the25[card_counter].numero >= 40) && (the25[card_counter].numero <= 52))
{
strcpy(the25[card_counter].suit, "S");
numeric_suit_identifier = 4;
}

//The next line gives each dealt card a unique numeric identifier which makes array sorting
//and the identification of poker hands much easier later in the program ... See card_id.txt
//See card_id_silly.txt for my original card identification system and the associated floating point grief.
the25[card_counter].card_id = (100 * ((the25[card_counter].numero % 13) + 1)) + numeric_suit_identifier;
//This gives a nice four digit I=N=T=E=G=R=A=L identification to the card ....
//Don't **** with floats and doubles when you can stick to good old "int".
//Who needs to find out that this "3" doesn't "EQUAL" that "3" because it differs by 8.88178e-015? **** it!!!
//So yeah ... Silly me ... I was comparing "3" to "2.99999999999999111822" and expecting a true!!! Dunce!!

if (card_counter == 0)
// If it's the first card on the table then position it on the table at (5,5)
{
row = 5;
column = 5;
table[row][column] = card_counter + 1;
}
// Otherwise ...
if (card_counter >= 1)
{

//Zeroise the compass_score array for forthcoming processing
for(x=0; x<=7; x++)
{
compass_score[x][0] = 0;
compass_score[x][1] = 0;
compass_score[x][2] = 0;
compass_score[x][3] = 0;
}

orig_row = row;
orig_col = column;



//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// P O Z Z I S H L O O P /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// B E G I N /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


// Plough through the eight possible positions to determine where best to place card
for(pozzish=0; pozzish<=7; pozzish++)
// There are generally eight possible positions for the drawn card to be placed ... clockwise from "East"
//
// Position 5 Position 6 Position 7
// (r-1,c-1) (r-1,c) (r-1,c+1)
//
// Position 4 Position 0
// (r,c-1) (r,c) (r,c+1)
//
// Position 3 Position 2 Position 1
// (r+1,c-1) (r+1,c) (r+1,c+1)
{
// What you wanna do here is slog through all eight possible positions ...
// With each possible position 0 through 7 do the following ...
// 1 ... Check to see if the card can be placed on the table ...
// (i) And will not replace an already existing card in the table
// (ii) And fits within the 5 x 5 frame reference
// 2 ... If it does then score it vertically & horizontlly
// This is handled by function evaluate_hand(...)
// 3 ... When you've done this for all eight positions sort the score array
// 4 ... Starting with the highest score see if game is completable
// This is handled by function go_figure(...)
// 5 ... Place card in first available position
// 6 ... Update row & column variables accordingly




if ((pozzish == 5) || (pozzish == 6) || (pozzish == 7)) row--;
if ((pozzish == 3) || (pozzish == 2) || (pozzish == 1)) row++;
if ((pozzish == 5) || (pozzish == 4) || (pozzish == 3)) column--;
if ((pozzish == 7) || (pozzish == 0) || (pozzish == 1)) column++;


legal_position = true;

if (table[row][column] != 0) legal_position = false;

if (card_counter >= 5)
{
if ((row < 0) || (row > 10)) legal_position = false;
if ((column < 0) || (column > 10)) legal_position = false;

// Find top, bottom, left & right of table array ... longwinded
top = find_top(table);
bottom = find_bottom(table);
left = find_left(table);
right = find_right(table);

wide = right - left + 1;
high = bottom - top + 1;

if (((wide == 5) && ((column < left) || (column > right))) || ((high == 5) && ((row < top) || (row > bottom)))) legal_position = false;

}


if (legal_position)
{
// Evaluate score for vertical hand
//Zeroise the5cards_before & after arrays
for(i=0; i<=4; i++)
the5cards_before = 0;
for(i=0; i<=4; i++)
the5cards_after = 0;
j = 0;
for(i=0; i<=10; i++)
{
if (table[column] != 0)
{
the5cards_before[j] = the25[table[column]-1].card_id;
j++;
}
}
for(i=0; i<=4; i++)
the5cards_after = the5cards_before;
//And now add in the current card at the end position
the5cards_after[4] = the25[card_counter].card_id;
compass_score[pozzish][1] = evaluate_before_unt_after_hands(the5cards_before, the5cards_after);

// Evaluate score for horizontal hand
//Zeroise the5cards_before & after arrays
for(i=0; i<=4; i++)
the5cards_before = 0;
for(i=0; i<=4; i++)
the5cards_after = 0;
j = 0;
for(i=0; i<=10; i++)
{
if (table[row] != 0)
{
the5cards_before[j] = the25[table[row]-1].card_id;
j++;
}
}
for(i=0; i<=4; i++)
the5cards_after = the5cards_before;
//And now add in the current card at the end position
the5cards_after[4] = the25[card_counter].card_id;
compass_score[pozzish][2] = evaluate_before_unt_after_hands(the5cards_before, the5cards_after);

// Add 'em together
compass_score[pozzish][3] = compass_score[pozzish][1] + compass_score[pozzish][2];

}
if (!legal_position) compass_score[pozzish][0] = 0;
if (legal_position) compass_score[pozzish][0] = 1;
// Reset row & column positions
row = orig_row;
column = orig_col;
// Next!!!
}
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// P O Z Z I S H L O O P /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////// E N D ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


// Right so here we are .... and we should have an array called compass_score containing the legal_position,
// horizontal, vertical & total scores for each of the 8 possible card placement positions (E, SE, S, SW, W, NW, N & NE).
//
// compass_score[n][0] compass_score[n][1] compass_score[n][2] compass_score[n][3]
// LEGAL VERTICAL HORIZONTAL TOTAL
// POSITION? SCORE SCORE SCORE
// 0 1 5 0 5
// 1 0 0 0 0
// 2 1 -30 0 -30
// 3 0 12 13 25
// 4 1 -5 10 5
// 5 1 80 -30 50
// 6 0 -25 30 5
// 7 0 15 10 25
//
// Thus the sorted_compass_score_array[] array would contain {5, 3, 7, 0, 4, 6, 1, 2} .. or it had better know why not


// So ... we need to create this sorted_compass_score_array[] and fill it with said elements ...

// First up, we'll make a copy of just the TOTAL SCORE
for(i=0; i<=7; i++) total_score = compass_score[3];

// Now sort this total_score array ... This will fill the array in ascending order ... thus {-30, 0, 5, 5, 5, 25, 25 ,50}
sort(total_score, total_score + the_number_8);
skr = -999;
k = 0;
for(i=7; i>=0; i--)
{
if (skr != total_score)
{
for(j=0; j<=7; j++)
{
if (compass_score[j][3] == total_score)
{
sorted_compass_score_array[k] = j;
k++;
}
}
}
skr = total_score;
}




//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// S L O G L O O P ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// B E G I N /////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////





// Now slog through sorted_compass_score_array & try and assess if card is placeable ....
for(slog=0; slog<=7; slog++)
// SLOG BEGIN
{
place_card_here = sorted_compass_score_array[slog];
if (compass_score[place_card_here][0] == 0) can_do = false;
if (compass_score[place_card_here][0] == 1) can_do = true;

if ((card_counter >= 1) && (card_counter <= 4))
{
// Don't worry about checking if position valid, first 5 cards on table impossible to bungle ... Stick 'em where you like
}
if (card_counter == 5)
{
// HEREWITH VALIDATION FOR PLACEMENT OF SIXTH CARD

// This sort of checking was originally left to the jolly old
// go_figure routine but the capture of these here 17 individual
// instances of "no_can_do"-ability makes program MUCHO QUICKER.

// As you can see, the placement of the first 6 cards is quite tricky
// and can easily (without validation) lead to a mullered game and
// a dead game with only 6 cards placed on the table is something
// I am really not interested in, not even a little bit. So there.

// I think I've got all valid instances of circumstances whereby
// the placement of the 6th card leads to a dead game but I ... er
// .... do .... ahem .... I do keep finding new ones. The old program
// (the Borland C++ Builder 1.0) only listed 10 of the 17 detailed here.

// Instance 1 (loft ladder)
// x x 1 2 3 x x
// x x x x 4 5 6
// x x x x x x x
//if ((table[5][6] == 2) && (table[5][7] == 3) && (table[6][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false;

// Instance 2 (loft ladder)
// x x 1 2 4 x x
// x x x x 3 5 6
// x x x x x x x
//if ((table[5][6] == 2) && (table[6][7] == 3) && (table[5][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false;

// Instance 3 (monkey wrench)
// x x 1 2 3 4 x
// x x x x x 5 6
// x x x x x x x
//if ((table[5][6] == 2) && (table[5][7] == 3) && (table[5][8] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false;

// Instance 4 (monkey wrench)
// x x 1 2 3 4 x
// x x x x x 6 5
// x x x x x x x
//if ((table[5][6] == 2) && (table[5][7] == 3) && (table[5][8] == 4) && (table[6][9] == 5) && (place_card_here == 4)) can_do = false;

// Instance 5 (monkey wrench)
// x x 1 2 3 5 x
// x x x x x 4 6
// x x x x x x x
//if ((table[5][6] == 2) && (table[5][7] == 3) && (table[6][8] == 4) && (table[5][8] == 5) && (place_card_here == 1)) can_do = false;

// Instance 6 (monkey wrench)
// x x 1 2 3 6 x
// x x x x x 4 5
// x x x x x x x
//if ((table[5][6] == 2) && (table[5][7] == 3) && (table[6][8] == 4) && (table[6][9] == 5) && (place_card_here == 5)) can_do = false;

// Instance 7 (monkey wrench)
// x x 1 2 x x x
// x x x 3 4 5 6
// x x x x x x x
//if ((table[5][6] == 2) && (table[6][6] == 3) && (table[6][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false;

// Instance 8 (monkey wrench)
// x x x 1 2 x x
// 6 5 4 3 x x x
// x x x x x x x
//if ((table[5][6] == 2) && (table[6][5] == 3) && (table[6][4] == 4) && (table[6][3] == 5) && (place_card_here == 4)) can_do = false;

// Instance 9 (monkey wrench)
// x 1 x x
// x 3 2 x
// x x 4 x
// x x 5 x
// x x 6 x
// x x x x
//if ((table[6][6] == 2) && (table[6][5] == 3) && (table[7][6] == 4) && (table[8][6] == 5) && (place_card_here == 2)) can_do = false;

// Instance 10 (monkey wrench)
// 6 5 4 1 x x
// x x x 3 2 x
// x x x x x x
//if ((table[6][6] == 2) && (table[6][5] == 3) && (table[5][4] == 4) && (table[5][3] == 5) && (place_card_here == 4)) can_do = false;

// Instance 11 (monkey wrench)
// x 1 3 x x x
// x x 2 4 5 6
// x x x x x x
//if ((table[6][6] == 2) && (table[5][6] == 3) && (table[6][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false;

// Instance 12 (buttercup)
// x 1 x x x x
// x x 2 x x x
// x x x 3 x x
// x x x x 4 5
// x x x x 6 x
// x x x x x x
//if ((table[6][6] == 2) && (table[7][7] == 3) && (table[8][8] == 4) && (table[8][9] == 5) && (place_card_here == 3)) can_do = false;

// Instance 13 (buttercup)
// x 1 x x x x
// x x 2 x x x
// x x x 3 x x
// x x x x 4 6
// x x x x 5 x
// x x x x x x
//if ((table[6][6] == 2) && (table[7][7] == 3) && (table[8][8] == 4) && (table[9][8] == 5) && (place_card_here == 7)) can_do = false;

// Instance 14 (butterfly wings)
// x x x 1 x x
// x x x 3 2 x
// x 6 4 x x x
// x x 5 x x x
// x x x x x x
//if ((table[6][6] == 2) && (table[6][5] == 3) && (table[7][4] == 4) && (table[8][4] == 5) && (place_card_here == 5)) can_do = false;

// Instance 15 (butterfly wings)
// x x x 1 x x
// x x x 3 2 x
// x 5 4 x x x
// x x 6 x x x
// x x x x x x
//if ((table[6][6] == 2) && (table[6][5] == 3) && (table[7][4] == 4) && (table[7][3] == 5) && (place_card_here == 1)) can_do = false;

// Instance 16 (butterfly wings)
// x x x x x x
// x x x 5 x x
// x x x 4 6 x
// x 1 3 x x x
// x x 2 x x x
//if ((table[6][6] == 2) && (table[5][6] == 3) && (table[4][7] == 4) && (table[3][7] == 5) && (place_card_here == 1)) can_do = false;

// Instance 17 (butterfly wings)
// x x x x x x
// x x x 6 x x
// x x x 4 5 x
// x 1 3 x x x
// x x 2 x x x
//if ((table[6][6] == 2) && (table[5][6] == 3) && (table[4][7] == 4) && (table[4][8] == 5) && (place_card_here == 5)) can_do = false;

// And that should be it ...
// Because of the way cards are placed (E-SE-S-SW-W-NW-N-NE) the only two possible starts are ...
// x x x x
// x 1 2 x
// x x x x
// ... as above if the computer likes the match between 1st and 2nd card (ie a pair, same suit, or has straight potential) or ...
// x x x x
// x 1 x x
// x x 2 x
// x x x x
// ... as above if the computer dislikes the match between 1st and 2nd card (ie the two cards are no good for nothing) ...



// Above block restructured ... This will save a couple of picoseconds per game ...


if (table[5][6] == 2)
{
if (table[5][7] == 3)
{
if ((table[6][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false; // Instance 1
if (table[5][8] == 4)
{
if ((table[6][8] == 5) && (place_card_here == 0)) can_do = false; // Instance 3
if ((table[6][9] == 5) && (place_card_here == 4)) can_do = false; // Instance 4
}
if (table[6][8] == 4)
{
if ((table[5][8] == 5) && (place_card_here == 1)) can_do = false; // Instance 5
if ((table[6][9] == 5) && (place_card_here == 5)) can_do = false; // Instance 6
}
}
if ((table[6][8] == 5) && (place_card_here == 0))
{
if ((table[6][7] == 3) && (table[5][7] == 4)) can_do = false; // Instance 2
if ((table[6][6] == 3) && (table[6][7] == 4)) can_do = false; // Instance 7
}
if ((table[6][5] == 3) && (table[6][4] == 4) && (table[6][3] == 5) && (place_card_here == 4)) can_do = false; // Instance 8
}
else if (table[6][6] == 2)
{
if (table[6][5] == 3)
{
if (table[7][4] == 4)
{
if ((table[8][4] == 5) && (place_card_here == 5)) can_do = false; // Instance 14
if ((table[7][3] == 5) && (place_card_here == 1)) can_do = false; // Instance 15
}
if ((table[7][6] == 4) && (table[8][6] == 5) && (place_card_here == 2)) can_do = false; // Instance 9
if ((table[5][4] == 4) && (table[5][3] == 5) && (place_card_here == 4)) can_do = false; // Instance 10
}
if ((table[7][7] == 3) && (table[8][8] == 4))
{
if ((table[8][9] == 5) && (place_card_here == 3)) can_do = false; // Instance 12
if ((table[9][8] == 5) && (place_card_here == 7)) can_do = false; // Instance 13
}
if (table[5][6] == 3)
{
if (table[4][7] == 4)
{
if ((table[3][7] == 5) && (place_card_here == 1)) can_do = false; // Instance 16
if ((table[4][8] == 5) && (place_card_here == 5)) can_do = false; // Instance 17
}
if ((table[6][7] == 4) && (table[6][8] == 5) && (place_card_here == 0)) can_do = false; // Instance 11
}
}


}
if ((card_counter >= 6) && (card_counter <= 23))
{

if ((compass_score[place_card_here][0]) == 1) // Legal position
{
// Now it's time to GO FIGURE



//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// T H E G O F I G U R E R O U T I N E ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// B E G I N //////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
{



// Try and figure out if the game is completable with card at this position
// First five cards on table a doddle ... no validation required
// Sixth card validation handled elsewhere
// HEREWITH validation for 7th to 24th cards (card_counter = 6 to 23)

v_row = row;
v_column = column;

if ((place_card_here == 5) || (place_card_here == 6) || (place_card_here == 7)) v_row--;
if ((place_card_here == 3) || (place_card_here == 2) || (place_card_here == 1)) v_row++;
if ((place_card_here == 5) || (place_card_here == 4) || (place_card_here == 3)) v_column--;
if ((place_card_here == 7) || (place_card_here == 0) || (place_card_here == 1)) v_column++;


// Make a copy of the "table" array
for (i=0; i<=10; i++)
for(j=0; j<=10; j++)
copy_of_table[j] = table[j];

// Reset variables for the GO FIGURISATION validation
new_card = true;
pozzy = 0;
can_do = false;
completable = false;
resolved_it = false;
backstop = card_counter;
current_card = backstop + 1;
card_placeable = false;
no_walls = true;

// Now place card on table
copy_of_table[v_row][v_column] = current_card;
// "copy_of_table" array now contains the card previously held in the hand
// Now we need to see if game can be completed





///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// R O U T I N E T O C H E C K F O R W A L L S ///////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// B E G I N ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//// ////
//// * * x x ////
//// x x x x x x x x ////
//// x x x x x x x x x x ////
//// x x x x x x x x x x * x x x x * ////
//// x x x x x x x x x x x ////
//// ////
//// For example: "Impassable vertical walls" "Impassable horizontal walls" ////
//// * = card we wanna place ////
//// ////
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////


// Find top, bottom, left & right of table array ... longwinded
q_top = find_top(copy_of_table);
q_bottom = find_bottom(copy_of_table);
q_left = find_left(copy_of_table);
q_right = find_right(copy_of_table);

wyde = q_right - q_left + 1;
hygh = q_bottom - q_top + 1;



if ((hygh == 5) || (wyde == 5)) // Simple as that
{
// Perform routines to look for "impassable walls"

// 0 = There are no cards in this column
// 1 = A vertical wall is found in this column
// 2 = Cards are known to be in this column but there is no vertical wall to be found here
no_walls = true;
if (hygh == 5) // Check for impassable (ie 5 cards high) vertical "walls"
{
for(i=0; i<=4; i++)
vertical_wall = 0;
for(y=q_left; y<=q_right; y++)
{
scoot = y - q_left;

vertical_wall[scoot] = 1; // Assume it's a "wall"
for(x=q_top; x<=(q_top + 4); x++)
if (copy_of_table[x][y] == 0) vertical_wall[scoot] = 2; // A-ha! But it isn't a "wall"!
}
// Look for 5 card high columns sandwiched by incomplete columns @ positions 1, 2 & 3 ...
if ((vertical_wall[1] == 1) && (vertical_wall[0] == 2) && ((vertical_wall[2] == 2) || (vertical_wall[3] == 2) || (vertical_wall[4] == 2))) no_walls = false;
if ((vertical_wall[2] == 1) && ((vertical_wall[0] == 2) || (vertical_wall[1] == 2)) && ((vertical_wall[3] == 2) || (vertical_wall[4] == 2))) no_walls = false;
if ((vertical_wall[3] == 1) && (vertical_wall[4] == 2) && ((vertical_wall[0] == 2) || (vertical_wall[1] == 2) || (vertical_wall[2] == 2))) no_walls = false;
}
if ((no_walls) && (wyde == 5)) // Check for impassable (ie 5 cards wide) horizontal "walls"
{
for(i=0; i<=4; i++)
horizontal_wall = 0;
for(x=q_top; x<=q_bottom; x++)
{
scoot = x - q_top;

horizontal_wall[scoot] = 1; // Assume it's a "wall"
for(y=q_left; y<=(q_left + 4); y++)
if (copy_of_table[x][y] == 0) horizontal_wall[scoot] = 2; // A-ha! But it isn't a "wall"!
}
// Look for 5 card wide rows sandwiched by incomplete rows @ positions 1, 2 & 3 ...
if ((horizontal_wall[1] == 1) && (horizontal_wall[0] == 2) && ((horizontal_wall[2] == 2) || (horizontal_wall[3] == 2) || (horizontal_wall[4] == 2))) no_walls = false;
if ((horizontal_wall[2] == 1) && ((horizontal_wall[0] == 2) || (horizontal_wall[1] == 2)) && ((horizontal_wall[3] == 2) || (horizontal_wall[4] == 2))) no_walls = false;
if ((horizontal_wall[3] == 1) && (horizontal_wall[4] == 2) && ((horizontal_wall[0] == 2) || (horizontal_wall[1] == 2) || (horizontal_wall[2] == 2))) no_walls = false;
}
}
// I have found at least one VERY VERY NASTY and VERY VERY UNPASSABLE W-A-L-L!!!! so "NO CAN DO"
if (!no_walls) can_do = false;


///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// R O U T I N E T O C H E C K F O R W A L L S ///////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// E N D /////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

if (no_walls)
// Alright, so there are no vertical or horizontal "walls" so we'll have to use some SLOGic to establish if game completable
{

// Zeroise crack array
for (i=0; i<=25; i++)
{
crack[0] = 0;
crack[1] = 0;
crack[2] = 0;
}

// And stick position variables to crack[] array
// This crack array is a sort of tracer, a document of card placements
// It might look like this ... but then again it might not
//
// It's a sort of tracer like I said, what more can I tell you?
//
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 1 5 7
// 3 5 6
// 6 4 6
// 0 3 5 etc etc

crack[current_card][0] = place_card_here;
crack[current_card][1] = v_row;
crack[current_card][2] = v_column;


// Begin W-H-I-L-E loop
do
{
if (new_card)
{
save_row = v_row;
save_column = v_column;
}
new_card = false;
card_placeable = true;





//WE NOW NEED NEED TO CHECK TO SEE IF THE CARD IS PLACE-ABLE AT pozzy AND IF SO "card_placeable = true;" ELSE "card_placeable = false;"
// card_placeable = check_position(true, pozzy, p_rowski, p_columnski);
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
//THAT's WHAT THIS (now defunct) FUNCTION USED TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THAT'S WHY IT DON'T WORK!!!!!!
//THIS IS THE VITAL BIT OF machinery THAT IS STOPPING IT ALL FROM WORKING

if ((pozzy == 5) || (pozzy == 6) || (pozzy == 7)) v_row--;
if ((pozzy == 3) || (pozzy == 2) || (pozzy == 1)) v_row++;
if ((pozzy == 5) || (pozzy == 4) || (pozzy == 3)) v_column--;
if ((pozzy == 7) || (pozzy == 0) || (pozzy == 1)) v_column++;

// Find top, bottom, left & right of table array ... longwinded
q_top = find_top(copy_of_table);
q_bottom = find_bottom(copy_of_table);
q_left = find_left(copy_of_table);
q_right = find_right(copy_of_table);

wyde = q_right - q_left + 1;
hygh = q_bottom - q_top + 1;

if ((v_row < 0) || (v_row > 10) || (v_column < 0) || (v_column > 10)) card_placeable = false;
if (copy_of_table[v_row][v_column] != 0) card_placeable = false;
if (((wyde == 5) && ((v_column < q_left) || (v_column > q_right))) || ((hygh == 5) && ((v_row < q_top) || (v_row > q_bottom)))) card_placeable = false;



//WE NOW NEED NEED TO CHECK TO SEE IF THE CARD IS PLACE-ABLE AT pozzy AND IF SO "card_placeable = true;" ELSE "card_placeable = false;"
// card_placeable = check_position(true, pozzy, p_rowski, p_columnski);
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
//THAT's WHAT THIS (now defunct) FUNCTION USED TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THAT'S WHY IT DON'T WORK!!!!!!
//THIS IS THE VITAL BIT OF machinery THAT IS STOPPING IT ALL FROM WORKING

//Ah shaddup ... I've only gone and fecking cracked it!!!

if (card_placeable && (pozzy <= 7))
{
// Extra checking ... Never a bad idea
// if (((v_row >= crack[current_card][1] - 1) && (v_row <= crack[current_card][1] + 1))
// && ((v_column >= crack[current_card][2] - 1) && (v_column <= crack[current_card][2] + 1)))
// {
current_card++;
crack[current_card][0] = pozzy;
crack[current_card][1] = v_row;
crack[current_card][2] = v_column;
copy_of_table[v_row][v_column] = current_card;
new_card = true;
pozzy = 0;
// }
if (current_card == 25)
{
completable = true;
resolved_it = true;
}
}
else
{
v_row = save_row;
v_column = save_column;
pozzy++;
if (pozzy == 8) // Slogged through all eight positions and found none legal. We now need to backup one level ...
{
do
{
// Backup one card ... And try different pozzish
copy_of_table[save_row][save_column] = 0;
// If the following pozzy is 8 then backup again
pozzy = crack[current_card][0] + 1;
// Erase values from crack[]
crack[current_card][0] = 0;
crack[current_card][1] = 0;
crack[current_card][2] = 0;
current_card--;
if (current_card == backstop)
{
resolved_it = true;
completable = false;
}
save_row = crack[current_card][1];
save_column = crack[current_card][2];
v_row = crack[current_card][1];
v_column = crack[current_card][2];
}
while (pozzy == 8);
}
}
}
while (!resolved_it);
// End W-H-I-L-E loop
}
if (completable) can_do = true;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////// T H E G O F I G U R E R O U T I N E ///////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// E N D ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


}
}
if (can_do)
{

if ((place_card_here == 5) || (place_card_here == 6) || (place_card_here == 7)) row--;
if ((place_card_here == 3) || (place_card_here == 2) || (place_card_here == 1)) row++;
if ((place_card_here == 5) || (place_card_here == 4) || (place_card_here == 3)) column--;
if ((place_card_here == 7) || (place_card_here == 0) || (place_card_here == 1)) column++;

table[row][column] = card_counter + 1;
break; // Exit the FOR loop
}
if (slog == 7 && !can_do)
{
cout<<"Oh dear. I appear to have fucked up (like the **** I am). I'm very sorry."<<endl;
phile<<"I'm afraid I've fucked this one up. Don't blame me though, I only do what I'm told."<<endl;
exit;
}

}
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////// S L O G L O O P ////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// E N D ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
}

}


//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////// W R I T E R E S U L T S F I L E T O D I S K ////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// B E G I N //////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////




// Write table to file BEGIN




top = find_top(table);
left = find_left(table);


// According to Hoyle ...
//
// One Pair - 1
// Two Pair - 3
// Flush - 5
// Threes - 6
// Full - 10
// Straight - 12
// Fours - 16
// Straight Flush - 30




phile<<"Game number - "<<current_game<<endl<<"===============";
if (current_game >= 10) phile<<"=";
if (current_game >= 100) phile<<"=";
if (current_game >= 100) phile<<"=";
if (current_game >= 1000) phile<<"=";
if (current_game >= 10000) phile<<"=";
phile<<endl<<endl;



for(i=0; i<=4; i++)
{

for(j=0; j<=4; j++)
{



k = table[i+top][j+left] - 1;
phile<<table[i+top][j+left];
if (k >= 0)
{
phile<<"-";
if ((table[i+top][j+left] >= 1) && (table[i+top][j+left] <= 9)) phile << " ";
phile<<the25[k].pips<<the25[k].suit<<" ";
}
if (j == 4)
// List score for horizontal hand ...
{
for(x=0; x<=4; x++)
horizontal_hand[x] = the25[table[top+i][left+x]-1].card_id;
identum = identify_hand(horizontal_hand);
if (identum == 31)
{
horizontal_score = 0;
phile<<" ---- shite";
bum_hands++;
}
if (identum == 32)
{
horizontal_score = 1;
phile<<" ---- 1pair";
one_pairs++;
}
if (identum == 33)
{
horizontal_score = 3;
phile<<" ---- 2pair";
two_pairs++;
}
if (identum == 34)
{
horizontal_score = 5;
phile<<" ---- flush";
flushes++;
}
if (identum == 35)
{
horizontal_score = 6;
phile<<" ---- prial";
prials++;
}
if (identum == 36)
{
horizontal_score = 10;
phile<<" ---- fulla";
full_hands++;
}
if (identum == 37)
{
horizontal_score = 12;
phile<<" ---- run";
straights++;
}
if (identum == 38)
{
horizontal_score = 16;
phile<<" ---- fours";
fours++;
}
if (identum == 39)
{
horizontal_score = 30;
phile<<" ---- S F";
straight_flushes++;
}
}

}
phile<<endl<<endl;
}

// List scores for vertical hands ...
for(i=0; i<=4; i++)
{
for(j=0; j<=4; j++)
vertical_hand[j] = the25[table[top+j][left+i]-1].card_id;
identum = identify_hand(vertical_hand);
if (i == 0) phile<<" | | | | | "<<endl<<" | | | | | "<<endl;
if (identum == 31)
{
vertical_score = 0;
phile<<" shite ";
bum_hands++;
}
if (identum == 32)
{
vertical_score = 1;
phile<<" 1pair ";
one_pairs++;
}
if (identum == 33)
{
vertical_score = 3;
phile<<" 2pair ";
two_pairs++;
}
if (identum == 34)
{
vertical_score = 5;
phile<<" flush ";
flushes++;
}
if (identum == 35)
{
vertical_score = 6;
phile<<" prial ";
prials++;
}
if (identum == 36)
{
vertical_score = 10;
phile<<" fulla ";
full_hands++;
}
if (identum == 37)
{
vertical_score = 12;
phile<<" run ";
straights++;
}
if (identum == 38)
{
vertical_score = 16;
phile<<" fours ";
fours++;
}
if (identum == 39)
{
vertical_score = 30;
phile<<" S F ";
straight_flushes++;
}
}

score_for_this_game = 0;
for(i=0; i<=4; i++)
score_for_this_game = score_for_this_game + vertical_score + horizontal_score;

if (current_game == 1)
{
best_score_ever = score_for_this_game;
worse_score_ever = score_for_this_game;
}
else if (current_game > 2)
{
if (score_for_this_game > best_score_ever)
{
best_score_ever = score_for_this_game;
best_game_ever = current_game;
}
if (score_for_this_game < worse_score_ever)
{
worse_score_ever = score_for_this_game;
worst_game_ever = current_game;
}
}

score_tally = score_tally + score_for_this_game;

phile<<" SCORE - "<<score_for_this_game<<endl<<endl<<endl<<endl;

// Write table to file END

// END nogtp current_game loop
}

average_score_per_game = (float)score_tally/nogtp;
anpg_bum_hands = (float) bum_hands/nogtp;
anpg_one_pairs = (float) one_pairs/nogtp;
anpg_two_pairs = (float) two_pairs/nogtp;
anpg_flushes = (float) flushes/nogtp;
anpg_prials = (float) prials/nogtp;
anpg_full_hands = (float) full_hands/nogtp;
anpg_straights = (float) straights/nogtp;
anpg_fours = (float) fours/nogtp;
anpg_straight_flushes = (float) straight_flushes/nogtp;

stop_time = time(NULL);
time_taken = stop_time - start_time;
average_time_per_game = (float) time_taken/nogtp;

phile<<endl<<endl<<endl<<endl;
phile<<"Number of Games played .......................... "<<nogtp<<endl;
phile<<"Total time taken ................................ "<<time_taken<<" seconds"<<endl;
phile<<"Average time per game ........................... "<<average_time_per_game<<" seconds"<<endl<<endl;

phile<<"AVerage S-C-O-R-E per game ...................... "<<average_score_per_game<<endl;
phile<<"Worst Game Score ................................ "<<worse_score_ever<<" (Game "<<worst_game_ever<<")"<<endl;
phile<<"Best Game Score ................................. "<<best_score_ever<<" (Game "<<best_game_ever<<")"<<endl<<endl;
phile<<"Average number of Bum Hands per game ............ "<<anpg_bum_hands<<endl;
phile<<"Average number of One Pairs per game ............ "<<anpg_one_pairs<<endl;
phile<<"Average number of Two Pairs per game ............ "<<anpg_two_pairs<<endl;
phile<<"Average number of Flushes per game .............. "<<anpg_flushes<<endl;
phile<<"Average number of Prials per game ............... "<<anpg_prials<<endl;
phile<<"Average number of Full Hands per game ........... "<<anpg_full_hands<<endl;
phile<<"Average number of Straights per game ............ "<<anpg_straights<<endl;
phile<<"Average number of Fours per game ................ "<<anpg_fours<<endl;
phile<<"Average number of Straight Flushes per game ..... "<<anpg_straight_flushes<<endl<<endl<<endl;

phile<<"Thank you for playing Mister Divvy Bollocks' Poker Patience, have a nice day.";

phile.close();

//////////////////////////////////////////////////////////////////////////////////////////////////
///////////////// W R I T E R E S U L T S F I L E T O D I S K ////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// E N D ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////





}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top