<commit_before>package it.playfellas.superapp.logic.master.game23;

import android.bluetooth.BluetoothDevice;
import android.util.Log;

import com.squareup.otto.Subscribe;

import org.apache.commons.lang3.ArrayUtils;

import java.util.Arrays;

import it.playfellas.superapp.InternalConfig;
import it.playfellas.superapp.events.EventFactory;
import it.playfellas.superapp.events.game.PopEvent;
import it.playfellas.superapp.events.game.PushEvent;
import it.playfellas.superapp.events.game.StartGameEvent;
import it.playfellas.superapp.logic.Config3;
import it.playfellas.superapp.logic.RandomUtils;
import it.playfellas.superapp.logic.db.TileSelector;
import it.playfellas.superapp.logic.db.query.BinaryOperator;
import it.playfellas.superapp.logic.db.query.Color;
import it.playfellas.superapp.logic.db.query.Conjunction;
import it.playfellas.superapp.logic.db.query.Shape;
import it.playfellas.superapp.logic.db.query.Type;
import it.playfellas.superapp.logic.tiles.Tile;
import it.playfellas.superapp.logic.tiles.TileColor;
import it.playfellas.superapp.logic.tiles.TileShape;
import it.playfellas.superapp.logic.tiles.TileType;
import it.playfellas.superapp.network.TenBus;

/**
 * Created by affo on 02/09/15.
 */
public class Master3Controller extends Master23Controller {
    private static final String TAG = Master3Controller.class.getSimpleName();
    private Config3 conf;
    private TileSelector ts;
    private Tile[] stack;
    private int stackPtr;

    public Master3Controller(TileSelector ts, Config3 conf) {
        super(conf);
        this.conf = conf;
        this.ts = ts;

        TenBus.get().register(this);
    }

    @Override
    protected Tile[] newBaseTiles() {
        final int size = InternalConfig.NO_FIXED_TILES;
        // remove NONE...
        TileColor[] colors = TileColor.values();
        TileShape[] shapes = TileShape.values();
        int noneIndex;

        noneIndex = ArrayUtils.indexOf(colors, TileColor.NONE);
        colors = ArrayUtils.remove(colors, noneIndex);

        noneIndex = ArrayUtils.indexOf(shapes, TileShape.NONE);
        shapes = ArrayUtils.remove(shapes, noneIndex);

        colors = RandomUtils.choice(colors, size).toArray(new TileColor[size]);
        shapes = RandomUtils.choice(shapes, size).toArray(new TileShape[size]);
        Tile[] tiles = new Tile[InternalConfig.NO_FIXED_TILES];

        for (int i = 0; i < size; i++) {
            tiles[i] = ts.random(1, new Conjunction(
                    new Shape(BinaryOperator.EQUALS, shapes[i]),
                    new Color(BinaryOperator.EQUALS, colors[i]),
                    new Type(BinaryOperator.EQUALS, TileType.ABSTRACT)
            )).get(0);
        }

        return tiles;
    }

    @Override
    protected synchronized void onBeginStage() {
        super.onBeginStage();
        this.stack = new Tile[InternalConfig.NO_FIXED_TILES];
        Arrays.fill(this.stack, null);
        this.stackPtr = 0;
        BluetoothDevice firstPlayer = nextPlayer();
        TenBus.get().post(EventFactory.yourTurn(firstPlayer, stack));
    }

    @Override
    protected void onEndStage() {
        // does nothing
    }

    private synchronized void nextTurn() {
        TenBus.get().post(EventFactory.yourTurn(nextPlayer(), stack));
    }

    @Override
    protected StartGameEvent getNewGameEvent() {
        return EventFactory.startGame3(conf);
    }<commit_msg>fix: reuse of nexTurn method. nextTurn no more synchronized (useless). Logging the stack at each turn<commit_after>package it.playfellas.superapp.logic.master.game23;

import android.util.Log;

import com.squareup.otto.Subscribe;

import org.apache.commons.lang3.ArrayUtils;

import java.util.Arrays;

import it.playfellas.superapp.InternalConfig;
import it.playfellas.superapp.events.EventFactory;
import it.playfellas.superapp.events.game.PopEvent;
import it.playfellas.superapp.events.game.PushEvent;
import it.playfellas.superapp.events.game.StartGameEvent;
import it.playfellas.superapp.logic.Config3;
import it.playfellas.superapp.logic.RandomUtils;
import it.playfellas.superapp.logic.db.TileSelector;
import it.playfellas.superapp.logic.db.query.BinaryOperator;
import it.playfellas.superapp.logic.db.query.Color;
import it.playfellas.superapp.logic.db.query.Conjunction;
import it.playfellas.superapp.logic.db.query.Shape;
import it.playfellas.superapp.logic.db.query.Type;
import it.playfellas.superapp.logic.tiles.Tile;
import it.playfellas.superapp.logic.tiles.TileColor;
import it.playfellas.superapp.logic.tiles.TileShape;
import it.playfellas.superapp.logic.tiles.TileType;
import it.playfellas.superapp.network.TenBus;

/**
 * Created by affo on 02/09/15.
 */
public class Master3Controller extends Master23Controller {
    private static final String TAG = Master3Controller.class.getSimpleName();
    private Config3 conf;
    private TileSelector ts;
    private Tile[] stack;
    private int stackPtr;

    public Master3Controller(TileSelector ts, Config3 conf) {
        super(conf);
        this.conf = conf;
        this.ts = ts;

        TenBus.get().register(this);
    }

    @Override
    protected Tile[] newBaseTiles() {
        final int size = InternalConfig.NO_FIXED_TILES;
        // remove NONE...
        TileColor[] colors = TileColor.values();
        TileShape[] shapes = TileShape.values();
        int noneIndex;

        noneIndex = ArrayUtils.indexOf(colors, TileColor.NONE);
        colors = ArrayUtils.remove(colors, noneIndex);

        noneIndex = ArrayUtils.indexOf(shapes, TileShape.NONE);
        shapes = ArrayUtils.remove(shapes, noneIndex);

        colors = RandomUtils.choice(colors, size).toArray(new TileColor[size]);
        shapes = RandomUtils.choice(shapes, size).toArray(new TileShape[size]);
        Tile[] tiles = new Tile[InternalConfig.NO_FIXED_TILES];

        for (int i = 0; i < size; i++) {
            tiles[i] = ts.random(1, new Conjunction(
                    new Shape(BinaryOperator.EQUALS, shapes[i]),
                    new Color(BinaryOperator.EQUALS, colors[i]),
                    new Type(BinaryOperator.EQUALS, TileType.ABSTRACT)
            )).get(0);
        }

        return tiles;
    }

    @Override
    protected synchronized void onBeginStage() {
        super.onBeginStage();
        this.stack = new Tile[InternalConfig.NO_FIXED_TILES];
        Arrays.fill(this.stack, null);
        this.stackPtr = 0;
        nextTurn();
    }

    private void nextTurn() {
        for (int i = 0; i < stack.length; i++) {
            Log.d(TAG, "[" + i + "]: " + stack[i]);
        }
        TenBus.get().post(EventFactory.yourTurn(nextPlayer(), stack));
    }

    @Override
    protected void onEndStage() {
        // does nothing
    }

    @Override
    protected StartGameEvent getNewGameEvent() {
        return EventFactory.startGame3(conf);
    }
{'fraction_non_alphanumeric': 0.11296458882060287, 'fraction_numerical': 0.006584723441615452, 'mean_word_length': 3.1702257474069553, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1698362', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2130, 'n_words': 394}