Advertisement
Guest User

Untitled

a guest
Apr 17th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.00 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.org
  2. // See the 'F# Tutorial' project for more help.
  3. open System
  4. open System.IO
  5. open ilf.pgn
  6. open ilf.pgn.Data
  7.  
  8. //open and process data
  9. let reader = new PgnReader()
  10. let gameDb = reader.ReadFromFile(@"C:\Users\Dmitriy\Downloads\ficsgamesdb_201501_standard2000_nomovetimes_1237064.pgn");
  11. let games = gameDb.Games
  12.  
  13. let moves = games.ConvertAll(fun x -> x.MoveText.GetMoves())
  14. let results = games.ConvertAll(fun x -> x.Result)
  15. let converted_results = List.ofSeq results
  16. let converted = List.ofSeq moves
  17. let to_f_sharp_lists = converted |> List.map (fun x -> List.ofSeq x)
  18.  
  19. let FreqDict S =
  20.     Seq.fold (
  21.         fun(ht:Map<_, int>) v ->
  22.             if Map.containsKey v ht then Map.add v ((Map.find v ht)+1) ht
  23.             else Map.add v 1 ht)
  24.             (Map.empty) S
  25.  
  26.  
  27. let finalized1 = to_f_sharp_lists |> List.map (fun x -> String.Join(",", x).Split(',') |> Array.toList)
  28.  
  29. let selectedList = finalized1 |> List.filter (fun x -> x.Length > 30)
  30.  
  31. let enumerate x =
  32.     x |> List.mapi (fun i x -> (i, x))
  33.  
  34. let whitePlays = [for item in selectedList -> ((enumerate item) |> List.filter (fun i -> fst (i) % 2 = 0)) |> List.unzip |> snd]
  35.  
  36. let blackPlays = [for item in selectedList -> (enumerate item) |> List.filter (fun i -> fst (i) % 2 = 1) |> List.unzip |> snd]
  37.  
  38. let whiteacc = [for item in whitePlays |> List.filter (fun x -> x.Length > 30) do
  39.                     for j in 1..30-> item |> List.splitAt j |> fst]
  40.                     |> FreqDict |> Map.toList |> List.filter (fun x -> snd x > 1)
  41.                     |> List.unzip |> fst
  42.                     |> List.maxBy (fun x -> List.length x) |> List.length
  43.                    
  44. let freq = [[for item in blackPlays |> List.filter (fun x -> x.Length > 30) do
  45.                 for j in 1..30-> item |> List.splitAt j]]
  46.                  |> FreqDict |> Map.toList |> List.filter (fun x -> snd x > 1)
  47.                  |> List.unzip |> fst
  48.                  |> List.maxBy (fun x -> List.length x) |> List.length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement