Skip to content

Instantly share code, notes, and snippets.

View ihodes's full-sized avatar

Isaac Hodes ihodes

View GitHub Profile
#! /bin/sh
SCRIPT_NAME=$(basename $0)
short_usage()
{
echo "Cf : $SCRIPT_NAME [--help]"
}
long_usage()
{
@ihodes
ihodes / reversi-move-valid.clj
Created May 1, 2012 00:10 — forked from mistercam/reversi-move-valid.clj
A function to determine if a move in Reversi is valid
(def directions
{:N [-1 0] :NE [-1 1] :E [0 1] :SE [1 1] :S [1 0] :SW [1 -1] :W [0 -1] :NW [-1 -1]})
(defn move-valid? [board piece move]
"Returns true if the specified move for the specified piece will cause
a piece to be flipped in any direction."
(let [r (move 0) c (move 1)]
(cond
(or (> r 7) (< r 0) (> c 7) (< c 0)) nil
(not= nil ((board r) c)) nil