This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 \ | |
[ \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-- | |
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:##### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Scorer exposing (..) | |
import Array exposing (fromList, get, map, set) | |
import List exposing (foldl, map) | |
import Maybe exposing (withDefault) | |
markerX : Char | |
markerX = | |
'X' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myAnswerArray = | |
Array.fromList ["S"] | |
|> Array.set 5279 "S" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
row1NextState = | |
set 2 'X' (withDefault (Array.initialize 3 (always ' ')) row1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-- | |
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 ]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nextBestMove gameNode = | |
let | |
cells = | |
fromList gameNode | |
nextGameState1 = | |
set 2 'X' cells | |
nextGameState2 = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |