<commit_before>import _ from "underscore";
import combo from "js-combinatorics";

import Card from "./card";
import Hand from "./hand";

export default class Round {
	constructor(...pocketCards) {
		this.pocket = _.sortBy(pocketCards, p => p.sortOrder());
		this.communityCards = [];
	}

	addCommunityCards(...cards) {
		this.communityCards = this.communityCards.concat(...cards);
	}

	getPlayerCurrentBestHand() {
		let combos = combo.combination(this.getSeenCards(), 5);
		return _.chain(combos.toArray())
				.map(h => new Hand(...h))
				.map(h => ({ hand: h, score: h.getScore() }))
				.max(h => h.score.points)
				.value();
	}

	getPlayerImprovedHands(numExtraCards) {
		let seen = this.getSeenCards();
		let unseen = this.getUnseenCards();
		let currentBest = this.getPlayerCurrentBestHand();

		let improved = [];

		let counter = 0;

		for(let extras of pickIndices(10, 2)) {
			counter++;
			//let combinedSet = seen.concat(..._.map(extras, e => unseen[e]));
			//improved.push(1);
/*			for(let handSet of pickIndices(combinedSet.length, 5)) {
				let hand = new Hand(..._.map(handSet, i => combinedSet[i]));
				let handScore = hand.getScore();
				if(handScore.points > currentBest.points) {
					improved.push({ hand: hand, score: handScore });
				}
			}*/
		}

		console.log(counter);

		//console.log(improved);
	}

	getPossibleCurrentBetterHands() {

	}

	getPossibleChasingHands(numExtraCards) {

	}

	getSeenCards() {
		return this.communityCards.concat(...this.pocket);
	}

	getUnseenCards() {
		return _.without(Card.types, ...this.getSeenCards());
	}
}

function* pickIndices(count, n) {
	console.log(count);
	let indices = [];
	_.range(n).forEach(x => indices.push(n - (x + 1)));

	for(;;) {
		var y = indices.slice(0);
		console.log(y);
		yield y;

		indices[0]++;
		for(;;) {
			let stable = true;
			for(let i = 0; i < n; i++) {
				if(indices[i] >= count) {
					if(i === n - 1) { return; }
					indices[i + 1]++;
					stable = false;
				}
			}
			for(let i = n-1; i >= 0; i--) {
				if(indices[i] >= count) {
					if(i === n - 1) { return; }
					indices[i] = indices[i + 1] + 1;
					stable = false;
				}
			}

			if(stable) { break; }
		}
	}
}<commit_msg>Now using combinations to find better hands<commit_after>import _ from "underscore";
import combo from "js-combinatorics";

import Card from "./card";
import Hand from "./hand";

export default class Round {
	constructor(...pocketCards) {
		this.pocket = _.sortBy(pocketCards, p => p.sortOrder());
		this.communityCards = [];
	}

	addCommunityCards(...cards) {
		this.communityCards = this.communityCards.concat(...cards);
	}

	getPlayerCurrentBestHand() {
		let combos = combo.combination(this.getSeenCards(), 5);
		return _.chain(combos.toArray())
				.map(h => new Hand(...h))
				.map(h => ({ hand: h, score: h.getScore() }))
				.max(h => h.score.points)
				.value();
	}

	getPlayerImprovedHands(numExtraCards) {
		let seen = this.getSeenCards();
		let unseen = this.getUnseenCards();
		let currentBest = this.getPlayerCurrentBestHand();

		let improved = [];

		for(let extras of getCombinations(unseen, 2)) {
			let combinedSet = seen.concat(...extras);
			for(let handSet of getCombinations(combinedSet, 5)) {
				let hand = new Hand(...handSet);
				let handScore = hand.getScore();
				if(handScore.points > currentBest.score.points) {
					improved.push({ hand: hand, score: handScore });
				}
			}
		}

		return improved;
	}

	getPossibleCurrentBetterHands() {

	}

	getPossibleChasingHands(numExtraCards) {

	}

	getSeenCards() {
		return this.communityCards.concat(...this.pocket);
	}

	getUnseenCards() {
		return _.without(Card.types, ...this.getSeenCards());
	}
}

function* getCombinations(list, n) {
	let indices = [];
	_.range(n).forEach(x => indices.push(n - (x + 1)));

	for(;;) {
		yield _.map(indices, i => list[i]);

		indices[0]++;
		for(;;) {
			let stable = true;
			for(let i = 0; i < n; i++) {
				if(indices[i] >= list.length) {
					if(i === n - 1) { return; }
					indices[i + 1]++;
					stable = false;
				}
			}
			for(let i = n-1; i >= 0; i--) {
				if(indices[i] >= list.length) {
					if(i === n - 1) { return; }
					indices[i] = indices[i + 1] + 1;
					stable = false;
				}
			}

			if(stable) { break; }
		}
	}
}
{'fraction_non_alphanumeric': 0.18248175182481752, 'fraction_numerical': 0.0072992700729927005, 'mean_word_length': 3.0611854684512427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544405', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1558, 'n_words': 320}