Mike Chambers

code = joy

ActionScript 3 Development Task Contest #1

with 118 comments

I was working on some code over the weekend and was spending a lot of time trying to figure out the best way to approach a problem, and how to get the best performance from the solution. I thought it would be useful and interesting to see how other developers would approach the problem. This gave me an idea for an ActionScript 3 contest, which I am announcing today.

What: ActionScript 3 Development Task Contest (AS3DTC)
When: Submissions must be received by Mike Chambers (mesh@adobe.com) by 12 Noon, PST, Friday, November 13th.
Who: Anyone is eligible (see details below)
Prizes : Copy of Flex Builder 3, choice of a T-shirt from threadless.org, lots of random swag, and the admiration and adulation of your ActionScript developer peers.

Goals of contest

  1. Get some solid implementations of classes that will be useful to everyone.
  2. Get multiple examples of high performance code that everyone can learn from.
  3. Drive discussions around implementations, and possible further optimizations (code and architectural).

Keep these goals in mind when writing your code and making your submission.

Contest Task

Implement a class named ProximityManager that divides the stage into a grid with cells sizes of 35px x 35px, and returns all of the display object instances within the same and adjacent cells as a specified display object (that will be passed in).

I have provided a TestRunner.as class that will be used to judge the contest. You cannot change this file. Your entry will consist of a class called ProximityManager.as that implements the constructor and public APIs in the included ProximityManager.as.

Update (November 11, 2009) : For the purposes of the contest, you can use the x, y coordinates of the display objects to determine which cell they are contained within (i.e. you dont have to worry about a display object straddling two cells).

The TestRunner will randomly place 10,000 display objects on the stage. It will then randomly place four target Sprites (checkSprites) instances on the stage.

The test that will be run is:

private function testProximityManager():void
{
	proximityManager.update(items);
	proximityManager.getNeighbors(checkSprite_1);
	proximityManager.getNeighbors(checkSprite_2);
	proximityManager.getNeighbors(checkSprite_3);
	proximityManager.getNeighbors(checkSprite_4);
}

 

Where items is a Vector of all DisplayObjects to be checked against, and checkSprite is the target Sprite, whose neighbors must be found and returned in a Vector of DisplayObjects.

Tests will be run and results determined using Grant Skinner’s ActionScript 3 Performance Test Harness.

Download Contest Files

All test files and entries will be posted to the ActionScript 3 Development Task Contests GitHub Repository.

Additional Rules

  • Code must be release under an MIT license.
  • Code must be fully commented.
  • Code must be human readable.
  • Code must implement the constructor and public APIs defined in the included ProximityManager.as file.
  • Code must be implemented in the provided ProximityManager.as class.
  • Contest is open to everyone.
  • Code must be authored by the submitter.
  • Code cannot have any external dependencies (including Flex).
  • Code cannot require any additional tools, pre or post processing steps.
  • All entry code must include the MIT license at the top, as well as the name of the developer who wrote and is submitting the code.
  • Developers may enter more than once, but only entries that take a significantly different approach will be accepted.

Note, that the rules and TestRunner may be tweaked after I post them, but I will try and make any changes or clarifications within 1 day. Please make sure to check back to this post for any changes.

Don’t try to game the contest. If you are not sure if you are, then ping me. This is a community contest for fun and learning. I will make the final call on all disputes and entries. If I think an entry doesn’t abide by the rules, or is trying to game the contest then I may reject the entry. I am very serious about this, so dont mess around.

Update (November 10, 2009) : Basically, the only information your class has access to is that which is passed to its constructors and methods. Your code cannot make assumptions based on information in the test which is not passed to the ProximityManager class (i.e., how many items there are on the stage, or the fact that the items are not moving, etc…). If I change the parameters of the test that your code does not know about, then your class should still work correctly.

The winning entry will be determined by compiling the TestRunner.as (included) and submission class with the latest public release of the mxmlc compiler. The TestRunner SWF will be run 5 times and total times will be combined. The submission with the lowest total time over the test iterations will be the winner. The return values from the getNeighbors API will be validated (an example validation test is included in the TestRunner).

Tests will be run on the latest Flash Player 10 Release (non-debug) version in the Safari browser (latest release version) on an Intel Mac Pro. All submissions will be posted online.

Once the results are announced, ranked, and posted, there will be a short period before the contest is finalized. This will give the community a chance to identify any bugs in the code logic. I will make the final decision about whether any bugs in the logic will disqualify the entry. Basically, if it is a minor bug that will not affect performance, then I will let it pass. If it is a major bug, or has a major impact on performance, then I will probably disqualify the entry. I may give the developer a chance to correct the bug.

