store int, MagicCounterType in MagicTuple
parent
f4d08ae7de
commit
ca1c47e758
|
@ -1,6 +1,10 @@
|
|||
package magic.model;
|
||||
|
||||
public interface MagicCopyable {
|
||||
MagicCopyable copy(final MagicCopyMap copyMap);
|
||||
long getStateId();
|
||||
default MagicCopyable copy(final MagicCopyMap copyMap) {
|
||||
return this;
|
||||
}
|
||||
default long getStateId() {
|
||||
return hashCode();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package magic.model;
|
||||
|
||||
public enum MagicCounterType {
|
||||
public enum MagicCounterType implements MagicCopyable {
|
||||
// scores: (All assume owner and controller of permanent with counters on it)
|
||||
// 0=Ignore (for counters that are used positively and negatively, or counters that mark a rule change for that card while present)
|
||||
// 1=Count (counters that are only used positively (eg. Counting a spendable resource, negative impact if decreased to certain #, positive impact if increased to certain #))
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package magic.model;
|
||||
|
||||
public class MagicInteger implements MagicCopyable {
|
||||
public final int value;
|
||||
|
||||
public MagicInteger(final int v) {
|
||||
value = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MagicCopyable copy(final MagicCopyMap copyMap) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStateId() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(value);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package magic.model;
|
||||
|
||||
public enum MagicLocationType {
|
||||
public enum MagicLocationType implements MagicCopyable {
|
||||
Stack,
|
||||
Battlefield,
|
||||
OwnersHand("your hand"),
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package magic.model;
|
||||
|
||||
import magic.model.stack.MagicItemOnStack;
|
||||
|
||||
public class MagicTuple implements MagicCopyable {
|
||||
|
||||
final MagicCopyable[] tuple;
|
||||
|
||||
public MagicTuple(final int n, final MagicCopyable... args) {
|
||||
tuple = new MagicCopyable[args.length + 1];
|
||||
tuple[0] = new MagicInteger(n);
|
||||
for (int i = 1; i < tuple.length; i++) {
|
||||
tuple[i] = args[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public MagicTuple(final MagicCopyable... args) {
|
||||
tuple = args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MagicTuple copy(final MagicCopyMap copyMap) {
|
||||
final MagicCopyable[] args = new MagicCopyable[tuple.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
args[i] = copyMap.copy(tuple[i]);
|
||||
}
|
||||
return new MagicTuple(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStateId() {
|
||||
final long[] keys = new long[tuple.length];
|
||||
for (int i = 0; i < tuple.length; i++) {
|
||||
keys[i] = tuple[i].getStateId();
|
||||
}
|
||||
return MurmurHash3.hash(keys);
|
||||
}
|
||||
|
||||
public final MagicItemOnStack getItemOnStack(int i) {
|
||||
return (MagicItemOnStack)tuple[i];
|
||||
}
|
||||
|
||||
public final MagicLocationType getLocationType(int i) {
|
||||
return (MagicLocationType)tuple[i];
|
||||
}
|
||||
|
||||
public final MagicCounterType getCounterType(int i) {
|
||||
return (MagicCounterType)tuple[i];
|
||||
}
|
||||
|
||||
public final int getInt(int i) {
|
||||
return ((MagicInteger)tuple[i]).value;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue