Package sudoku
Class PlayerMemory
- java.lang.Object
-
- sudoku.PlayerMemory
-
public class PlayerMemory extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PlayerMemory.MaskState
Definition of sudoku field mask.private static class
PlayerMemory.WeightValuePair
-
Field Summary
Fields Modifier and Type Field Description private int[]
_accepted
Array of digits that Player accepted on a Table.private boolean[][]
_collisions
Array of collisions.private int[][]
_digitPriorities
Array of digits ordered from highest to lowest priority for a specific Table.private int[]
_digitVector
Vector of current sudoku digitsprivate boolean[]
_finished
Array of flags indicating that a Table linked to a certain field ended negotiations.private int
_iterationId
Id of current iteration.private PlayerMemory.MaskState[]
_mask
Array of flags indicating hard-coded fields.private float[][]
_rewards
Array of reward values.private int[]
_tablePriorities
Array of Table internal indices ordered from highest to lowest priority.
-
Constructor Summary
Constructors Constructor Description PlayerMemory(int sudokuSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
alreadyAccepted(int digit)
void
finish(int n)
private void
genericReset(int sudokuSize, PlayerMemory.MaskState mState)
int
getAccepted(int n)
float
getAward(int n, int digit)
boolean
getCollision(int n, int digit)
int
getDigit(int n)
int
getDigitPriority(int n, int p)
int
getIterationId()
boolean
getMask(int n)
int
getSudokuSize()
int
getTablePriority(int p)
void
hardReset()
Reset memory values that are not retained between "big" iterations.boolean
isFinished(int n, int iterationId)
void
prioritizeTables()
void
rewardCurrentDigits(float amount)
Add reward for current combination of digits.void
setAccepted(int n, int value)
void
setCollision(int n, int digit)
void
setDigit(int n, int digit)
Set digit of mutable sudoku field.void
setDigitColliding(int digit)
void
setField(int n, int digit, boolean mask)
Set properties of a sudoku field.void
softReset()
Reset memory values that are not retained between "small" iterations.
-
-
-
Field Detail
-
_rewards
private final float[][] _rewards
Array of reward values. The first index is for field and the second for digit.
-
_collisions
private final boolean[][] _collisions
Array of collisions. The first index is for field and the second for digit. If true, collision occurs.
-
_digitVector
private final int[] _digitVector
Vector of current sudoku digits
-
_mask
private final PlayerMemory.MaskState[] _mask
Array of flags indicating hard-coded fields.
-
_digitPriorities
private final int[][] _digitPriorities
Array of digits ordered from highest to lowest priority for a specific Table. The first index is for field and the second for priority.
-
_tablePriorities
private final int[] _tablePriorities
Array of Table internal indices ordered from highest to lowest priority.
-
_accepted
private final int[] _accepted
Array of digits that Player accepted on a Table. Zero means the offer was not accepted.
-
_finished
private final boolean[] _finished
Array of flags indicating that a Table linked to a certain field ended negotiations.
-
_iterationId
private int _iterationId
Id of current iteration.
-
-
Method Detail
-
getSudokuSize
public int getSudokuSize()
-
getAccepted
public int getAccepted(int n)
-
setAccepted
public void setAccepted(int n, int value)
-
isFinished
public boolean isFinished(int n, int iterationId)
-
finish
public void finish(int n)
-
alreadyAccepted
public boolean alreadyAccepted(int digit)
-
rewardCurrentDigits
public void rewardCurrentDigits(float amount)
Add reward for current combination of digits.- Parameters:
amount
- reward added for each non-empty, mutable sudoku field
-
setDigit
public void setDigit(int n, int digit)
Set digit of mutable sudoku field. This should be called after accepting a digit by the Table. If the sudoku field is hard-coded (immutable), DigitImmutableException is thrown. If the digit is out of range (0 is acceptable - means the field is empty), DigitOutOfRangeException is thrown.- Parameters:
n
- internal index of sudoku fielddigit
- digit to be inserted
-
setField
public void setField(int n, int digit, boolean mask)
Set properties of a sudoku field. Should be called only at the initialization phase. Sets both digit and mask of a field indexed internally.- Parameters:
n
- internal index of the fielddigit
- digit value to be setmask
- mask value to be set
-
getDigit
public int getDigit(int n)
-
getMask
public boolean getMask(int n)
-
getAward
public float getAward(int n, int digit)
-
getCollision
public boolean getCollision(int n, int digit)
-
setCollision
public void setCollision(int n, int digit)
-
setDigitColliding
public void setDigitColliding(int digit)
-
getTablePriority
public int getTablePriority(int p)
-
getDigitPriority
public int getDigitPriority(int n, int p)
-
prioritizeTables
public void prioritizeTables()
-
genericReset
private void genericReset(int sudokuSize, PlayerMemory.MaskState mState)
-
hardReset
public void hardReset()
Reset memory values that are not retained between "big" iterations. Should be called each time before starting solving original sudoku (before every "big" iteration). Digit vector and mask have to be initialized for this to work.
-
softReset
public void softReset()
Reset memory values that are not retained between "small" iterations. Should be called each time before starting solving sudoku (before every "small" iteration). Digit vector and mask have to be initialized for this to work.
-
getIterationId
public int getIterationId()
-
-