#include <windows.h>
#include <stdio.h>//for sprintf
#include "resource.h"
#define WM_USER2 WM_USER+1
#define SPACING 12
#define SPADES 0
#define HEARTS 1
#define DIAMONDS 2
#define CLUBS 3

char About[] = "Apr 29, 2008\njdmcox.com";

int westx = 140;
int westspadesy = 200;
int northx = 330;
int northspadesy = 20;
int eastx = 540;
int eastspadesy = 200;
int southx = 330;
int southspadesy = 370;
int NumOfCards[4];
int x, y, z, X = 0, xLoc = 0, yLoc = 0, b = 0, c, dealer = 0, player, Player, leader = -1, tempx, BidSize[20];
int one, played = 0, EWSpades, EWHearts, EWDiamonds, EWClubs, bidder = 0, Opener, Responder, index;
int highcardpoints[4];
int length[4];
int totalpoints[4];
int dummypoints[4];
int SuitLength[4][4];//W[4], N[4], E[4], S[4];
char *AutoBid;
int bidx[] = {20, 210, 420, 210, 20, 210, 420, 210, 20, 210, 420, 210, 20, 210, 420, 210, 20, 210, 420, 210, 0};
int bidy[4][20] = {\
200,  20, 200, 370, 230,  50, 230, 400, 260,  80, 260, 430, 290, 110, 290, 460, 320, 140, 320, 490,\
 20, 200, 370, 200,  50, 230, 400, 230,  80, 260, 430, 260, 110, 290, 460, 290, 140, 320, 490, 320,\
200, 370, 200,  20, 230, 400, 230,  50, 260, 430, 260,  90, 290, 460, 290, 120, 320, 490, 320, 150,\
370, 200,  20, 200, 400, 230,  50, 230, 430, 260,  80, 260, 460, 290, 110, 290, 490, 320, 140, 320};
int pts[] = {4,3,2,1,0,0,0,0,0,0,0,0,0};
DWORD fileSize, dwBytesRead, dwBytesWritten;
char szAppName[] = "Bridge";
char SavedGames[] = "BridgeGames.txt";
char Trump;
char SuitLed = 0;
char TricksLost[] = "Tricks Lost: 0";
char Suit[] = "AKQJT98765432";
char Suits[] = "SHDC";
char Huh[] = "Huh?";
char Spade[] = " SPADE";
char Spades[] = " SPADES";
char OneSpade[] = "1 SPADE";
char TwoSpades[] = "2 SPADES";
char ThreeSpades[] = "3 SPADES";
char FourSpades[] = "4 SPADES";
char FiveSpades[] = "5 SPADES";
char SixSpades[] = "6 SPADES";
char SevenSpades[] = "7 SPADES";
char Heart[] = " HEART";
char Hearts[] = " HEARTS";
char OneHeart[] = "1 HEART";
char TwoHearts[] = "2 HEARTS";
char ThreeHearts[] = "3 HEARTS";
char FourHearts[] = "4 HEARTS";
char Diamond[] = " DIAMOND";
char Diamonds[] = " DIAMONDS";
char OneDiamond[] = "1 DIAMOND";
char TwoDiamonds[] = "2 DIAMONDS";
char ThreeDiamonds[] = "3 DIAMONDS";
char Club[] = " CLUB";
char Clubs[] = " CLUBS";
char OneClub[] = "1 CLUB";
char TwoClubs[] = "2 CLUBS";
char ThreeClubs[] = "3 CLUBS";
char NT[] = " NOTRUMP";
char OneNT[] = "1 NOTRUMP";
char TwoNT[] = "2 NOTRUMP";
char Pass[] = "PASS";
char Double[] = "DOUBLE";
char Redouble[] = "REDOUBLE";
char Points[] = "(   points)";
char Bid[20][20];
char *Cardinals[] = {" West","North"," East","South"};
char *ByCardinals[] = {" by West "," by North"," by East "," by South"};
char Buffer[11];
char Savedtime[24];
char *PreviousGames;
BOOL first = TRUE, bidding = TRUE, noopen = TRUE, oldgame = FALSE;

struct {
	int x;
	int y;
} PlayedLoc[4] = {\
	320, 245,\
	360, 215,\
	400, 245,\
	360, 275};

struct Cards {
	int Order;
	int RandomNumber;
} cards[52];

struct Hands {
	int number;
	char card[2];
};
struct Hands west[13];
struct Hands north[13];
struct Hands east[13];
struct Hands south[13];

struct Hands westcopy[13];
struct Hands northcopy[13];
struct Hands eastcopy[13];
struct Hands southcopy[13];

struct Hands Played[4];

struct Hands *ptr;

COLORREF Green = 0x30D050, Red = 0xE0;//0x14D000
HWND hwnd, hwndBid, hwndDlg, hwndList, hwndNext;
HINSTANCE hInstance;
HANDLE hFile;
HDC hdc;
PAINTSTRUCT ps;
RECT rect, bidRect;
HBRUSH hBrush;
HFONT hFont, hFont2;
SYSTEMTIME st;
FILETIME ft;
ULARGE_INTEGER ul;
SIZE Size;
LOGFONT lf, lf2;
char Sanserif[] = "Sanserif";
char Symbol[] = "Symbol";
WNDPROC pBidProc;

char* GetBid(int Player);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	MSG          msg;
	WNDCLASS     wndclass;

	wndclass.style         = CS_HREDRAW|CS_VREDRAW;
	wndclass.lpfnWndProc   = WndProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = hInstance;
	wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (hBrush = CreateSolidBrush(Green));
	wndclass.lpszMenuName  = "MENU";
	wndclass.lpszClassName = szAppName;

	if (!RegisterClass(&wndclass))
		return 0;

	hwnd = CreateWindow(szAppName, szAppName,
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, NULL, hInstance, NULL);

	hwndNext = GetWindow(hwnd, GW_HWNDNEXT);

	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

//sub-class procedure
LRESULT CALLBACK BidProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	char *p;

	if (message == WM_KEYDOWN)
	{
		p = NULL;
		switch (wParam)
		{
		case VK_ESCAPE:
			DestroyWindow(hwnd);//strange, but it works...
			break;
		case VK_RETURN:
		case VK_TAB:
			BidSize[b] = GetWindowText(hwndBid, Bid[b], 20);
			DestroyWindow(hwndBid);
			break;
		
		case '1':
			one = 1;
			break;
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
			one = 2;
			break;
		case 'S':
			if (one == 1)
				p = Spade;
			else if (one != -1)
				p = Spades;
			break;
		case 'H':
			if (one == 1)
				p = Heart;
			else if (one != -1)
				p = Hearts;
			break;
		case 'D':
			if (one == 1)
				p = Diamond;
			else if (one != -1)
				p = Diamonds;
			else if (one == -1)
				p = Double;
			break;
		case 'C':
			if (one == 1)
				p = Club;
			else if (one != -1)
				p = Clubs;
			break;
		case 'N':
			p = NT;
			break;
		case 'P':
			p = Pass;
			break;
		case 'R':
			p = Redouble;
		}

		if (p)
		{
			SendMessage(hwndBid, EM_REPLACESEL, TRUE, (LPARAM)p);
			BidSize[b] = GetWindowText(hwndBid, Bid[b], 20);
			DestroyWindow(hwndBid);
		}
	}
	return CallWindowProc(pBidProc, hwnd, message, wParam, lParam);
}

int compare1(const void *x, const void *y)
{
	if (((struct Cards*)x)->RandomNumber > ((struct Cards*)y)->RandomNumber)
		return 1;
	else if (((struct Cards*)x)->RandomNumber < ((struct Cards*)y)->RandomNumber)
		return -1;
	else
		return 0;
}

int compare2(const void *x, const void *y)
{
	if (((struct Hands*)x)->number > ((struct Hands*)y)->number)
		return 1;
	else if (((struct Hands*)x)->number < ((struct Hands*)y)->number)
		return -1;
	else
		return 0;
}

void ConvertNumbersToNames(Hands *ptr)
{
	if (ptr[x].number < 13)
		ptr[x].card[0] = 'S';
	else if (ptr[x].number < 26)
		ptr[x].card[0] = 'H';
	else if (ptr[x].number < 39)
		ptr[x].card[0] = 'D';
	else//if (ptr[x].number < 52)
		ptr[x].card[0] = 'C';
	ptr[x].card[1] = Suit[ptr[x].number % 13];
}

void SaveTime(void)
{
	x = 0;
	Savedtime[x++] = (st.wYear / 1000) + '0';
	Savedtime[x++] = ((st.wYear % 1000) / 100) + '0';
	Savedtime[x++] = ((st.wYear % 100) / 10) + '0';
	Savedtime[x++] = (st.wYear % 10) + '0';
	Savedtime[x++] = ' ';
	Savedtime[x++] = (st.wMonth / 10) + '0';
	Savedtime[x++] = (st.wMonth % 10) + '0';
	Savedtime[x++] = ' ';
	Savedtime[x++] = (st.wDay / 10) + '0';
	Savedtime[x++] = (st.wDay % 10) + '0';
	Savedtime[x++] = ' ';
	Savedtime[x++] = (st.wHour / 10) + '0';
	Savedtime[x++] = (st.wHour % 10) + '0';
	Savedtime[x++] = (st.wMinute / 10) + '0';
	Savedtime[x++] = (st.wMinute % 10) + '0';
	Savedtime[x++] = ':';
	Savedtime[x++] = (st.wSecond / 10) + '0';
	Savedtime[x++] = (st.wSecond % 10) + '0';
	Savedtime[x++] = ':';
	Savedtime[x++] = (st.wMilliseconds / 100) + '0';
	Savedtime[x++] = ((st.wMilliseconds % 100) / 10) + '0';
	Savedtime[x++] = (st.wMilliseconds % 10) + '0';
	Savedtime[x++] = '\r';
	Savedtime[x] = '\n';
	hFile = CreateFile(SavedGames, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
	SetFilePointer(hFile, 0, NULL, FILE_END);
	WriteFile(hFile, Savedtime, 24, &dwBytesWritten, NULL);
	CloseHandle(hFile);
}

void NewDeal(void)
{
//shuffle
	if (oldgame == FALSE)
		GetLocalTime(&st);
	else
		oldgame = FALSE;
	SystemTimeToFileTime(&st, &ft);
	ul.LowPart = ft.dwLowDateTime;
	ul.HighPart = ft.dwHighDateTime;
	ul.QuadPart /= 10000;//because low 4 digits are 0's
	srand(ul.LowPart);
	srand(rand());
	for (x = 0; x < 52; x++)
	{
		cards[x].Order = x;
		cards[x].RandomNumber = rand();
	}
	qsort(cards, 52, sizeof(struct Cards), compare1);
//deal
	for (x = 0, y = 0; x < 52; y++)
	{
		west[y].number = cards[x++].Order;
		north[y].number = cards[x++].Order;
		east[y].number = cards[x++].Order;
		south[y].number = cards[x++].Order;
	}
//sort hands
	qsort(west, 13, sizeof(struct Hands), compare2);
	qsort(north, 13, sizeof(struct Hands), compare2);
	qsort(east, 13, sizeof(struct Hands), compare2);
	qsort(south, 13, sizeof(struct Hands), compare2);
//convert numbers to names
	for (x = 0; x < 13; x++)
	{
		ConvertNumbersToNames(west);
		ConvertNumbersToNames(north);
		ConvertNumbersToNames(east);
		ConvertNumbersToNames(south);
	}
	for (x = 0; x < 13; x++)
		westcopy[x] = west[x];
	for (x = 0; x < 13; x++)
		northcopy[x] = north[x];
	for (x = 0; x < 13; x++)
		eastcopy[x] = east[x];
	for (x = 0; x < 13; x++)
		southcopy[x] = south[x];

	for (x = 0; x < 4; x++)
		NumOfCards[x] = 13;
	for (x = 0; x < 4; x++)
		*(WORD*)&Played[x].card = 0x2020;
}

void RotateDeal(void)
{
	dealer++;
	if (dealer == 4)
		dealer = 0;
	tempx = bidx[0];
	for (x = 0; x < 20; x++)
		bidx[x] = bidx[x+1];
	bidx[19] = tempx;
}

void GetyLoc(void)
{
	if (ptr[X].card[0] == 'S')
		yLoc = 0;
	else if (ptr[X].card[0] == 'H')
		yLoc = 1;
	else if (ptr[X].card[0] == 'D')
		yLoc = 2;
	else if (ptr[X].card[0] == 'C')
		yLoc = 3;
}

int CALLBACK PreviousGamesProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_INITDIALOG:
		hwndList = GetDlgItem(hwndDlg, IDC_LIST1);
		for (x = 0, index = 0; x < (int)fileSize; x += 24, index++)
		{
			PreviousGames[x+22] = 0;
			SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)&PreviousGames[x]);
		}
		SendMessage(hwndList, LB_SETCURSEL, index-1, 0);
		SetFocus(hwndList);
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDOK:
			index = SendMessage(hwndList, LB_GETCURSEL, 0, 0);
			EndDialog (hwndDlg, TRUE);
			return TRUE;

		case IDCANCEL:
			EndDialog (hwndDlg, FALSE);
			return FALSE;
		}
	}
	return FALSE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_CREATE:
		lf.lfHeight = -13;
		lf.lfWeight = 700;
		lf.lfItalic = 0;
		lf.lfUnderline = 0;
		lf.lfStrikeOut = 0;
		lf.lfCharSet = 0;
		lf.lfOutPrecision = 1;
		lf.lfClipPrecision = 2;
		lf.lfQuality = 1;
		lf.lfPitchAndFamily = 0x22;
		for (x = 0; Sanserif[x] != 0; x++)
			lf.lfFaceName[x] = Sanserif[x];
		lf.lfFaceName[x] = 0;

		lf2.lfHeight = -21;
		lf2.lfWeight = 400;
		lf2.lfItalic = 0;
		lf2.lfUnderline = 0;
		lf2.lfStrikeOut = 0;
		lf2.lfCharSet = 0;
		lf2.lfOutPrecision = 1;
		lf2.lfClipPrecision = 2;
		lf2.lfQuality = 1;
		lf2.lfPitchAndFamily = 0x22;
		for (x = 0; Symbol[x] != 0; x++)
			lf2.lfFaceName[x] = Symbol[x];
		lf2.lfFaceName[x] = 0;

		hFont = CreateFontIndirect(&lf);
		hFont2 = CreateFontIndirect(&lf2);

		rect.left = rect.top = 0;
		rect.right = GetSystemMetrics(SM_CXFULLSCREEN);
		rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN)+GetSystemMetrics(SM_CYCAPTION)+(2*GetSystemMetrics(SM_CYBORDER));
		MoveWindow(hwnd, (rect.right/2)-400, (rect.bottom/2)-300, 800, 600, TRUE);

		NewDeal();
		return 0;

	case WM_SETFOCUS:
		if (BidSize[b])
			SendMessage(hwnd, WM_USER2, 0, 0);
		return 0;

	case WM_USER2:
		InvalidateRect(hwnd, &rect, FALSE);
		UpdateWindow(hwnd);
		b++;
		if (b == 20)
			bidding = FALSE;
		//fall thru...
	case WM_USER:
		BidSize[b] = 0;//flag
		if (bidding)
		{
			Player = (b+dealer)%4;
			AutoBid = GetBid(Player);
			one = -1;
			hwndBid = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT", NULL,
				WS_CHILD|WS_VISIBLE,
				bidx[b], bidy[dealer][b], 100, 20,
				hwnd, (HMENU)1, hInstance, NULL);
			pBidProc = (WNDPROC)SetWindowLong(hwndBid, GWL_WNDPROC, (LONG)BidProc);//sub-class
			SetFocus(hwndBid);
			if (AutoBid)
				SetWindowText(hwndBid, AutoBid);
		}
		return 0;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_FILE_EXIT:
//			DestroyWindow(hwnd);
			SendMessage(hwnd, WM_DESTROY, 0, 0);
			break;
		case ID_NEWDEAL:
			for (x = 0; x < 20; x++)
				Bid[x][0] = 0;
			b = 0;
			SuitLed = 0;
			played = 0;
			bidder = 0;
			TricksLost[13] = '0';
			leader = -1;
			ptr = NULL;
			RotateDeal();
			first = TRUE;
			bidding = TRUE;
			noopen = TRUE;
			NewDeal();
			xLoc = yLoc = X = 0;
			GetClientRect(hwnd, &rect);
			InvalidateRect(hwnd, &rect, FALSE);
			break;
		case ID_REPLAY:
			for (x = 0; x < 20; x++)
				Bid[x][0] = 0;
			b = 0;
			SuitLed = 0;
			played = 0;
			bidder = 0;
			TricksLost[13] = '0';
			leader = -1;
			ptr = NULL;
			first = TRUE;
			bidding = TRUE;
			noopen = TRUE;
			for (x = 0; x < 4; x++)
				NumOfCards[x] = 13;
			for (x = 0; x < 4; x++)
				*(WORD*)&Played[x].card = 0x2020;
			for (x = 0; x < 13; x++)
				west[x] = westcopy[x];
			for (x = 0; x < 13; x++)
				north[x] = northcopy[x];
			for (x = 0; x < 13; x++)
				east[x] = eastcopy[x];
			for (x = 0; x < 13; x++)
				south[x] = southcopy[x];
			xLoc = yLoc = X = 0;
			GetClientRect(hwnd, &rect);
			InvalidateRect(hwnd, &rect, FALSE);
			break;
		case ID_FILE_SAVEDEAL:
			SaveTime();
			Savedtime[23] = 0;
			MessageBox(hwnd, Savedtime, SavedGames, MB_OK);
			Savedtime[23] = '\r';
			break;
		case ID_FILE_PREVIOUSDEALS:
			if (INVALID_HANDLE_VALUE != (hFile = CreateFile(SavedGames, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)))
			{
				fileSize = GetFileSize(hFile, NULL);
				if (fileSize)
				{
					PreviousGames = (char*)VirtualAlloc(NULL, fileSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
					ReadFile(hFile, PreviousGames, fileSize, &dwBytesRead, NULL) ;
					if (DialogBox(hInstance, "PREVIOUSGAMES", NULL, PreviousGamesProc))
					{
						x = index*24;
						st.wYear = ((PreviousGames[x]-'0')*1000) + ((PreviousGames[x+1]-'0')*100) + ((PreviousGames[x+2]-'0')*10) + (PreviousGames[x+3]-'0');
						x += 5;
						st.wMonth = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0');
						x += 3;
						st.wDay = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0');
						x += 3;
						st.wHour = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0');
						x += 2;
						st.wMinute = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0');
						x += 3;
						st.wSecond = ((PreviousGames[x]-'0')*10) + (PreviousGames[x+1]-'0');
						x += 3;
						st.wMilliseconds = ((PreviousGames[x]-'0')*100) + ((PreviousGames[x+1]-'0')*10) + (PreviousGames[x+2]-'0');
						oldgame = TRUE;
					}
					VirtualFree(PreviousGames, 0, MEM_RELEASE);
				}
				CloseHandle(hFile);
				if (oldgame)
				{
					DestroyWindow(hwndBid);
					SendMessage(hwnd, WM_COMMAND, ID_NEWDEAL, 0);
				}
			}
			break;
		case ID_ROTATEHANDS:
			if (!bidding)
			{
				leader = -1;
				SuitLed = 0;
				played = 0;
				ptr = NULL;
				for (x = 0; x < 4; x++)
					*(WORD*)&Played[x].card = 0x2020;
				RotateDeal();
				for (x = 0; x < 13; x++)
					west[x] = southcopy[x];
				for (x = 0; x < 13; x++)
					north[x] = westcopy[x];
				for (x = 0; x < 13; x++)
					east[x] = northcopy[x];
				for (x = 0; x < 13; x++)
					south[x] = eastcopy[x];

				for (x = 0; x < 13; x++)
					westcopy[x] = west[x];
				for (x = 0; x < 13; x++)
					northcopy[x] = north[x];
				for (x = 0; x < 13; x++)
					eastcopy[x] = east[x];
				for (x = 0; x < 13; x++)
					southcopy[x] = south[x];
				xLoc = yLoc = X = 0;
				GetClientRect(hwnd, &rect);
				InvalidateRect(hwnd, &rect, FALSE);
			}
			break;
		case HELP:
			MessageBox(hwnd, About, szAppName, MB_OK);
			break;
		}
		return 0;

	case WM_KEYDOWN:
		switch (wParam)
		{
		case VK_ESCAPE:
//			DestroyWindow(hwnd);
			SendMessage(hwnd, WM_DESTROY, 0, 0);
		case 'N':
			SendMessage(hwnd, WM_COMMAND, ID_NEWDEAL, 0);
			break;
		case 'A':
			SendMessage(hwnd, WM_COMMAND, ID_REPLAY, 0);
			break;
		case 'R':
			SendMessage(hwnd, WM_COMMAND, ID_ROTATEHANDS, 0);
			break;
		case 'H':
			SendMessage(hwnd, WM_COMMAND, HELP, 0);
		case VK_RIGHT:
			if (ptr)
			{
				if (ptr[X+1].card[0] == ptr[X].card[0])
				{
					X++;
					xLoc++;
				}
				InvalidateRect(hwnd, &rect, FALSE);
				UpdateWindow(hwnd);
			}
			break;
		case VK_LEFT:
			if (ptr)
			{
				if ((X) && (ptr[X-1].card[0] == ptr[X].card[0]))
				{
					X--;
					xLoc--;
				}
				InvalidateRect(hwnd, &rect, FALSE);
				UpdateWindow(hwnd);
			}
			break;
		case VK_DOWN:
			if (ptr)
			{
				if (yLoc < 3)
				{
					for (x = X; (x < NumOfCards[leader]) && (ptr[x].card[0] == ptr[X].card[0]); x++)
						;//go to next suit
					if (x < NumOfCards[leader])
					{
						X = x;
						xLoc = 0;
						InvalidateRect(hwnd, &rect, FALSE);
						UpdateWindow(hwnd);
					}
				}
			}
			break;
		case VK_UP:
			if (ptr)
			{
				if (yLoc != 0)
				{
					for (x = X; (x) && (ptr[x].card[0] == ptr[X].card[0]); x--)
						;
					if (ptr[x].card[0])
					{
						X = x;
						for ( ; (x) && (ptr[x-1].card[0] == ptr[X].card[0]); x--)
							;
						X = x;
						xLoc = 0;
						InvalidateRect(hwnd, &rect, FALSE);
						UpdateWindow(hwnd);
					}
				}
			}
			break;

		case VK_TAB:
			if (bidding)
				SetFocus(hwndBid);
			break;

		case VK_RETURN:
			if (bidding)
				SetFocus(hwndBid);
			if (played == -1)
			{
				InvalidateRect(hwnd, &rect, FALSE);
				UpdateWindow(hwnd);
				played = 0;
				break;
			}
			if ((bidding == FALSE) && (NumOfCards[leader]) && (ptr[X].card[0]))
			{
				if (SuitLed == 0)
				{
					SuitLed = ptr[X].card[0];
					for (x = 0; x < 4; x++)
						*(WORD*)&Played[x].card = 0x2020;
				}
				else if (ptr[X].card[0] != SuitLed)
				{
					for (x = 0; (x < NumOfCards[leader]) && (ptr[x].card[0] != SuitLed); x++)
						;
					if (x != NumOfCards[leader])
					{
						MessageBeep(MB_OK);
						break;//out of VK_RETURN if card isn't same as lead suit
					}
				}
				Played[leader] = ptr[X];
				for (x = X; x < NumOfCards[leader]; x++)//NumOfCards bug!
					ptr[x] = ptr[x+1];
				x--;
				*(DWORD*)&ptr[x].card = 0;
				NumOfCards[leader]--;
				played++;
				if (played == 4)
				{
					struct {int card; int player; int trump;} Winner;

					Winner.trump = 0;
					Winner.card = 53;
					for (x = 0; x < 4; x++)
					{
						if (Played[x].card[0] == SuitLed)
						{
							if ((Winner.trump == 0) && (Played[x].number < Winner.card))//smaller numbers are higher cards
							{
								Winner.card = Played[x].number;
								Winner.player = x;
							}
						}
						else if (Played[x].card[0] == Trump)
						{
							if ((Winner.trump == 0) || (Played[x].number < Winner.card))
							{
								Winner.card = Played[x].number;
								Winner.player = x;
								Winner.trump = 1;
							}
						}
					}
					leader = Winner.player;
					SuitLed = 0;
					if ((leader & 1) != (player & 1))
						TricksLost[13]++;
				}
				else
				{
					leader++;
					if (leader == 4)
						leader = 0;
				}
				xLoc = X = 0;
				InvalidateRect(hwnd, &rect, FALSE);
				UpdateWindow(hwnd);
			}
			break;
		}
		break;

	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
		FillRect(hdc, &rect, hBrush);
		SetBkMode(hdc, TRANSPARENT);
		sprintf(Buffer, "%s dealt", Cardinals[dealer]);
		TextOut(hdc, 0, 20, Buffer, 11);
		if (bidding)
		{
			if ((b >= 3) && (Bid[b][0] == 'P') && (Bid[b-1][0] == 'P') && (Bid[b-2][0] == 'P'))
			{
				c = b-3;
				bidding = FALSE;
				DestroyWindow(hwndBid);
			}
			highcardpoints[0] = highcardpoints[1] = highcardpoints[2] = highcardpoints[3] = 0;
			for (x = 0; x < 13; x++)
			{//get high card points
				highcardpoints[0] += pts[(west[x].number) % 13];
				highcardpoints[1] += pts[(north[x].number) % 13];
				highcardpoints[2] += pts[(east[x].number) % 13];
				highcardpoints[3] += pts[(south[x].number) % 13];
			}
			SelectObject(hdc, hFont);
			if (highcardpoints[0] > 9)
				Points[1] = (highcardpoints[0]/10)+'0';
			else
				Points[1] = ' ';
			Points[2] = (highcardpoints[0]%10)+'0';
			TextOut(hdc, westx, westspadesy+120, Points, 11);
			if (highcardpoints[1] > 9)
				Points[1] = (highcardpoints[1]/10)+'0';
			else
				Points[1] = ' ';
			Points[2] = (highcardpoints[1]%10)+'0';
			TextOut(hdc, northx, northspadesy+120, Points, 11);
			if (highcardpoints[2] > 9)
				Points[1] = (highcardpoints[2]/10)+'0';
			else
				Points[1] = ' ';
			Points[2] = (highcardpoints[2]%10)+'0';
			TextOut(hdc, eastx, eastspadesy+120, Points, 11);
			if (highcardpoints[3] > 9)
				Points[1] = (highcardpoints[3]/10)+'0';
			else
				Points[1] = ' ';
			Points[2] = (highcardpoints[3]%10)+'0';
			TextOut(hdc, southx, southspadesy+120, Points, 11);

			for (x = 0; x <= b; x++)
			{
				if (BidSize[x])
				{
					bidRect.left = bidx[x];
					bidRect.top = bidy[dealer][x];
					bidRect.right = bidRect.left + 100;
					bidRect.bottom = bidRect.top + 20;
					DrawText(hdc, Bid[x], BidSize[x], &bidRect, DT_RIGHT);
				}
			}
		}
		if (!bidding)
		{
			TextOut(hdc, 0, 40, Bid[c], BidSize[c]);
			GetTextExtentPoint32(hdc, Bid[c], BidSize[c], &Size) ;
			for (x = 0; x < 11; x++)
				if ((Bid[c][x] >= 'A') && (Bid[c][x] <= 'Z'))
					break;
			Trump = Bid[c][x];
			for (y = 0; y <= c; y++)
			{
				for (x = 0; x < 11; x++)
					if ((Bid[y][x] >= 'A') && (Bid[y][x] <= 'Z'))
						break;
				if (Bid[y][x] == Trump)
				{
					player = (y+dealer)%4;
					TextOut(hdc, Size.cx, 40, ByCardinals[player], 9);
					if (leader == -1)
					{
						leader = player+1;
						if (leader == 4)
							leader = 0;
					}
					break;
				}
			}
			EWSpades = EWHearts = EWDiamonds = EWClubs = 0;
			for (x = 0; x < NumOfCards[0]; x++)
			{
				if (west[x].card[0] == 'S')
					EWSpades++;
				else if (west[x].card[0] == 'H')
					EWHearts++;
				else if (west[x].card[0] == 'D')
					EWDiamonds++;
				else if (west[x].card[0] == 'C')
					EWClubs++;
			}
			for (x = 0; x < NumOfCards[2]; x++)
			{
				if (east[x].card[0] == 'S')
					EWSpades++;
				else if (east[x].card[0] == 'H')
					EWHearts++;
				else if (east[x].card[0] == 'D')
					EWDiamonds++;
				else if (east[x].card[0] == 'C')
					EWClubs++;
			}

			x = sprintf(Buffer, "(%i, %i, %i, %i)", EWSpades, EWHearts, EWDiamonds, EWClubs);
			TextOut(hdc, 0, 100, Buffer, x);
		}
		SelectObject(hdc, hFont2);
		TextOut(hdc, westx, westspadesy-8, "\xAA", 1);
		SetTextColor(hdc, Red);
		TextOut(hdc, westx, westspadesy+22, "\xA9", 1);
		TextOut(hdc, westx, westspadesy+52, "\xA8", 1);
		SetTextColor(hdc, 0);
		TextOut(hdc, westx, westspadesy+82, "\xA7", 1);
		TextOut(hdc, northx, northspadesy-8, "\xAA", 1);
		SetTextColor(hdc, Red);
		TextOut(hdc, northx, northspadesy+22, "\xA9", 1);
		TextOut(hdc, northx, northspadesy+52, "\xA8", 1);
		SetTextColor(hdc, 0);
		TextOut(hdc, northx, northspadesy+82, "\xA7", 1);
		TextOut(hdc, eastx, eastspadesy-8, "\xAA", 1);
		SetTextColor(hdc, Red);
		TextOut(hdc, eastx, eastspadesy+22, "\xA9", 1);
		TextOut(hdc, eastx, eastspadesy+52, "\xA8", 1);
		SetTextColor(hdc, 0);
		TextOut(hdc, eastx, eastspadesy+82, "\xA7", 1);
		TextOut(hdc, southx, southspadesy-8, "\xAA", 1);
		SetTextColor(hdc, Red);
		TextOut(hdc, southx, southspadesy+22, "\xA9", 1);
		TextOut(hdc, southx, southspadesy+52, "\xA8", 1);
		SetTextColor(hdc, 0);
		TextOut(hdc, southx, southspadesy+82, "\xA7", 1);
		SelectObject(hdc, hFont);

		for (z = 0, x = westx+20; (west[z].card[0] == 'S'); z++, x += SPACING)
			TextOut(hdc, x, westspadesy, &west[z].card[1], 1);
		for ( x = westx+20; (west[z].card[0] == 'H'); z++, x += SPACING)
			TextOut(hdc, x, westspadesy+30, &west[z].card[1], 1);
		for (x = westx+20; (west[z].card[0] == 'D'); z++, x += SPACING)
			TextOut(hdc, x, westspadesy+60, &west[z].card[1], 1);
		for (x = westx+20; (west[z].card[0] == 'C'); z++, x += SPACING)
			TextOut(hdc, x, westspadesy+90, &west[z].card[1], 1);

		for (z = 0, x = northx+20; (north[z].card[0] == 'S'); z++, x += SPACING)
			TextOut(hdc, x, northspadesy, &north[z].card[1], 1);
		for ( x = northx+20; (north[z].card[0] == 'H'); z++, x += SPACING)
			TextOut(hdc, x, northspadesy+30, &north[z].card[1], 1);
		for (x = northx+20; (north[z].card[0] == 'D'); z++, x += SPACING)
			TextOut(hdc, x, northspadesy+60, &north[z].card[1], 1);
		for (x = northx+20; (north[z].card[0] == 'C'); z++, x += SPACING)
			TextOut(hdc, x, northspadesy+90, &north[z].card[1], 1);

		for (z = 0, x = eastx+20; (east[z].card[0] == 'S'); z++, x += SPACING)
			TextOut(hdc, x, eastspadesy, &east[z].card[1], 1);
		for ( x = eastx+20; (east[z].card[0] == 'H'); z++, x += SPACING)
			TextOut(hdc, x, eastspadesy+30, &east[z].card[1], 1);
		for (x = eastx+20; (east[z].card[0] == 'D'); z++, x += SPACING)
			TextOut(hdc, x, eastspadesy+60, &east[z].card[1], 1);
		for (x = eastx+20; (east[z].card[0] == 'C'); z++, x += SPACING)
			TextOut(hdc, x, eastspadesy+90, &east[z].card[1], 1);

		for (z = 0, x = southx+20; (south[z].card[0] == 'S'); z++, x += SPACING)
			TextOut(hdc, x, southspadesy, &south[z].card[1], 1);
		for ( x = southx+20; (south[z].card[0] == 'H'); z++, x += SPACING)
			TextOut(hdc, x, southspadesy+30, &south[z].card[1], 1);
		for (x = southx+20; (south[z].card[0] == 'D'); z++, x += SPACING)
			TextOut(hdc, x, southspadesy+60, &south[z].card[1], 1);
		for (x = southx+20; (south[z].card[0] == 'C'); z++, x += SPACING)
			TextOut(hdc, x, southspadesy+90, &south[z].card[1], 1);

		if (bidding == FALSE)
		{
			TextOut(hdc, 0, 60, TricksLost, 14);

			if ((played != -1) && (played != 0))
			{
				SelectObject(hdc, hFont2);
				for (x = 0; x < 4; x++)
				{
					if (Played[x].card[0] == 'S')
						TextOut(hdc, PlayedLoc[x].x+10, PlayedLoc[x].y-8, "\xAA", 1);
					SetTextColor(hdc, Red);
					if (Played[x].card[0] == 'H')
						TextOut(hdc, PlayedLoc[x].x+10, PlayedLoc[x].y-8, "\xA9", 1);
					if (Played[x].card[0] == 'D')
						TextOut(hdc, PlayedLoc[x].x+10, PlayedLoc[x].y-8, "\xA8", 1);
					SetTextColor(hdc, 0);
					if (Played[x].card[0] == 'C')
						TextOut(hdc, PlayedLoc[x].x+10, PlayedLoc[x].y-8, "\xA7", 1);
				}
				SelectObject(hdc, hFont);

				for (x = 0; x < 4; x++)
					TextOut(hdc, PlayedLoc[x].x, PlayedLoc[x].y, &Played[x].card[1], 1);
			}

			if (played == 4)
				played = -1;
			else
			{
				SetBkMode(hdc, OPAQUE);
				if (leader == 0)
				{
					ptr = west;
					GetyLoc();
					if (west[X].card[1])
						TextOut(hdc, westx+20+(xLoc*SPACING), westspadesy+(yLoc*30), &west[X].card[1], 1);
				}
				else if (leader == 1)
				{
					ptr = north;
					GetyLoc();
					if (north[X].card[1])
						TextOut(hdc, northx+20+(xLoc*SPACING), northspadesy+(yLoc*30), &north[X].card[1], 1);
				}
				else if (leader == 2)
				{
					ptr = east;
					GetyLoc();
					if (east[X].card[1])
						TextOut(hdc, eastx+20+(xLoc*SPACING), eastspadesy+(yLoc*30), &east[X].card[1], 1);
				}
				else if (leader == 3)
				{
					ptr = south;
					GetyLoc();
					if (south[X].card[1])
						TextOut(hdc, southx+20+(xLoc*SPACING), southspadesy+(yLoc*30), &south[X].card[1], 1);
				}
				SetBkMode(hdc, TRANSPARENT);
			}
		}
		if (first)
		{
			first = FALSE;
			for (x = 0; x < NumOfCards[0]; x++)
			{
				SuitLength[0][x] = 0;
				if (west[x].card[0] == 'S')
					SuitLength[0][0]++;
				else if (west[x].card[0] == 'H')
					SuitLength[0][1]++;
				else if (west[x].card[0] == 'D')
					SuitLength[0][2]++;
				else if (west[x].card[0] == 'C')
					SuitLength[0][3]++;
			}
			for (x = 0; x < NumOfCards[1]; x++)
			{
				SuitLength[1][x] = 0;
				if (north[x].card[0] == 'S')
					SuitLength[1][0]++;
				else if (north[x].card[0] == 'H')
					SuitLength[1][1]++;
				else if (north[x].card[0] == 'D')
					SuitLength[1][2]++;
				else if (north[x].card[0] == 'C')
					SuitLength[1][3]++;
			}
			for (x = 0; x < NumOfCards[2]; x++)
			{
				SuitLength[2][x] = 0;
				if (east[x].card[0] == 'S')
					SuitLength[2][0]++;
				else if (east[x].card[0] == 'H')
					SuitLength[2][1]++;
				else if (east[x].card[0] == 'D')
					SuitLength[2][2]++;
				else if (east[x].card[0] == 'C')
					SuitLength[2][3]++;
			}
			for (x = 0; x < NumOfCards[3]; x++)
			{
				SuitLength[3][x] = 0;
				if (south[x].card[0] == 'S')
					SuitLength[3][0]++;
				else if (south[x].card[0] == 'H')
					SuitLength[3][1]++;
				else if (south[x].card[0] == 'D')
					SuitLength[3][2]++;
				else if (south[x].card[0] == 'C')
					SuitLength[3][3]++;
			}
			SendMessage(hwnd, WM_USER, 0, 0);
		}
		EndPaint(hwnd, &ps);
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		SetForegroundWindow(hwndNext);
		return 0;
	}
	return DefWindowProc(hwnd, message, wParam, lParam);
}

