Skip to content

Instantly share code, notes, and snippets.

View dschinkel's full-sized avatar
💻

Dave Schinkel dschinkel

💻
View GitHub Profile
@dschinkel
dschinkel / PlayingWithElmDictionaries.elm
Last active September 20, 2018 05:27
Elm - Dictionaries
-- instead of using a 2D list or 2D array to represent a game node/board, lets use a Dict instead
-- with Dict unlike List or Array, it's much easier to insert, find, and update values
{--
repl:
make sure you have no trailing spaces after \. Also, might need to uses spaces not tab in Sublime text
import Dict
board = Dict.fromList \
[ \
@dschinkel
dschinkel / ArrayCustomHelpers.elm
Last active September 16, 2018 02:47
Elm - Helper Functions I've Created
{--
Overview
- this only works with List or Array of Char. I'll change it to be generic soon.
- Example list sent in: [['X',' ',' '],['O','O',' '],['X',' ',' ']] : List (List Char)
- After Conversion it's type of Array.Array (Array.Array Char)
##### If you'd like to try this out in elm repl, run the following:#####
@dschinkel
dschinkel / Scorer.elm
Created September 11, 2018 23:41
miniMax Algorithm in Elm - Tests - next move wins - Implementation 3 - Fold using List.all instead
module Scorer exposing (..)
import Array exposing (fromList, get, map, set, toList)
import List exposing (all, foldl, map)
import Maybe exposing (withDefault)
markerX : Char
markerX =
'X'
@dschinkel
dschinkel / Scorer.elm
Created September 11, 2018 22:49
miniMax Algorithm in Elm - Tests - next move wins - Implementation 3 - With Fold
module Scorer exposing (..)
import Array exposing (fromList, get, map, set)
import List exposing (foldl, map)
import Maybe exposing (withDefault)
markerX : Char
markerX =
'X'
@dschinkel
dschinkel / FunctionalApplication-Example1.elm
Created September 11, 2018 22:06
Elm - Basics - Example
myAnswerArray =
Array.fromList ["S"]
|> Array.set 5279 "S"
@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 / 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
{--
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 / 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 =
@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