Since one of the main goals of the contest is to help generate knowledge on techniques and optimizations, the contest is open to everyone, including Adobe employees. However, if an Adobe employee wins, the prizes will go to the highest ranked non-Adobe employee.

This is the first time I have tried this, so there will be some kinks in the process. Please be patient, and keep the goals and spirit of the contest in mind. If it goes well, then we will do more contests, with different tasks.

If you find any errors / bugs in the TestRunner class, please post them in the comments, and I will get them fixed.

If you have any questions, or want clarification on something, post it in the comments. All clarifications made by me in this post and its comments should be considered part of the rule set.

Watch this blog post, and my twitter account (@mesh) for contest updates and reminders.

File Updates:

Release 0.7 (November 12, 2009)

  • TestRunner now waits one second after it has loaded before it runs the performance tests.

Release 0.6 (November 12, 2009)

  • checkResults now removes all result items from the stage. This makes it easier to view and validate results

Release 0.5 (November 12, 2009)

  • All circles are now drawn so the top left of their bounds is at 0,0.

Release 0.4 (November 11, 2009)

  • bounds argument is now required in ProximityManager constructor. This specifies the bounds of the collision detection / grid area.

Release 0.3 (November 11, 2009)

  • Fixed Release dates in README.txt
  • Added visual validation code to TestRunner.as (thanks to Sean Christmann for the help)
  • Made a minor change to how circles are drawn in Display Objects on stage.
    From : disp.graphics.drawCircle( 0 , 0 , 5 );
    To : disp.graphics.drawCircle( 5 , 5 , 5 );

Release 0.2 (November 10, 2009)

  • Move SWF meta data from ProximityManager to TestRunner
  • Added README.txt file

Release 0.1 (November 10, 2009)

  • Initial Release

Written by mikechambers

November 10th, 2009 at 11:59 am

Posted in General

Tagged with ,

118 Responses to 'ActionScript 3 Development Task Contest #1'

