Esempio n. 1
0
/**
 * checks if the peasant can produce
 * produce the unit and returns 0 if succesful and 1 if not
 * checks if the peasant can produce
 */
static int produceUnit(int x1, int y1, int x2, int y2, enum unitType type) {
	// only on the neighbouring field
	if(!isNeighbour(x1, y1, x2, y2)) return 1;
	
	// is it inside the board
	if(!insideBoard(x1, y1, globalBoardSize)) return 1;
	if(!insideBoard(x2, y2, globalBoardSize)) return 1;
	
	// no unit or it is not a peasant on (x1, y1)
	UnitsList peasant = findUnit(x1, y1);
	if (peasant == NULL || peasant->type != PEASANT) return 1;
	
	// has the unit moved last two turns
	if (actualTurnNumber - peasant->lastMove < 3) return 1;
	
	UnitsList secondUnit = findUnit(x2, y2);
	
	// is there any other unit on (x2, y2)
	if(secondUnit != NULL) return 1;
	
	addUnit(x2, y2, type);
		
	// updates the last move of the peasant
	peasant->lastMove = actualTurnNumber;

	return 0;	
}
Esempio n. 2
0
void calcSignatures(int col)
{
    //generate neighbours for each row in each col
    int col_neighbours[4400][200];
    int exist_neighbours = 0;
    for (int row = 0; row < 4400; row++)
    {
        col_neighbours[row][0] = -2;
        int index = 0;
        for (int x = row + 1; x < 4400; x++)
        {
            if (isNeighbour(row, x, col) == 1)
            {
                col_neighbours[row][index] = x;
                index += 1;
            }
        }
        if (index < 3)
        {
            col_neighbours[row][0] = -2;
        }
        else
        {
            col_neighbours[row][index] = -2;
            col_neighbours[row][index + 1] = -2;
            col_neighbours[row][index + 2] = -2;
            exist_neighbours = 1;
            fprintf(log_txt, "Col %d row %d find neighbour number %d\n", col, row, index);
        }
    }
    int index = 0;
    if (exist_neighbours == 1)
    {
        total_col_has_neighbours += 1;
        for (int row = 0; row < 4400; row++)
        {
            if (col_neighbours[row][0] >= 0)
            {
                for (int x = 0; col_neighbours[row][x] > 0; x++)
                {
                    for (int y = x + 1; col_neighbours[row][y] > 0; y++)
                    {
                        for (int z = y + 1; col_neighbours[row][z] > 0; z++)
                        {
                            long signature = getOneSignature(row, col_neighbours[row][x], col_neighbours[row][y], col_neighbours[row][z]);
                            setSignature(col, -1, signature, row, col_neighbours[row][x], col_neighbours[row][y], col_neighbours[row][z]);
                            index += 1;
                            total_block_number += 1;
                        }
                    }
                }
            }
        }
        printf("Col %d has blocks %d\n", col, index);
        fprintf(log_txt, "Col %d has blocks %d\n", col, index);
    }
    signature_number[col] = index;
}
Esempio n. 3
0
/**
 * moves the unit and returns 0
 * returns 1 if not possible
 */
int move(int x1, int y1, int x2, int y2) {
	// moves only to the neighbouring
	if(!isNeighbour(x1, y1, x2, y2)) return 1;
	
	// inside board
	if(!insideBoard(x1, y1, globalBoardSize)) return 1;
	if(!insideBoard(x2, y2, globalBoardSize)) return 1;

	UnitsList unitFirst = findUnit(x1, y1);

	// first unit does not exist
	if (unitFirst == NULL) return 1;
	
	// has the unit moved already
	if (unitFirst->lastMove == actualTurnNumber) return 1;
	
	// does the player move his own unit
	if (unitFirst->player != actualPlayer) return 1;
	
	UnitsList unitSecond = findUnit(x2, y2);	
	
	// moving onto the own unit
	if(unitSecond != NULL && unitSecond->player == actualPlayer) return 1;

	// moving on the enemy unit or the empty field
	if (x1 <= 10 && y1 <= 10) {
		topleft[unitFirst->x][unitFirst->y] = '.';
	}
	unitFirst->x = x2;
	unitFirst->y = y2;
	unitFirst->lastMove = actualTurnNumber;
	
	// unit first is on the field for sure
	int winner = 1;
	
	// starts the fight if there is an enemy unit
	if (unitSecond != NULL) 
		winner = walka(unitFirst, unitSecond);
		
	if (x2 <= 10 && y2 <= 10) {
		if (winner == 0) topleft[x2][y2] = '.';
		else if (winner == 1)
			topleft[x2][y2] = mark(unitFirst->type, unitFirst->player);
		else 
			topleft[x2][y2] = mark(unitSecond->type, unitSecond->player);
	}
	
	return 0;
}
bool point_struct_t::isNeighbour(point_struct_t const& point, uint16_t resolution)
{
    return isNeighbour(coord_t(point.x, point.y), resolution);
}