示例#1
0
        public async Task Start()
        {
            try
            {
                var v = await _p.Next();

                while (v.status.inPlay)
                {
                    if (v.nextSide == _p.Side)
                    {
                        var a = _policy(v);
                        await _p.PerformAction(a);
                    }
                    v = await _p.Next();
                }
            }
            catch (System.Threading.Channels.ChannelClosedException)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel closed");
            }
            catch (System.OperationCanceledException)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel cancelled");
            }
            catch (Exception)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel exception");
            }
        }
        public async Task RunPlayer()
        {
            try {
                var v = await _p.Next();

                while (v.status.inPlay)
                {
                    TbConsole.updatePlayer(_p.Name, v);
                    if (v.nextSide == _p.Side)
                    {
                        var a = TbConsole.getPlayerMove(_p.Name, v); // TODO: This blocks, implement as await
                        await _p.PerformAction(a);
                    }
                    v = await _p.Next();
                }
                TbConsole.updatePlayer(_p.Name, v);
            }
            catch (System.Threading.Channels.ChannelClosedException)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel closed");
            }
            catch (System.OperationCanceledException)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel cancelled");
            }
            catch (System.Exception)
            {
                await Console.Out.WriteLineAsync($"{_p.Name} channel exception");
            }
        }