Esempio n. 1
0
void Run(UI* ui)
{   if(ui == NULL) return;
    NewGame(ui->game);
    NextTurn(ui->game);
    int c, running = 1;
    while(running && ui->game->status != GAME_STATUS_ERROR)
    {   DisplayGame(ui);
        c = getch();
        switch(c)
        {
        case KEY_LEFT:
            if(ui->game->status != GAME_STATUS_LOST)
            {	if(PushLeft(ui->game)) NextTurn(ui->game);
                else CheckTurn(ui->game);
            }
            break;
        case KEY_RIGHT:
            if(ui->game->status != GAME_STATUS_LOST)
            {	if(PushRight(ui->game)) NextTurn(ui->game);
                else CheckTurn(ui->game);
            }
            break;
        case KEY_UP:
            if(ui->game->status != GAME_STATUS_LOST)
            {	if(PushUp(ui->game)) NextTurn(ui->game);
                else CheckTurn(ui->game);
            }
            break;
        case KEY_DOWN:
            if(ui->game->status != GAME_STATUS_LOST)
            {	if(PushDown(ui->game)) NextTurn(ui->game);
                else CheckTurn(ui->game);
            }
            break;
        case 'q':
            running = 0;
            break;
        case 'n':
            NewGame(ui->game);
            NextTurn(ui->game);
            break;
        case 'r':
            StartGame(ui->game);
            NextTurn(ui->game);
            break;
        default:
            break;
        }
    }
}
Esempio n. 2
0
void UpdateBottomHull(Point insert, BottomHull* hull){
	Neighbors neighbors = hull->put_return_neighbors(insert, insert);
	if (!CheckTurn(neighbors.first, insert, neighbors.second) && neighbors.first != insert && neighbors.second != insert){
		hull->erase(insert);
	}
}
Esempio n. 3
0
FullHull CombineHulls(TopHull top, BottomHull bottom){
	FullHull* full;

	LN* current;

	int count = 0;

	auto i = top.begin();

	current = new LN(i->second);
	// saves the first member in order to stitch it to the final node to create a circular linked list
	full = current;
	i++;
	// Iterates through the top hull creating the LinkedList FullHull and counts its members
	for (; i != top.end(); i++){
		current = new LN(i->second, current);
		count++;
	}

	auto j = bottom.begin();
	j++;
	// Iterates through the bottom hull creating the LinkedList FullHull and counts its members
	for (; j != bottom.end(); j++){
		current = new LN(j->second, current);
		count++;
	}
	//because the first node of one hull is the same as he last of the other skipping the member in each hull allows
	// the linked list to be simply stitched together
	full->next->SetPrev(current);
	full = current;

	// Iterates through the circular linked list removing every member that doesnt fit on the final hull

	// The first node is skipped because the first pass of the algorithm can create edges on the corner that cannot be interpreted
	// once it is skipped the edges are still present but are resolved through inference
	LN* ptr = full;
	if (ptr->prev->value == ptr->next->value){
		ptr = ptr->next;
	}
	//loops through the LinkedList to remove invalid points
	do {
		// a quirk of the algorithm can create edges where both neighbor nodes to a node are the same
		// if this is the first node to be analzed it will cause the algorithm to be incorrect
		// after the first node it can be inferred that the second of the neighbors must not be a viable member node
		if (ptr->prev->value == ptr->next->value){
			ptr->SetNext(ptr->next->next);
			count--;
		}
		// finds neighbors of the current value and determines if the next value is part of the final hull
		while (!CheckTurn(ptr->prev->value, ptr->value, ptr->next->value)){
			ptr->prev->SetNext(ptr->next);
			ptr = ptr->prev;
		}
		count--;
		ptr = ptr->next;
	} while(count > 0);

	full = ptr->prev;

	return *full;
}