Beispiel #1
0
E3StateWidget::E3StateWidget(const E3Config* _config, const E3State* _state){
	if(_config)
		this->config = new E3Config(*_config);
	else
		this->config = new E3Config();

	if(_state)
		this->state = new E3State(*_state);
	else
		// TODO: may be state should remember its config?!
		this->state = new E3State(this->config);

	this->d_state = new E3State();

	Glib::RefPtr<Gtk::Builder> b = Gtk::Builder::create_from_file(UI_FILE_STATE);

	Gtk::Widget* root;
	b->get_widget("root", root);

	b->get_widget("entry_e", entry_e);
	b->get_widget("entry_phi", entry_phi);
	b->get_widget("entry_a", entry_a);

	b->get_widget("button_apply", button_apply);

	this->add(*root);

	state_to_widget();
	if(!this->state->simulated())
		generateState();

	// signals
	entry_e->signal_changed().connect(sigc::mem_fun(*this, &E3StateWidget::edit_anything_cb));
	entry_phi->signal_changed().connect(sigc::mem_fun(*this, &E3StateWidget::edit_anything_cb));
	entry_a->signal_changed().connect(sigc::mem_fun(*this, &E3StateWidget::edit_anything_cb));

	button_apply->signal_clicked().connect(sigc::mem_fun(*this, &E3StateWidget::on_apply_cb));
}
Beispiel #2
0
void E3StateWidget::on_apply_cb(){
	generateState();
	m_signal_changed.emit();
}
Beispiel #3
0
void E3StateWidget::widget_to_state(){
	if(!state->simulated()){
		generateState();
	}
}
Beispiel #4
0
int main()
{
	int i, j, currentPlayer;
	int handPos, choice1, choice2, choice3, bonus;
	int failFlag;
	choice1 = choice2 = choice3 = bonus = 0;
	struct gameState state, controlState;

	srand(time(NULL));

	printf("Beginning Village Random Testing\n\n");

	//Test Expected Results
	for(i = 0; i < NUM_TESTS; i++)
	{
		//Generate randomized game state, copy to a control, and call cardEffect
		handPos = generateState(&state);
		memcpy(&controlState, &state, sizeof(struct gameState));
		
		//cardEffect(village, choice1, choice2, choice3, &state, handPos, &bonus);
		currentPlayer = state.whoseTurn;
		playVillage(&state, currentPlayer, handPos);
		
		failFlag = 0;
		
		printf("------------ %d ------------\n", i);

		//Test hand count
		
		//Expected: unchanged
		if(state.handCount[currentPlayer] != controlState.handCount[currentPlayer])
		{
			failFlag = 1;
			printf("FAIL: Hand Count | Expected: %d | Actual: %d\n", controlState.handCount[currentPlayer], state.handCount[currentPlayer]);
		}

		//Test deck count
		//Expected: decrement by one
		if(controlState.deckCount[currentPlayer] - 1 < state.deckCount[currentPlayer])
		{
			failFlag = 1;
			printf("FAIL: Deck Count | Expected: %d or less | Actual: %d\n", controlState.handCount[currentPlayer] - 1, state.deckCount[currentPlayer]);
		}

		//Test action count
		//Expected: increment by one
		if(controlState.numActions + 1 != state.numActions)
		{
			failFlag = 1;
			printf("FAIL: Action count | Expected: %d | Actual: %d\n", controlState.numActions + 1, state.numActions);
		}


		//Test other players' hand count and deck count
		//Expected: unchanged
		for(j = 0; j < state.numPlayers; j++)
		{
			if(j != currentPlayer)
			{
				if(state.handCount[j] != controlState.handCount[j])
				{
					failFlag = 1;
					printf("FAIL: Player %d's Hand Count | Expected: %d | Actual: %d\n", j, controlState.handCount[j], state.handCount[j]);
				}
				if(state.deckCount[j] != controlState.deckCount[j])
				{
					failFlag = 1;
					printf("FAIL: Player %d's Deck Count | Expected: %d | Actual: %d\n", j, controlState.deckCount[j], state.deckCount[j]);
				}

			}
		}

		//Test supply piles
		//Expected: unchanged
		for(j = 0; j < 25; j++)
		{
			if(state.supplyCount[j] != controlState.supplyCount[j])
			{
				failFlag = 1;
				printf("FAIL: Supply Count %d | Expected: %d | Actual: %d\n", j, controlState.supplyCount[j], state.supplyCount[j]);
			}
		}

		//Print out the inputs that lead to a failure
		if(failFlag == 1)
		{
			printf("Inputs: \n numPlayers %d\n current player %d\n numActions %d\n handCount %d\n deckCount %d\n discardCount %d\n", 
				state.numPlayers, currentPlayer, state.numActions, state.handCount[currentPlayer], state.deckCount[currentPlayer], state.discardCount[currentPlayer]);
		}
		else
		{
			printf("All tests passed!\n");
		}

		printf("\n");
	}
	printf("Village tests complete.\n");

	return 0;
}