예제 #1
0
TEST (LayoutSamplingTest, GenerateSimpleLayout) {
	for (uint32_t iter = 0; iter < 100; iter++) {
		GameState gameState = GenLayout();
		vector<shared_ptr<IPlayer>> players = {
			CreatePlayer("random", nullptr),
			CreatePlayer("random", nullptr),
			CreatePlayer("random", nullptr)
		};
		GameManager manager(players);
		manager.SetNewLayout(gameState, /*openCards=*/true);
		manager.PlayForNMoves(15);
		auto sampler = LayoutSampler(manager.GetState(), gameState.GetFirstPlayer(), 0);
		auto newLayouts = sampler.DoSample(5, /*playMoveHistory=*/false);
		for (const auto& newLayout : newLayouts) {
			// 2. If suit is out for some player, cards of suit in sampled layout must be the same
			// 3. Moves in history must be in the player hands
			ASSERT_EQ(newLayout.Hand(0).Size(), 10);
			ASSERT_EQ(newLayout.Hand(1).Size(), 10);
			ASSERT_EQ(newLayout.Hand(2).Size(), 10);
			ASSERT_EQ(newLayout.Hand(0).Add(newLayout.Hand(1).Add(newLayout.Hand(2))).Size(), 30);

			for (uint32_t player = 0; player < 3; player++) {
				for (Suit suit = (Suit)0; (uint8_t)suit < 4; suit = (Suit)((uint8_t)suit + 1)) {
					if (manager.GetState().IsSuitOut(player, suit)) {
						ASSERT_EQ(newLayout.Hand(player).GetSubsetOfSuit(suit), gameState.Hand(player).GetSubsetOfSuit(suit));
					}
				}
			}

			for (const auto moveData : manager.GetState().GetMoveHistory()) {
				ASSERT_TRUE(newLayout.Hand(moveData.player_).IsInSet(moveData.card_));
			}
		}
	}
}
예제 #2
0
static FeaturesSet CalcPlayFeatures(const GameState& playerView, Card move, uint32_t ourHero) {
	static PlayFeaturesRegistry reg;

	FeaturesSet result = reg.CreateEmptySet();
	CardsSet knownCards = playerView.GetKnownCards();
	auto setCardF = [&](FeaturesRange& fr, Card c, float value) {
		result.Set(fr, GetCardBit(c), value);
	};

	for (Suit s = Spades; s != NoSuit; s = (Suit)(uint32_t(s) + 1)) {
		uint32_t realRank = 0;
		for (Rank r = 0; r < 8; ++r) {
			auto card = MakeCard(s, r);
			auto cardForFeature = card; //MakeCard(s, realRank);
			if (IsCardCovers(card, playerView.OnDesk(playerView.PlayerWithGreaterCard()), playerView.GetTrump())) {
				setCardF(reg.IsGreaterCard, cardForFeature, 1.0f);
			}
			setCardF(reg.IsValidMove, cardForFeature, playerView.IsValidMove(card) ? 1.0f : 0.0f);
			for (uint32_t i = 0, player = playerView.GetFirstPlayer(); i < 2; player = (player + 1) % 3, i++) {
				if (playerView.OnDesk(player) == card) {
					setCardF(reg.CardsOnDesk[i], cardForFeature, 1.0f);
				}
			}
			if (playerView.Hand(ourHero).IsInSet(card)) {
				setCardF(reg.PlayerCards[0], cardForFeature, 1.0f);
			}
			if (playerView.Out().IsInSet(card)) {
				setCardF(reg.NotInGameCards, cardForFeature, 1.0f);
			}
			realRank++;
		}
	}

	return result;
}