Can someone take a look to a little project I made? Is not finished yet, but Iβd like to have some feedback. Itβs my first almost-complete Clojure software: https://github.com/mdallastella/fen-to-graph
Thanks
mdallastella coord-list, isn't that a map
on a (range 0 9)
I've never had the ability to read loops in clojure.
@slipset: coord-list should be a vector like [:a8 :b8 :c8 β¦ :f1 :g1 :h1]
probably there are better ways to do it
any idea?
Yes, I mean a map
as in the function map
, not the datastructure
A thing I often look for when code-reviewing javascript is code like:
function f(ints) {
var result = [];
ints.forEach(i) {
result.push(i++);
}
return result;
}
instead of using map, I see
exactly
let me try to rewrite it using map
might just be that map-indexed is what you're looking for
crap, it might actually be a reduce of some sort, since you might need to keep track of the row you're on π
@slipset: what about this:
(map-indexed (fn [i v] (keyword (str v (mod (inc i) 8 )))) (flatten (repeat 8 column-list)))
Doesn't quite get what you want, but with some more math skillz it might work.
(def coord-list
(flatten
(map (fn [n] (map #(keyword (str % n)) column-list))
(range 8 0 -1))))
double map
@slipset what about the rest?
This is what I was looking for:
(map #(keyword (str %1 %2))(cycle column-list) (mapcat (partial repeat 8) (range 1 9)))
π
@slipset: this is what I need, thanks: (map #(keyword (str %1 %2)) (cycle files) (mapcat (partial repeat 8) (range 8 0 -1)))
from :a8 down to :h1
cool!
I guess expand-row-empty-squares
could get some of the same treatment
also, I guess your number->underscore
could make some use of ->
or ->>
and why (Integer/parseInt (str n))
shouldn't n
suffice?
mdallastella: kudos for using juxt!
althugh seems like (filter board/valid-coord? ((apply juxt functions) position))
is repeated across all the pieces?
@slipset: juxt is a mind blowing and amazing function π
Yep, some code can be refactored π
mdallastella: rook-moves and bishop-moves are basically the same, just a function of how they move? up-left up-right-down-left down-right vs up right down left
Maybe the pieces could have the allowed moves as a value on them?
or Piece could have a get-moves which would return [up right down left] for a rook?
To me it seems a bit strange with a record called Rook and a function called rook-moves, that's sort of what I'm trying to address.
I guess you could also make a (defmulti valid-moves type)
and then (defmethod valid-moves fen-to-graph.pieces.King ...)
But I'm not sure on the stylishness in mixing records/protocols and multimethods
@slipset: as soon as I come home from a customer, Iβll answer you, thanks :simple_smile:
no worries :simple_smile:
I like reading code, and especially golfing with other peoples code :simple_smile:
π :simple_smile:
coord-list is simplest as a for comprehension isn't it? (for [row (range 1 9) col column-list] ...)
apply concat map in fen.clj can just be mapcat