Exemple #1
0
function should_challenge (data) {
	var hand_total = 0;
	for (var i = 0; i < data.state.hand.length; i++) {
		hand_total = hand_total + data.state.hand[i];
	}
	if (hand_total > (data.state.hand.length * 7)) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});	
	}
	else {
		find_min(data, function(min) {
			kallisti.send({
				type: 'move',
				request_id: data.request_id,
				response: {
						type: 'play_card',
						card: data.state.hand[min]
					}
			});	
		});
	}
}
Exemple #2
0
		find_min(data, function(min) {
			kallisti.send({
				type: 'move',
				request_id: data.request_id,
				response: {
						type: 'play_card',
						card: data.state.hand[min]
					}
			});	
		});
Exemple #3
0
			find_min(data, function (min_pos){
				console.log("Starting hand, playing min: " + data.state.hand[min_pos]);
				console.log("game id is " + data.state.game_id);
				kallisti.send({
					type: 'move',
					request_id: data.request_id,
					response: {
						type: 'play_card',
						card: data.state.hand[min_pos]
					}
				});
			});
Exemple #4
0
						play_min_to_win(data, function (to_play) {
							console.log("Playing min to win: Opp = " + data.state.card + ", me = " + data.state.hand[to_play]);
							console.log("game id is " + data.state.game_id);
							kallisti.send({
								type: 'move',
								request_id: data.request_id,
								response: {
									type: 'play_card',
									card: data.state.hand[to_play]
								}
							});
						});
Exemple #5
0
kallisti.on('challenge_offered', function(data) {
	var hand_total = 0;
	for (var i = 0; i < data.state.hand.length; i++) {
		hand_total = hand_total + data.state.hand[i];
	}
	if (data.state.your_tricks >= data.state.their_tricks && data.state.hand.length === 1 && data.state.hand[0] === 13) { //if i only have 1 card and I get 13, must accept.
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'accept_challenge'
			}
		});
	}
	else if (data.state.their_points === 9) { //if they have 9 pts and they challenge me, I must accept...
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'accept_challenge'
			}
		});
	}
	else if (data.state.your_tricks >= data.state.their_tricks && data.state.hand.length > 2 && hand_total > data.state.hand.length * 10) { //If there is more than 2 card and average > 10, accept
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'accept_challenge'
			}
		});
	}
	else if (data.state.your_tricks >= data.state.their_tricks && data.state.hand.length === 2 && hand_total > data.state.hand.length * 11) { //If there exactly 2 card and average > 11, accept
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'accept_challenge'
			}
		});
	}
	else if (data.state.your_tricks >= data.state.their_tricks && (data.state.their_points - data.state.your_points > 6) && hand_total > data.state.hand.length * 9) { //If there exactly 2 card and average > 11, accept
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'accept_challenge'
			}
		});
	}
	else {
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'reject_challenge'
			}
		});
	}
});
Exemple #6
0
kallisti.on('request_card', function(data) {
	var hand_total = 0;
	for (var i = 0; i < data.state.hand.length; i++) {
		hand_total = hand_total + data.state.hand[i];
	}
	///Issue challenge if I have 1-4 card and average = 13
	if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && hand_total > (data.state.hand.length * 13) && data.state.hand.length < 5) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	///Issue challenge if I have 5 cards and have 13, 13, 13, 13, 12
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && hand_total > (data.state.hand.length * 12) && data.state.hand.length === 5) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	////If I am up by a lot and my average in hand is 10 and there are more than 3,4,5 cards in hand, issue challenge.
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && hand_total > (data.state.hand.length * 10) && data.state.hand.length > 2 && (data.state.your_points - data.state.their_points) > 5) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	////If i have 9 points and my chance of winning is good, issue a challenge
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && data.state.your_points === 9 && hand_total > (data.state.hand.length * 10)) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	///Issue challenge if they are going to win and I am not close
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && data.state.your_points < 8 && data.state.their_points === 9) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	///Issue challenge if they are winning by a lot and my chances are good
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge &&  data.state.their_points - data.state.your_points > 4 && hand_total > (data.state.hand.length * 9)) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	
	////Issue challenge if no one is very close to winning and I have a good chance of winning: card average >= 9
	else if (data.state !== undefined && data.state.your_tricks >= data.state.their_tricks && data.state.can_challenge && hand_total > (data.state.hand.length * 9) && data.state.hand.length > 2 && (data.state.your_points - data.state.their_points < 3)) { //Modify challenge metric....should use mean, mode, median (statistics)
		kallisti.send({
			type: 'move',
			request_id: data.request_id,
			response: {
				type: 'offer_challenge'
			}
		});
	}
	else {
		if (data.state !== undefined && data.state.card !== undefined) { //There is a card on table
			if (data.state.card === 13) { //Oppo plays 13, will never win. Play min.
				find_min(data, function (min_pos) {
					console.log("oppo play 13, give up, playing " + data.state.hand[min_pos]);
					console.log("game id is " + data.state.game_id);
					kallisti.send({
						type: 'move',
						request_id: data.request_id,
						response: {
							type: 'play_card',
							card: data.state.hand[min_pos]
						}
					});
				});
			}
			else {
				find_max (data, function (max_pos){
					if (data.state.hand[max_pos] <= data.state.card) { //play min if card on table is same or greater than my max <-- give up
						console.log("opp: " + data.state.card + " vs my max: " + data.state.hand[max_pos] + ", giving up");
						find_min(data, function (min_pos){
							console.log('playing '+data.state.hand[min_pos]);
							console.log("game id is " + data.state.game_id);
							kallisti.send({
								type: 'move',
								request_id: data.request_id,
								response: {
									type: 'play_card',
									card: data.state.hand[min_pos]
								}
							});
						});
					}
					else { //Can win, so play min to win
						play_min_to_win(data, function (to_play) {
							console.log("Playing min to win: Opp = " + data.state.card + ", me = " + data.state.hand[to_play]);
							console.log("game id is " + data.state.game_id);
							kallisti.send({
								type: 'move',
								request_id: data.request_id,
								response: {
									type: 'play_card',
									card: data.state.hand[to_play]
								}
							});
						});
					}
				});
			}
		}
		else { //if there's no card on table, just play min <---- this is a tricky one...final fix
			find_min(data, function (min_pos){
				console.log("Starting hand, playing min: " + data.state.hand[min_pos]);
				console.log("game id is " + data.state.game_id);
				kallisti.send({
					type: 'move',
					request_id: data.request_id,
					response: {
						type: 'play_card',
						card: data.state.hand[min_pos]
					}
				});
			});
		}
	}
	
});