Implemented config options
This commit is contained in:
@@ -2,40 +2,111 @@ package com.bernard.nodecames.model;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.bernard.nodecames.model.Card.Color;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.Value;
|
||||
import lombok.With;
|
||||
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.BB;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.BG;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.BW;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.GB;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.GG;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.GW;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.WB;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.WG;
|
||||
import static com.bernard.nodecames.model.GridConfig.CardColors.WW;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class GridConfig {
|
||||
|
||||
public static final List<CardColors> CLASSICAL25 = List.of(
|
||||
BB,BW,WB,BG,GB,GG,GG,GG,WG,WG,WG,WG,WG,GW,GW,GW,GW,GW,WW,WW,WW,WW,WW,WW,WW
|
||||
);
|
||||
public static final Set<Integer> BASE_HINTWORDCOUNT = Set.of(
|
||||
0,1,2,3,4,5,6,7,8,9,-1
|
||||
);
|
||||
public static final GridConfig CODENAMES_CLASSICAL = new GridConfig(
|
||||
9, true, true, CLASSICAL25, true,
|
||||
true, true, 9, BASE_HINTWORDCOUNT, true,
|
||||
Integer.MAX_VALUE, true, true,
|
||||
true, false);
|
||||
|
||||
public static final GridConfig ZERO = new GridConfig(
|
||||
9, false, false, CLASSICAL25, true,
|
||||
true, false, 1, Set.of(1), false,
|
||||
3, false, false,
|
||||
false, false);
|
||||
|
||||
|
||||
// Immutable options
|
||||
// Maximum of maximom number of hints
|
||||
// This is to trigger end of game
|
||||
private int maxMaxHint;//TODO
|
||||
private boolean structuredGrid;//TODO
|
||||
private int maxMaxHint;
|
||||
private boolean structuredGrid;
|
||||
private boolean anyoneStarts;
|
||||
private List<CardColors> wordDistribution;
|
||||
private boolean maybeSuddenDeath; //TODO
|
||||
private boolean maybeOneMoreGuess; //TODO
|
||||
// If onlyOneGreenGreen is false and having it true would have meant we won,
|
||||
// prevend death and enter WIN_IF_GREEN_GREEN state, else just die
|
||||
private boolean onlyOneGreenGreenPreventDeath;
|
||||
|
||||
|
||||
// Mutable options
|
||||
private int maxHint;//TODO
|
||||
private Set<Integer> availableHintWordCount;//TODO
|
||||
private boolean oneMoreGuess;//TODO
|
||||
|
||||
private int hintMaxLength;//TODO
|
||||
private boolean endGuessing;//TODO
|
||||
private boolean onlyOneGreenGreen;//TODO
|
||||
private boolean suddenDeath;//TODO
|
||||
private boolean hintsInARow;//TODO
|
||||
private int maxHint;
|
||||
private Set<Integer> availableHintWordCount;
|
||||
private boolean oneMoreGuess;
|
||||
private int hintMaxLength;
|
||||
private boolean endGuessing;
|
||||
private boolean onlyOneGreenGreen;
|
||||
private boolean suddenDeath;
|
||||
private boolean hintsInARow;
|
||||
|
||||
public int getWordCount() {
|
||||
return wordDistribution.size();
|
||||
}
|
||||
|
||||
public void set(MutableOption opt, Object value) {
|
||||
try{
|
||||
switch(opt) {
|
||||
case MAX_HINT:
|
||||
this.maxHint = (Integer) value;
|
||||
return;
|
||||
case AVAILABLE_HINT_WORD_COUNT:
|
||||
// We check value is a set of integers
|
||||
this.availableHintWordCount = ((Set<?>)value).stream().map(i -> (Integer)i).collect(Collectors.toUnmodifiableSet());
|
||||
return;
|
||||
case ONE_MORE_GUESS:
|
||||
this.oneMoreGuess = (Boolean) value;
|
||||
return;
|
||||
case HINT_MAX_LENGTH:
|
||||
this.hintMaxLength = (Integer) value;
|
||||
return;
|
||||
case END_GUESSING:
|
||||
this.endGuessing = (Boolean) value;
|
||||
return;
|
||||
case ONLY_ONE_GREEN_GREEN:
|
||||
this.onlyOneGreenGreen = (Boolean) value;
|
||||
return;
|
||||
case SUDDEN_DEATH:
|
||||
this.suddenDeath = (Boolean) value;
|
||||
return;
|
||||
case HINTS_IN_A_ROW:
|
||||
this.hintsInARow = (Boolean) value;
|
||||
return;
|
||||
}
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException("Given value does not have the right type: "+opt.getDataClass().toGenericString(),e);
|
||||
}
|
||||
}
|
||||
|
||||
@Value(staticConstructor = "of")
|
||||
public static final class CardColors {
|
||||
Color faceA;
|
||||
@@ -51,4 +122,19 @@ public class GridConfig {
|
||||
public static final CardColors BG = CardColors.of(Color.BLACK, Color.GREEN);
|
||||
public static final CardColors BB = CardColors.of(Color.BLACK, Color.BLACK);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum MutableOption {
|
||||
MAX_HINT(Integer.class),
|
||||
AVAILABLE_HINT_WORD_COUNT(Set.class),
|
||||
ONE_MORE_GUESS(Boolean.class),
|
||||
HINT_MAX_LENGTH(Integer.class),
|
||||
END_GUESSING(Boolean.class),
|
||||
ONLY_ONE_GREEN_GREEN(Boolean.class),
|
||||
SUDDEN_DEATH(Boolean.class),
|
||||
HINTS_IN_A_ROW(Boolean.class);
|
||||
|
||||
Class<?> dataClass;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user