Esempio n. 1
0
        public static async Task MainGameLoop(grpcClientConnection grpcClientConnection, string playerName, bool connectionTesting)
        {
            Log(Environment.NewLine);
            var startInformation = await grpcClientConnection.Initialize(playerName);

            Log($"Received game start information.");
            if (startInformation.WhitePlayer)
            {
                Log($"{playerName} starts the game.");
            }
            else
            {
                Log($"Opponent starts the game.");
            }

            Log(Environment.NewLine);

            Log("Starting logic...");
            LogicBase ai;

            if (connectionTesting)
            {
                ai = new ConnectionTesterLogic(startInformation.WhitePlayer);
            }
            else
            {
                ai = new Logic(startInformation);
            }

            Log("Start game loop");

            // Inject ai to connection module and play game
            // TODO cancellation token here
            await grpcClientConnection.Play(ai);
        }
Esempio n. 2
0
        static void Main()
        {
            using var connection = new grpcClientConnection("127.0.0.1:30052");
            var startInformation = connection.Initialize("example player");

            // Wait for the server to respond
            startInformation.Wait();

            // Server tells the client is either starting player (white),
            // or black. If black, info also contains white players first move
            var result = startInformation.Result;

            // Initialize your own ai
            var ai = new ExampleAiLogic(result.WhitePlayer, result);

            // Inject ai to connection module and play game
            var playTask = connection.Play(ai);

            playTask.Wait();

            // Game finished
            // Dispose should handle connection closing
            // connection.CloseConnection();
        }