Created
June 14, 2017 19:16
-
-
Save JeffML/c7fd3fb6549b71f5f3c65157bdef5493 to your computer and use it in GitHub Desktop.
calculating diagonal moves with friendly blockers
This file contains hidden or 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
// m: proposed move | |
// blockers: blocking pieces | |
// pp: current piece position | |
function diagonalChecks(m, blockers, pp) { | |
let isGood = true; | |
for (const b of blockers) { | |
if (b.rank > pp.rank && b.file > pp.file) { | |
if (m.rank > pp.rank && m.file > pp.file) { | |
isGood = isGood && (m.rank < b.rank && m.file < b.file); | |
} | |
} | |
if (b.rank > pp.rank && b.file < pp.file) { | |
if (m.rank > pp.rank && m.file < pp.file) { | |
isGood = isGood && (m.rank < b.rank && m.file > b.file) | |
} | |
} | |
if (b.rank < pp.rank && b.file > pp.file) { | |
if (m.rank < pp.rank && m.file > pp.file) { | |
isGood = isGood && (m.rank > b.rank && m.file < b.file) | |
} | |
} | |
if (b.rank < pp.rank && b.file < pp.file) { | |
if (m.rank < pp.rank && m.file < pp.file) { | |
isGood = isGood && (m.rank > b.rank && m.file > b.file) | |
} | |
} | |
} | |
return isGood; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment