// BJ_Switch score table. http://www.thewizardofodds.com/game/bj_switch.html
var bj_score = new Array(34);
bj_score[0] = new Array(-0.2688, -0.1884, -0.1531, -0.1165, -0.087, -0.1571, -0.2232, -0.2992, -0.3965, -0.5188);	// 5
bj_score[1] = new Array(-0.2821, -0.2007, -0.1647, -0.1275, -0.0989, -0.1882, -0.251, -0.3241, -0.4179, -0.5358);	// 6
bj_score[2] = new Array(-0.2517, -0.1703, -0.1352, -0.0998, -0.0569, -0.1165, -0.2551, -0.326, -0.4091, -0.545);	// 7
bj_score[3] = new Array(-0.1649, -0.0859, -0.0535, -0.0218, 0.0288, 0.0334, -0.1054, -0.2527, -0.3466, -0.4678);	// 8
bj_score[4] = new Array(-0.0692, 0.0072, 0.0365, 0.0654, 0.143, 0.122, 0.0519, -0.0956, -0.2584, -0.3774);	// 9
bj_score[5] = new Array(0.0561, 0.2162, 0.2716, 0.3269, 0.4016, 0.2632, 0.1661, 0.0722, -0.0947, -0.2761);	// 10
bj_score[6] = new Array(0.1678, 0.3247, 0.3767, 0.4291, 0.4934, 0.3336, 0.2301, 0.1152, -0.0078, -0.2334);	// 11
bj_score[7] = new Array(-0.3549, -0.3005, -0.2791, -0.2575, -0.2308, -0.2463, -0.3028, -0.3691, -0.4557, -0.5666);	// 12
bj_score[8] = new Array(-0.4009, -0.3488, -0.3057, -0.26, -0.2407, -0.3001, -0.3526, -0.4142, -0.4946, -0.5976);	// 13
bj_score[9] = new Array(-0.4437, -0.3488, -0.3057, -0.26, -0.2407, -0.3501, -0.3988, -0.456, -0.5307, -0.6263);	// 14
bj_score[10] = new Array(-0.4442, -0.3488, -0.3057, -0.26, -0.2407, -0.3965, -0.4418, -0.4949, -0.5642, -0.653);	// 15
bj_score[11] = new Array(-0.4442, -0.3488, -0.3057, -0.26, -0.2407, -0.4396, -0.4816, -0.531, -0.5953, -0.6778);	// 16
bj_score[12] = new Array(-0.3044, -0.2138, -0.1752, -0.1378, -0.0753, -0.1714, -0.4422, -0.4794, -0.5166, -0.6701);	// 17
bj_score[13] = new Array(-0.0297, 0.0517, 0.0812, 0.1067, 0.1964, 0.3349, 0.0457, -0.2394, -0.2938, -0.4085);	// 18
bj_score[14] = new Array(0.2349, 0.3078, 0.3285, 0.3467, 0.409, 0.5514, 0.5336, 0.2313, -0.0709, -0.1469);	// 19
bj_score[15] = new Array(-0.0851, -0.0194, 0.0106, 0.0408, 0.0757, 0.0767, 0.0114, -0.0763, -0.2095, -0.3689);	// A,2
bj_score[16] = new Array(-0.1199, -0.0429, -0.012, 0.0193, 0.0531, 0.0355, -0.0278, -0.1123, -0.2402, -0.3934);	// A,3
bj_score[17] = new Array(-0.1432, -0.0648, -0.033, -0.0006, 0.0321, -0.0053, -0.0666, -0.148, -0.2705, -0.4177);	// A,4
bj_score[18] = new Array(-0.1647, -0.0851, -0.0525, -0.0192, 0.0126, -0.0456, -0.1048, -0.1831, -0.3004, -0.4416);	// A,5
bj_score[19] = new Array(-0.1447, -0.0653, -0.0333, -0.0014, 0.0821, 0.0029, -0.1204, -0.1932, -0.299, -0.4563);	// A,6
bj_score[20] = new Array(-0.0297, 0.0517, 0.0812, 0.1096, 0.2075, 0.3349, 0.0457, -0.1451, -0.2508, -0.3968);	// A,7
bj_score[21] = new Array(0.2349, 0.3078, 0.3285, 0.3467, 0.409, 0.5514, 0.5336, 0.2313, -0.0709, -0.1469);	// A,8
bj_score[22] = new Array(0.4885, 0.5537, 0.5664, 0.5775, 0.6169, 0.7086, 0.7315, 0.7021, 0.3827, 0.1147);	// A,9
bj_score[23] = new Array(1, 1, 1, 1, 1, 1, 1, 1, 0.9231, 0.6923);	// A,10
bj_score[24] = new Array(0.1678, 0.3247, 0.3767, 0.4291, 0.4934, 0.3336, 0.2301, 0.1152, -0.0925, -0.3442);	// A,A
bj_score[25] = new Array(-0.2546, -0.1755, -0.1407, -0.0972, -0.0063, -0.1128, -0.1957, -0.2744, -0.3752, -0.5018);	// 2,2
bj_score[26] = new Array(-0.2821, -0.2007, -0.1647, -0.1264, -0.0413, -0.1701, -0.251, -0.3241, -0.4179, -0.5358);	// 3,3
bj_score[27] = new Array(-0.1649, -0.0859, -0.0535, -0.0218, 0.0288, 0.0334, -0.1054, -0.2527, -0.3466, -0.4678);	// 4,4
bj_score[28] = new Array(0.0561, 0.2162, 0.2716, 0.3269, 0.4016, 0.2632, 0.1661, 0.0722, -0.0947, -0.2761);	// 5,5
bj_score[29] = new Array(-0.3549, -0.3005, -0.2791, -0.1879, -0.1013, -0.2463, -0.3028, -0.3691, -0.4557, -0.5666);	// 6,6
bj_score[30] = new Array(-0.4437, -0.293, -0.2085, -0.1236, -0.0084, -0.1892, -0.3988, -0.456, -0.5307, -0.6263);	// 7,7
bj_score[31] = new Array(-0.2968, -0.0992, -0.0211, 0.0551, 0.1806, 0.1681, -0.1596, -0.5014, -0.5953, -0.6778);	// 8,8
bj_score[32] = new Array(-0.0297, 0.0517, 0.1047, 0.1723, 0.2665, 0.3349, 0.1207, -0.1838, -0.2938, -0.4085);	// 9,9
bj_score[33] = new Array(0.4885, 0.5537, 0.5664, 0.5775, 0.6169, 0.7086, 0.7315, 0.7021, 0.3827, 0.1147);	// 10,10

// Calculate scores for switched and non-switched hands.
function calculate(){
	cardDL = Number(document.cardForm.dealer.value);		// Dealer's card value = column index
	cardP1 = Number(document.cardForm.card1.value);			// Player's card1 value
	cardP2 = Number(document.cardForm.card2.value);			// Player's card2 value
	cardP3 = Number(document.cardForm.card3.value);			// Player's card3 value
	cardP4 = Number(document.cardForm.card4.value);			// Player's card4 value

	// Score for non-switched hands
	hand1NS = bj_score[rowIndex(cardP1, cardP3)][cardDL];
//	document.write("Non-switch hand1 score: " + hand1NS + "<br>");
	hand2NS = bj_score[rowIndex(cardP2, cardP4)][cardDL];
//	document.write("Non-switch hand2 score: " + hand2NS + "<br>");
	scoreNS = hand1NS + hand2NS;
//  document.write("non-switch score: " + scoreNS + "<br>")

	// Score for switched hands
	hand1SW = bj_score[rowIndex(cardP1, cardP4)][cardDL];
//	document.write("Switch hand1 score: " + hand1SW + "<br>");
	hand2SW = bj_score[rowIndex(cardP2, cardP3)][cardDL];
//	document.write("Switch hand2 score: " + hand2SW + "<br>");
	scoreSW = hand1SW + hand2SW;
//	document.write("switch score: " + scoreSW + "<br>")

  // Make decision
	if(scoreNS >= scoreSW)
    document.cardForm.answer.value = "No";
  else
		document.cardForm.answer.value = "Yes";
}

// Get row index given 2 player cards
function rowIndex(c1, c2){
	var ri = c1 + c2 - 1;
	if(c1 == c2){ ri = c1 + 25; }
	if(c1 == 9){ ri = c2 + 15; }
	if(c2 == 9){ ri = c1 + 15; }
//	document.write("row index for card " + c1 + " and " + c2 + ": " + ri + "<br>");
	return ri;
}

