use of br.edu.ifspsaocarlos.sdm.kifurecorder.models.Move in project kifu-recorder by leonardost.
the class RecordGameActivity method addMoveToGameRecord.
private void addMoveToGameRecord() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
final EditText input = new EditText(RecordGameActivity.this);
dialog.setTitle(R.string.dialog_add_move).setMessage(getString(R.string.dialog_add_move)).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Move manuallyAddedMove = processManualMove(input.getText().toString());
Board newBoard = game.getLastBoard().generateNewBoardWith(manuallyAddedMove);
if (game.addMoveIfItIsValid(newBoard)) {
newMoveWasAdded();
game.updateNumberOfManualAdditions();
logger.addToLog("Move " + manuallyAddedMove + " was manually added");
}
}
}).setNegativeButton(R.string.no, null).setView(input).show();
}
use of br.edu.ifspsaocarlos.sdm.kifurecorder.models.Move in project kifu-recorder by leonardost.
the class RecordGameActivity method processManualMove.
private Move processManualMove(String moveString) {
moveString = moveString.trim();
if (moveString.length() != 3)
return null;
moveString = moveString.toLowerCase();
int color = moveString.charAt(0) == 'b' ? Board.BLACK_STONE : Board.WHITE_STONE;
int row = moveString.charAt(1) - 'a';
int column = moveString.charAt(2) - 'a';
return new Move(row, column, color);
}
use of br.edu.ifspsaocarlos.sdm.kifurecorder.models.Move in project kifu-recorder by leonardost.
the class StoneDetector method detect.
/**
* Uses the information of the last game state to improve the detection
* precision of the last move made. The parameters inform if the detector
* should look for a black stone, a white stone or both, according to the
* current game state.
*/
public Board detect(Board lastBoard, boolean canBeBlackStone, boolean canBeWhiteStone) {
long startTime = System.currentTimeMillis();
double[][] averageColors = new double[3][boardImage.channels()];
int[] counters = new int[3];
snapshot = new StringBuilder();
getAverageColors(lastBoard, averageColors, counters);
List<MoveHypothesis> moveHypothesesFound = new ArrayList<>();
for (int i = 0; i < boardDimension; ++i) {
for (int j = 0; j < boardDimension; ++j) {
// Log.i("KifuRecorder", "(" + i + ", " + j + ")\n");
snapshot.append(String.format("(%1$2d, %2$2d)", i, j) + "\n");
// Ignores the intersections of moves that were already made
if (lastBoard.getPosition(i, j) != Board.EMPTY)
continue;
double[] colorAroundPosition = calculateAverageColorOnPosition(i, j);
double[][] colorsOnEmptyAdjacentPositions = new double[4][];
colorsOnEmptyAdjacentPositions[0] = (i > 0) ? lastBoard.getPosition(i - 1, j) == Board.EMPTY ? calculateAverageColorOnPosition(i - 1, j) : null : null;
colorsOnEmptyAdjacentPositions[1] = (j < boardDimension - 1) ? lastBoard.getPosition(i, j + 1) == Board.EMPTY ? calculateAverageColorOnPosition(i, j + 1) : null : null;
colorsOnEmptyAdjacentPositions[2] = (i < boardDimension - 1) ? lastBoard.getPosition(i + 1, j) == Board.EMPTY ? calculateAverageColorOnPosition(i + 1, j) : null : null;
colorsOnEmptyAdjacentPositions[3] = (j > 0) ? lastBoard.getPosition(i, j - 1) == Board.EMPTY ? calculateAverageColorOnPosition(i, j - 1) : null : null;
/* Log.d("KifuRecorder", "Cor média ao redor de (" + i + ", " + j + ") = " + printColor(colorAroundPosition));
Log.d("KifuRecorder", "Luminancia ao redor de (" + i + ", " + j + ") = " + luminance(colorAroundPosition));
Log.d("KifuRecorder", "Variância ao redor de (" + i + ", " + j + ") = " + variance(colorAroundPosition));*/
snapshot.append(" Average color around = " + printColor(colorAroundPosition) + "\n");
snapshot.append(" Luminance around = " + luminance(colorAroundPosition) + "\n");
snapshot.append(" Variance around = " + variance(colorAroundPosition) + "\n");
snapshot.append(" ---\n");
MoveHypothesis hypothesis = calculateColorHypothesis5(colorAroundPosition, averageColors, counters, colorsOnEmptyAdjacentPositions);
hypothesis.row = i;
hypothesis.column = j;
snapshot.append(" Hypothesis = " + hypothesis.color + " (confidence: " + hypothesis.confidence + ")\n");
if (hypothesis.color != Board.EMPTY) {
moveHypothesesFound.add(hypothesis);
}
/*
Ao invés de filtrar as jogadas por cor antes, vamos filtrá-las depois, acho que faz mais
sentido. Pega-se a jogada mais provável e verifica-se se ela é possível.
if (hypothesis.color != Board.EMPTY) {
if (canBeBlackStone && hypothesis.color == Board.BLACK_STONE ||
canBeWhiteStone && hypothesis.color == Board.WHITE_STONE) {
moveHypothesesFound.add(hypothesis);
}
}
*/
}
}
// Chooses the move that obtained highest confidence
// IMPORTANT: Could verify if the difference in confidence between the
// two most probable moves is too small, discard both, because that's
// a sign that the detector is confused
Move chosenMove = null;
double biggestConfidence = 0;
for (MoveHypothesis hypothesis : moveHypothesesFound) {
if (hypothesis.confidence > biggestConfidence) {
biggestConfidence = hypothesis.confidence;
chosenMove = new Move(hypothesis.row, hypothesis.column, hypothesis.color);
}
}
if (chosenMove != null && (canBeBlackStone && chosenMove.color == Board.BLACK_STONE || canBeWhiteStone && chosenMove.color == Board.WHITE_STONE)) {
snapshot.append("Chosen move = " + chosenMove + " with confidence " + biggestConfidence + "\n");
} else {
snapshot.append("No move detected.\n");
chosenMove = null;
}
Log.d("KifuRecorder", "TIME (detect()): " + (System.currentTimeMillis() - startTime));
return lastBoard.generateNewBoardWith(chosenMove);
}
use of br.edu.ifspsaocarlos.sdm.kifurecorder.models.Move in project kifu-recorder by leonardost.
the class JogadaTest method testSgf.
@Test
public void testSgf() {
Move move = new Move(0, 0, Board.BLACK_STONE);
assertEquals("[aa]", move.sgf());
}
Aggregations