Exemple #1
0
        public async Task <GameStateResponse> PlayMove(string gameToken, GameStateResponse gs)
        {
            if (gs.winnerId == null && gs.actualPlayerId == UserId)
            {
                Board board = PrepareBoard(gs);
                int   moveX = 0; int moveY = 0;

                if (board.BoardIsEmpty)
                {
                    moveX = -BoardStartPos; moveY = -BoardStartPos;
                }
                else
                {
                    string boardString = board.BoardToString();
                    if (!MoveCache.ContainsKey(boardString))
                    {
                        EngineResponse result = await engineHandler.GetMoveAsync(
                            boardString, CheckPlayer(gs.actualPlayerId), threadNum : 1
                            );

                        moveX = Int32.Parse(result.result["move_c"]);
                        moveY = Int32.Parse(result.result["move_r"]);
                        MoveCache[boardString] = new Move
                        {
                            playerId = null,
                            x        = moveX,
                            y        = moveY
                        };
                    }
                    else
                    {
                        Move move = MoveCache[boardString];
                        moveX = move.x;
                        moveY = move.y;
                    }

                    if (Debug)
                    {
                        Console.WriteLine($"{moveX} {moveY}");
                    }
                }
                gs = await SendMoveSafe(gameToken, moveX, moveY);

                if (Verbose)
                {
                    Console.WriteLine($"{CheckPlayer(gs.actualPlayerId)} {moveX} {moveY}");
                }

                if (Verbose)
                {
                    board.PrintBoard(offset: 20);
                }
            }
            return(gs);
        }
        public async Task <EngineResponse> GetMoveAsync(string board, int player, int threadNum = 12, int depth = 10)
        {
            EngineResponse engineResult = new EngineResponse();

            if (UseSettings == "url")
            {
                string urlPath = $"{EngineUrl}/move?s={board}&p={player}&t={threadNum}&d={depth}";
                engineResult = await GetResponse(urlPath);
            }
            else if (UseSettings == "path")
            {
                engineResult = await EngineCommand(board, player, threadNum, depth);
            }

            return(engineResult);
        }
        public EngineResponse GetMove(string board, int player, int threadNum = 12, int depth = 10)
        {
            EngineResponse engineResult = new EngineResponse();

            if (UseSettings == "url")
            {
                string urlPath = $"{EngineUrl}/move?s={board}&p={player}&t={threadNum}&d={depth}";
                var    urlTask = GetResponse(urlPath);
                engineResult = urlTask.GetAwaiter().GetResult();
            }
            else if (UseSettings == "path")
            {
                throw new NotImplementedException();
            }

            return(engineResult);
        }