From 0deab59db1dc882d5599f9b9e5099f09d3494a2c Mon Sep 17 00:00:00 2001 From: Chris Holt Date: Sun, 7 Sep 2014 13:45:43 -0500 Subject: [PATCH] performance fixes --- Dojo/Canopy2048/Interactions.fs | 22 ++++++++++++---------- Dojo/Canopy2048/Program.fs | 6 +++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Dojo/Canopy2048/Interactions.fs b/Dojo/Canopy2048/Interactions.fs index bb5d626..51c4525 100644 --- a/Dojo/Canopy2048/Interactions.fs +++ b/Dojo/Canopy2048/Interactions.fs @@ -4,23 +4,25 @@ open canopy open runner module Interactions = + let lostSelector = css ".game-message.game-over" + let winSelector = css ".game-message.game-won" + let gameOverSelector = css ".game-message.game-won, .game-message.game-over" - let lost () = - match someElement <| css ".game-message.game-over" with + let lost () = + match someElement <| lostSelector with | None -> false | Some(_) -> true - let won () = - match someElement <| css ".game-message.game-won" with + + let won () = + match someElement <| winSelector with | None -> false | Some(_) -> true - let gameEnded = - let driver = lazy(Seq.head browsers) - let css = ".game-message.game-won, .game-message.game-over" - let selector = OpenQA.Selenium.By.CssSelector(css) - fun () -> - driver.Value.FindElements(selector).Count > 0 + let gameEnded () = + match someElement <| gameOverSelector with + | None -> false + | Some(_) -> true let state () = elements ".tile" diff --git a/Dojo/Canopy2048/Program.fs b/Dojo/Canopy2048/Program.fs index 5ddc92f..f0bcc3f 100644 --- a/Dojo/Canopy2048/Program.fs +++ b/Dojo/Canopy2048/Program.fs @@ -40,7 +40,7 @@ open Interactions module program = configuration.optimizeBySkippingIFrameCheck <- true - configuration.optmizeByDisablingCoverageReport <- true + configuration.optimizeByDisablingCoverageReport <- true "starting a game of 2048" &&& fun _ -> @@ -157,8 +157,8 @@ module program = | Up -> press up | Right -> press right | Down -> press down - if lost() || won() - //if gameEnded() + //if lost() || won() + if gameEnded() then ignore() else play (shuffle moves) (counter + 1)