Subscribe to comments with RSS or TrackBack to 'ActionScript 3 Development Task Contest #1'.

  1. Sounds like a fantastic contest, and a very useful class to boot! Didn’t Grant Skinner make and release a proximity manager class recently?

    Troy Gilbert

    10 Nov 09 at 12:06 pm

  2. He did write just such a class, maybe it is not a good fit for all workloads?

    Ben Garney

    10 Nov 09 at 12:10 pm

  3. Yeah, if Grant wrote such a class how could anyone improve upon it?

    Good idea for a contest.

    By the way, is the winner the one that runs FASTEST? or LEAST RAM? Or SMALLEST MEMORY LEAK? Or, MOST ELEGANT CODE? Or, some combination thereof?

    Phillip Kerman

    10 Nov 09 at 12:34 pm

  4. So is that a grid of squares that are each 35px to a side, or a grid that’s 35 squares to a side and square size is relative to total size of the bounds?

    Mykola

    10 Nov 09 at 12:35 pm

  5. @phillip

    From the blog post:


    The winning entry will be determined by compiling the TestRunner.as (included) and submission class with the latest public release of the mxmlc compiler. The TestRunner SWF will be run 5 times and total times will be combined. The submission with the lowest total time over the test iterations will be the winner.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 12:38 pm

  6. @Mykola

    The size of each cell of the grid should be 35 x 35.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 12:40 pm

  7. @Troy

    Grant did write a class, but it was written for Flash Player 9 a couple of years ago.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 12:40 pm

  8. The famous contest, let’s go !

  9. Yes. The original ProximityManager class was AS2, and the AS3 version was just a quick port. There is a LOT of room for improvement!

    Grant Skinner

    10 Nov 09 at 1:10 pm

  10. [...] Przez flexibleair Dodaj komentarz Kategorie: Adobe AIR Mike Chambers og?osi? konkurs dla ActionScripterów w wersji 3.0. Polega on na napisaniu klasy która b?dzie zwraca? wszystkie [...]

  11. Does adjacent include diagonally adjacent as well?

    Also, if the bound size is not a multiple of grid size then are the edge grid squares just smaller?

    Marcin

    10 Nov 09 at 2:27 pm

  12. Great contest. I’ll try to do something.

    jessicatv

    10 Nov 09 at 2:28 pm

  13. Maybe the test should check the output validity as well? I’m sure I could make a damn-fast implementation if it didn’t need to be accurate. :)

    Marc Hughes

    10 Nov 09 at 2:35 pm

  14. Why don’t you use a KD tree and the nearest neighbor algorithm?

    Adam

    10 Nov 09 at 2:38 pm

  15. Sorry if I’m making this overly complicated, but when you talk about dividing the stage into 35×35 grid cells and finding nodes within those cells and adjacent cell, I don’t see that happening in your checkResults() method. What I see is a distance function checking for all nodes within a ~198 diameter circle. Is this correct?

    Sean Christman

    10 Nov 09 at 2:46 pm

  16. Hey Mike,

    Shouldn’t the test runner reinitialize the item list and generate a new set of check sprites on each run?

    Otherwise, there really isn’t any need to update the proximity manager class, and any measurements of the getNeighbors() calls’ performance won’t generate very useful results as we can just cache and return the stored results from the very first iteration.

    Jim

    Jim Cheng

    10 Nov 09 at 2:48 pm

  17. Maybe I’m misunderstanding, but if it is only access speed that matters, isn’t it always just precomputed with the results in an array, based on an index on displayObject (like depth or something)? Or maybe it is about the fastest way of accessing that array?

    Robin Debreuil

    10 Nov 09 at 2:58 pm

  18. @Marcin


    Does adjacent include diagonally adjacent as well?

    Yes. 9 total cells, unless you are on the edge.


    Also, if the bound size is not a multiple of grid size then are the edge grid squares just smaller?

    yes.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:00 pm

  19. @Marc


    Maybe the test should check the output validity as well

    Yes, it will check the validity of the results. Right now, there is a simple check in there, but I will be writing more thorough one.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:02 pm

  20. @Sean

    That check is just an initial, simple check. Im working on more thorough ones.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:02 pm

  21. oh nm, I see now that is not a grid, and the precompute (update) is the speed thing. Nice idea for a contest : )

    Robin Debreuil

    10 Nov 09 at 3:03 pm

  22. @Robin,

    There are a number of approaches you could take on this, but some of the variables might be how you represent the grid data, how you store and access, how you look positions, etc…

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:04 pm

  23. I’d also question whether 4 samples is enough to actually create some interesting results. I like this contest but my gut is telling me that the overhead needed to beat out 4000 Point.distance() calls might be too high.

    I very naive implementation of this code only costs 8 milliseconds on my 3 year old macbook pro.

    var points:Vector. = new Vector.();
    var i:int;
    var randX:Number;
    var randY:Number;
    for(i=0; i<1000; i++){
    randX = Math.random() * 1000;
    randY = Math.random() * 1000;
    points.push( new Point(randX, randY));
    }

    trace(getTimer());
    var dist:Number = 98.994;
    var outPoints:Vector. = new Vector.();
    var point:Point;
    for(i=0; i<4; i++){
    randX = Math.random() * 1000;
    randY = Math.random() * 1000;
    var randPoint:Point = new Point(randX, randY);
    for each(point in points){
    if(Point.distance(randPoint, point) < dist){
    outPoints.push(point);
    }
    }
    }
    trace(getTimer());
    trace("points found", outPoints.length);

    Sean Christman

    10 Nov 09 at 3:11 pm

  24. You wrote :
    @Mykola
    The size of each cell of the grid should be 35 x 35.
    mike chambers

    What I’d like to know, is this grid defined as 35 cells by 35 cells, divided evenly across an irrelevant stage dimension, or a grid where each cell is 35 pixels square, and there may be any number of cells on the stage ?

    Thanks,

    Dave.

    Dave Vaughan

    10 Nov 09 at 3:12 pm

  25. also what functions should there be exposed to the test class ?

    Is the class we build informed as objects are placed on stage or is it just told the stage/movieclip that is to be used when returning the adjacent objects ?

    Dave Vaughan

    10 Nov 09 at 3:16 pm

  26. nvm. looking at the code explained what you actually wanted. Not quite what you had described.

    Dave Vaughan

    10 Nov 09 at 3:24 pm

  27. @Dave

    Read the blog post again, and then view the test files. Those will answer all of your questions.

    As far as cell size, the gridSize property passed into ProximityManager specifies the dimension of each cell.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:26 pm

  28. You can’t unzip that file in Windows. Can you post a zip file that works?

    Iain

    10 Nov 09 at 3:35 pm

  29. @Dave

    If you see any discrepancies, please let me know so I can correct them.

    Thanks…

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 3:36 pm

  30. the zip file works just fine here. windows 7 native opened it.

    Dave Vaughan

    10 Nov 09 at 3:43 pm

  31. @Iain

    The zip works for me using WinRAR in Windows 7.

    Tim

    10 Nov 09 at 4:02 pm

  32. Are the positions of the DisplayObjects expected to change between the call to ProximityManager#update and ProximityManager#getNeighbors? (I mean—Would ProximityManager#update be called every time before actual tests?)

  33. When I tried to extract-all the files I had some mac files interfere. Managed to drag the files out in the end. Blaming Vista.

    Iain

    10 Nov 09 at 5:48 pm

  34. I assume that the provision of

    “Code cannot require any additional tools, pre or post processing steps.”

    means that you can’t use either Pixel Bender or Alchemy?

    Doug McCune

    10 Nov 09 at 6:16 pm

  35. Will you be having a contest to script a system that can take out your trash and mow your lawn, too? ;)

    Edward

    10 Nov 09 at 7:15 pm

  36. @Mihai


    Are the positions of the DisplayObjects expected to change between the call to ProximityManager#update and ProximityManager#getNeighbors?

    No. If the positions of the DisplayObjects change, update will be called again.

    Sorry about the confusion.

    Edited to make answer clearer.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 7:18 pm

  37. @Doug McCune

    Yeah, Alchemy and PixelBender are not allowed.

    I have been going back and forth on PixelBender, but it is not allowed.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 7:20 pm

  38. Why use Skinner’s test harness? Doesnt the flex profiler determine a much more accurate and rich description of execution time?

    gArbage!

    Matt Bolt

    10 Nov 09 at 7:28 pm

  39. @Matt


    Why use Skinner’s test harness?

    Because I like it.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 7:34 pm

  40. Just made a clarification in the rules about gaming the contest:


    Basically, the only information your class has access to is that which is passed to its constructors and methods. Your code cannot make assumptions based on information in the test which is not passed to the ProximityManager class (i.e., how many items there are on the stage, or the fact that the items are not moving, etc…). If I change the parameters of the test that your code does not know about, then your class should still work correctly.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 9:24 pm

  41. Do we need to keep account the radius of the circles that are the DisplayObjects, or do we just use the x,y coordinates of them?

    Brandon

    10 Nov 09 at 9:26 pm

  42. @mikechambersh

    Because I like it.
    -
    But do you gLike it? :)

    Also, just letting you know that your “time-machine” trickery won’t fool anymore (aka, you have a date typo in the blog)

    “Update (November 9, 2010) :”

    Matt Bolt

    10 Nov 09 at 9:56 pm

  43. In the checkResults() function you compare only the .x and .y coordinate of both display object. is the whole test base only on position of the sprite, or also size of it. (Can you use a 100x100px Display object and overlap many tiles of the grid?)

    jpauclair

    10 Nov 09 at 10:00 pm

  44. @Brandon


    Do we need to keep account the radius of the circles

    Remember, your code doesnt necessarily know that the display objects are circles. It just knows that they are display objects with a width, height, x, y, …etc…

    mike chambers

    mikechambers

    10 Nov 09 at 10:08 pm

  45. @ jpauclair

    Yeah, that is just an initial, simple validation. I am going to be writing some more.

    mike chambers

    mikechambers

    10 Nov 09 at 10:10 pm

  46. In the getNeighbors() call, is it permissible to return duplicates?

    Jon

    10 Nov 09 at 10:37 pm

  47. Also, lets say you change the test and pass in an irregular shape (ProximityManager should be shape agnostic). Would ProximityManager test against the rectangular boundary of the shape, or take into account its irregularity?

    Jon

    10 Nov 09 at 10:41 pm

  48. @Jon


    In the getNeighbors() call, is it permissible to return duplicates?

    No.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 11:10 pm

  49. @Jon


    Would ProximityManager test against the rectangular boundary of the shape, or take into account its irregularity?

    Well, some of that would depending on what you were doing with the data once it was returned.

    For the contest, you can just use x/y coordinates of the display object.

    mike chambers

    mesh@adobe.com

    mikechambers

    10 Nov 09 at 11:13 pm

  50. Do we need to consider the shape of 4 test object? or just count the x, y of the test object lie on which cell?

    How above it lie on the edge?

    wailam

    10 Nov 09 at 11:21 pm

  51. @mikechambers
    For the contest, you can just use x/y coordinates of the display object.
    -
    Earlier you mentioned one should use the bounding box of the DisplayObject. Can we make it clear which it is?

  52. @Mihai


    Earlier you mentioned one should use the bounding box of the DisplayObject.

    Can you point to my comments where I said that?

    mike chambers

    mikechambers

    11 Nov 09 at 2:30 am

  53. If the bounds as passed in is null, should we take the constraints defined in the test (ie that the stage will be 550×400) as the constraints on the system?

    Also, if the test requires that the grid size is 35, then why pass in the gridSize into the ProximityManager? You would score a performance improvement if you don’t take that as a member variable but hard-code 35 into the work.

    It feels to me that I could shortcut some of the development process using these articles of knowledge and gain a performance improvement, but I would feel like I hadn’t fulfilled the spirit of the challenge :)

    Alec McEachran

    11 Nov 09 at 3:08 am

  54. @mikechambers
    In this comment http://www.mikechambers.com/blog/2009/11/10/actionscript-3-development-task-contest-1/#comment-17598 where you specified the width and height of the DisplayObject. But I guess it must have been misleading only to myself.

  55. Mike: The description of the rules is indeed a little bit strange. Why should the stage be divided into cells of 35×35?

    It would be much clearer to state that you want to find the set of neighbours N of a DisplayObject x. A DisplayObject y is called a neighbour of x if it satisfys the condition distance(x,y) < d where distance is the eucledian distance and d in |R.

    This would be more interesting since you could change d as well and see how algorithms perform for different distances.

    Joa Ebert

    11 Nov 09 at 4:59 am

  56. Hi Mike,

    Can you confirm that you want a vector of display objects that represents the neighbouring display objects based on their x and y position in the grid.

    So a circle with a radius of 1000 will only appear in one grid area, where the grid size is 35 x 35, rather than multiple grid areas?

    Cheers,

    Mark ( @mark_star )

    Mark Starling

    11 Nov 09 at 6:06 am

  57. In the case that the update method is called more than once, will it pass only objects which have actually been updated since the previous call, or the complete set every time?

    Andrew Traviss

    11 Nov 09 at 7:06 am

  58. Are we allowed to import any native Flash Player classes? Like Point? Or when you say no other dependencies does that mean only use the included imports and top level classes/data types?

    Phil

    11 Nov 09 at 7:31 am

  59. Do the Display Objects get relocated between calls to the update method? Also, does the Vector itself get modified between calls to the update method?

    I’m assuming the data doesn’t change until the update method is called. Is that a correct assumption?

    Brandon

    11 Nov 09 at 7:47 am

  60. To help me test that my code was producing the right results I transformed the colour of the neighbouring display objects using a simple ColorTransform. I applied this before adding it to the vector to be returned.

    currentObject.transform.colorTransform = new ColorTransform( 0, 0, 0, 1, 0, 0, 0 );

    @mikechambers It might be worth using a setTimeout on the runTests function. This would allow the swf to initialize properly before running the test (as recommended by Grant Skinner).

    Mark ( @mark_star )

    Mark Starling

    11 Nov 09 at 7:50 am

  61. Any chance that you can post results from submissions as you receive them? Doing so will give entrants a better idea of what kind of performance they should aim for and drive the bar higher (early submissions may need to be revised as spank-age occurs). That is… if you want this to be a true performance exercise. ;-)

    Rick Winscot

    11 Nov 09 at 8:08 am

  62. @mikechambers
    How about the test object lie on the edge? Say it is on x:35,y30. which cell should be included?

    wailam

    11 Nov 09 at 8:34 am

  63. @Alec


    Also, if the test requires that the grid size is 35, then why pass in the gridSize into the ProximityManager?

    Well, for this test I am passing in 35 but your code needs to work even if I pass i a different size.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:32 am

  64. @mark


    Can you confirm that you want a vector of display objects that represents the neighbouring display objects based on their x and y position in the grid.

    Yes, you can base it on the x, y position. I will update the rules / blog post to mention that.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:34 am

  65. @Joa


    It would be much clearer to state that you want to find the set of neighbours N of a DisplayObject x. A DisplayObject y is called a neighbour of x if it satisfys the condition distance(x,y) < d where distance is the eucledian distance and d in |R.
    --

    Yes, that would be interesting. Maybe that could be the next contest (if we have another one).

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:35 am

  66. @Andrew

    Update always gets passed the complete set of DisplayObjects to check against.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:36 am

  67. @Phil

    Yes, you can use native flash player classes, such as Point.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:37 am

  68. @Brandon


    Do the Display Objects get relocated between calls to the update method?

    Yes, you should assume they do. That is the entire point of the update method, i.e. the data set has updated.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:38 am

  69. @Mark

    Ill look into the set timeout. Thanks for the suggestion.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:38 am

  70. @Rick


    Any chance that you can post results from submissions as you receive them?

    No, that would not be fair to the people who submit early.

    We will be posting all entries once the contest is over.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:39 am

  71. Just clarified how to determine which cells a display object belongs to:


    For the purposes of the contest, you can use the x, y coordinates of the display objects to determine which cell they are contained within (i.e. you dont have to worry about a display object straddling two cells).

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 9:44 am

  72. Just so I’m clear. This situation won’t happen:

    update() invoked
    Display Objects get moved around
    getNeighbors() invoked

    If the DOs get moved around, the update method is called before getNeighbors gets called. Right?

    Brandon

    11 Nov 09 at 10:58 am

  73. fyi, I just updated the contest files for the test.

    You can see the changes at the end of the blog post.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 11:19 am

  74. @Brandon


    If the DOs get moved around, the update method is called before getNeighbors gets called. Right?

    That is correct.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 11:20 am

  75. I just created a GitHub project for the contests:

    http://github.com/mikechambers/ActionScript-3-Development-Task-Contests

    Latest contest files can be found there, as well as entries (once contest is closed).

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 11:47 am

  76. Why the bounds rectangle can be passed as null? Can you confirm that sometimes it will be a Rectangle and sometimes null.

    Also, what happens when an object is on the cell boundary? Which cell should it be included in?

    Does the objects on the boundaries of the adjacent cells count as neighbors of the specified display object?

    Vladimir

    11 Nov 09 at 1:20 pm

  77. @Vladimir


    Why the bounds rectangle can be passed as null? Can you confirm that sometimes it will be a Rectangle and sometimes null.

    Because some implementations dont require it. Ill change the test code so it is always passed in (and you can use it if you need to).

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 1:33 pm

  78. Should we place our resulting ProximityManager in our own package (e.g. com.example.utils.ProximityManager) or leave the package as it is? Just thinking if you plan to put everything on GitHub you might want to have each contribution in a unique package…

    Jens Wegar

    11 Nov 09 at 1:52 pm

  79. @Jens

    Keep it in the default package please.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 1:54 pm

  80. Well, that’s a bit annoying. Yesterday when Mihai asked whether the objects could move between calls to update and getNeighbour (http://www.mikechambers.com/blog/2009/11/10/actionscript-3-development-task-contest-1/#comment-17585) you essentially said “sometimes”, now you say update will always be called when positions have changed.

    I was wondering about the logic of that from an API point of view, but went with it anyway (after all, it’s just a contest).

    Sorry, just venting because I spent a lot of time yesterday making it cope with the fact objects could have moved when getNeighbors is called :) You did say there would be teething isuses.

    Marcin

    11 Nov 09 at 1:56 pm

  81. @mikechambers
    -
    Because some implementations dont require it. Ill change the test code so it is always passed in (and you can use it if you need to).
    -
    This is misleading… Any implementation will require at least this rectangle’s origin. Otherwise you should make a statement that the rectangle’s x and y coordinates are always both 0 or at least divisible with gridSize.

  82. @Marcin
    I find it natural for update() to be called only when the list of DisplayObjects is altered. Also, since the specs don’t say update() is called after the DisplayObjects have updated their coordinates, the implementation must assume that when getNeighbors() is called the DisplayObjects might have changed their coordinates.

  83. @Mihai
    http://www.mikechambers.com/blog/2009/11/10/actionscript-3-development-task-contest-1/#comment-17641

    The update method gets called if the DOs get moved around.

    Brandon

    11 Nov 09 at 2:25 pm

  84. @Mihail


    Otherwise you should make a statement that the rectangle’s x and y coordinates are always both 0 or at least divisible with gridSize.

    The test is being updated to always pass in bounds to the constructor, which will include the information you need.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 2:39 pm

  85. @mihai


    the implementation must assume that when getNeighbors() is called the DisplayObjects might have changed their coordinates.

    That is incorrect.

    http://www.mikechambers.com/blog/2009/11/10/actionscript-3-development-task-contest-1/#comment-17641

    As Brandon points out:

    “The update method gets called if the DOs get moved around.”

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 2:41 pm

  86. @Marcin

    Yes. I wasnt as clear as I could have been in my answer.

    I have tried to clarify it in the comments above:

    The update method gets called if the DOs get moved around.

    Sorry about the hassle and confusion.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 2:43 pm

  87. Just updated test files.

    bounds is now a required argument to the ProximityManager constructor.

    You can grab the latest files here:

    http://github.com/mikechambers/ActionScript-3-Development-Task-Contests/tree/master/AS3DTC_1/

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 2:50 pm

  88. Should we assume that DO’s can move/be outside of the bounds but still be passed into the update method? If so, should we assume that DO’s outside of the bounds are not valid neighbors even if they would be within the allowed range from the target DO?

    Jens Wegar

    11 Nov 09 at 3:30 pm

  89. @mesh

    Simple question but you haven’t defined a stage size? Is it set or are you making assumptions of a stage.scaleMode = StageScaleMode.NO_SCALE; alignment at TL and the exported swf to be contained withing a 100% html embed? Or is it a fixed size? Does this 36px 36px grid align to the TL of the stage?

    Cheers mate

    Elliot Rock

    11 Nov 09 at 4:12 pm

  90. Mike,

    It looks like you needed to consult a lawyer before creating rules for the competition! Sorry, I have another ambiguous case for you to rule on:

    In the rules you state that: “Code must be implemented in the provided ProximityManager.as class”

    My implementation uses an internal class as a helper. I didn’t realise this condition before I wrote it. Must all code be in ProximityManager.as or in the ProximityManager class? If it’s the former, I could put my internal class at the bottom (in which case, why can’t I just leave it as an external class? It’s much neater that way IMO). The latter seems a bit unfortunate, as it precludes many potential elegant solutions.

    Obviously I’m pushing towards the former, mostly because I don’t want to have wasted my time on an ineligible solution!

    Finally, and I must be missing something pretty fundamental, but how do you submit a solution? Do I just email you? I have put my code on GitHub as it happens. Can I just post/send you the repo?

    Regards, Alec

    Alec McEachran

    11 Nov 09 at 4:17 pm

  91. @Alec

    If you can, I would prefer if you use an internal class, as it just makes it a little easier for me to test. But if you need helper classes, that is fine.

    What I meant by the rule, is that you had to implement the public APIs in the included ProximityManager class. This is so I can easy do all of the tests.

    So, if you need extra custom classes, that is fine, but they cannot be part of, or from an existing library or framework.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 5:07 pm

  92. @Alec

    Email entries to me : mesh@adobe.com

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 5:07 pm

  93. @Elliot

    Stage size is set in TestRunner.as, although your code doesn’t know about that. I pass in the bounds to the constructor.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 5:08 pm

  94. @Jens


    Should we assume that DO’s can move/be outside of the bounds but still be passed into the update method?

    Good question. For the contest, assume all items have their x,y coordinates within the stage bounds.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 5:09 pm

  95. could you please provide an image of what the result should be (with the grid and the valid colored circle)

    The check result is only based on distance, is this the goal? or is it realy the adjacent grid cell (event if the distance from the checkSprite is a bit more than sqrt(grid*2+grid*2)). Also, is the adjacent cells from the checkSprite considering only the center of it, or include the bounds (with the default size, is it always 9 cells or it can be more)

    Thanks

    jpauclair

    11 Nov 09 at 8:36 pm

  96. since you moved the circles from 0,0,5 to 5,5,5 they can now mostly appear on one cell even if the exact x,y position is in the adjacent cell.

    jpauclair

    11 Nov 09 at 8:38 pm

  97. @jpauclair


    could you please provide an image of what the result should be (with the grid and the valid colored circle)

    Grab the latest files. The validate function now draws a grid and colors the items you select. Makes it easier to test.

    mike chambers

    mesh@adobe.com

    mikechambers

    11 Nov 09 at 10:18 pm

  98. @jpauclair


    since you moved the circles from 0,0,5 to 5,5,5 they can now mostly appear on one cell even if the exact x,y position is in the adjacent cell.

    Yes. That is fine.

    mike chambers

    mikechambers

    11 Nov 09 at 10:19 pm

  99. @mikechambers
    Seem the TestRunner.as will not call the checkResults and draw the result screen.

    I add some code after the runTests(); for drawing the result.

    var v:Vector.
    proximityManager.update(items);
    v = proximityManager.getNeighbors(checkSprite_1);
    checkResults(checkSprite_1,v);
    v = proximityManager.getNeighbors(checkSprite_2);
    checkResults(checkSprite_2,v);
    v = proximityManager.getNeighbors(checkSprite_3);
    checkResults(checkSprite_3,v);
    v = proximityManager.getNeighbors(checkSprite_4);
    checkResults(checkSprite_4,v);

    Here is a sample output. http://pic.gd/2485a3

    wailam

    11 Nov 09 at 11:35 pm

  100. Assumption: It is not safe to rely on or manipulate the objects vector that is passed in the update method, a copy must be made.

    Andrew Traviss

    11 Nov 09 at 11:35 pm

  101. @Andrew Traviss
    I think mike should state this assumption in the rule. Otherwise, i can cache the result. I have tested, it have different of 20X performance if i cache the result.

    wailam

    11 Nov 09 at 11:54 pm

  102. @wailam

    Yeah, you have to hook up that call.

    mike chambers

    mikechambers

    12 Nov 09 at 12:26 am

  103. @Andrew


    Assumption: It is not safe to rely on or manipulate the objects vector that is passed in the update method, a copy must be made.

    Yes, since it is passed in by reference, it is not safe to change it, since you dont know what else is using it.

    mike chambers

    mesh@adobe.com

    mikechambers

    12 Nov 09 at 12:28 am

  104. Mike, you mentioned briefly that we cannot assume “the fact that the items are not moving.” However, since this rule isn’t enforced by checkResults(), it seems like submissions ignoring this requirement could possibly have a performance advantage. Is there any way we can add some code that shuffles the positions of the displayobjects in checkResults?

    Jon

    12 Nov 09 at 1:01 am

  105. @jon

    I check the code, and if I miss anything, all of the top entries will have a public review period before we announce the final winner.

    I was going to write up some code that would randomize it, but, im never going to have a perfect test, and I expect people to follow the spirit of the contest.

    If they dont, then I will simply reject their entries (which I have already done more than once).

    mike chambers

    mikechambers

    12 Nov 09 at 1:40 am

  106. @mikechambers

    You say “Your code cannot make assumptions [...] the fact that items are not moving”. This assumptions thing is bugging me, the rules aren’t that clear.

    Can we at least assume the items aren’t moving between the update() call and the getNeighbors call()? This would allow some caching.

    Also: can we assume the stage has fixed dimensions, that all items are within a [0,0,stageWidth,stageHeight] rectangle and can you tell us what’s the maximum stageWidth/stageHeight to support?

    Arnaud Gatouillat

    12 Nov 09 at 4:13 am

  107. Hi Mike. Great competition, I’m just finishing my version, but I would just like to say that maybe it would be good to update the checkResult function with this:

    disp.graphics.drawCircle( 0 , 0 , 5 );

    instead of this:

    disp.graphics.drawCircle( 5 , 5 , 5 );

    It makes it easier (for me anyway) to check if the right circles are returned :-)

    best, Michael

    Michael

    12 Nov 09 at 5:35 am

  108. Suggestion: Create a list of all submitted entries with a marker “Accepted/Rejected” next to them, so everyone knows the status of their entry. Might save you a couple of “What happened to my entry” -emails

    Not sure if there is any difference if this is done before or after the contest closes…

    Jens Wegar

    12 Nov 09 at 8:34 am

  109. [...] through the comments in the original contest post, especially the comments that I made. There are some rule [...]

  110. @Jens

    I have emailed everyone whose submissions had an issue thus far.

    mike chambers

    mesh@adobe.com

    mikechambers

    12 Nov 09 at 11:39 am

  111. @Arnauld

    All of your questions are addressed in clarifications I have made in the comments.

    mike chambers

    mesh@adobe.com

    mikechambers

    12 Nov 09 at 11:40 am

  112. Hey, there.

    Quick question:
    Who’s the getNeighbors() response (the vectors) owner?
    Can we reuse them or should we leave them for outside use?

    Kishi

    12 Nov 09 at 12:42 pm

  113. By the way, you said that the bounds are passed ‘because some implementations dont require it. Ill change the test code so it is always passed in (and you can use it if you need to)’.

    Does that mean that we don’t have to respect it?
    I mean, what if you getNeighbors() to a DO near the bounds and it returns a DO outside it?
    If you can just ignore the bounds because of your implementation, you wouldn’t know it’s outside the box.

    - mrkishi

    Kishi

    12 Nov 09 at 2:11 pm

  114. @Kishi

    Yes, you need to use the bounds passed in. That is what I was trying to clarify.

    mike chambers

    mesh@adobe.com

    mikechambers

    12 Nov 09 at 2:13 pm

  115. @Kishi

    You need to return a new Vector from getNeighbors().

    mike chambers

    mesh@adobe.com

    mikechambers

    12 Nov 09 at 2:39 pm

  116. Just submitted my entry, looking forward to seeing the top entries (I’m pretty certain mine isn’t one of them!) to see how they got such blazing performance!

    anatomic

    13 Nov 09 at 6:58 am

  117. Submitted my entry last night; you just want the ProximityManager class via mesh@adobe.com, correct?

    Steve Sedlmayr

    13 Nov 09 at 10:54 am

  118. [...] Friday I participated in the first ActionScript 3 Development Task Contest, which challenged users to divide the stage into a grid and to find all the neighbors of a given [...]

Leave a Reply