diff options
author | rexim <reximkut@gmail.com> | 2024-03-17 01:59:06 +0700 |
---|---|---|
committer | rexim <reximkut@gmail.com> | 2024-03-17 01:59:06 +0700 |
commit | ee5d0dae7738e0cb480465ae0ecd6e15fd8ed118 (patch) | |
tree | a1691e76f2ebe6b2e9da91afacd532f8398c500f /game.adb | |
parent | 074c3b9d787aacd13ba87fd49b01537fb99bbac0 (diff) |
Optimize path finding, remove custom queue.
Diffstat (limited to 'game.adb')
-rw-r--r-- | game.adb | 12 |
1 files changed, 4 insertions, 8 deletions
@@ -12,7 +12,6 @@ use Ada.Containers; with Ada.Strings.Fixed; use Ada.Strings.Fixed; with Ada.Strings; with Ada.Exceptions; use Ada.Exceptions; -with Queue; procedure Game is DEVELOPMENT : constant Boolean := True; @@ -267,9 +266,6 @@ procedure Game is Items: Hashed_Map_Items.Map; end record; - package IVector2_Queue is new Queue(Item => IVector2); - use IVector2_Queue; - type Game_State is record Map: Map_Access := Null; Player: Player_State; @@ -287,7 +283,6 @@ procedure Game is Checkpoint: Checkpoint_State; - Q: IVector2_Queue.Queue; Duration_Of_Last_Turn: Double; end record; @@ -411,10 +406,11 @@ procedure Game is if not Boss_Can_Stand_Here(Game, New_Position, Me) then exit; end if; - if Game.Bosses(Me).Path(New_Position.Y, New_Position.X) < 0 then - Game.Bosses(Me).Path(New_Position.Y, New_Position.X) := Game.Bosses(Me).Path(Position.Y, Position.X) + 1; - Q.Append(New_Position); + if Game.Bosses(Me).Path(New_Position.Y, New_Position.X) >= 0 then + exit; end if; + Game.Bosses(Me).Path(New_Position.Y, New_Position.X) := Game.Bosses(Me).Path(Position.Y, Position.X) + 1; + Q.Append(New_Position); Step(Dir, New_Position); end loop; end; |