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.
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.
(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.
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.
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.
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.
I think map is a better method for this (and the following line). Thoughts?
There was a problem hiding this comment.
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.
Could you maybe use something like: map-indexed?
There was a problem hiding this comment.
Yup, that'd work great. I just didn't know that was an available function. Thanks!
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.
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 | |||
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.
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 ))) |
| 2 :about-face | ||
| 3 :right))) | ||
|
|
||
| (defn can-shoot |
There was a problem hiding this comment.
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.
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.
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.
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; |
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)); |
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: