Permalink
Browse files

Let david2 and david3 measure chains from the middle too

  • Loading branch information...
dvrensk committed Jan 15, 2013
1 parent 8a355cb commit cdd59b17391bdf1301262c1fdfcbc99a7fb0bfeb
Showing with 14 additions and 4 deletions.
  1. +7 −2 src/gomoku/team_david2.clj
  2. +7 −2 src/gomoku/team_david3.clj
@@ -13,9 +13,12 @@
y (range -1 2)
:when (not (and (= 0 x) (= 0 y)))]
[x y]))
+(def half-dirs [ [-1 -1] [-1 0] [-1 +1] [0 -1] ])
(defn add-pos [p1 p2]
(map + p1 p2))
+(defn opposite-dir [[x y]]
+ [(- 0 x) (- 0 y)])
(defn neighbours2 [position]
(map #(add-pos position %) dirs))
@@ -31,8 +34,10 @@
(defn positions-with-chain-length [candidates state player]
(let [moves (gameplay/get-positions-of-moves-for-player state player)]
(for [pos candidates
- dir dirs]
- [pos (gameplay/nr-of-moves-in-dir (cons pos moves) pos dir)])))
+ dir half-dirs]
+ [pos (+ (gameplay/nr-of-moves-in-dir (cons pos moves) pos dir)
+ (gameplay/nr-of-moves-in-dir (cons pos moves) pos (opposite-dir dir))
+ -1)])))
(defn middle-of-board [a b]
[(int (/ a 2)) (int (/ b 2))])
@@ -13,9 +13,12 @@
y (range -1 2)
:when (not (and (= 0 x) (= 0 y)))]
[x y]))
+(def half-dirs [ [-1 -1] [-1 0] [-1 +1] [0 -1] ])
(defn add-pos [p1 p2]
(map + p1 p2))
+(defn opposite-dir [[x y]]
+ [(- 0 x) (- 0 y)])
(defn neighbours2 [position]
(map #(add-pos position %) dirs))
@@ -31,8 +34,10 @@
(defn positions-with-chain-length [candidates state player]
(let [moves (gameplay/get-positions-of-moves-for-player state (gameplay/other-player player))]
(for [pos candidates
- dir dirs]
- [pos (gameplay/nr-of-moves-in-dir (cons pos moves) pos dir)])))
+ dir half-dirs]
+ [pos (+ (gameplay/nr-of-moves-in-dir (cons pos moves) pos dir)
+ (gameplay/nr-of-moves-in-dir (cons pos moves) pos (opposite-dir dir))
+ -1)])))
(defn middle-of-board [a b]
[(int (/ a 2)) (int (/ b 2))])

0 comments on commit cdd59b1

Please sign in to comment.