The.
This commit is contained in:
@@ -174,8 +174,6 @@ interface ILo<A> {
|
|||||||
// Find the largest from the evaluator.
|
// Find the largest from the evaluator.
|
||||||
A argmax(IEvaluator<A> eval);
|
A argmax(IEvaluator<A> eval);
|
||||||
A argmaxHelper(IEvaluator<A> eval, A prev, Integer prevVal);
|
A argmaxHelper(IEvaluator<A> eval, A prev, Integer prevVal);
|
||||||
// Skip this element of the list.
|
|
||||||
ILo<A> skip();
|
|
||||||
// Sort the list with the comparator.
|
// Sort the list with the comparator.
|
||||||
ILo<A> sort(IComparator<A> comp);
|
ILo<A> sort(IComparator<A> comp);
|
||||||
ILo<A> sortHelper(IComparator<A> comp, ILo<A> sorted);
|
ILo<A> sortHelper(IComparator<A> comp, ILo<A> sorted);
|
||||||
@@ -207,11 +205,7 @@ class Cons<A> implements ILo<A> {
|
|||||||
|
|
||||||
return prevVal >= nowVal
|
return prevVal >= nowVal
|
||||||
? this.rest.argmaxHelper(eval, prev, prevVal)
|
? this.rest.argmaxHelper(eval, prev, prevVal)
|
||||||
: this.rest.skip().argmaxHelper(eval, now, nowVal);
|
: this.rest.argmaxHelper(eval, now, nowVal);
|
||||||
}
|
|
||||||
|
|
||||||
public ILo<A> skip() {
|
|
||||||
return this.rest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILo<A> sort(IComparator<A> comp) {
|
public ILo<A> sort(IComparator<A> comp) {
|
||||||
@@ -246,10 +240,6 @@ class Mt<A> implements ILo<A> {
|
|||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILo<A> skip() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ILo<A> sort(IComparator<A> comp) {
|
public ILo<A> sort(IComparator<A> comp) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@@ -67,7 +67,34 @@ class Examples {
|
|||||||
|
|
||||||
Feedback exampleFeedback = new Feedback(2, 2);
|
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) {
|
boolean testDrawMethods(Tester t) {
|
||||||
// WorldImage incomplete = new IncompleteGuess(exampleDotsOne).draw();
|
// WorldImage incomplete = new IncompleteGuess(exampleDotsOne).draw();
|
||||||
@@ -364,9 +391,8 @@ class Game extends World {
|
|||||||
if (choice <= this.conf.options.len()) return this.addDot(
|
if (choice <= this.conf.options.len()) return this.addDot(
|
||||||
choice - 1
|
choice - 1
|
||||||
);
|
);
|
||||||
} else if (key.equals("backspace")) {
|
} else if (key.equals("backspace")) return this.dropDot();
|
||||||
return this.dropDot();
|
else if (key.equals("enter")) return this.commitGuess();
|
||||||
}
|
|
||||||
return this;
|
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.
|
// Calculate the width of the window without drawing anything.
|
||||||
int calcW() {
|
int calcW() {
|
||||||
return (
|
return (
|
||||||
@@ -411,7 +448,7 @@ class Game extends World {
|
|||||||
int calcH() {
|
int calcH() {
|
||||||
return (
|
return (
|
||||||
((this.conf.nguesses + 2) * Dot.r * 2) +
|
((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.
|
// Draw the solution.
|
||||||
WorldImage draw_sol() {
|
WorldImage draw_sol() {
|
||||||
if (this.done) return this.draw_sol_rev();
|
/*if (this.done)*/return this.draw_sol_rev();
|
||||||
else return this.draw_sol_hid();
|
/*else return this.draw_sol_hid();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the revealed answer.
|
// Draw the revealed answer.
|
||||||
@@ -490,6 +527,12 @@ interface ILoGuess {
|
|||||||
WorldImage draw();
|
WorldImage draw();
|
||||||
ILoGuess addToIncomplete(Dot dot, int limit);
|
ILoGuess addToIncomplete(Dot dot, int limit);
|
||||||
ILoGuess dropFromIncomplete();
|
ILoGuess dropFromIncomplete();
|
||||||
|
ILoGuess commitIncomplete(int limit, ILoDot solution);
|
||||||
|
ILoGuess commitIncompleteHelper(
|
||||||
|
int limit,
|
||||||
|
ILoDot solution,
|
||||||
|
boolean premoved
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class ConsGuess implements ILoGuess {
|
class ConsGuess implements ILoGuess {
|
||||||
@@ -513,6 +556,21 @@ class ConsGuess implements ILoGuess {
|
|||||||
public ILoGuess dropFromIncomplete() {
|
public ILoGuess dropFromIncomplete() {
|
||||||
return new ConsGuess(this.guess, this.nxt.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 {
|
class ConsIncompleteGuess implements ILoGuess {
|
||||||
@@ -542,6 +600,26 @@ class ConsIncompleteGuess implements ILoGuess {
|
|||||||
this.nxt
|
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.
|
// Placeholder for guesses yet to be guessed.
|
||||||
@@ -562,7 +640,7 @@ class ConsPlaceholderGuess implements ILoGuess {
|
|||||||
|
|
||||||
// Fill a list with n placeholders.
|
// Fill a list with n placeholders.
|
||||||
static ILoGuess mkN(int n) {
|
static ILoGuess mkN(int n) {
|
||||||
if (n == 0) return new ConsIncompleteGuess(
|
if (n == 1) return new ConsIncompleteGuess(
|
||||||
new IncompleteGuess(new MtDot()),
|
new IncompleteGuess(new MtDot()),
|
||||||
new MtGuess()
|
new MtGuess()
|
||||||
);
|
);
|
||||||
@@ -576,6 +654,25 @@ class ConsPlaceholderGuess implements ILoGuess {
|
|||||||
public ILoGuess dropFromIncomplete() {
|
public ILoGuess dropFromIncomplete() {
|
||||||
return new ConsPlaceholderGuess(this.nxt.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 {
|
class MtGuess implements ILoGuess {
|
||||||
@@ -591,6 +688,18 @@ class MtGuess implements ILoGuess {
|
|||||||
public ILoGuess dropFromIncomplete() {
|
public ILoGuess dropFromIncomplete() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ILoGuess commitIncomplete(int limit, ILoDot solution) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ILoGuess commitIncompleteHelper(
|
||||||
|
int limit,
|
||||||
|
ILoDot solution,
|
||||||
|
boolean premoved
|
||||||
|
) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A guess.
|
// A guess.
|
||||||
@@ -636,6 +745,11 @@ class IncompleteGuess {
|
|||||||
if (len == 0) return this;
|
if (len == 0) return this;
|
||||||
else return new IncompleteGuess(this.guessSoFar.remove(len - 1));
|
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.
|
// Feedback for a guess.
|
||||||
|
Reference in New Issue
Block a user