Skip to content

Commit

Permalink
Not really smart bot added =) for
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Aug 25, 2014
1 parent d6ebca2 commit c16859a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Dojo/Canopy2048/Canopy2048.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="canopy">
<HintPath>packages\canopy.0.9.8\lib\canopy.dll</HintPath>
<HintPath>packages\canopy.0.9.13\lib\canopy.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>packages\Newtonsoft.Json.5.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<HintPath>packages\Newtonsoft.Json.6.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="SizSelCsZzz">
<HintPath>packages\SizSelCsZzz.0.3.35.0\lib\SizSelCsZzz.dll</HintPath>
<HintPath>packages\SizSelCsZzz.0.3.36.0\lib\SizSelCsZzz.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="WebDriver">
<HintPath>packages\Selenium.WebDriver.2.41.0\lib\net40\WebDriver.dll</HintPath>
<HintPath>packages\Selenium.WebDriver.2.42.0\lib\net40\WebDriver.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="WebDriver.Support">
<HintPath>packages\Selenium.Support.2.41.0\lib\net40\WebDriver.Support.dll</HintPath>
<HintPath>packages\Selenium.Support.2.42.0\lib\net40\WebDriver.Support.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand Down
36 changes: 34 additions & 2 deletions Dojo/Canopy2048/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ module program =
you may have to install a browser driver
on your machine.
*)

start chrome


(*
Task 2: open the game url.
*)

url "http://gabrielecirulli.github.io/2048/"


(*
Expand Down Expand Up @@ -124,6 +124,38 @@ module program =
smarter!
*)

let shuffle moves =
let x::xs = moves
xs@[x]

let scores =
Map.ofSeq [ (Right, 2.0); (Up, 2.1); (Left,2.0); (Down, -10.0) ]

let rec getBestMove depth state moves =
let scores =
moves |> List.map (fun move ->
let score01, state1 = execute state move
let score1 = float(score01) * scores.[move]
if depth = 0
then move, score1
else
let _, score2 = getBestMove (depth-1) state1 (shuffle moves)
move, float(score1)+score2*0.5 )
scores |> List.maxBy snd

let rec play moves =
let move = getBestMove 3 (state()) moves
printfn "%A" move
match fst move with
| Left -> press left
| Up -> press up
| Right -> press right
| Down -> press down
if lost() || won()
then ignore()
else play (shuffle moves)

play [Up; Right; Left; Down]


// Just to make sure the test function
Expand Down

0 comments on commit c16859a

Please sign in to comment.