Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Learn more about F# at http://fsharp.org
- // See the 'F# Tutorial' project for more help.
- open System
- open System.IO
- open ilf.pgn
- open ilf.pgn.Data
- //open and process data
- let reader = new PgnReader()
- let gameDb = reader.ReadFromFile(@"C:\Users\Dmitriy\Downloads\ficsgamesdb_201501_standard2000_nomovetimes_1237064.pgn");
- let games = gameDb.Games
- let moves = games.ConvertAll(fun x -> x.MoveText.GetMoves())
- let results = games.ConvertAll(fun x -> x.Result)
- let converted_results = List.ofSeq results
- let converted = List.ofSeq moves
- let to_f_sharp_lists = converted |> List.map (fun x -> List.ofSeq x)
- let FreqDict S =
- Seq.fold (
- fun(ht:Map<_, int>) v ->
- if Map.containsKey v ht then Map.add v ((Map.find v ht)+1) ht
- else Map.add v 1 ht)
- (Map.empty) S
- let finalized1 = to_f_sharp_lists |> List.map (fun x -> String.Join(",", x).Split(',') |> Array.toList)
- let selectedList = finalized1 |> List.filter (fun x -> x.Length > 30)
- let enumerate x =
- x |> List.mapi (fun i x -> (i, x))
- let whitePlays = [for item in selectedList -> ((enumerate item) |> List.filter (fun i -> fst (i) % 2 = 0)) |> List.unzip |> snd]
- let blackPlays = [for item in selectedList -> (enumerate item) |> List.filter (fun i -> fst (i) % 2 = 1) |> List.unzip |> snd]
- let whiteacc = [for item in whitePlays |> List.filter (fun x -> x.Length > 30) do
- for j in 1..30-> item |> List.splitAt j |> fst]
- |> FreqDict |> Map.toList |> List.filter (fun x -> snd x > 1)
- |> List.unzip |> fst
- |> List.maxBy (fun x -> List.length x) |> List.length
- let freq = [[for item in blackPlays |> List.filter (fun x -> x.Length > 30) do
- for j in 1..30-> item |> List.splitAt j]]
- |> FreqDict |> Map.toList |> List.filter (fun x -> snd x > 1)
- |> List.unzip |> fst
- |> List.maxBy (fun x -> List.length x) |> List.length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement