Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Pelensky pelensky

View GitHub Profile
@pelensky
pelensky / unbeatable_computer.clj
Created Jul 28, 2017
Negamax in Clojure - no Alpha Beta pruning
View unbeatable_computer.clj
(ns tic-tac-toe.unbeatable-computer
(:require [tic-tac-toe.board :as ttt-board]))
(declare negamax)
(def starting-depth 0)
(def starting-colour 1)
(defn find-computer-marker [board-state]
(if ( #(even? (count %)) (get board-state :board))
"X" "O"))
@pelensky
pelensky / display.clj
Created Aug 1, 2017
Game Of Life Display for an Infinite World in Clojure
View display.clj
(ns game-of-life.display)
(defn- current-x [coordinates]
(get (first coordinates) 0))
(defn- current-y [coordinates]
(get (first coordinates) 1))
(defn- remaining [coordinates]
into [] (rest coordinates))
@pelensky
pelensky / life.clj
Last active Aug 1, 2017
Game Of Life Logic for an Infinite World in Clojure
View life.clj
(ns game-of-life.life)
(def fewest-neighbours-to-stay-living 2)
(def most-neighbours-to-stay-living 3)
(def exact-neighbours-to-regenerate 3)
(def neighbours
[ [-1 1] [0 1] [1 1]
[-1 0] [1 0]
[-1 -1] [0 -1] [1 -1]])
@pelensky
pelensky / boardObject.java
Created Aug 11, 2017
Board Object class with a getter and a setter to get JSON into Clojure
View boardObject.java
package networkplayer;
public class BoardObject {
private String boardState;
public void setBoardState(String boardState) {
this.boardState = boardState;
}
@pelensky
pelensky / computer.clj
Last active Aug 11, 2017
All functions required for Network Computer Player Lambda
View computer.clj
(ns computer
(:gen-class
:methods [[handler [networkplayer.BoardObject] Long]]) )
(declare negamax)
(def starting-depth 0)
(def starting-colour 1)
; Code removed
@pelensky
pelensky / app-runner.clj
Created Aug 11, 2017
App Runner namespace, with parts of the code I haven't changed removed.
View app-runner.clj
(ns tic-tac-toe.app-runner
(:require clj-http.client :as client]))
; Code removed
(defn- api-call [board-state]
(let [result (client/post "https://xast1bug7h.execute-api.us-east-1.amazonaws.com/ttt" {:form-params {"boardState" (str board-state)} :content-type :json} )]
(read-string (get result :body))))
(defn- player-move [board-state player]
View keybase.md

Keybase proof

I hereby claim:

  • I am pelensky on github.
  • I am pelensky (https://keybase.io/pelensky) on keybase.
  • I have a public key ASAFyvEoyVgoewByUAdPqSca5BlRi00zTZHBQTmmJ7UdEAo

To claim this, I am signing this object: