Closed malob closed 1 year ago
The problem is that senses are executed instantly when called, while actions are stored to be performed at the end of the turn.
You see, prepareTurn()
eventually runs the player-defined playTurn()
, which executes everything on the Turn
object. All the senses get executed instantly, while the action is stored in the action
variable of the Turn
.
Then, in performTurn()
, the turn.action
is executed.
Actions are saved for later:
while senses:
are instantly executed.
Still thinking of a solution, someone else can suggest something at this point if they want.
The problem with delaying the execution of senses until the action is executed is the fact that the senses return values, and having the sense wait until an action is performed could be seen as a breakage of separation.
The problem with executing the action instantly is that while it works, it breaks the prepare
and perform
separation. Not to mention how it may damage other ordered events, like the Effects for example.
Given the structure and event flow, I don't even think senses are supposed to happen after actions in the first place, which may be why it doesn't work.
If this is true and senses aren't supposed to be executed after an action is performed, an error should be throw, something like Senses cannot be performed after actions
.
Would it not make sense to return the desired action from playTurn that way it would be clear that the action happens last. It also may be wise to seperate the actions so it is clear that they are actions.
class Player {
constructor() {
this.emptyAhead = true;
}
playTurn(w) {
this.emptyAhead = w.feel().isEmpty();
if (this.emptyAhead) { return w.actions.walk(); }
else { return w.actions.walk('backward'); }
}
}
I agree with @pigalot. When I was playing, I always saw the action as the last thing to do in a turn (especially since you can only perform one action per turn). Thus I started to return them instead of having multiple else if
s.
I also agree with @pigalot. Maybe add some syntactic sugar like:
return warrior.walk // default forward
// or
return warrior.walk.backward
Thanks everyone here for the suggestions. Unfortunately, I don't have time to implement any major API changes right now.
Environment
System:
Binaries:
Steps to reproduce
Run the following code on level 4 in the beginner tower:
Expected Behavior
First turn:
this.emptyAhead
is initialized astrue
sow.walk()
is called at the start of the first turn.w.feel().isEmpty()
should returnfalse
which would setthis.emptyAhead
tofalse
.Second turn:
this.emptyAhead
should be equal tofalse
, and sow.walk('backward')
should be called.Actual Behavior
What actually seems to happen is that the
feel()
sense, if called after the warrior moves, does not account for the movement of the warrior. This behavior seems counterintuitive to me.