-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,071 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
all: coffee js | ||
all: coffee js graph | ||
coffee: | ||
svgtiler -f map.coffee *.asc | ||
js: | ||
svgtiler -f map.jsx *.asc | ||
graph: | ||
svgtiler -f -o graph map.coffee graph.coffee *.asc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
b..r...r | ||
k....p.p | ||
p..q.np. | ||
NppP.... | ||
...p.Q.. | ||
P....PPB | ||
.PP....P | ||
.K.RR... |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Render piece attack graph | ||
|
||
size = 45 # width and height of svg files | ||
|
||
graphs = share.graphs ? 'knprbq' # which piece attack graphs to draw | ||
friendly = share.friendly ? false # include friendly fire attacks? | ||
graphColor = 'hsl(286,65%,50%,70%)' | ||
pieces = new Set ['k', 'n', 'p', 'r', 'b', 'q'] | ||
pieces.add lc.toUpperCase() for lc in (x for x from pieces) | ||
|
||
player = (key) -> | ||
key == key.toLowerCase() | ||
|
||
svgtiler.afterRender (render) -> | ||
{drawing} = render | ||
edges = [] | ||
for row, y in drawing.keys | ||
for key, x in row | ||
p1 = player key | ||
key = key.toLowerCase() | ||
continue unless graphs.includes key | ||
|
||
longMove = (dx, dy) -> | ||
x2 = x + dx | ||
y2 = y + dy | ||
while (neighbor = drawing.get x2, y2)? | ||
return [x2, y2] if pieces.has neighbor | ||
x2 += dx | ||
y2 += dy | ||
return null # no piece found | ||
|
||
switch key | ||
when 'k' | ||
neighbors = [[x-1, y+1], [x, y+1], [x+1, y], [x+1, y+1]] | ||
when 'n' | ||
neighbors = [[x-2, y+1], [x-1, y+2], [x+1, y+2], [x+2, y+1]] | ||
when 'p' | ||
neighbors = [[x-1, y+1], [x+1, y+1]] | ||
when 'r' | ||
neighbors = [ | ||
longMove +1, 0 | ||
longMove 0, +1 | ||
] | ||
when 'b' | ||
neighbors = [ | ||
longMove +1, +1 | ||
longMove -1, +1 | ||
] | ||
when 'q' | ||
neighbors = [ | ||
longMove +1, 0 | ||
longMove 0, +1 | ||
longMove +1, +1 | ||
longMove -1, +1 | ||
] | ||
else | ||
console.warn "Unknown piece type for graph: #{graph}" | ||
continue | ||
|
||
for neighbor in neighbors when neighbor? | ||
[x2, y2] = neighbor | ||
key2 = drawing.get x2, y2 | ||
continue unless pieces.has key2 | ||
p2 = player key2 | ||
continue unless friendly or p1 != p2 | ||
edges.push \ | ||
<line x1={x * size + size/2} | ||
y1={y * size + size/2} | ||
x2={x2 * size + size/2} | ||
y2={y2 * size + size/2} | ||
stroke={graphColor} stroke-width="10" stroke-linecap="round" | ||
/> | ||
|
||
<svg>{edges}</svg> | ||
|
||
null |
Oops, something went wrong.