char* GetBid(int Player)
{
	int Twos = 0, Threes = 0, Fours = 0, Fives = 0;

	length[Player] = 0;
	dummypoints[Player] = 0;
	for (x = 0; x < 4; x++)
	{
		if (SuitLength[Player][x] > 4)
			length[Player] += SuitLength[Player][x] - 4;
		if (SuitLength[Player][x] == 0)
			dummypoints[Player] += 5;
		else if (SuitLength[Player][x] == 1)
			dummypoints[Player] += 3;
		else if (SuitLength[Player][x] == 2)
			dummypoints[Player] += 1;
	}
	totalpoints[Player] = highcardpoints[Player] + length[Player];

	if (noopen)
	{
		if (totalpoints[Player] < 13)
			return Pass;
		noopen = FALSE;
		bidder++;//opening bidder is 0
		Opener = Player;
		Responder = (Opener+2)%4;

		for (x = 0; x < 4; x++)
		{//check balanced hand
			if (SuitLength[Player][x] == 2)
				Twos++;
			else if (SuitLength[Player][x] == 3)
				Threes++;
			else if (SuitLength[Player][x] == 4)
				Fours++;
			else if (SuitLength[Player][x] == 5)
				Fives++;
		}

		if  (totalpoints[Player] >= 22)
			return TwoClubs;

		else
		{
			if (SuitLength[Player][SPADES] >= 5)
			{
				if (SuitLength[Player][HEARTS] >= 5)
				{
					if (SuitLength[Player][HEARTS] > SuitLength[Player][SPADES])
						return OneHeart;
					else
						return OneSpade;
				}
				else
					return OneSpade;
			}
			if (SuitLength[Player][HEARTS] >= 5)
				return OneHeart;

			if (((Threes == 2) && (Fives == 1) && (Twos == 1))
			 || ((Fours == 2) && (Threes == 1) && (Twos == 1))
			 || ((Fours == 1) && (Threes == 3)))
			{
				if ((highcardpoints[Player] >= 15) && (highcardpoints[Player] <= 17))
					return OneNT;
				else if ((highcardpoints[Player] == 20) || (highcardpoints[Player] == 21))
					return TwoNT;
			}

			if (SuitLength[Player][DIAMONDS] >= 4)
			{
				if (SuitLength[Player][DIAMONDS] > SuitLength[Player][CLUBS])
					return OneDiamond;
				else
					return OneClub;
			}
			if (SuitLength[Player][CLUBS] >= 3)
				return OneClub;
			if (SuitLength[Player][DIAMONDS] >= 3)
				return OneDiamond;
		}
	}
	if (bidder == 1)
	{
		bidder++;
		return Pass;
	}
	if (bidder == 2)
	{
		bidder++;
		if ((Bid[b-2][0] == '1'))//opening bid
		{
//response to 1 NT
			if (Bid[b-2][2] == 'N')
			{
				if (totalpoints[Player] <= 7)
				{
					if (SuitLength[Player][SPADES] >= 5)
						return OneSpade;
					else if (SuitLength[Player][HEARTS] >= 5)
						return OneHeart;
					else if (SuitLength[Player][DIAMONDS] >= 5)
						return OneDiamond;
					else
						return Pass;
				}
				else if ((totalpoints[Player] == 8) || (totalpoints[Player] == 9))
				{
					if ((SuitLength[Player][SPADES] >= 4) || (SuitLength[Player][HEARTS] >= 4))
						return TwoClubs;//Stayman
					else
						return TwoNT;
				}
				else//totalpoints[Player] >= 10
				{
					if (SuitLength[Player][SPADES] >= 6)
						return FourSpades;
					else if (SuitLength[Player][HEARTS] >= 6)
						return FourHearts;
					else if ((SuitLength[Player][SPADES] == 5) && (SuitLength[Player][HEARTS] < 4))
						return TwoSpades;
					else if ((SuitLength[Player][HEARTS] == 5) && (SuitLength[Player][SPADES] < 4))
						return TwoHearts;
					else if (SuitLength[Player][DIAMONDS] == 5)
						return TwoDiamonds;
					else
						return TwoClubs;//Stayman
				}
			}

//response to 1 of a suit
			if (Bid[b-2][2] == 'S')
			{
				if (SuitLength[Player][SPADES] >= 3)
				{
					if ((highcardpoints[Player]+dummypoints[Player]) <= 5)
						return Pass;
					else if ((highcardpoints[Player]+dummypoints[Player]) <= 9)
						return TwoSpades;
					else if ((highcardpoints[Player]+dummypoints[Player] == 10) || (highcardpoints[Player]+dummypoints[Player] == 11))
						return ThreeSpades;
					else
						return FourSpades;
				}
				else//if (SuitLength[Player][0] < 3)
				{
					if (totalpoints[Player] <= 5)
						return Pass;
					else if (totalpoints[Player] <= 9)
							return OneNT;
					else if ((totalpoints[Player] == 10) || (totalpoints[Player] == 11))
					{
						if ((SuitLength[Player][HEARTS] >= 4) && (SuitLength[Player][HEARTS] > SuitLength[Player][SPADES]) && (SuitLength[Player][HEARTS] > SuitLength[Player][DIAMONDS]))
							return TwoHearts;
						else if ((SuitLength[Player][DIAMONDS] >= 4) && (SuitLength[Player][DIAMONDS] > SuitLength[Player][SPADES]) && (SuitLength[Player][DIAMONDS] > SuitLength[Player][HEARTS]))
							return TwoDiamonds;
						else if ((SuitLength[Player][CLUBS] >= 4) && (SuitLength[Player][CLUBS] > SuitLength[Player][HEARTS]) && (SuitLength[Player][CLUBS] > SuitLength[Player][DIAMONDS]))
							return TwoClubs;
					}
				}
			}
			else if (Bid[b-2][2] == 'H')
			{
				if (SuitLength[Player][HEARTS] >= 3)
				{
					if ((highcardpoints[Player]+dummypoints[Player]) <= 5)
						return Pass;
					else if ((highcardpoints[Player]+dummypoints[Player]) <= 9)
						return TwoHearts;
					else if ((highcardpoints[Player]+dummypoints[Player] == 10) || (highcardpoints[Player]+dummypoints[Player] == 11))
						return ThreeHearts;
					else
						return FourHearts;
				}
				else//if (SuitLength[Player][0] < 3)
				{
					if (totalpoints[Player] <= 5)
						return Pass;
					else if (SuitLength[Player][SPADES] >= 4)
						return OneSpade;
					else if (totalpoints[Player] <= 9)
							return OneNT;
					else if ((totalpoints[Player] == 10) || (totalpoints[Player] == 11))
					{
						return Huh;
					}
				}
			}
			else if (Bid[b-2][2] == 'D')
			{
				if (totalpoints[Player] <= 5)
					return Pass;
				else
				{
					if (SuitLength[Player][SPADES] == SuitLength[Player][HEARTS])
					{
						if (SuitLength[Player][HEARTS] == 4)
							return OneHeart;
						else if (SuitLength[Player][SPADES] == 5)
							return OneSpade;
					}
					else if ((SuitLength[Player][SPADES] >= 4) && (SuitLength[Player][SPADES] > SuitLength[Player][HEARTS]))
						return OneSpade;
					else if ((SuitLength[Player][HEARTS] >= 4) && (SuitLength[Player][HEARTS] > SuitLength[Player][SPADES]))
						return OneHeart;
					if (totalpoints[Player] <= 9)
					{
						if (SuitLength[Player][DIAMONDS] >= 5)
							return TwoDiamonds;
						else
							return OneNT;
					}
					else if ((totalpoints[Player] == 10) || (totalpoints[Player] == 11))
					{
						if (SuitLength[Player][DIAMONDS] >= 5)
							return ThreeDiamonds;
					}
				}
			}
			else if (Bid[b-2][2] == 'C')
			{
				if (totalpoints[Player] <= 5)
					return Pass;
				else
				{
					if ((SuitLength[Player][SPADES] >= 4) && (SuitLength[Player][SPADES] == SuitLength[Player][HEARTS]))
					{
						if (SuitLength[Player][SPADES] == 4)
							return OneHeart;
						else if (SuitLength[Player][SPADES] == 5)
							return OneSpade;
					}
					else if ((SuitLength[Player][SPADES] >= 4) && (SuitLength[Player][SPADES] == SuitLength[Player][DIAMONDS]))
					{
						if (SuitLength[Player][SPADES] == 4)
							return OneDiamond;
						else if (SuitLength[Player][SPADES] == 5)
							return OneSpade;
					}
					else if ((SuitLength[Player][HEARTS] >= 4) && (SuitLength[Player][HEARTS] == SuitLength[Player][DIAMONDS]))
					{
						if (SuitLength[Player][HEARTS] == 4)
							return OneDiamond;
						else if (SuitLength[Player][HEARTS] == 5)
							return OneHeart;
					}
					else if ((SuitLength[Player][SPADES] >= 4) && (SuitLength[Player][SPADES] > SuitLength[Player][HEARTS]) && (SuitLength[Player][SPADES] > SuitLength[Player][DIAMONDS]))
						return OneSpade;
					else if ((SuitLength[Player][HEARTS] >= 4) && (SuitLength[Player][HEARTS] > SuitLength[Player][SPADES]) && (SuitLength[Player][HEARTS] > SuitLength[Player][DIAMONDS]))
						return OneHeart;
					else if ((SuitLength[Player][DIAMONDS] >= 4) && (SuitLength[Player][DIAMONDS] > SuitLength[Player][SPADES]) && (SuitLength[Player][DIAMONDS] > SuitLength[Player][HEARTS]))
						return OneDiamond;
					if (totalpoints[Player] <= 9)
					{
						if (SuitLength[Player][CLUBS] >= 5)
							return TwoClubs;
						else
							return OneNT;
					}
					else if ((totalpoints[Player] == 10) || (totalpoints[Player] == 11))
					{
						if (SuitLength[Player][CLUBS] >= 5)
							return ThreeClubs;
					}
				}
			}
		}
	}
	return 0;
}
