The.
This commit is contained in:
@@ -67,7 +67,34 @@ class Examples {
|
||||
|
||||
Feedback exampleFeedback = new Feedback(2, 2);
|
||||
|
||||
Game exampleGame = new Game();
|
||||
Game exampleGame = new Game(
|
||||
new GameConf(
|
||||
true,
|
||||
6,
|
||||
4,
|
||||
new ConsDot(
|
||||
redDot,
|
||||
new ConsDot(greenDot, new ConsDot(blueDot, new MtDot()))
|
||||
)
|
||||
),
|
||||
new ConsDot(
|
||||
redDot,
|
||||
new ConsDot(
|
||||
greenDot,
|
||||
new ConsDot(
|
||||
blueDot,
|
||||
new ConsDot(
|
||||
greenDot,
|
||||
new ConsDot(redDot, new ConsDot(greenDot, new MtDot()))
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
4,
|
||||
ConsPlaceholderGuess.mkN(4),
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
boolean testDrawMethods(Tester t) {
|
||||
// WorldImage incomplete = new IncompleteGuess(exampleDotsOne).draw();
|
||||
@@ -364,9 +391,8 @@ class Game extends World {
|
||||
if (choice <= this.conf.options.len()) return this.addDot(
|
||||
choice - 1
|
||||
);
|
||||
} else if (key.equals("backspace")) {
|
||||
return this.dropDot();
|
||||
}
|
||||
} else if (key.equals("backspace")) return this.dropDot();
|
||||
else if (key.equals("enter")) return this.commitGuess();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -397,6 +423,17 @@ class Game extends World {
|
||||
);
|
||||
}
|
||||
|
||||
Game commitGuess() {
|
||||
return new Game(
|
||||
this.conf,
|
||||
this.solution,
|
||||
this.guessesLeft - 1,
|
||||
this.guesses.commitIncomplete(this.conf.len, this.solution),
|
||||
this.won,
|
||||
this.done
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate the width of the window without drawing anything.
|
||||
int calcW() {
|
||||
return (
|
||||
@@ -411,7 +448,7 @@ class Game extends World {
|
||||
int calcH() {
|
||||
return (
|
||||
((this.conf.nguesses + 2) * Dot.r * 2) +
|
||||
((this.conf.nguesses) * Util.gapW)
|
||||
((this.conf.nguesses) * (Util.gapW + 2))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -427,8 +464,8 @@ class Game extends World {
|
||||
|
||||
// Draw the solution.
|
||||
WorldImage draw_sol() {
|
||||
if (this.done) return this.draw_sol_rev();
|
||||
else return this.draw_sol_hid();
|
||||
/*if (this.done)*/return this.draw_sol_rev();
|
||||
/*else return this.draw_sol_hid();*/
|
||||
}
|
||||
|
||||
// Draw the revealed answer.
|
||||
@@ -490,6 +527,12 @@ interface ILoGuess {
|
||||
WorldImage draw();
|
||||
ILoGuess addToIncomplete(Dot dot, int limit);
|
||||
ILoGuess dropFromIncomplete();
|
||||
ILoGuess commitIncomplete(int limit, ILoDot solution);
|
||||
ILoGuess commitIncompleteHelper(
|
||||
int limit,
|
||||
ILoDot solution,
|
||||
boolean premoved
|
||||
);
|
||||
}
|
||||
|
||||
class ConsGuess implements ILoGuess {
|
||||
@@ -513,6 +556,21 @@ class ConsGuess implements ILoGuess {
|
||||
public ILoGuess dropFromIncomplete() {
|
||||
return new ConsGuess(this.guess, this.nxt.dropFromIncomplete());
|
||||
}
|
||||
|
||||
public ILoGuess commitIncomplete(int limit, ILoDot solution) {
|
||||
return this.commitIncompleteHelper(limit, solution, false);
|
||||
}
|
||||
|
||||
public ILoGuess commitIncompleteHelper(
|
||||
int limit,
|
||||
ILoDot solution,
|
||||
boolean premoved
|
||||
) {
|
||||
return new ConsGuess(
|
||||
this.guess,
|
||||
this.nxt.commitIncompleteHelper(limit, solution, premoved)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ConsIncompleteGuess implements ILoGuess {
|
||||
@@ -542,6 +600,26 @@ class ConsIncompleteGuess implements ILoGuess {
|
||||
this.nxt
|
||||
);
|
||||
}
|
||||
|
||||
public ILoGuess commitIncomplete(int limit, ILoDot solution) {
|
||||
return this.commitIncompleteHelper(limit, solution, false);
|
||||
}
|
||||
|
||||
public ILoGuess commitIncompleteHelper(
|
||||
int limit,
|
||||
ILoDot solution,
|
||||
boolean premoved
|
||||
) {
|
||||
if (!premoved) throw new Error("Here");
|
||||
if (this.guessSoFar.full(limit)) {
|
||||
ILoDot guessDots = this.guessSoFar.guessSoFar;
|
||||
Feedback feedback = guessDots.compare(solution);
|
||||
return new ConsIncompleteGuess(
|
||||
new IncompleteGuess(new MtDot()),
|
||||
new ConsGuess(new Guess(guessDots, feedback), this.nxt)
|
||||
);
|
||||
} else return this;
|
||||
}
|
||||
}
|
||||
|
||||
// Placeholder for guesses yet to be guessed.
|
||||
@@ -562,7 +640,7 @@ class ConsPlaceholderGuess implements ILoGuess {
|
||||
|
||||
// Fill a list with n placeholders.
|
||||
static ILoGuess mkN(int n) {
|
||||
if (n == 0) return new ConsIncompleteGuess(
|
||||
if (n == 1) return new ConsIncompleteGuess(
|
||||
new IncompleteGuess(new MtDot()),
|
||||
new MtGuess()
|
||||
);
|
||||
@@ -576,6 +654,25 @@ class ConsPlaceholderGuess implements ILoGuess {
|
||||
public ILoGuess dropFromIncomplete() {
|
||||
return new ConsPlaceholderGuess(this.nxt.dropFromIncomplete());
|
||||
}
|
||||
|
||||
public ILoGuess commitIncompleteHelper(
|
||||
int limit,
|
||||
ILoDot solution,
|
||||
boolean premoved
|
||||
) {
|
||||
if (!premoved) return this.nxt.commitIncompleteHelper(
|
||||
limit,
|
||||
solution,
|
||||
true
|
||||
);
|
||||
else return new ConsPlaceholderGuess(
|
||||
this.nxt.commitIncomplete(limit, solution)
|
||||
);
|
||||
}
|
||||
|
||||
public ILoGuess commitIncomplete(int limit, ILoDot solution) {
|
||||
return this.commitIncompleteHelper(limit, solution, false);
|
||||
}
|
||||
}
|
||||
|
||||
class MtGuess implements ILoGuess {
|
||||
@@ -591,6 +688,18 @@ class MtGuess implements ILoGuess {
|
||||
public ILoGuess dropFromIncomplete() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILoGuess commitIncomplete(int limit, ILoDot solution) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ILoGuess commitIncompleteHelper(
|
||||
int limit,
|
||||
ILoDot solution,
|
||||
boolean premoved
|
||||
) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// A guess.
|
||||
@@ -636,6 +745,11 @@ class IncompleteGuess {
|
||||
if (len == 0) return this;
|
||||
else return new IncompleteGuess(this.guessSoFar.remove(len - 1));
|
||||
}
|
||||
|
||||
// Is the guess full?
|
||||
boolean full(int limit) {
|
||||
return this.guessSoFar.len() == limit;
|
||||
}
|
||||
}
|
||||
|
||||
// Feedback for a guess.
|
||||
|
Reference in New Issue
Block a user