implement function to trace left jump, thereby completing 'build-graph.sml' (and fix a bug in trace-jump.sml where a left-tracing function mistakenly made a tail call to a right-tracing function)
This commit is contained in:
@@ -184,6 +184,48 @@ struct
|
|||||||
traceRightJumpAscent (x, y, 0, platTree, env, state)
|
traceRightJumpAscent (x, y, 0, platTree, env, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun traceLeftDescent (x, y, platTree, env, state) =
|
||||||
|
if x <= 0 orelse y >= Constants.worldHeight then
|
||||||
|
state
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val width = Constants.moveEnemyBy
|
||||||
|
val height = Constants.worldHeight - y
|
||||||
|
val state = Horizontal.foldRegion
|
||||||
|
(x, y, width, height, env, state, platTree)
|
||||||
|
|
||||||
|
val nextX = x - Constants.moveEnemyBy
|
||||||
|
val nextY = y + Constants.moveEnemyBy
|
||||||
|
in
|
||||||
|
traceLeftDescent (nextX, nextY, platTree, env, state)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun traceLeftJumpAscent (x, y, remainingJump, platTree, env, state) =
|
||||||
|
if remainingJump >= Constants.jumpLimit - Constants.enemySize then
|
||||||
|
traceLeftDescent (x, y, platTree, env, state)
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val width = Constants.moveEnemyBy
|
||||||
|
val height = Constants.worldHeight - y
|
||||||
|
|
||||||
|
val state = Horizontal.foldRegion
|
||||||
|
(x, y, width, height, env, state, platTree)
|
||||||
|
|
||||||
|
val nextX = x - Constants.moveEnemyBy
|
||||||
|
val nextY = y - Constants.moveEnemyBy
|
||||||
|
val nextJump = remainingJump + Constants.moveEnemyBy
|
||||||
|
in
|
||||||
|
traceLeftJumpAscent (nextX, nextY, nextJump, platTree, env, state)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun traceLeftJump (currentPlat: GameType.platform, env, state, platTree) =
|
||||||
|
let
|
||||||
|
val {x, y, ...} = currentPlat
|
||||||
|
val x = x + Constants.enemySize
|
||||||
|
in
|
||||||
|
traceLeftJumpAscent (x, y, 0, platTree, env, state)
|
||||||
|
end
|
||||||
|
|
||||||
fun start (currentPlat: GameType.platform, env: env, state, platformTree) =
|
fun start (currentPlat: GameType.platform, env: env, state, platformTree) =
|
||||||
let
|
let
|
||||||
val {x, y, width, ...} = currentPlat
|
val {x, y, width, ...} = currentPlat
|
||||||
@@ -197,6 +239,6 @@ struct
|
|||||||
|
|
||||||
val state = traceRightJump (currentPlat, env, state, platformTree)
|
val state = traceRightJump (currentPlat, env, state, platformTree)
|
||||||
in
|
in
|
||||||
state
|
traceLeftJump (currentPlat, env, state, platformTree)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ struct
|
|||||||
val nextY = y + Constants.moveEnemyBy
|
val nextY = y + Constants.moveEnemyBy
|
||||||
in
|
in
|
||||||
shouldJumpLeft
|
shouldJumpLeft
|
||||||
orelse traceRightDescent (nextX, nextY, nextPlatID, platTree)
|
orelse traceLeftDescent (nextX, nextY, nextPlatID, platTree)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun traceLeftDrop (enemy: GameType.enemy, nextPlatID, platTree) =
|
fun traceLeftDrop (enemy: GameType.enemy, nextPlatID, platTree) =
|
||||||
|
|||||||
Reference in New Issue
Block a user