示例#1
0
        public void Execute(
            Guid playerId,
            Guid gameId,
            GameBoard gameBoard)
        {
            var moveSucceeded = false;

            for (int i = 0; i < 20; i++)
            {
                Thread.Sleep(50);
                var trainIds = gameBoard
                               .PlayerTrains
                               .Select(pt => pt.Value)
                               .Union(new[] { gameBoard
                                              .MexicanTrain
                                              .Key });
                var trainCount    = trainIds.Count();
                var trainIdToPlay = trainIds
                                    .Skip(random.Next(0, trainCount--))
                                    .First();

                var tileCount    = gameBoard.Hand.Count();
                var tileIdToPlay = gameBoard
                                   .Hand
                                   .Skip(random.Next(0, tileCount--))
                                   .First()
                                   .Id;

                Console.WriteLine($"trying with traingId: {trainIdToPlay}, tileId: {tileIdToPlay}");
                try
                {
                    gameHttpClient.MakeMove(
                        gameId,
                        playerId,
                        trainIdToPlay,
                        tileIdToPlay);
                    i             = 100;
                    moveSucceeded = true;
                }
                catch
                {
                }
                Console.WriteLine($"Move succeeded");
            }
            if (!moveSucceeded)
            {
                gameHttpClient.DrawTile(
                    gameId,
                    playerId);
            }
            Thread.Sleep(100);
            gameBoard = gameHttpClient
                        .GetGameBoard(gameId, playerId);
        }
示例#2
0
 private void RefreshGameBoard()
 {
     if (doingMove)
     {
         return;
     }
     Console.WriteLine($"Refreshing board");
     gameBoard = gameClient
                 .GetGameBoard(gameId, playerId);
     Console.WriteLine(gameBoard.ToString());
     TryDoMove();
 }