From 73947100de525923fd6bac5458f071f2fb3c82aa Mon Sep 17 00:00:00 2001 From: Nicolas Glondu Date: Sun, 6 Nov 2011 05:14:23 +0100 Subject: [PATCH] ghosts with guard ia now avoid pacman direction --- src/ghost.opa | 14 ++++++++++---- src/opacman.opa | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ghost.opa b/src/ghost.opa index c100d4f..1b4b7af 100644 --- a/src/ghost.opa +++ b/src/ghost.opa @@ -72,7 +72,7 @@ @private move_one_dumb(ghost:Ghost.t) = move_one_generic(ghost, build_move_options(_, true)) - @private move_one_guard(ghost:Ghost.t, bp:Base.t) = + @private move_one_guard(ghost:Ghost.t, bp:Base.t, flee) = move_fun(bg) = opts = build_move_options(bg, false) can_see(dir) = @@ -86,13 +86,18 @@ else if bg.pos.y == bp.pos.y && bg.pos.x < bp.pos.x && dir == {right} then true else false - bias = List.filter(can_see, opts) + bias = List.filter( + dir -> if flee then not(can_see(dir)) else can_see(dir), + opts) if bias == [] then if List.length(opts) == 1 then opts else back = Base.Dir.back(bg.dir) List.filter(x -> x!=back, opts) - else bias + else if List.length(bias) == 1 then bias + else + back = Base.Dir.back(bg.dir) + List.filter(x -> x!=back, bias) move_one_generic(ghost, move_fun) @private move_prison(ghost:Ghost.t) = @@ -111,12 +116,13 @@ else {ghost with prison = some(t-1)} move(g:Game.status) = + flee = Option.is_some(g.on_steroids) ghosts = List.map( (gid, ghost) -> ghost = (match ghost.ai with | {dumb} -> move_one_dumb(ghost) - | {guard} -> move_one_guard(ghost, g.pacman.base) + | {guard} -> move_one_guard(ghost, g.pacman.base, flee) ) |> move_prison (gid, ghost), g.ghosts) diff --git a/src/opacman.opa b/src/opacman.opa index 51b6c64..27b2ff6 100644 --- a/src/opacman.opa +++ b/src/opacman.opa @@ -81,7 +81,7 @@ check_collision(g:Game.status):Game.status = Set.random_get(Default.ghost_prison) |> Option.get base = Base.make(x, y, {up}, 11) - prison = some(300) + prison = some(100) (gid, {ghost with ~base ~prison}), g.ghosts) score = g.score + (match s.combo with