Skip to content

Commit

Permalink
Add justification to PIRI Value 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsPIRI committed Jan 28, 2020
1 parent 2051669 commit 5c2c18b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.thisispiri.mnk"
minSdkVersion 14
targetSdkVersion 28
versionCode 32
versionName "1.13.1"
versionCode 33
versionName "1.13.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
26 changes: 16 additions & 10 deletions app/src/main/java/com/thisispiri/mnk/PiriValue01Ai.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.thisispiri.common.Point;

import java.util.LinkedList;
import java.util.Locale;

/**This is the oldest surviving version of PIRI Value AI, with some refactoring to make it work on the current version of PIRI MNK.*/
public class PiriValue01Ai implements MnkAi {
Expand All @@ -15,14 +16,20 @@ private class Pair<LEFT, RIGHT> {
}
}
private MnkGame game;
/* has AI play a turn.
* determine every cell's importance and place a stone on the cell with highest importance.
* cells that can block a line of a higher number always have higher importance than cells that can block many lines of a lower number.
* if two cells can block lines of a same number, the cell that can block more lines has higher importance.
* if a line can't be a line of maxStreak cells(because it's blocked by wall or the other symbol), ignore it.
* cells that can end game(by granting the player win) have infinite importance(represented as 9999999)
/** has AI play a turn.
* determine every cell's importance and place a stone on the cell with highest importance.
* cells that can block a line of a higher number always have higher importance than cells that can block many lines of a lower number.
* if two cells can block lines of a same number, the cell that can block more lines has higher importance.
* if a line can't be a line of maxStreak cells(because it's blocked by wall or the other symbol), ignore it.
* cells that can end game(by granting the player win) have infinite importance(represented as 9999999)
*/
public MnkAiDecision playTurnJustify(final MnkGame game) { //the parameter will be true if executed inside a thread.
@Override public MnkAiDecision playTurnJustify(final MnkGame game) {
return play(game, true);
}
@Override public Point playTurn(final MnkGame game) {
return play(game, false).coord;
}
private MnkAiDecision play(final MnkGame game, final boolean justify) { //the parameter will be true if executed inside a thread.
this.game = game;
int maxStreak = 0, maxLine = 0; //maximum streak appeared until now in the evaluation loop, maximum number of lines of maxStreak cells that can be blocked by a cell
Pair<Integer, Integer> temp;
Expand All @@ -48,13 +55,12 @@ else if(temp.first == maxStreak) {
else if(temp.second == maxLine) //if a cell that can block maxLine lines of maxStreak, add it to list.
list.addLast(new Point(j, i));
}
if(justify)
justification[i][j] = String.format(Locale.US, "%d,%d", temp.first, temp.second);
}
}
return new MnkAiDecision(new Point(list.get(0).x, list.get(0).y), justification);
}
public Point playTurn(final MnkGame game) {
return playTurnJustify(game).coord;
}

//first : maximum length of lines the cell can block. second : the value(how many lines of [first] cells it can block) of the cell.
private int maxStreak = 0, maxLine = 0, streak = 0;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/thisispiri/mnk/PiriValueAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private class CellValue {
private MnkAiDecision play(final MnkGame game, final boolean justify) {
this.game = game;
valueLength = Math.max(game.getHorSize(), game.getVerSize()) * STREAK_SCALE;
//valueLength = (game.winStreak + 1) * STREAK_SCALE; Better for performances on larger boards, but causes crashes
//valueLength = (game.winStreak + 1) * STREAK_SCALE; Better for performance on larger boards, but causes crashes
CellValue bestValue = new CellValue(valueLength); //the list of lines that a cell can block and has highest value
LinkedList<Point> list = new LinkedList<>(); //list of cells to consider.
String[][] values = null;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/thisispiri/mnk/andr/DebugBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import android.graphics.Canvas;
import android.graphics.Paint;

public class DebugBoard extends Board {
public class DebugBoard extends Board { //TODO support stone numbering
private final Paint textPaint = new Paint();
private String[][] aiInternals;
public DebugBoard(android.content.Context context, android.util.AttributeSet attr) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">피리 오목</string>
<string name="backgroundColor">바탕빛</string>
<string name="boardSize">판 크기</string>
<string name="changeSide">편 바꾸기</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name" translatable="false">PIRI MNK</string>
<string name="app_name">PIRI MNK</string>
<string name="settings">Settings</string>
<string name="restart">Restart</string>
<string name="draw">Draw</string>
Expand Down

0 comments on commit 5c2c18b

Please sign in to comment.