Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void execute_turn(int field[SIZE_Y][SIZE_X], const int player, const int pos_x, const int pos_y)
- {
- // Process all possible directions
- int opponent = 3 - player; // the same as: if player = 1 -> opponent = 2 else
- // if player = 2 -> opponent = 1
- if (field[pos_y][pos_x] != 0) //check if field is currently empty
- {
- return;
- }
- for (int i = -1; i <= 1; i++)
- {
- for (int j = -1; j <= 1; j++)
- {
- //Skip current loop if neighboring field isn't opponent
- if(field[pos_y + j][pos_x+i] == opponent) {
- int p = 2; //Used to find maximum path
- while((pos_x + p*i) < SIZE_X && (pos_y + p*j) < SIZE_Y && (pos_y + p*j) >= 0 && (pos_x + p*i) >= 0) {
- if(field[pos_y + p*j][pos_x + p*i] == player) {
- while(field[pos_y + p*j][pos_x + p*i]) {
- for(int k = p-1; k > 0; k--) {
- field[pos_y + k *j][pos_x + k*i] = player;
- }
- } break;
- } else if (field[pos_y + j][pos_x + i] == 0) break;
- p++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement