This commit is contained in:
2024-12-01 16:08:41 -05:00
parent 0df296a22d
commit 1c0ea769bb
2 changed files with 123 additions and 19 deletions

View File

@@ -174,8 +174,6 @@ interface ILo<A> {
// Find the largest from the evaluator.
A argmax(IEvaluator<A> eval);
A argmaxHelper(IEvaluator<A> eval, A prev, Integer prevVal);
// Skip this element of the list.
ILo<A> skip();
// Sort the list with the comparator.
ILo<A> sort(IComparator<A> comp);
ILo<A> sortHelper(IComparator<A> comp, ILo<A> sorted);
@@ -207,11 +205,7 @@ class Cons<A> implements ILo<A> {
return prevVal >= nowVal
? this.rest.argmaxHelper(eval, prev, prevVal)
: this.rest.skip().argmaxHelper(eval, now, nowVal);
}
public ILo<A> skip() {
return this.rest;
: this.rest.argmaxHelper(eval, now, nowVal);
}
public ILo<A> sort(IComparator<A> comp) {
@@ -246,10 +240,6 @@ class Mt<A> implements ILo<A> {
return prev;
}
public ILo<A> skip() {
return this;
}
public ILo<A> sort(IComparator<A> comp) {
return this;
}

View File

@@ -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.