-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/lambda #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Feature/lambda #405
Conversation
src/wombats/lib/wombat_lib.clj
Outdated
|
|
||
| (defn add-to-state | ||
| "Update the global saved state with the given element and position" | ||
| [matrix elem] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably would be cleaner to destructure in the args list so you don't need the let block.
(defn add-to-state
[matrix {:keys [x y] :as elem}]
(assoc matrix y (assoc (nth matrix y) x elem))
src/wombats/lib/wombat_lib.clj
Outdated
| If no self coordinates are provided, use distance from {:x 3 :y 3}" | ||
| ([dir {x_tar :x y_tar :y} arena-half {x_self :x y_self :y}] | ||
| (case dir | ||
| "n" (and (not (= y_tar y_self)) (>= arena-half (mod (- y_self y_tar) (* arena-half 2)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not= would probably be better
src/wombats/lib/wombat_lib.clj
Outdated
|
|
||
| (defn can-shoot-barrier? | ||
| "Returns true if there is a barrier within shooting range" | ||
| ([dir arena arena-size shot-range self] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't shooting range constant? If so it might be good to have this as a constant defined up top and use it down here.
src/wombats/lib/wombat_lib.clj
Outdated
| "Return true if you can move forward without a collision or poison" | ||
| [arena {x :x y :y}] | ||
| (not (in? (get-in (nth (nth arena y) x) [:contents :type]) | ||
| ["zakano" "wombat" "wood-barrier" "steel-barrier" "poison"]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good for these strings to be constants up that can be used in a user's own functions / used here. Maybe something like zakano-key, etc.
src/wombats/lib/wombat_lib.clj
Outdated
| "Constructs an initial global state populated by fog" | ||
| [global-size] | ||
| (add-locs (into [] (map (fn [_] | ||
| (into [] (map (fn [_] {:type "fog"}) (range global-size)))) (range global-size))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to have this also as a constant up on top ("fog")
src/wombats/lib/wombat_lib.clj
Outdated
| [arena] | ||
| (reduce | ||
| #(conj %1 | ||
| (reduce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think map is a better method for this (and the following line). Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that using reduce isn't the clearest method here, but how would I be able to do this using map? I'm adding the location data to each tile in the arena so I need to know the position of the element relative to the beginning of the array. I was able to accomplish this by tracking the state in reduce's accumulator, but I couldn't see how I would be able to use map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe use something like: map-indexed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that'd work great. I just didn't know that was an available function. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions. Still need to review some more. Looks good though!
CHANGELOG.md
Outdated
| [/oconn]: https://github.com/oconn | ||
| [/erochest]: https://github.com/erochest | ||
| [/elibosley]: http://github.com/elibosley | ||
| [/daniel-hoerauf]: http://github.com/Daniel-Hoerauf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this https for consistency.
lambda/javascript/index.js
Outdated
| @@ -0,0 +1,34 @@ | |||
| // Import the standard library and add elper functions to the same namespace | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[h]elper
src/wombats/lib/wombat_lib.clj
Outdated
|
|
||
| (defn get-arena-size | ||
| "Fetches the size of one side of the arena from the state" | ||
| [state] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm not entirely sure that I like this more but figured I'd show some additional options. Feel free to use whichever you like the best.
(defn get-arena-size
[{[width height] :global-dimensions}]
{:width width
:height height})
src/wombats/lib/wombat_lib.clj
Outdated
| size (get-arena-size state)] | ||
| (if (nil? saved) | ||
| (build-initial-global-state size) | ||
| saved ))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space here
| 2 :about-face | ||
| 3 :right))) | ||
|
|
||
| (defn can-shoot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this end with a ? since it returns a boolean.
src/wombats/lib/wombat_lib.js
Outdated
| y: local_state['global-coords'][1] | ||
| }; | ||
|
|
||
| for (i = 0; i < local_tiles.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have to use a for loop, you should declare the variable.
for (let i = 0; i < ...
src/wombats/lib/wombat_lib.js
Outdated
| }; | ||
|
|
||
| this.get_global_state = function(state, path) { | ||
| var temp = state; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are you trying to do with temp here?
src/wombats/lib/wombat_lib.js
Outdated
| break; | ||
| case 'w': | ||
| return (target.x != wombat.x) && (x_half >= mod(wombat.x - target.x, (x_half * 2))); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break isn't needed since you already have returned.
src/wombats/lib/wombat_lib.js
Outdated
| break; | ||
| case 'e': | ||
| return wom.y == tile.y && (shot_range >= mod(tile.x - wom.x, arena_size.width)); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break not needed.
src/wombats/lib/wombat_lib.js
Outdated
| return wom.x == tile.x && (shot_range >= mod(tile.y - wom.y, arena_size.height)); | ||
| break; | ||
| case 'w': | ||
| return wom.x == tile.x && (shot_range >= mod(wom.y - tile.y, arena_size.width)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
===
PR for issue # .
Ready for a PR?
Implementation Notes:
Migrated wombats-lambda and created a script to manage updating the Lambda functions.
Also includes the shell of the wombats standard library to work with Lambda and running locally, but it is not yet ported to all languages or documented.
Breaking changes: