Skip to content

Instantly share code, notes, and snippets.

View dschinkel's full-sized avatar
💻

Dave Schinkel dschinkel

💻
View GitHub Profile
@dschinkel
dschinkel / elm-package.json
Last active September 7, 2018 02:22
Example of Setting up elm-test-bdd-style and getting it talking to an Elm Module
{
"version": "1.0.0",
"summary": "minMax TDD Kata",
"repository": "https://github.com/dschinkel/elm-minmax-kata.git",
"license": "MIT",
"source-directories": [
"tests"
],
"exposed-modules": [
"Example"
@dschinkel
dschinkel / Solver.elm
Last active September 9, 2018 23:25
miniMax Algorithm in Elm - Tests - Will Win With Next Move - Attempt 1
module Solver exposing (..)
import Array exposing (fromList, get)
import List exposing (filter)
nextBestMove : List Char -> Int
nextBestMove gameNode =
3
@dschinkel
dschinkel / SolverSpec.elm
Last active September 9, 2018 23:56
miniMax Algorithm in Elm - Tests - next move wins for a row - Attempt 1 - Test Only
it "next move wins for a row" <|
let
gameNode =
[ markerX, markerX, empty, empty, empty, empty, empty, empty, empty ]
cellThreeIndex =
2
nextMove =
Solver.nextBestMove gameNode
@dschinkel
dschinkel / SolverSpec.elm
Last active September 9, 2018 23:56
miniMax Algorithm in Elm - Tests - next move wins for a column - Attempt 1 - Test Only
it "next move wins for a column" <|
let
gameNode =
[ markerX, empty, empty, markerX, empty, empty, empty, empty, empty ]
cellSevenIndex =
6
nextMove =
Scorer.nextBestMove gameNode
@dschinkel
dschinkel / Scorer.elm
Last active September 10, 2018 20:00
miniMax Algorithm in Elm - Tests - next move wins for row 2
module Scorer exposing (..)
import Array exposing (fromList, get, set)
-- below won't work, you can't do this in elm. You can't have two statements in the in of a let like this
nextBestMove : List Char -> Int
nextBestMove gameNode =
let
cells =
fromList gameNode
@dschinkel
dschinkel / ScorerSpec.elm
Last active September 11, 2018 18:37
miniMax Algorithm in Elm - Tests - next move wins for row 2
nextBestMove gameNode =
let
cells =
fromList gameNode
nextGameState1 =
set 2 'X' cells
nextGameState2 =
{--
Below shows some code commands that if entered into elm repl shows the output received
--}
import List
empty = ' '
markerX = 'X'
markerO = 'O'
gameNode = [ [ markerX, empty, empty ], [ markerO, markerO, empty ], [ markerX, empty, empty ]]
@dschinkel
dschinkel / Scorer.elm
Last active September 11, 2018 19:09
miniMax Algorithm in Elm - Tests - next move wins for row 2 - With a 2-dimensional array instead
module Scorer exposing (..)
import Array exposing (fromList, get, set)
import List exposing (map)
import Maybe exposing (withDefault)
nextBestMove : List (List Char) -> Int
nextBestMove gameNode =
let
@dschinkel
dschinkel / Scorer.elm
Created September 11, 2018 19:02
Elm - Maybe Examples
row1NextState =
set 2 'X' (withDefault (Array.initialize 3 (always ' ')) row1)
@dschinkel
dschinkel / FunctionalApplication-Example1.elm
Created September 11, 2018 22:06
Elm - Basics - Example
myAnswerArray =
Array.fromList ["S"]
|> Array.set 5279 "S"