java - What's wrong with my random wandering algorithm? -


I have created a 2-dimensional grid for a game world in Java. I made 'Winders' mode algorithm I Is having a problem with

I have seen a problem that objects will appear in the side of the lower right corner of the grid. I changed the algorithm and thought it was fixed.

Today, while testing stress, I came to know that the problem was not fixed, and now wandering objects liked the top left corner of the grid, but it takes more time for them to roam in that area. .

works by the algorithm: 1. Obtaining the current values ​​of the person's position 2. Applying all sections in a linked list in the 3 block radius 3. Make the list random 3. List Choose a random value from 5. Setting that value indicates the next goal

Here is a code snippet:

  dot personatt = this.getTopLeftPoint (); PersonAt = Game.getGame (). ScreenTog Game (personAt); LinkedList & LT; Point & gt; Isets = new linked list & lt; Point & gt; (); For (int x = personAt.x - 2; x & lt; personAt.x + 3; x ++) {for (int y = personAt.y - 2; y & lt; personAt.y + 3; y ++) {if (! (X == person AT & amp; y = AT person ati)) // TODO: clean the next line of code if (x> 0 & amp; amp ; Amp; amp; amp; amp; amp;! Amp;; board.getBoard (). GetSquare (x, y) .getSquareType (.) Equal (squirtepe.)) {If (Game. GetGame () .get map (). Blocked (X, Y)) {thisSet.add (new point (X, Y)); }}}}} collection. Shuffle (offset); // random random = new random (); // integer not random = random.edit.size (); SetNextTarget (thisSet.get (0));  

Am I missing anything?

I am confused as to why they still end up in the upper left quarter of the grid.

Edit: I completely removed the random object, yet it ends with the same result.

EDIT: Update code to fix a part of this issue, so now that person is currently only ignored, but all classes of current X or Y co-ordination such as by rsp Recommended.

It's hard to find any problem in that code, but you're calling a lot out of the code All methods start with GetTopLeftPoint (), my first doubt is, if you are certain that you are using the same reference for Coordinate, GetTopLeftPoint () returns the highest point on the left side, but setNextTarget determines the middle point , Then we have a problem!

Next: screenToGame () coordinates also changes ... The source of the problem can also be

It is true that if the part is true

  ! Board.getBoard () GetSquare (x, y) .getSquareType (). Equal (SquareType.Path)  

You can only walk a class that is not the path? (Nothing to do with the problem ...)

Another: Blocked () Not sure what exactly does it happen if all the intersections were blocked in the middle of the person and living , Then it will end in the top left corner.

The last, similar to the previous one: setNextTarget () similar to the same coordinate reference (as screentog)?

Summary: Improve any kind of unit exams to test random wander algorithms without all these "noise".
I have found good results in doing this (nothing is blocked, no way out) ... person

Another point: I instead alter all the list to get one element Instead of using a random one ...


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -