コード例 #1
0
        ////
        //// GET: /Game/

        public JsonResult Index(int bucket1, int bucket2, int target)
        {
            IEnumerable <StateTransition> steps = GameSolver.Solve(bucket1, bucket2, target);

            string result = serializer.Serialize(new { Steps = steps.ToArray(), Message = string.Empty });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public void SolveBoard(string seed, string result, int numGenerations, string reason)
        {
            var seedBoard      = seed.FromString();
            var expectedResult = result.FromString();

            var actualResult = GameSolver.Solve(seedBoard, numGenerations);

            expectedResult.Should().BeEquivalentTo(actualResult, because: reason);
        }
コード例 #3
0
ファイル: GameSolverTest.cs プロジェクト: seylom/BucketGame
        public void SolveCapaCity2and18WithTarget4Returns4Steps()
        {
            int bucket1capacity = 2;
            int bucket2capacity = 18;
            int target          = 4;

            IEnumerable <StateTransition> result = GameSolver.Solve(bucket1capacity, bucket2capacity, target);

            Assert.AreEqual(result.ToList().Count, 4);
        }
コード例 #4
0
        private void OnSolvePuzzle_Click(object sender, EventArgs e)
        {
            bool couldSolve;

            UIGameBoard.SuspendLayout();
            PuzzleSolution = GameSolver.Solve(UIGameBoard.Board, out couldSolve);
            if (!couldSolve)
            {
                new TooHardBox().ShowDialog();
            }

            CurrentStep = PuzzleSolution.Count;
            ButtonUndoAll_Click(null, null);
            ButtonSolve.Visible = false;
            UpdateRuleButtons();
            UIGameBoard.ResumeLayout(true /*performLayout*/);
        }
コード例 #5
0
        // [TestCase(SampleGames.GosperGliderGunInitial, gosperGliderGun43rdGen, 43, "Gun is shooting down and to the right")]
        public void SolveJsonBoard(string seed, string result, int numGenerations, string reason)
        {
            var seedBoard      = JsonSerializer.Deserialize <IEnumerable <Coordinate> >(seed);
            var expectedResult = JsonSerializer.Deserialize <IEnumerable <Coordinate> >(result);


            var actualResult = GameSolver.Solve(seedBoard, numGenerations);

            Console.WriteLine();

            Console.WriteLine(JsonSerializer.Serialize(expectedResult));
            Console.WriteLine(JsonSerializer.Serialize(actualResult));

            Console.WriteLine(expectedResult.SequenceEqual(actualResult));

            expectedResult.All(actualResult.Contains).Should().BeTrue(reason);
        }
コード例 #6
0
ファイル: UIController.cs プロジェクト: nickem12/CodingTest
    public void GetTextInput()
    {
        switch (numberOfInputs)
        {
        case 0:
            solver.arraySizeX = int.Parse(uiText.text);
            break;

        case 1:
            solver.arraySizeY = int.Parse(uiText.text);
            break;

        case 2:
            solver.numKing = int.Parse(uiText.text);
            break;

        case 3:
            solver.numQueen = int.Parse(uiText.text);
            break;

        case 4:
            solver.numBishop = int.Parse(uiText.text);
            break;

        case 5:
            solver.numRook = int.Parse(uiText.text);
            break;

        case 6:
            solver.numKnight = int.Parse(uiText.text);
            break;
        }
        numberOfInputs++;
        if (numberOfInputs < titleStrings.Length)
        {
            titleText.text = titleStrings[numberOfInputs];
        }
        else
        {
            inputField.SetActive(false);
            solver.Solve();
        }
        DisplaySolutions();
    }
コード例 #7
0
        static async Task Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Pass the server address as the 1st parameter.");
                return;
            }

            var server     = args[0];
            var clientName = Environment.UserName;

            if (args.Length > 1)
            {
                clientName = args[1];
            }

            HttpWebResponse response;
            var             timer = Stopwatch.StartNew();

            do
            {
                Console.WriteLine($"Connecting to server @ {server}");
                var request = WebRequest.CreateHttp(server);
                response = (HttpWebResponse)request.GetResponse();
            } while (response.StatusCode != HttpStatusCode.OK && timer.Elapsed.TotalSeconds < 30);
            if (response.StatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine("Server didn't come up.  What's going on?");
                return;
            }

            client = RestService.For <IContestServer>(server);
            var registerRequest = new RegisterRequest {
                Name = clientName
            };
            RegisterResponse registerResponse;

            while (true)
            {
                try
                {
                    registerResponse = await client.Register(registerRequest);

                    break;
                }
                catch
                {
                    registerRequest.Name += "_1";
                }
            }

            token  = registerResponse.Token;
            status = ClientStatus.Waiting;

            UpdateResponse updateResponse = null;

            do
            {
                if (updateResponse != null)
                {
                    Console.WriteLine("Waiting for game to start... {0}", DateTime.Now);
                    Thread.Sleep(TimeSpan.FromSeconds(1));
                }
                updateResponse = await client.Update(new UpdateRequest
                {
                    Token = token
                });
            } while (updateResponse.GameState == GameState.NotStarted);

            var seedBoard = updateResponse.SeedBoard;

            generationsToCompute = updateResponse.GenerationsToCompute ?? 0;
            Console.WriteLine($"Got seed board w/{seedBoard.Count()} live cells counting {generationsToCompute} generations.");

            heartbeatTimer = new Timer(new TimerCallback(heartbeat), state: null, dueTime: 500, period: 500);

            status = ClientStatus.Processing;
            GameSolver.GenerationBatchCompleted += (s, e) => Interlocked.Exchange(ref generationsComputed, e.GenerationsComputed);
            solvedBoard = GameSolver.Solve(seedBoard, generationsToCompute, batchSize: 5);
            status      = ClientStatus.Complete;


            Console.WriteLine("You finished!");
            Console.ReadLine();
        }