Skip to content

Conversation

@dgoswami
Copy link

A* algorithm implemented. Does not impact any other code. Compiles cleanly, but correctness needs further testing.

dgoswami added 13 commits March 8, 2014 11:17
Preferences screen when the button is pressed. MenuScreen is
inactive while Preferences is active. Clicking Back and Save
buttons for the moment simply closes the Preferences screen
and brings the user back to the main MenuScreen. Data structures
for saving settings need to be added.
Conflicts:
	bubolo/src/bubolo/ui/MenuScreen.java

Conflict resolved by discarding version on branch Debbie (ours) and using
version on branch production (theirs).
- All meta-data for algorithm (f, g, pointers, etc.) are now stored
  in a separate per-tile data structure, but original Tile class is
  un-touched.
- Calculations are now in floating point, because the tie-breaking
  heuristic uses a small fractional perturbation.
- Complete structure of the algorithm is now in place. The code
  compiles without any errors or warnings. However, the movement
  costs are currently set to a constant of 1.
TODO:
- Movement cost should query tile properties and assign an
  appropriate cost.
- Integration with tank/engineer controller.
- Several bug fixes.
- Algorithm now queries movement speed in Terrain class to scale
  cost based on terrain properties.
- TODO:
  - Need some corner-case checks. For example, if the goal is
    at an un-reachable tile, the algorithm will probably go
    into an infinite loop.
  - Integration into controller.
@ChristopherCanfield ChristopherCanfield mentioned this pull request Apr 27, 2014
@ChristopherCanfield
Copy link
Member

Queued behind #373

@ChristopherCanfield
Copy link
Member

This is queued behind #373, but I've done an initial review so you can address the issues:

  • AStarNode has 3 warnings:
    • 2 warnings are because the javadoc @param value for the constructor is incorrect. It should refer to t, not tile
    • The third warning occurs because the compareTo method should be marked with the @OverRide annotation, since it overrides a method. This allows the compiler to perform additional checks.
  • The code formatting for the getters and setters in AStarNode doesn't meet our standards. Braces should be on their own line.
  • The non-braces version of if statements are banned by our code standards, since this is known to cause problems in multi-developer projects. This is used by the series of if statements starting on line 190 in AStar.java
  • AStar has 0% test coverage. All non-private methods must be covered by unit tests.
  • AStarNode has 0% test coverage. All non-private methods must be covered by unit tests.

I used the same source for pseudocode and descriptions of the algorithm when I first implemented A* last semester (Amit Patel's game programming pages). I found that it had by far the clearest description of the algorithm our of any of the sources I looked at.

@ChristopherCanfield ChristopherCanfield self-assigned this Apr 27, 2014
AStar pathfinding AI. Engineer can now be evicted from the tank.
Clicking on a screen location invokes the pathfinding AI, and
the engineer can be seen moving to the destination. There are
still some bugs and corner cases that need to be resolved -
clicking on certain locations causes the algorithm to crash.
@dgoswami
Copy link
Author

I have fixed all issues except the test coverage. I have managed to get an Engineer running around using this algorithm, but some corner cases still need to be handled. Because we have so little time, I would like to complete that before writing any unit tests. Please feel free to cancel this pull request, I can create another one once the Engineer work is done, and you can integrate everything together.

@ChristopherCanfield
Copy link
Member

So you're not going to write the unit tests?

…isbehaving

  the destination was unreachable. It now returns null and appears to be
  fully stable.
- Added Network Move command for engineer.
- Removed some debugging messages.
- Updated allowable terrain/tiles for engineer eviction and pathfinding. Solid
  stationary elements are disallowed, all other elements are allowed. For
  terrain, the assumption is that the engineer can swim over shallow water but
  will drown over deep water.
@ChristopherCanfield
Copy link
Member

Preliminary Review:

  • There are 5 warnings: 3 in AIEngineerController, and 2 in Engineer
  • Regression: Tank-based integration tests fail with an array index out of bounds exception if e is pressed when the tank is offscreen
  • CollisionTestApplication: clicking a wall when the engineer is moving causes the game to crash
  • CollisionTestApplication: clicking deep water when the engineer is out of the tank causes the game to crash
  • Approximately 27 new non-private methods do not have unit tests
  • Please resolve the merge conflicts with Production

@dgoswami
Copy link
Author

Will push some updates into my branch soon.

  • There are 5 warnings: 3 in AIEngineerController, and 2 in Engineer

I don't see any warnings, I always try to revolve all warnings before pushing. If you could let me know the warnings you see, I can try to fix them.

  • Regression: Tank-based integration tests fail with an array index out of bounds exception if e is pressed when the tank is offscreen

Fixed.

  • CollisionTestApplication: clicking a wall when the engineer is moving causes the game to crash

Fixed.

  • CollisionTestApplication: clicking deep water when the engineer is out of the tank causes the game to crash

Could not replicate, but above fix probably fixed this too.

  • Approximately 27 new non-private methods do not have unit tests

Added a number of unit tests, including the earlier missing tests for AStar and AStarNode. This includes testing for trivial functions like getters and setters, but I did not count how many I actually added.

  • Please resolve the merge conflicts with Production

Latest merge with production did indeed result in conflicts. I have fixed them and pushed everything out into my branch.

- Updated unit tests for Tank to include testing Engineer eviction
- Added Mock Engineer Creator for testing
- Fixed a bug where attempting to evict an engineer from an off-screen
  tank would cause the game to crash.
- Fixed a bug where clicking on an unreachable destination while the
  engineer was already moving would cause the game to crash.
Conflicts:
	bubolo/src/bubolo/world/entity/concrete/Engineer.java
	bubolo/src/bubolo/world/entity/concrete/Tank.java
	bubolo/test/bubolo/world/entity/concrete/TankTest.java
@ChristopherCanfield
Copy link
Member

Thank you for resolving many of the issues.

Regarding the warnings: Are you using the preferences file from the tools directory? It was last updated on 3/21 to include warnings that were defined by our SQAP, but that were missed in the original preferences file.

The asserts used in the A* tests are java asserts, which are ignored by JUnit and the JVM by default. Use JUnit's assertEquals, assertTrue, assertFalse, etc methods instead.

Yes, getters and setter tests are trivial to write. But they're necessary since people make mistakes, especially when refactoring code in a multi-developer project.

@dgoswami
Copy link
Author

Regarding the warnings: Are you using the preferences file from the tools directory? It was last updated on 3/21 to include warnings that were defined by our SQAP, but that were missed in the original preferences file.

Done, thanks.

The asserts used in the A* tests are java asserts, which are ignored by JUnit and the JVM by default. Use JUnit's assertEquals, assertTrue, assertFalse, etc methods instead.

Fixed.

@ChristopherCanfield
Copy link
Member

Review:

  • TankTest.evictEngineer fails with an assertion error
  • There are 2 documentation warnings in Engineer
  • Engineer.setTank, getTank and the new Engineer(Tank) constructor aren't covered by tests
  • What is the use case of the Engineer(Tank) constructor? Constructors that take parameters aren't compatible with either our World.addEntity or Network systems, so I'm not sure what could use this.
  • If multiple tanks release engineers, every tank controls the most recently released engineer
  • If multiple tanks release engineers, and both tanks try to control it, the engineer shakes in place uncontrollably, and is no longer controllable
  • Clicking on deepwater when the engineer is out of the tank causes extreme lag, with processor usage more than tripling. Do you know why this is?

The A* unit test looks to be an effective test. Nice work.

…ering

pathfinding and movement for both the local and remote engineers. This was
because an AIEngineerController was being instantiated for each engineer.
The fixes are:
- Added a NetworkEngineerController (similar to NetworkTankController)
- Added a CreateEngineer class (similar to CreateTank), which creates
  a NetworkEngineerController instead of an AIEngineerController.
- Updated KeyboardTankController to call CreateEngineer() instead of
  CreateEntity().
- Added unit tests for NetworkEngineerController and CreateEngineer,
  and ran JUnit testing to make sure all tests passed.
if the clicked destination tile is on non-traversable terrain. Earlier
the AStar algorithm would run on the entire map before it realized
the destination was unreachable.
@dgoswami
Copy link
Author

TankTest.evictEngineer fails with an assertion error

Fixed.

There are 2 documentation warnings in Engineer

Fixed.

Engineer.setTank, getTank and the new Engineer(Tank) constructor aren't covered by tests

Fixed.

What is the use case of the Engineer(Tank) constructor? Constructors that take parameters aren't compatible with either our World.addEntity or Network systems, so I'm not sure what could use this.

Removed.

If multiple tanks release engineers, every tank controls the most recently released engineer
If multiple tanks release engineers, and both tanks try to control it, the engineer shakes in place uncontrollably, and is no longer controllable

Fixed.

Clicking on deepwater when the engineer is out of the tank causes extreme lag, with processor usage more than tripling. Do you know why this is?

Fixed. This is because I was not checking to see if the destination tile is even traversable before calling AStar. The algorithm was scanning the entire map before realizing there was no path. The check fixes the lag. However, note that clicking on a traversable tile (e.g. grass) that is unreachable because there is no path to it, will cause AStar to run on the full map and cause a lag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants