Skip to content

Commit

Permalink
Fix: cut by bribe
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkbeforecoding committed Jun 29, 2020
1 parent 9267aa2 commit 92c7bf1
Show file tree
Hide file tree
Showing 12 changed files with 1,761 additions and 576 deletions.
79 changes: 47 additions & 32 deletions ReplayClientLog.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#r "c:/Users/jerem/.nuget/packages/fable.jsonconverter/1.0.8/lib/net45/Fable.JsonConverter.dll"
#r "c:/Users/jerem/.nuget/packages/fable.remoting.json/2.6.0/lib/netstandard2.0/Fable.Remoting.Json.dll"
#r "c:/Users/jerem/.nuget/packages/fable.core/3.1.5/lib/netstandard2.0/Fable.Core.dll"

#r "c:/Development/packages/FSharp.Data/lib/net45/FSharp.Data.dll"
#I "c:/Development/crazy/src/Shared/"
#load "Shared.fs" "SharedGame.fs"
#load "../Server/SharedServer.fs"
Expand All @@ -13,52 +13,67 @@ open Shared
open Fable
open Fable.Remoting.Json
open Newtonsoft.Json
open FSharp.Data

//type Envelope =
// { data: Data }
//and Data =
// { data: Notif [] }
//and Notif =
// { channel: string
// data: NotifData[] }
//and NotifData =
// { args: Args}

type Envelope =
{ data: Data }
and Data =
{ data: Notif [] }
and Notif =
{ channel: string
data: NotifData[] }
and NotifData =
{ args: Args}

and Args =
{ version: int
events: Board.Event []}
//and Args =
// { version: int
// events: Board.Event []}


let s =
let js = Newtonsoft.Json.JsonSerializer()
js.Converters.Add (FableJsonConverter())
js
let data =
use json = IO.File.OpenText @"C:\Development\crazy\dump\93831282\gamenotifs.json"
s.Deserialize<Envelope>(new JsonTextReader(json))
//let data =
// use json = IO.File.OpenText @"C:\Users\jerem\Downloads\gamelog.json"
// s.Deserialize<Envelope>(new JsonTextReader(json))

let events =
data.data.data
|> Array.collect(fun d -> if d.channel.StartsWith @"/table/" then d.data else [||])
|> Array.filter (fun d -> if isNull(box d) || isNull (box d.args) || isNull(d.args.events) then false else d.args.version < 200 )
|> Array.collect(fun d -> d.args.events)
Http.RequestStream("http://localhost/convert.php")
|> fun stream -> s.Deserialize<Board.Event []>(new JsonTextReader(new IO.StreamReader(stream.ResponseStream)))
|> Array.toList
|> List.takeWhile(function
| Board.Played(_, Player.CardPlayed(PlayBribe _)) -> false
| _ -> true )



let state = List.fold Board.evolve Board.initialState events

let es = Board.decide (Board.Play("88218789", Player.PlayCard(PlayBribe(Parcel(Axe(-1,0))) ))) state

//let events =
// data.data.data
// |> Array.collect(fun d -> if d.channel.StartsWith @"/table/" then d.data else [||])
// |> Array.filter (fun d -> if isNull(box d) || isNull (box d.args) || isNull(d.args.events) then false else d.args.version < 200 )
// |> Array.collect(fun d -> d.args.events)
// |> Array.toList


let start = Board.Start { Players = [ Color.Red, "85860037", "Chauff"; Color.Blue, "87747553", "Kenners2K"];
Goal = Common 27
Undo = FullUndo }
//let start = Board.Start { Players = [ Color.Blue, "88302919", "TEMPVSCANIS"; Color.Yellow, "88218789", "Ryochou"];
// Goal = Common 27
// Undo = FullUndo
// UseGameOver = false}

let started = Board.decide start Board.initialState
let startedBoard = List.fold Board.evolve Board.initialState started |> SharedServer.privateUndoableBoard ""
//let started = Board.decide start Board.initialState
//let startedBoard = List.fold Board.evolve Board.initialState started |> SharedServer.privateUndoableBoard ""

let state =
List.fold Board.evolve startedBoard (SharedServer.privateEvents "" events)
//let state =
// List.fold Board.evolve startedBoard (SharedServer.privateEvents "" events)

let cmd = Board.Play("87747553", Player.Move { Direction = Down; Destination = Crossroad(Axe(-2,2), CRight)})
//let cmd = Board.Play("87747553", Player.Move { Direction = Down; Destination = Crossroad(Axe(-2,2), CRight)})

let result = Board.decide cmd state
//let result = Board.decide cmd state

let finalState =
List.fold Board.evolve state ( SharedServer.privateEvents "" result)
//let finalState =
// List.fold Board.evolve state ( SharedServer.privateEvents "" result)
506 changes: 246 additions & 260 deletions bga/modules/crazyfarmers.php

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions php/FSharp.Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ function __construct($value)
{
$this->ErrorValue = $value;
}
}

class Option {
static function defaultArg($opt, $val)
{
return is_null($opt) ? $val : $opt;
}
}
15 changes: 15 additions & 0 deletions php/FSharpArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ public static function filter($filter,$array)
}
return $result;
}

public static function findIndex($predicate, $array)
{
$index = 0;
foreach ($array as $item)
{
if ($predicate($item))
{
return $index;
}
$index++;
}

return -1;
}
}
12 changes: 6 additions & 6 deletions php/FSharpList.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,24 @@ static function collect($projection, $list)

static function groupBy($property, $list)
{
$map = [];
$comparer = [ 'Compare' => 'Util::compare' ];
$map = Map::empty($comparer);

while($list instanceof Cons)
{
$key = $property($list->value);
$items = $map[$key] ?? [];
$items = Map::tryFind($key, $map) ?? [];
array_push($items, $list->value);
$map[$key] = $items;

$map = Map::add($key, $items, $map);
$list = $list->next;
}

$lst = NULL;
$p = &$lst;

foreach (array_keys($map) as $key)
foreach (Map::toSeq($map) as $kv)
{
$p = new Cons([ $key, FSharpList::ofArray($map[$key])], NULL);
$p = new Cons([ $kv[0], FSharpList::ofArray($kv[1])], NULL);
$p = &$p->next;
}

Expand Down
6 changes: 3 additions & 3 deletions php/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static function count($table)
static function ofList($list)
{
$tree = new MapEmpty();
$comparer = [ 'Compare' => 'Util::comparePrimitives' ];
$comparer = [ 'Compare' => 'Util::compare' ];

while ($list instanceof Cons)
{
Expand All @@ -335,7 +335,7 @@ static function ofList($list)
static function ofSeq($seq)
{
$tree = new MapEmpty();
$comparer = [ 'Compare' => 'Util::comparePrimitives' ];
$comparer = [ 'Compare' => 'Util::compare' ];

foreach ($seq as $item)
{
Expand All @@ -348,7 +348,7 @@ static function ofSeq($seq)
static function ofArray($seq)
{
$tree = new MapEmpty();
$comparer = [ 'Compare' => 'Util::comparePrimitives' ];
$comparer = [ 'Compare' => 'Util::compare' ];

foreach ($seq as $item)
{
Expand Down
14 changes: 14 additions & 0 deletions php/Seq.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ public static function map($projection, $seq)
yield $projection($item);
}
}

public static function choose($projection, $seq)
{
foreach($seq as $item)
{
$value = $projection($item);
if (!is_null($value))
{
yield $value;
}
}
}


public static function collect($projection, $seq)
{
foreach($seq as $item)
Expand Down
Loading

0 comments on commit 92c7bf1

Please sign in to comment.